IssueCouponsSendLog.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace addons\IssueCoupons\common\models;
  3. use common\models\user\User;
  4. use Yii;
  5. use yii\db\Exception;
  6. /**
  7. * This is the model class for table "{{%addons_issue_coupons_send_log}}".
  8. *
  9. * @property int $id
  10. * @property int|null $rule_id 规则ID
  11. * @property int $mall_id 商城id
  12. * @property int $created_at
  13. * @property int $updated_at
  14. * @property int $status 状态[-1:删除;0:禁用;1启用]
  15. * @property float|null $e_coupon_num 电子券数量
  16. * @property float|null $coupon_num 优惠卷数量
  17. * @property float|null $redpack_num 红包统计
  18. * @property float|null $balance_num 金额统计
  19. * @property float|null $score_num 积分统计
  20. * @property int $grant_object 发放对象:1:全部会员 2:会员等级 3:会员标签 4:会员id 5:指定区域
  21. * @property string $grant_object_content 对象内容
  22. */
  23. class IssueCouponsSendLog extends \common\models\base\BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addons_issue_coupons_send_log}}';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['rule_id', 'mall_id', 'created_at', 'updated_at', 'status', 'grant_object'], 'integer'],
  39. [['mall_id', 'grant_object_content'], 'required'],
  40. [['e_coupon_num', 'coupon_num', 'redpack_num', 'balance_num', 'score_num'], 'number'],
  41. [['grant_object_content'], 'string'],
  42. ];
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'id' => 'ID',
  51. 'rule_id' => '规则ID',
  52. 'mall_id' => '商城id',
  53. 'created_at' => 'Created At',
  54. 'updated_at' => 'Updated At',
  55. 'status' => '状态[-1:删除;0:禁用;1启用]',
  56. 'e_coupon_num' => '电子券数量',
  57. 'coupon_num' => '优惠卷数量',
  58. 'redpack_num' => '红包统计',
  59. 'balance_num' => '金额统计',
  60. 'score_num' => '积分统计',
  61. 'grant_object' => '发放对象:1:全部会员 2:会员等级 3:会员标签 4:会员id 5:指定区域',
  62. 'grant_object_content' => '对象内容',
  63. ];
  64. }
  65. /**
  66. * 保存数据
  67. * @Author: ltm
  68. * @DateTime: 2022/6/28 0015 9:26
  69. * @Copyright: copyright (c) 2021 广东七件事集团
  70. * @param $mall_id
  71. * @param array $params
  72. * @return Rebate|bool
  73. */
  74. public static function setData(array $params){
  75. try{
  76. $mall_id = $params['mall_id'];
  77. $model = new self();
  78. $model->loadDefaultValues();
  79. $model->mall_id = $mall_id;
  80. // 将内容转为json字符串
  81. if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  82. return $model;
  83. }catch(\Exception $e){
  84. self::setStaticError($e->getMessage());
  85. return false;
  86. }
  87. }
  88. /**
  89. * 关联用户信息
  90. * @Author:ltm
  91. * @DateTime: 2022/5/6 0022 17:13
  92. * @Copyright: copyright (c) 2021 广东七件事集团
  93. * @return \yii\db\ActiveQuery
  94. */
  95. public function getUser()
  96. {
  97. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,username,mobile,avatar_url');
  98. }
  99. public function getRule()
  100. {
  101. return $this->hasOne(IssueCouponsRule::class, ['id' => 'rule_id']);
  102. }
  103. }