最新服务器上的版本,以后用这个
zhangmeng
2023-04-19 e3f5aa12f58d986098a9de0f5cb38060e403036d
commit | author | age
2207d6 1 <?php
W 2
3 namespace app\models;
4
5 use app\models\Order;
6 use app\models\OrderExpressSingle;
7
8 /**
9  * This is the model class for table "{{%order_detail_express}}".
10  *
11  * @property int $id
12  * @property int $mall_id
13  * @property int $mch_id
14  * @property int $send_type;
15  * @property string $city_name;
16  * @property string $city_info;
17  * @property string $city_mobile;
18  * @property string $shop_order_id;
19  * @property string $status;
20  * @property string $express
21  * @property string $express_no
22  * @property string $merchant_remark 商家留言
23  * @property string $express_content 物流内容
24  * @property string $customer_name 京东物流编码
25  * @property int $is_delete
26  * @property int $order_id
27  * @property int $express_single_id
28  * @property int $city_service_id
29  * @property string $created_at
30  * @property string $updated_at
31  * @property string $deleted_at
32  * @property OrderDetailExpressRelation $expressRelation
33  */
34 class OrderDetailExpress extends ModelActiveRecord
35 {
36     /**
37      * {@inheritdoc}
38      */
39     public static function tableName()
40     {
41         return '{{%order_detail_express}}';
42     }
43
44     /**
45      * {@inheritdoc}
46      */
47     public function rules()
48     {
49         return [
50             [['mall_id', 'mch_id', 'created_at', 'updated_at', 'deleted_at', 'send_type'], 'required'],
51             [['mall_id', 'mch_id', 'is_delete', 'send_type', 'order_id', 'express_single_id', 'status', 'city_service_id'], 'integer'],
52             [['created_at', 'updated_at', 'deleted_at'], 'safe'],
53             [['express'], 'string', 'max' => 65],
54             [['city_info'], 'string'],
55             [['express_no', 'merchant_remark', 'express_content', 'customer_name', 'city_name', 'shop_order_id', 'city_mobile'], 'string', 'max' => 255],
56         ];
57     }
58
59     /**
60      * {@inheritdoc}
61      */
62     public function attributeLabels()
63     {
64         return [
65             'id' => 'ID',
66             'mall_id' => 'Mall ID',
67             'mch_id' => 'Mch ID',
68             'express' => 'Express',
69             'send_type' => '1.快递|2.其它方式',
70             'express_no' => 'Express No',
71             'merchant_remark' => '商家留言',
72             'express_content' => '物流内容',
73             'customer_name' => '京东物流编码',
74             'is_delete' => 'Is Delete',
75             'order_id' => 'Order Id',
76             'created_at' => 'Created At',
77             'updated_at' => 'Updated At',
78             'deleted_at' => 'Deleted At',
79             'express_single_id' => '电子面单ID',
80         ];
81     }
82
83     public function getExpressRelation()
84     {
85         return $this->hasMany(OrderDetailExpressRelation::className(), ['order_detail_express_id' => 'id'])->andWhere(['is_delete' => 0]);
86     }
87
88     public function getExpressSingle()
89     {
90         return $this->hasOne(OrderExpressSingle::className(), ['id' => 'express_single_id'])->andWhere(['is_delete' => 0]);
91     }
92
93     public function getOrder()
94     {
95         return $this->hasOne(Order::className(), ['id' => 'order_id'])->andWhere(['is_delete' => 0]);
96     }
97
98     public function getExpressCityText($express)
99     {
100         $text = '';
101         if ($express['send_type'] == 1 && $express['status'] && !in_array($express['status'], [101, 102, 202, 301, 302])) {
102             $cityInfo = json_decode($express['city_info'], true);
103             switch ($express['express_type']) {
104                 case '微信':
105                     # code...
106                     break;
107                 case '顺丰同城急送':
108                     if (isset($cityInfo[$express['status']]) && isset($cityInfo[$express['status']]['cancel_reason'])) {
109                         $text = $cityInfo[$express['status']]['cancel_reason'];
110                     }
111                     break;
112                 case '达达':
113                     if (isset($cityInfo[$express['status']]) && isset($cityInfo[$express['status']]['cancel_reason'])) {
114                         $text = $cityInfo[$express['status']]['cancel_reason'];
115                     }
116                     break;
117                 case '闪送':
118                     if (isset($cityInfo[$express['status']]) && isset($cityInfo[$express['status']]['abortReason'])) {
119                         $text = $cityInfo[$express['status']]['abortReason'];
120                     }
121                     break;
122                 default:
123                     # code...
124                     break;
125             }
126             $text = $text ?: '配送订单异常 已取消';
127         }
128
129         return $text;
130     }
131 }