PondSettingForm.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\modules\admin\models\pond;
  3. use yii\base\Model;
  4. /**
  5. * @property \app\models\PondSetting $model;
  6. */
  7. class PondSettingForm extends Model
  8. {
  9. public $store_id;
  10. public $model;
  11. public $start_time;
  12. public $end_time;
  13. public $integral;
  14. public $rule;
  15. public function rules()
  16. {
  17. return [
  18. [['store_id', 'integral'], 'integer'],
  19. [['start_time', 'end_time'], 'required'],
  20. [['rule'], 'string', 'max' => 1000],
  21. ];
  22. }
  23. public function attributeLabels()
  24. {
  25. return [
  26. 'id' => 'ID',
  27. 'store_id' => 'Store ID',
  28. 'start_time' => '开始时间',
  29. 'end_time' => '结束时间',
  30. 'rule' => '规则说明',
  31. 'integral' => '单次扣减积分数量'
  32. ];
  33. }
  34. public function save()
  35. {
  36. if (!$this->validate()) {
  37. return $this->errorResponse;
  38. }
  39. if ($this->integral <= 0) {
  40. return [
  41. 'code' => 1,
  42. 'msg' => '参数错误:积分数量错误'
  43. ];
  44. }
  45. $this->model->store_id = $this->store_id;
  46. $this->model->rule = $this->rule;
  47. $this->model->start_time = $this->start_time;
  48. $this->model->end_time = $this->end_time;
  49. $this->model->integral = intval($this->integral);
  50. if ($this->model->save()) {
  51. return [
  52. 'code' => 0,
  53. 'msg' => '保存成功'
  54. ];
  55. } else {
  56. return $this->getErrorResponse($this->model);
  57. }
  58. }
  59. }