45], [['remark','check_remark'], 'string', 'max' => 1000], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'mobile' => 'Mobile', 'name' => 'Name', 'remark' => 'remark', 'check_remark' => 'check_remark', 'status' => 'Status', 'check_status' => 'Check Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public function getUser() { return $this->hasOne(User::class, ['id' => 'user_id']); } public static function setData(array $params) { $t = Yii::$app->db->beginTransaction(); try { if(!empty($params['id'])){ $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) throw new Exception('服务不存在或已删除'); $params['user_id'] = $model->user_id; }else{ $model = new self(); $model->loadDefaultValues(); } if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage()); if (!$model->save()) throw new \Exception($model->getErrorMessage()); if(!empty($params['check_status'])&&$params['check_status']==1){ //不需要审核 $res = Agent::findOne(['mall_id'=>$params['mall_id'],'user_id'=>$params['user_id'],'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]); if(!empty($res)) throw new Exception('该会员已经开启渠道分红'); // $agent_model = new Agent(); // $agent_model->mall_id = $params['mall_id']; // $agent_model->user_id = $params['user_id']; // $agent_model->level = 0; // $agent_model->upgrade_level_at = 0; // $agent_model->upgrade_status = 0; // $res = $agent_model->save(); // if(!$res) throw new \Exception($agent_model->getErrorMessage()); } $t->commit(); return $model; } catch (\Exception $e) { $t->rollBack(); self::$static_error = $e->getMessage(); return false; } } /** * 申请通过后,升级处理 * @param $params * @return array|bool */ public function upgradeLevel($params) { try{ $mall_id = $params['mall_id']; $user_id = $params['user_id']; $order = [ 'mall_id' => $mall_id, 'user_id' => $user_id, 'id' => 0 ]; $cond_upgrade = new \addons\Agent\common\logic\ConditionUpgrade(); $cond_uids = $cond_upgrade->execute(AddonsEnum::ADDONS_NAME_AGENT, (new Agent()), (new AgentLevel()), $order); return $cond_uids; }catch(\Exception $e){ $exception = FormatHelper::exception($e, 'AgentApply:upgradeLevel err:' . $e->getMessage()); Yii::error($exception); return false; } } }