RecommenReward.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace addons\Recommen\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_recommen_reward}}".
  8. *
  9. * @property int $id
  10. * @property int|null $active_id 活动ID
  11. * @property int|null $mall_id 商城ID
  12. * @property int|null $user_id 会员ID
  13. * @property string|null $be_reward 被推荐人奖励
  14. * @property string|null $reward 推荐人奖励内容
  15. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  16. * @property int|null $created_at
  17. * @property int|null $updated_at
  18. * @property int $index
  19. */
  20. class RecommenReward extends \common\models\base\BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%addons_recommen_reward}}';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['active_id','be_reward', 'mall_id', 'user_id', 'status', 'created_at', 'updated_at', 'index'], 'integer'],
  36. [['reward'], 'string'],
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'active_id' => '活动ID',
  47. 'mall_id' => '商城ID',
  48. 'user_id' => '会员ID',
  49. 'be_reward' => '被推荐人奖励',
  50. 'reward' => '推荐人奖励内容',
  51. 'status' => '状态[-1:删除;0:禁用;1启用]',
  52. 'created_at' => 'Created At',
  53. 'updated_at' => 'Updated At',
  54. ];
  55. }
  56. /**
  57. * 保存数据
  58. * @Author: ltm
  59. * @DateTime: 2022/5/16 0022 17:13
  60. * @Copyright: copyright (c) 2021 广东七件事集团
  61. * @param array $params
  62. * @return string
  63. */
  64. public static function setData(array $params){
  65. try{
  66. $model = new self();
  67. $model->loadDefaultValues();
  68. $model->mall_id = $params['mall_id'];
  69. $params['reward'] = json_encode($params['reward'], JSON_UNESCAPED_UNICODE);
  70. if(!$model->load($params,'') || !$model->save()){
  71. throw new Exception($model->getErrorMessage());
  72. }
  73. return $model;
  74. }catch(\Exception $e){
  75. self::$static_error = $e->getMessage();
  76. return false;
  77. }
  78. }
  79. /**
  80. * 关联用户信息
  81. * @Author:ltm
  82. * @DateTime: 2022/5/6 0022 17:13
  83. * @Copyright: copyright (c) 2021 广东七件事集团
  84. * @return \yii\db\ActiveQuery
  85. */
  86. public function getUser()
  87. {
  88. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,username,mobile,avatar_url');
  89. }
  90. /**
  91. * 关联活动信息
  92. * @Author:ltm
  93. * @DateTime: 2022/5/6 0022 17:13
  94. * @Copyright: copyright (c) 2021 广东七件事集团
  95. * @return \yii\db\ActiveQuery
  96. */
  97. public function getRecommen()
  98. {
  99. return $this->hasOne(Recommen::class, ['id' => 'active_id']);
  100. }
  101. }