IssueCouponsUser.php 3.0 KB

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