diff --git a/app/data/controller/ShopTruckTemplate.php b/app/data/controller/ShopTruckTemplate.php index c5474cb42..dd3bbd4a9 100644 --- a/app/data/controller/ShopTruckTemplate.php +++ b/app/data/controller/ShopTruckTemplate.php @@ -39,13 +39,19 @@ class ShopTruckTemplate extends Controller * 配送区域管理 * @auth true * @menu true + * @throws \think\db\exception\DbException */ public function region() { if ($this->request->isGet()) { $this->title = '配送区域管理'; - $this->citys = TruckService::instance()->region(3); + $this->citys = TruckService::instance()->region(3, null); $this->fetch('form_region'); + } else { + $data = $this->_vali(['nos.default' => '', 'oks.default' => '']); + if ($data['nos']) $this->app->db->name('ShopTruckRegion')->whereIn('id', explode(',', $data['nos']))->update(['status' => 0]); + if ($data['oks']) $this->app->db->name('ShopTruckRegion')->whereIn('id', explode(',', $data['oks']))->update(['status' => 1]); + $this->success('修改配送区域成功!'); } } @@ -85,7 +91,7 @@ class ShopTruckTemplate extends Controller $data['code'] = CodeExtend::uniqidDate(12, 'T'); } if ($this->request->isGet()) { - $this->citys = TruckService::instance()->region(2); + $this->citys = TruckService::instance()->region(2, 1); } } diff --git a/app/data/service/TruckService.php b/app/data/service/TruckService.php index 6cc9c138c..4e7e5837f 100644 --- a/app/data/service/TruckService.php +++ b/app/data/service/TruckService.php @@ -14,28 +14,38 @@ use think\admin\service\InterfaceService; class TruckService extends Service { /** - * 楚才开放平台接口账号 - * 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥 - * @var string + * 模拟计算快递费用 + * @return string */ - protected $appid = '6998081316132228'; - - /** - * 楚才开放平台接口密钥 - * 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥 - * @var string - */ - protected $appkey = '193fc1d9a2aac78475bc8dbeb9a5feb1'; - public function amount() { - + return '0.00'; } - public function region($level = 3) + /** + * 配送区域树型数据 + * @param integer $level 最大级别 + * @param integer $status 状态筛选 + * @return array + */ + public function region($level = 3, $status = null) { - $items = $this->app->db->name('ShopTruckRegion')->where('level', '<=', $level)->column('id,pid,name,status', 'id'); - return DataExtend::arr2tree($items, 'id', 'pid', 'subs'); + $query = $this->app->db->name('ShopTruckRegion'); + if (is_numeric($level)) $query->where('level', '<=', $level); + if (is_numeric($status)) $query->where(['status' => $status]); + $items = DataExtend::arr2tree($query->column('id,pid,name,status', 'id'), 'id', 'pid', 'subs'); + // 排序子集为空的省份和城市 + foreach ($items as $ik => $item) { + foreach ($item['subs'] as $ck => $city) { + if (isset($city['subs']) && empty($city['subs'])) { + unset($items[$ik]['subs'][$ck]); + } + } + if (isset($item['subs']) && empty($item['subs'])) { + unset($items[$ik]); + } + } + return $items; } /** @@ -47,9 +57,7 @@ class TruckService extends Service */ public function query($code, $number) { - $service = InterfaceService::instance(); - $service->setAuth($this->appid, $this->appkey); - return $service->doRequest('https://open.cuci.cc/user/api.auth.express/query', [ + return $this->_getInterface()->doRequest('https://open.cuci.cc/user/api.auth.express/query', [ 'type' => 'free', 'express' => $code, 'number' => $number, ]); } @@ -60,10 +68,20 @@ class TruckService extends Service * @throws \think\admin\Exception */ public function company() + { + return $this->_getInterface()->doRequest('https://open.cuci.cc/user/api.auth.express/getCompany'); + } + + /** + * 获取楚才开放平台接口实例 + * @return InterfaceService + */ + private function _getInterface(): InterfaceService { $service = InterfaceService::instance(); - $service->setAuth($this->appid, $this->appkey); - return $service->doRequest('https://open.cuci.cc/user/api.auth.express/getCompany'); + // 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥 + $service->setAuth("6998081316132228", "193fc1d9a2aac78475bc8dbeb9a5feb1"); + return $service; } } \ No newline at end of file diff --git a/app/data/view/shop_truck_template/form_region.html b/app/data/view/shop_truck_template/form_region.html index ba73b0442..eb6ec1da6 100644 --- a/app/data/view/shop_truck_template/form_region.html +++ b/app/data/view/shop_truck_template/form_region.html @@ -4,36 +4,33 @@
-
配送区域
+
配送区域
-
- - +
+
-
{{province.name}} 可选区域
+
可选区域
-
- - +
+
-
{{city.name}} 可选区域
+
可选区域
-
- - +
+
-
-
- -
+
+
+
+
@@ -43,11 +40,14 @@