quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
 
namespace app\common\model\settings;
 
use app\common\library\express\Kuaidi100;
use app\common\model\BaseModel;
 
/**
 * 物流公司模型
 */
class Express extends BaseModel
{
    protected $name = 'express';
    protected $pk = 'express_id';
 
    /**
     * 获取全部
     */
    public function getAll()
    {
        return $this->order(['sort' => 'asc'])->select();
    }
 
    /**
     * 获取列表
     */
    public function getList($limit = 20)
    {
        return $this->order(['sort' => 'asc'])
            ->paginate($limit);
    }
 
    /**
     * 物流公司详情
     */
    public static function detail($express_id)
    {
        return (new static())->find($express_id);
    }
 
    /**
     * 物流公司详情
     */
    public static function findByName($express_name)
    {
        return (new static())->where('express_name', '=', $express_name)->find();
    }
 
    /**
     * 获取物流动态信息
     */
    public function dynamic($express_name, $express_code, $express_no)
    {
        $data = [
            'express_name' => $express_name,
            'express_no' => $express_no
        ];
        // 实例化快递100类
        $config = Setting::getItem('store');
        $Kuaidi100 = new Kuaidi100($config['kuaidi100']);
        // 请求查询接口
        $data['list'] = $Kuaidi100->query($express_code, $express_no);
        if ($data['list'] === false) {
            $this->error = $Kuaidi100->getError();
            return false;
        }
        return $data;
    }
}