IssueCouponsRule.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace addons\IssueCoupons\common\models;
  3. use Yii;
  4. use yii\db\Exception;
  5. /**
  6. * This is the model class for table "{{%addons_issue_coupons_rule}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城id
  10. * @property string $name 规则名称
  11. * @property int $grant_object 发放对象:1:全部会员 2:会员等级 3:会员标签 4:会员id 5:指定区域
  12. * @property string $grant_object_content 对象内容
  13. * @property int|null $timing_time 定时发送时间
  14. * @property int|null $grant_time 上一次发放券的时间
  15. * @property int $grant_type 发放类型:1:手动发放 2:自动发放 3:失效
  16. * @property int $grant_status 发放状态:1:未发放 2:已发放 3:发放中
  17. * @property int|null $is_grant 是否发放:0:未发放 1:已发放
  18. * @property string|null $redpack_remark 红包备注
  19. * @property string|null $score_remark 积分备注
  20. * @property string|null $balance_remark 余额备注
  21. * @property int $admin_id 管理员id
  22. * @property string|null $remark 备注
  23. * @property int $created_at
  24. * @property int $updated_at
  25. * @property int $status 状态[-1:删除;0:禁用;1启用]
  26. * @property float|null $e_coupon 电子券数量
  27. * @property float|null $coupon 优惠卷数量
  28. * @property float|null $redpack 红包统计
  29. * @property float|null $balance 金额统计
  30. * @property float|null $score 积分统计
  31. */
  32. class IssueCouponsRule extends \common\models\base\BaseActiveRecord
  33. {
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public static function tableName()
  38. {
  39. return '{{%addons_issue_coupons_rule}}';
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function rules()
  45. {
  46. return [
  47. [['mall_id', 'grant_object_content'], 'required'],
  48. [['mall_id', 'grant_object', 'timing_time', 'grant_time', 'grant_type', 'grant_status', 'is_grant', 'admin_id', 'created_at', 'updated_at', 'status'], 'integer'],
  49. [['e_coupon', 'coupon','grant_object_content'], 'string'],
  50. [['redpack', 'balance', 'score'], 'number'],
  51. [['name'], 'string', 'max' => 200],
  52. [['redpack_remark', 'score_remark', 'balance_remark'], 'string', 'max' => 300],
  53. [['remark'], 'string', 'max' => 255],
  54. ];
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function attributeLabels()
  60. {
  61. return [
  62. 'id' => 'ID',
  63. 'mall_id' => '商城id',
  64. 'name' => '规则名称',
  65. 'grant_object' => '发放对象:1:全部会员 2:会员等级 3:会员标签 4:会员id 5:指定区域',
  66. 'grant_object_content' => '对象内容',
  67. 'timing_time' => '定时发送时间',
  68. 'grant_time' => '上一次发放券的时间',
  69. 'grant_type' => '发放类型:1:手动发放 2:自动发放 3:失效',
  70. 'grant_status' => '发放状态:1:未发放 2:已发放 3:发放中',
  71. 'is_grant' => '是否发放:0:未发放 1:已发放',
  72. 'redpack_remark' => '红包备注',
  73. 'score_remark' => '积分备注',
  74. 'balance_remark' => '余额备注',
  75. 'admin_id' => '管理员id',
  76. 'remark' => '备注',
  77. 'created_at' => 'Created At',
  78. 'updated_at' => 'Updated At',
  79. 'status' => '状态[-1:删除;0:禁用;1启用]',
  80. 'e_coupon' => '电子券数量',
  81. 'coupon' => '优惠卷数量',
  82. 'redpack' => '红包统计',
  83. 'balance' => '金额统计',
  84. 'score' => '积分统计',
  85. ];
  86. }
  87. /**
  88. * 保存数据
  89. * @Author: ltm
  90. * @DateTime: 2022/6/28 0015 9:26
  91. * @Copyright: copyright (c) 2021 广东七件事集团
  92. * @param $mall_id
  93. * @param array $params
  94. * @return Rebate|bool
  95. */
  96. public static function setData(array $params){
  97. try{
  98. $mall_id = $params['mall_id'];
  99. $model = self::findOne(['id'=>$params['id'],'mall_id' => $mall_id]);
  100. if(empty($model)){
  101. $model = new self();
  102. $model->loadDefaultValues();
  103. $model->mall_id = $mall_id;
  104. }
  105. // 将内容转为json字符串
  106. if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  107. return $model;
  108. }catch(\Exception $e){
  109. self::setStaticError($e->getMessage());
  110. return false;
  111. }
  112. }
  113. }