RebateRewardLog.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /*
  3. * @Descripttion:
  4. * @copyright: Copyright (c) 2021 广东七件事集团
  5. * @Author: lun
  6. * @Date: 2022-01-01 01:10:32
  7. */
  8. namespace addons\Rebate\common\models;
  9. use common\models\user\User;
  10. use yii\db\Exception;
  11. /**
  12. * This is the model class for table "qimall_addons_rebate_reward_log".
  13. *
  14. * @property int $id
  15. * @property int $mall_id 商城id
  16. * @property int $r_id 对应qimall_addons_rebate.id
  17. * @property int $user_id 用户id
  18. * @property string|null $reward_title 奖励名称
  19. * @property string|null $content 奖励内容
  20. * @property string|null $setting 结算时的配置
  21. * @property int $status 状态[-1:删除;0:禁用;1启用]
  22. * @property int $created_at 创建时间
  23. * @property int $updated_at 更新时间
  24. * @property int $is_frozen 是否冻结
  25. */
  26. class RebateRewardLog extends \common\models\base\BaseActiveRecord
  27. {
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function tableName()
  32. {
  33. return 'qimall_addons_rebate_reward_log';
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['mall_id'], 'required'],
  42. [['mall_id', 'r_id', 'user_id', 'status', 'created_at', 'updated_at', 'is_frozen'], 'integer'],
  43. [['reward_title'], 'string', 'max' => 50],
  44. [['content', 'setting'], 'string'],
  45. ];
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function attributeLabels()
  51. {
  52. return [
  53. 'id' => 'ID',
  54. 'mall_id' => 'Mall ID',
  55. 'r_id' => 'R ID',
  56. 'user_id' => 'User ID',
  57. 'reward_title' => '奖励名称',
  58. 'content' => 'Content',
  59. 'setting' => 'Setting',
  60. 'status' => 'Status',
  61. 'created_at' => 'Created At',
  62. 'updated_at' => 'Updated At',
  63. 'is_frozen' => 'Is Frozen',
  64. ];
  65. }
  66. /***
  67. * 关联用户
  68. */
  69. public function getUser()
  70. {
  71. return $this->hasOne(User::class, ['id' => 'user_id']);
  72. }
  73. /**
  74. * 保存数据
  75. * @Author: lun
  76. * @DateTime: 2022/1/15 0015 9:36
  77. * @Copyright: copyright (c) 2021 广东七件事集团
  78. * @param $mall_id
  79. * @param array $params
  80. * @return array|bool
  81. */
  82. public static function setData($mall_id, array $params){
  83. try{
  84. $model = new self();
  85. $model->loadDefaultValues();
  86. $model->mall_id = $mall_id;
  87. if(!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  88. return $model->toArray();
  89. }catch(\Exception $e){
  90. self::setStaticError($e->getMessage());
  91. return false;
  92. }
  93. }
  94. }