123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types = 1);
- namespace app\common\model;
- use app\api\controller\points\Log;
- use app\common\library\express\Kuaidi100;
- use app\common\model\store\Setting as SettingModel;
- use app\common\enum\Setting as SettingEnum;
- /**
- * 物流公司模型
- * Class Express
- * @package app\common\model
- */
- class Express extends BaseModel
- {
- // 定义表名
- protected $name = 'express';
- // 定义主键
- protected $pk = 'express_id';
- /**
- * 获取全部记录
- * @param array $param
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getAll($param = [])
- {
- // 检索查询条件
- $filter = $this->getFilter($param);
- // 查询列表数据
- return $this->where($filter)->order(['sort', $this->getPk()])->select();
- }
- /**
- * 获取列表
- * @param array $param
- * @return \think\Paginator
- * @throws \think\db\exception\DbException
- */
- public function getList($param = [])
- {
- // 检索查询调价你
- $filter = $this->getFilter($param);
- // 查询列表数据
- return $this->where($filter)->order(['sort', 'express_id'])->paginate(15);
- }
- /**
- * 检索查询条件
- * @param array $param
- * @return array
- */
- private function getFilter($param = [])
- {
- // 默认查询条件
- $params = $this->setQueryDefaultValue($param, ['search' => '']);
- // 检索查询条件
- $filter = [];
- !empty($params['search']) && $filter[] = ['express_name', 'like', "%{$params['search']}%"];
- !empty($params['type']) && $filter[] = ['type', '=', $params['type']];
- return $filter;
- }
- /**
- * 物流公司详情
- * @param int $expressId
- * @return null|static
- */
- public static function detail(int $expressId)
- {
- return self::get($expressId);
- }
- /**
- * 获取物流动态信息
- * @param string $expressName
- * @param string $expressCode
- * @param string $expressNo
- * @return false|string[]
- * @throws \app\common\exception\BaseException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function dynamic(string $expressName, string $expressCode, string $expressNo, $phone = '')
- {
- $data = [
- 'express_name' => $expressName,
- 'express_no' => $expressNo
- ];
- // 获取快递100配置项
- $config = $this->getKuaidi100Config();
- // 实例化快递100类
- $Kuaidi100 = new Kuaidi100($config);
- // 请求查询接口
- $data['list'] = $Kuaidi100->query($expressCode, $expressNo,$phone);
- if ($data['list'] === false) {
- $this->error = $Kuaidi100->getError();
- return false;
- }
- return $data;
- }
- /**
- * 获取物流信息
- * @param string $expressNo 快递单号
- * @param string $delivery_time 订单发货的时间
- * @param int $type 1获取列表 2获取最新消息
- * @return array|bool
- * @throws \app\common\exception\BaseException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author: zjwhust
- * @Time: 2021/9/29 13:51
- */
- public function deliverylist(string $expressNo, string $delivery_time, int $type = 1)
- {
- // $data = [
- // 'express_no' => $expressNo
- // ];
- // 获取快递100配置项
- $config = $this->getKuaidi100Config();
- // 实例化快递100类
- $Kuaidi100 = new Kuaidi100($config);
- // 请求查询接口
- $data = $Kuaidi100->deliverylist($expressNo, $delivery_time, $type);
- \think\facade\Log::info('delivery:'.$expressNo.':'.json_encode($data));
- if ($data === false) {
- $this->error = $Kuaidi100->getError();
- return false;
- }
- return $data;
- }
- /**
- * 获取快递100配置项
- * @return mixed
- * @throws \app\common\exception\BaseException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function getKuaidi100Config()
- {
- // 实例化快递100类
- $config = SettingModel::getItem(SettingEnum::DELIVERY);
- if (empty($config['kuaidi100']['customer']) || empty($config['kuaidi100']['key'])) {
- throwError('请先到后台-设置-配送方式 补充物流查询API配置');
- }
- return $config['kuaidi100'];
- }
- public static function getExpressNames(){
- $names = self::field('express_name')->select()->column('express_name');
- return implode(',',$names);
- }
- /**
- * 获取所有列表
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function getAllList()
- {
- // 查询列表数据
- return self::field('express_id,express_name')->order(['sort', 'express_id'])->select()->toArray();
- }
- }
|