| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace addons\BossThree\common\models;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Exception;
- use Yii;
- /**
- * This is the model class for table "{{%addons_boss_three}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property int $level 股东等级
- * @property float $commission 累计永久佣金,单位:元
- * @property float $extra_commission 累计额外佣金,单位:元
- * @property float $temp_extra_commission 额外分红金额,主要用于判断是否会导致超额
- * @property float $total_commission 累计总佣金,单位:元
- * @property int $upgrade_status 1条件升级,2购买指定商品升级,3手动升级
- * @property int $upgrade_level_at 股东等级升级时间
- * @property string|null $remark
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- * @property string $goods_ids 商品ID
- * @property int $is_percent 类型 0百分比 1 固定金额
- * @property float $price 分佣比例配置
- */
- class BossThree extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_boss_three}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'level', 'upgrade_status', 'upgrade_level_at', 'status', 'created_at', 'updated_at','is_percent'], 'integer'],
- [['commission', 'extra_commission', 'temp_extra_commission', 'total_commission','price'], 'number'],
- [['remark'], 'string', 'max' => 255],
- [['goods_ids'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'level' => 'Level',
- 'commission' => 'Commission',
- 'extra_commission' => 'Extra Commission',
- 'temp_extra_commission' => 'Temp Extra Commission',
- 'total_commission' => 'Total Commission',
- 'upgrade_status' => 'Upgrade Status',
- 'upgrade_level_at' => 'Upgrade Level At',
- 'remark' => 'Remark',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id');
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2021/10/22 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsBoss|bool
- */
- public static function setData(array $params){
- try{
- if(!empty($params['user_id'])){
- $model = self::findOne(['user_id' => $params['user_id'],'mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED]);
- if(empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- //$model->upgrade_status = LevelEnum::UPGRADE_MANUAL;
- //$model->upgrade_level_at = time();
- }
- } else {
- throw new \Exception('股东数据不存在或已删除');
- }
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|