ScoreExpansionWalletLog.php 4.0 KB

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