| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace addons\WriteOff\common\models;
- use Yii;
- use common\models\user\User;
- use common\enums\StatusEnum;
- use common\models\mall\MallAddons;
- /**
- * This is the model class for table "{{%addons_write_off_user}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property int $store_id
- * @property int $level 股东等级
- * @property float $commission 核销佣金,单位:元
- * @property float $promote_commission 促销佣金,单位:元
- * @property float $manage_commission 管理佣金,单位:元
- * @property float $total_commission 累计总佣金,单位:元
- * @property int|null $is_enable_manage_reward 是否开启管理奖[0:关闭;1启用]
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class WriteOffUser extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_write_off_user}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'store_id', 'level', 'is_enable_manage_reward', 'status', 'created_at', 'updated_at','total_num'], 'integer'],
- [['commission', 'promote_commission', 'manage_commission', 'total_commission'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'store_id' => 'Store ID',
- 'level' => 'Level',
- 'commission' => 'Commission',
- 'promote_commission' => 'Promote Commission',
- 'manage_commission' => 'Manage Commission',
- 'total_commission' => 'Total Commission',
- 'is_enable_manage_reward' => 'Is Enable Manage Reward',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'total_num' => 'Total Num',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id');
- }
- public function getLevel(){
- return $this->hasOne(WriteOffLevel::class, ['level' => 'level','mall_id'=>'mall_id'])->andWhere(['<>','status',StatusEnum::DELETE]);
- }
- 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'];
- }
- }elseif(!empty($params['id'])){
- $model = self::findOne($params['id']);
- if(empty($model)) throw new \Exception('数据不存在或已删除');
- } 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;
- }
- }
- /**
- * @desc:推广中心-调用
- * @return array
- */
- public static function getIncomeInfo(array $params){
- $is_install = MallAddons::isInstall($params['mall_id'], $params['addons_name']);
- $data['total_commission'] = 0;
- $data['is_install'] = 0;
- $data['is_show_at_center'] = 1;
- if($is_install){
- $model = self::findOne(['user_id'=>$params['user_id'],'mall_id'=>$params['mall_id'],'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]);
- $data['total_commission'] = $model['total_commission']??0;
- $data['is_install'] = $is_install;
- }
- return $data;
- }
- }
|