| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace addons\BusinessBonus\common\models;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "{{%addons_business_bonus_upgrade_record}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property float|null $bonus_rate 升级后的分红比例,仅记录作用
- * @property int|null $upgrade_type 升级方式:0未知,1无条件,2前端申请,3购买知道商品,4后台添加,5后台调整
- * @property int|null $upgrade_time 升级时间
- * @property string|null $extra_data 额外信息,json格式,根据不同升级方式保存不同信息
- * @property int|null $status 状态:-1删除,0禁用,1启用
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- */
- class BusinessBonusUpgradeRecord extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_business_bonus_upgrade_record}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'business_bonus_level', 'upgrade_type', 'upgrade_time', 'status', 'created_at', 'updated_at'], 'integer'],
- [['bonus_rate'], 'number'],
- [['extra_data'], 'safe'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '会员ID',
- 'business_bonus_level' => '招商员等级',
- 'bonus_rate' => '升级后的分红比例,仅记录作用',
- 'upgrade_type' => '升级方式:0未知,1无条件,2前端申请,3购买指定商品,4后台添加,5后台调整',
- 'upgrade_time' => '升级时间',
- 'extra_data' => '额外信息,json格式,根据不同升级方式保存不同信息',
- 'status' => '状态:-1删除,0禁用,1启用',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 数据设置
- */
- public static function setData(array $params)
- {
- try{
- if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID');
- if (isset($params['id']) && !empty($params['id'])) {
- $model = self::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if(empty($model)) throw new Exception('升级记录不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- }
- if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }catch(Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
- }
- }
|