64], [['consignee', 'phone'], 'string', 'max' => 20], [['province', 'city', 'area'], 'string', 'max' => 10], [['payment_sn'], 'string', 'max' => 120], [['remarks'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'id', 'user_id' => '用户id', 'order_sn' => '订单号', 'invoice_id' => '发票单号', 'status' => '状态', 'type' => '类型', 'goods_count' => '商品数量', 'goods_amount' => '商品金额', 'shipping_amount' => '物流金额', 'shipping_type' => '物流类型', 'consignee' => '收件人', 'phone' => '手机号码', 'province' => '省份', 'city' => '城市', 'area' => '区域', 'taking_site' => '自提点', 'pay_type' => '支付方式', 'pay_at' => '支付时间', 'payment_sn' => '付款单号', 'payment_amount' => '支付金额', 'receivables' => '应收款', 'remarks' => '备注', 'discount_amount' => '折扣金额', 'discount_description' => '折扣说明', 'updated_at' => '更新时间', 'created_at' => '创建时间', 'address' => '详细地址', ]; } public function beforeSave($insert) { $address = Yii::createObject([ 'class' => 'api\logic\AddressLogic', ]); if ($insert) { $default = $address->getDefault(); $this->province = $default['province'] ?? ''; $this->city = $default['city'] ?? ''; $this->area = $default['area'] ?? ''; } if (!$insert && $this->status == self::STATUS_UNCONFIRMED && $this->type == self::TYPE_SHOPPING) { $express = Yii::createObject([ 'class' => 'api\logic\ExpressLogic', ]); $this->shipping_amount = $express->countShippingAmount($this); $this->receivables = $this->goods_amount + $this->shipping_amount; $this->payment_amount = $this->receivables - $this->discount_amount; } return parent::beforeSave($insert); } /** * @author linyao * @email 602604991@qq.com * @created Nov 8, 2019 * * 行为存储创建时间和更新时间 */ public function behaviors() { return [ [ 'class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at', 'value' => function () { return time(); }, ], ]; } public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id']); } public function getProvinceId() { return $this->hasOne(Province::className(), ['province_id' => 'province']); } public function getCityId() { return $this->hasOne(City::className(), ['city_id' => 'city']); } public function getAreaId() { return $this->hasOne(Area::className(), ['area_id' => 'area']); } /** * @param $column * @param null $value * @return bool * 获取各状态数组 */ public static function dropDown($column, $value = null) { $dropDownList = [ 'shipping_type' => [ self::SHIPPING_TYPE_VIRTUAL_GOODS => '虚拟货物', self::SHIPPING_TYPE_PICKED_UP => '自提', self::SHIPPING_TYPE_EXPRESS => '快递物流', ], 'type' => [ self::TYPE_SHOPPING => '普通购物订单', ], 'status' => [ self::STATUS_UNCONFIRMED => '待确认', self::STATUS_NONPAYMENT => '待支付', self::STATUS_CANCEL => '已取消', self::STATUS_PAYMENT_TO_BE_CONFIRMED => '支付待确认', self::STATUS_APPLY_REFUND => '申请退款', self::STATUS_REFUND => '已退款', self::STATUS_TO_BE_SHIPPING => '待发货', self::STATUS_SHIPMENT_ALL => '全部发货', self::STATUS_SHIPMENT_PORTION => '部分发货', self::STATUS_FINISH => '已完成', ] ]; //根据具体值显示对应的值 if ($value !== null) return array_key_exists($column, $dropDownList) ? $dropDownList[$column][$value] : false; //返回关联数组,用户下拉的filter实现 else return array_key_exists($column, $dropDownList) ? $dropDownList[$column] : false; } }