diff --git a/app/data/controller/ShopOrder.php b/app/data/controller/ShopOrder.php index adb0f15f7..3aab30c48 100644 --- a/app/data/controller/ShopOrder.php +++ b/app/data/controller/ShopOrder.php @@ -3,6 +3,7 @@ namespace app\data\controller; use app\data\service\OrderService; +use app\data\service\TruckService; use think\admin\Controller; use think\exception\HttpResponseException; @@ -123,7 +124,7 @@ class ShopOrder extends Controller 'code.require' => '快递编号不能为空!', 'number.require' => '配送单号不能为空!', ]); - $this->result = OrderService::instance()->trackExpress($data['code'], $data['number']); + $this->result = TruckService::instance()->query($data['code'], $data['number']); if (empty($this->result['code'])) $this->error($this->result['info']); $this->fetch('truck_query'); } catch (HttpResponseException $exception) { diff --git a/app/data/controller/ShopTruckCompany.php b/app/data/controller/ShopTruckCompany.php new file mode 100644 index 000000000..a92b5525d --- /dev/null +++ b/app/data/controller/ShopTruckCompany.php @@ -0,0 +1,112 @@ +title = '快递公司管理'; + $query = $this->_query($this->table); + $query->like('name,code')->equal('status')->dateBetween('craete_at'); + // 加载对应数据 + $this->type = $this->request->get('type', 'index'); + if ($this->type === 'index') $query->where(['status' => '1']); + elseif ($this->type === 'recycle') $query->where(['status' => '0']); + // 列表显示分页 + $query->where(['deleted' => 0])->order('sort desc,id desc')->page(); + } + + /** + * 添加快递公司 + * @auth true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function add() + { + $this->title = '添加快递公司'; + $this->_form($this->table, 'form'); + } + + /** + * 编辑快递公司 + * @auth true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function edit() + { + $this->title = '编辑快递公司'; + $this->_form($this->table, 'form'); + } + + /** + * 修改快递公司状态 + * @auth true + * @throws \think\db\exception\DbException + */ + public function state() + { + $this->_save($this->table); + } + + /** + * 删除快递公司 + * @auth true + * @throws \think\db\exception\DbException + */ + public function remove() + { + $this->_delete($this->table); + } + + /** + * 同步快递公司 + * @auth true + */ + public function synchronize() + { + try { + $result = TruckService::instance()->company(); + if (empty($result['code'])) $this->error($result['info']); + foreach ($result['data'] as $vo) SystemService::instance()->save($this->table, [ + 'code_1' => $vo['code_1'], 'code_2' => $vo['code_2'], + 'code_3' => $vo['code_3'], 'name' => $vo['title'], 'deleted' => 0, + ], 'code_1'); + $this->success('同步快递公司成功!'); + } catch (HttpResponseException $exception) { + throw $exception; + } catch (\Exception $exception) { + $this->error('同步快递公司数据失败!'); + } + } + +} \ No newline at end of file diff --git a/app/data/controller/api/auth/Order.php b/app/data/controller/api/auth/Order.php index 80169cf9d..6491dc288 100644 --- a/app/data/controller/api/auth/Order.php +++ b/app/data/controller/api/auth/Order.php @@ -5,6 +5,7 @@ namespace app\data\controller\api\auth; use app\data\controller\api\Auth; use app\data\service\GoodsService; use app\data\service\OrderService; +use app\data\service\TruckService; use app\wechat\service\WechatService; use think\admin\extend\CodeExtend; use think\exception\HttpResponseException; @@ -297,7 +298,7 @@ class Order extends Auth $data = $this->_vali([ 'code.require' => '快递编号不能为空!', 'number.require' => '配送单号不能为空!', ]); - $result = OrderService::instance()->trackExpress($data['code'], $data['number']); + $result = TruckService::instance()->query($data['code'], $data['number']); empty($result['code']) ? $this->error($result['info']) : $this->success('快递追踪信息', $result); } catch (HttpResponseException $exception) { throw $exception; diff --git a/app/data/service/OrderService.php b/app/data/service/OrderService.php index 5d1bcf47c..c54565d83 100644 --- a/app/data/service/OrderService.php +++ b/app/data/service/OrderService.php @@ -3,7 +3,6 @@ namespace app\data\service; use think\admin\Service; -use think\admin\service\InterfaceService; /** * 订单数据服务 @@ -48,23 +47,6 @@ class OrderService extends Service return true; } - /** - * 楚才开放平台快递查询 - * @param string $code 快递公司编号 - * @param string $number 快递配送单号 - * @return array - * @throws \think\admin\Exception - */ - public function trackExpress($code, $number) - { - $service = InterfaceService::instance(); - // 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥 - $service->setAuth('6998081316132228', '193fc1d9a2aac78475bc8dbeb9a5feb1'); - return $service->doRequest('https://open.cuci.cc/user/api.auth.express/query', [ - 'type' => 'free', 'express' => $code, 'number' => $number, - ]); - } - /** * 绑定订单详情数据 * @param array $data diff --git a/app/data/service/TruckService.php b/app/data/service/TruckService.php index 18efbe371..ea44cff28 100644 --- a/app/data/service/TruckService.php +++ b/app/data/service/TruckService.php @@ -3,6 +3,7 @@ namespace app\data\service; use think\admin\Service; +use think\admin\service\InterfaceService; /** * 快递运输服务 @@ -11,9 +12,51 @@ use think\admin\Service; */ class TruckService extends Service { + /** + * 楚才开放平台接口账号 + * 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥 + * @var string + */ + protected $appid = '6998081316132228'; + + /** + * 楚才开放平台接口密钥 + * 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥 + * @var string + */ + protected $appkey = '193fc1d9a2aac78475bc8dbeb9a5feb1'; + public function amount() { } + /** + * 楚才开放平台快递查询 + * @param string $code 快递公司编号 + * @param string $number 快递配送单号 + * @return array + * @throws \think\admin\Exception + */ + 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', [ + 'type' => 'free', 'express' => $code, 'number' => $number, + ]); + } + + /** + * 楚才开放平台快递公司 + * @return array + * @throws \think\admin\Exception + */ + public function company() + { + $service = InterfaceService::instance(); + $service->setAuth($this->appid, $this->appkey); + return $service->doRequest('https://open.cuci.cc/user/api.auth.express/getCompany'); + } + } \ No newline at end of file diff --git a/app/data/view/shop_truck_company/form.html b/app/data/view/shop_truck_company/form.html new file mode 100644 index 000000000..a588447cd --- /dev/null +++ b/app/data/view/shop_truck_company/form.html @@ -0,0 +1,42 @@ +
diff --git a/app/data/view/shop_truck_company/index.html b/app/data/view/shop_truck_company/index.html new file mode 100644 index 000000000..26aa1a1a9 --- /dev/null +++ b/app/data/view/shop_truck_company/index.html @@ -0,0 +1,91 @@ +{extend name="../../admin/view/main"} + +{block name="button"} + + + + + + + + + + + + + + + +{/block} + +{block name="content"} ++ + | ++ + | +快递名称 | +快递鸟接口编码 | +快递100百度编码 | +快递100接口编码 | +创建时间 | ++ |
---|---|---|---|---|---|---|---|
+ + | ++ + | +{$vo.name|default=''} | +{$vo.code_1|default='-'} | +{$vo.code_2|default='-'} | +{$vo.code_3|default='-'} | +{$vo.create_at|format_datetime} | ++ + 编 辑 + + + 禁 用 + + 启 用 + + + 删 除 + + | +