| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- namespace addons\BossWeight\common\models;
- use addons\Agent\common\models\AgentLevel;
- use addons\BossWeight\common\enums\LevelEnum;
- use common\enums\StatusEnum;
- use common\models\common\Addons;
- use common\models\mall\MallAddons;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_boss_weight}}".
- *
- * @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 $remark 备注
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class AddonsBoss extends \common\models\base\BaseActiveRecord
- {
- const ADDONS_NAME = 'BossWeight';
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_boss_weight}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'level', 'upgrade_status', 'upgrade_level_at', 'status', 'created_at', 'updated_at','fixed_weight'], 'integer'],
- [['commission', 'extra_commission', 'temp_extra_commission', 'total_commission'], 'number'],
- [['remark'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户ID',
- 'level' => '股东等级',
- 'commission' => '累计永久佣金,单位:元',
- 'extra_commission' => '累计额外佣金,单位:元',
- 'temp_extra_commission' => '额外分红金额,主要用于判断是否会导致超额',
- 'total_commission' => '累计总佣金,单位:元',
- 'upgrade_status' => '1条件升级,2购买指定商品升级,3手动升级',
- 'upgrade_level_at' => '股东等级升级时间',
- 'remark' => '备注',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- 'fixed_weight' => '固定权重',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id');
- }
- /**
- * @desc:关联股东等级
- * @Author: hua
- * @Date: 2021/11/5
- * @Time: 10:04
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getBossLevel(){
- return $this->hasOne(AddonsBossLevel::class, ['level' => 'level'])->andWhere(['<>','status',StatusEnum::DELETE]);
- }
- /**
- * 保存数据
- * @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(!empty($params['fixed_weight'])){
- $params['fixed_weight'] = $model->fixed_weight + $params['fixed_weight'];
- }
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- /**
- * 获取股东列表
- * @Author: lun
- * @DateTime: 2021/10/25 0025 10:05
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $cond
- * @param array $with
- * @param bool $is_array
- * @param string $select
- * @return array|\yii\db\ActiveRecord[]
- */
- public static function getBoss(array $cond=[], array $with=[],bool $is_array=true,string $select='*'){
- $default_cond = [['<>','status',StatusEnum::DELETE]];
- $cond = array_merge($default_cond,$cond);
- $query = self::find()->select($select);
- self::paramPack(['where'=>$cond, 'with'=>$with],$query);
- $data = $query->asArray($is_array)->all();
- return $data;
- }
- /**
- * @desc:推广中心-调用
- * @Author: hua
- * @Date: 2021/11/12
- * @Time: 9:30
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $user_id
- * @param $mall_id
- * @param $name
- * @return array
- */
- public static function getIncomeInfo($params){
- $mall_id = $params["mall_id"];
- $name = $params["addons_name"];
- $user_id = $params["user_id"];
- $is_install = MallAddons::isInstall($mall_id, $name);
- $data['total_commission'] = 0;
- $data['is_install'] = 0;
- if($is_install){
- $model = self::findOne(['user_id'=>$user_id,'status'=>StatusEnum::ENABLED]);
- $data['total_commission'] = $model['total_commission']??0;
- $data['is_install'] = $is_install;
- }
- return $data;
- }
- public static function getAddons(array $params){
- $addons_name = $params['addons_name'];
- $is_install = MallAddons::isInstall($params['mall_id'], $addons_name);
- if($is_install){
- $detail = Addons::getOne([['name' =>$addons_name], ['is_online' => 1]], true,);
- return [
- 'addons_name'=>$addons_name,
- 'title'=>$detail['title'],
- ];
- }
- return [];
- }
- }
|