RedpackWalletLog.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace addons\Redpack\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_redpack_wallet_log}}".
  8. *
  9. * @property int $id
  10. * @property int $mall_id
  11. * @property int $user_id
  12. * @property int $redpack_wallet_type 红包类型[frozen_redpack:冻结红包,redpack:激活红包]
  13. * @property string $change_type 操作类型:add-增加,sub-减少
  14. * @property float $change_num 操作数量
  15. * @property float $after_num 当前数量
  16. * @property string $desc 变动说明
  17. * @property string $source_table 来源表
  18. * @property int $source_table_id 操作来源业务id
  19. * @property string $from_type 来源类型
  20. * @property int $status 状态,-1:失效,1:正常,2:冻结
  21. * @property int $created_at 添加时间戳
  22. * @property int $updated_at 更新时间戳
  23. */
  24. class RedpackWalletLog extends \common\models\base\BaseActiveRecord
  25. {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public static function tableName()
  30. {
  31. return '{{%addons_redpack_wallet_log}}';
  32. }
  33. public static function briefTableName()
  34. {
  35. return 'addons_redpack_wallet_log';
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function rules()
  41. {
  42. return [
  43. [['mall_id', 'user_id', 'source_table_id', 'from_type', 'status', 'created_at', 'updated_at'], 'integer'],
  44. [['change_num', 'after_num'], 'number'],
  45. [['change_type'], 'string', 'max' => 12],
  46. [['redpack_wallet_type'], 'string', 'max' => 20],
  47. [['desc', 'source_table'], 'string', 'max' => 255],
  48. ];
  49. }
  50. public function getUser()
  51. {
  52. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function attributeLabels()
  58. {
  59. return [
  60. 'id' => 'ID',
  61. 'mall_id' => 'Mall ID',
  62. 'user_id' => 'User ID',
  63. 'redpack_wallet_type' => '红包类型[frozen_redpack:冻结红包,redpack:激活红包]',
  64. 'change_type' => '操作类型:add-增加,sub-减少',
  65. 'change_num' => '操作数量',
  66. 'after_num' => '当前数量',
  67. 'desc' => '变动说明',
  68. 'source_table' => '来源表',
  69. 'source_table_id' => '操作来源业务id',
  70. 'from_type' => '来源类型',
  71. 'status' => '状态,-1:失效,1:正常,2:冻结',
  72. 'created_at' => '添加时间戳',
  73. 'updated_at' => '更新时间戳',
  74. ];
  75. }
  76. /**
  77. * 保存数据
  78. * @Author: lun
  79. * @DateTime: 2022/3/22 0022 10:54
  80. * @Copyright: copyright (c) 2021 广东七件事集团
  81. * @param $params
  82. * @return bool
  83. */
  84. public static function setData($params)
  85. {
  86. try {
  87. $model = new self();
  88. $model->mall_id = $params['mall_id'];
  89. $model->user_id = $params['user_id'];
  90. $model->redpack_wallet_type = $params['redpack_wallet_type'];
  91. $model->change_type = $params['change_type'];
  92. $model->change_num = $params['change_num'];
  93. $model->after_num = $params['after_num'];
  94. $model->desc = $params['desc'];
  95. $model->source_table = $params['source_table'];
  96. $model->source_table_id = $params['source_table_id'];
  97. $model->from_type = $params['from_type'];
  98. $model->loadDefaultValues();
  99. if (!$model->save()) throw new Exception($model->getErrorMessage());
  100. return true;
  101. } catch (\Exception $e) {
  102. self::setStaticError($e->getMessage());
  103. return false;
  104. }
  105. }
  106. }