TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at','updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'], ], ], ]; } public function decodeDetail() { $detail = json_decode($this->detail,true); if (!isset($detail[0]['condition'])) { $newItem['condition'] = $this->price; $newItem['list'] = $detail; $detail = [$newItem]; } return $detail; } public function getTypeText() { switch ($this->type) { case 1: return '订单满额包邮'; case 2: return '订单满件包邮'; case 3: return '单商品满额包邮'; case 4: return '单商品满件包邮'; default: return ''; } } // 设置默认包邮规则(一个商城仅有一个默认运费规则) public static function setStatus($id = null) { $model = static::findOne([ 'id' => $id, 'is_delete' => 0, 'mall_id' => \Yii::$app->mallId, ]); if (!$model) { throw new ApiException("包邮规则不存在"); } else { static::updateAll(['status' => 0], [ 'mall_id' => \Yii::$app->mallId, ]); $model->status = 1; if ($model->save()) { return [ ]; } else { throw new ApiException($model->errors[0]); } } } }