UpgradeGiftGrantLog.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace addons\UpgradeGift\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\user\User;
  5. use Yii;
  6. use yii\db\Exception;
  7. /**
  8. * This is the model class for table "{{%addons_upgrade_gift_grant_log}}".
  9. *
  10. * @property int $id
  11. * @property int $mall_id 商城id
  12. * @property int $gift_type 礼包类型
  13. * @property int $user_id 用户id
  14. * @property int $level 等级id
  15. * @property string|null $coupon 优惠券详细
  16. * @property int|null $coupon_num 优惠券数量
  17. * @property float|null $score 积分
  18. * @property float|null $balance 余额
  19. * @property int $status 状态[-1:删除;0:禁用;1启用]
  20. * @property int $goods_id 商品id
  21. * @property int $goods_name 商品名称
  22. * @property int $created_at 创建时间
  23. * @property int $updated_at 更新时间
  24. */
  25. class UpgradeGiftGrantLog extends \common\models\base\BaseActiveRecord
  26. {
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public static function tableName()
  31. {
  32. return '{{%addons_upgrade_gift_grant_log}}';
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function rules()
  38. {
  39. return [
  40. [['mall_id'], 'required'],
  41. [['mall_id', 'user_id', 'level', 'coupon_num', 'status', 'created_at', 'updated_at', 'goods_id', 'attr_id'], 'integer'],
  42. [['score', 'balance'], 'number'],
  43. [['gift_type'], 'string', 'max' => 20],
  44. [['coupon'], 'string', 'max' => 1024],
  45. [['goods_name'], 'string', 'max' => 120],
  46. [['attr_name'], 'string', 'max' => 500],
  47. ];
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => 'ID',
  56. 'mall_id' => '商城id',
  57. 'gift_type' => '礼包类型',
  58. 'user_id' => '用户id',
  59. 'level' => '等级id',
  60. 'coupon' => '优惠券详细',
  61. 'coupon_num' => '优惠券数量',
  62. 'score' => '积分',
  63. 'balance' => '余额',
  64. 'status' => '状态[-1:删除;0:禁用;1启用]',
  65. 'created_at' => '创建时间',
  66. 'updated_at' => '更新时间',
  67. ];
  68. }
  69. /**
  70. * 关联用户
  71. * @Author: lun
  72. * @DateTime: 2021/12/20 0020 14:37
  73. * @Copyright: copyright (c) 2021 广东七件事集团
  74. * @return \yii\db\ActiveQuery
  75. */
  76. public function getUser()
  77. {
  78. return $this->hasOne(User::class, ['id' => 'user_id']);
  79. }
  80. /**
  81. * 保存数据
  82. * @Author: lun
  83. * @DateTime: 2021/12/20 0020 9:30
  84. * @Copyright: copyright (c) 2021 广东七件事集团
  85. * @param $params
  86. * @return UpgradeGiftGrantLog|bool
  87. */
  88. public static function setData($params)
  89. {
  90. try{
  91. $model = new self();
  92. $model->loadDefaultValues();
  93. // 保存
  94. if(!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  95. return $model;
  96. }catch(\Exception $e){
  97. self::setStaticError($e->getMessage());
  98. return false;
  99. }
  100. }
  101. }