ConsumeGiftGrantLog.php 2.7 KB

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