最新服务器上的版本,以后用这个
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
 
namespace app\models;
 
use app\models\Order;
use app\models\OrderExpressSingle;
 
/**
 * This is the model class for table "{{%order_detail_express}}".
 *
 * @property int $id
 * @property int $mall_id
 * @property int $mch_id
 * @property int $send_type;
 * @property string $city_name;
 * @property string $city_info;
 * @property string $city_mobile;
 * @property string $shop_order_id;
 * @property string $status;
 * @property string $express
 * @property string $express_no
 * @property string $merchant_remark 商家留言
 * @property string $express_content 物流内容
 * @property string $customer_name 京东物流编码
 * @property int $is_delete
 * @property int $order_id
 * @property int $express_single_id
 * @property int $city_service_id
 * @property string $created_at
 * @property string $updated_at
 * @property string $deleted_at
 * @property OrderDetailExpressRelation $expressRelation
 */
class OrderDetailExpress extends ModelActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%order_detail_express}}';
    }
 
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['mall_id', 'mch_id', 'created_at', 'updated_at', 'deleted_at', 'send_type'], 'required'],
            [['mall_id', 'mch_id', 'is_delete', 'send_type', 'order_id', 'express_single_id', 'status', 'city_service_id'], 'integer'],
            [['created_at', 'updated_at', 'deleted_at'], 'safe'],
            [['express'], 'string', 'max' => 65],
            [['city_info'], 'string'],
            [['express_no', 'merchant_remark', 'express_content', 'customer_name', 'city_name', 'shop_order_id', 'city_mobile'], 'string', 'max' => 255],
        ];
    }
 
    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'mall_id' => 'Mall ID',
            'mch_id' => 'Mch ID',
            'express' => 'Express',
            'send_type' => '1.快递|2.其它方式',
            'express_no' => 'Express No',
            'merchant_remark' => '商家留言',
            'express_content' => '物流内容',
            'customer_name' => '京东物流编码',
            'is_delete' => 'Is Delete',
            'order_id' => 'Order Id',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
            'deleted_at' => 'Deleted At',
            'express_single_id' => '电子面单ID',
        ];
    }
 
    public function getExpressRelation()
    {
        return $this->hasMany(OrderDetailExpressRelation::className(), ['order_detail_express_id' => 'id'])->andWhere(['is_delete' => 0]);
    }
 
    public function getExpressSingle()
    {
        return $this->hasOne(OrderExpressSingle::className(), ['id' => 'express_single_id'])->andWhere(['is_delete' => 0]);
    }
 
    public function getOrder()
    {
        return $this->hasOne(Order::className(), ['id' => 'order_id'])->andWhere(['is_delete' => 0]);
    }
 
    public function getExpressCityText($express)
    {
        $text = '';
        if ($express['send_type'] == 1 && $express['status'] && !in_array($express['status'], [101, 102, 202, 301, 302])) {
            $cityInfo = json_decode($express['city_info'], true);
            switch ($express['express_type']) {
                case '微信':
                    # code...
                    break;
                case '顺丰同城急送':
                    if (isset($cityInfo[$express['status']]) && isset($cityInfo[$express['status']]['cancel_reason'])) {
                        $text = $cityInfo[$express['status']]['cancel_reason'];
                    }
                    break;
                case '达达':
                    if (isset($cityInfo[$express['status']]) && isset($cityInfo[$express['status']]['cancel_reason'])) {
                        $text = $cityInfo[$express['status']]['cancel_reason'];
                    }
                    break;
                case '闪送':
                    if (isset($cityInfo[$express['status']]) && isset($cityInfo[$express['status']]['abortReason'])) {
                        $text = $cityInfo[$express['status']]['abortReason'];
                    }
                    break;
                default:
                    # code...
                    break;
            }
            $text = $text ?: '配送订单异常 已取消';
        }
 
        return $text;
    }
}