99999999], [['image_url'], 'string', 'max' => 255], ]; } public function attributeLabels() { return [ 'id' => 'ID', 'store_id' => 'Store ID', 'type' => '1.谢谢惠顾 2.商品', 'name' => '奖品名称', 'image_url' => '图片', 'winning_rate' => '中奖率', 'stock' => '库存', 'gift_id' => '赠品', 'create_time' => 'Create Time', 'update_time' => 'Update Time', 'user_id' => '指定中奖用户id', ]; } public function save() { if (!$this->validate()) { return $this->errorResponse; } $this->model->store_id = $this->store_id; $this->model->name = $this->name; $this->model->image_url = $this->image_url; $this->model->winning_rate = $this->winning_rate; $this->model->type = $this->type; switch ($this->type) { case 1: $this->model->stock = $this->stock; $this->model->gift_id = ''; $this->model->user_id = ''; break; case 2: $this->model->stock = $this->stock; $this->model->gift_id = $this->gift_id; $this->model->user_id = $this->user_id; break; default: } if ($this->model->save()) { return [ 'code' => 0, 'msg' => '保存成功' ]; } else { return $this->getErrorResponse($this->model); } } }