PondForm.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\modules\admin\models\pond;
  3. use yii\base\Model;
  4. /**
  5. * @property \app\models\Pond $model;
  6. */
  7. class PondForm extends Model
  8. {
  9. public $store_id;
  10. public $model;
  11. public $type;
  12. public $image_url;
  13. public $stock;
  14. public $gift_id;
  15. public $user_id;
  16. public $name;
  17. public $winning_rate;
  18. public function rules()
  19. {
  20. return [
  21. [['store_id', 'name'], 'required'],
  22. [['store_id', 'type', 'stock', 'gift_id', 'user_id', 'winning_rate'], 'integer'],
  23. [['stock'], 'integer', 'max' => 99999999],
  24. [['image_url'], 'string', 'max' => 255],
  25. ];
  26. }
  27. public function attributeLabels()
  28. {
  29. return [
  30. 'id' => 'ID',
  31. 'store_id' => 'Store ID',
  32. 'type' => '1.谢谢惠顾 2.商品',
  33. 'name' => '奖品名称',
  34. 'image_url' => '图片',
  35. 'winning_rate' => '中奖率',
  36. 'stock' => '库存',
  37. 'gift_id' => '赠品',
  38. 'create_time' => 'Create Time',
  39. 'update_time' => 'Update Time',
  40. 'user_id' => '指定中奖用户id',
  41. ];
  42. }
  43. public function save()
  44. {
  45. if (!$this->validate()) {
  46. return $this->errorResponse;
  47. }
  48. $this->model->store_id = $this->store_id;
  49. $this->model->name = $this->name;
  50. $this->model->image_url = $this->image_url;
  51. $this->model->winning_rate = $this->winning_rate;
  52. $this->model->type = $this->type;
  53. switch ($this->type) {
  54. case 1:
  55. $this->model->stock = $this->stock;
  56. $this->model->gift_id = '';
  57. $this->model->user_id = '';
  58. break;
  59. case 2:
  60. $this->model->stock = $this->stock;
  61. $this->model->gift_id = $this->gift_id;
  62. $this->model->user_id = $this->user_id;
  63. break;
  64. default:
  65. }
  66. if ($this->model->save()) {
  67. return [
  68. 'code' => 0,
  69. 'msg' => '保存成功'
  70. ];
  71. } else {
  72. return $this->getErrorResponse($this->model);
  73. }
  74. }
  75. }