| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\modules\admin\models\pond;
- use yii\base\Model;
- /**
- * @property \app\models\Pond $model;
- */
- class PondForm extends Model
- {
- public $store_id;
- public $model;
- public $type;
- public $image_url;
- public $stock;
- public $gift_id;
- public $user_id;
- public $name;
- public $winning_rate;
- public function rules()
- {
- return [
- [['store_id', 'name'], 'required'],
- [['store_id', 'type', 'stock', 'gift_id', 'user_id', 'winning_rate'], 'integer'],
- [['stock'], 'integer', 'max' => 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);
- }
- }
- }
|