| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace addons\ScoreExpansion\common\models;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_redpack_wallet_log}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id
- * @property int $integral_wallet_type 积分类型[frozen_integral:冻结积分,integral:激活积分]
- * @property string $change_type 操作类型:add-增加,sub-减少
- * @property float $change_num 操作数量
- * @property float $after_num 当前数量
- * @property string $desc 变动说明
- * @property string $source_table 来源表
- * @property int $source_table_id 操作来源业务id
- * @property string $from_type 来源类型
- * @property int $status 状态,-1:失效,1:正常,2:冻结
- * @property int $created_at 添加时间戳
- * @property int $updated_at 更新时间戳
- */
- class ScoreExpansionWalletLog extends \common\models\base\BaseActiveRecord
- {
- const CHANGE_TYPE_ADD = 'add'; //收入
- const CHANGE_TYPE_SUB = 'sub'; //支出
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_score_expansion_wallet_log}}';
- }
- public static function briefTableName()
- {
- return 'addons_score_expansion_wallet_log';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'source_table_id', 'from_type', 'status', 'created_at', 'updated_at'], 'integer'],
- [['change_num', 'after_num'], 'number'],
- [['change_type'], 'string', 'max' => 12],
- [['integral_wallet_type'], 'string', 'max' => 20],
- [['addon_name'], 'string', 'max' => 64],
- [['desc', 'source_table'], 'string', 'max' => 255],
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'integral_wallet_type' => '积分类型[frozen_redpack:冻结积分,redpack:激活积分]',
- 'change_type' => '操作类型:add-增加,sub-减少',
- 'change_num' => '操作数量',
- 'after_num' => '当前数量',
- 'desc' => '变动说明',
- 'source_table' => '来源表',
- 'source_table_id' => '操作来源业务id',
- 'from_type' => '来源类型',
- 'status' => '状态,-1:失效,1:正常,2:冻结',
- 'created_at' => '添加时间戳',
- 'updated_at' => '更新时间戳',
- 'addon_name' => '来源插件名称',
- ];
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2022/3/22 0022 10:54
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @return bool|$this
- */
- public static function setData($params)
- {
- try {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- $model->user_id = $params['user_id'];
- $model->integral_wallet_type = $params['integral_wallet_type'];
- $model->change_type = $params['change_type'];
- $model->change_num = $params['change_num'];
- $model->after_num = $params['after_num'];
- $model->desc = $params['desc'];
- $model->source_table = $params['source_table'];
- $model->source_table_id = $params['source_table_id'];
- $model->from_type = $params['from_type'];
- $model->addon_name = $params['addon_name'];
- if (!$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|