|
|
|
@ -15,6 +15,7 @@ use app\model\User as UserModel; |
|
|
|
use app\model\CustomerService as CustomerServiceModel; |
|
|
|
use app\model\WithdrawalRecords; |
|
|
|
use app\validate\Agent; |
|
|
|
use app\validate\User as UserValidate; |
|
|
|
use think\exception\ValidateException; |
|
|
|
use think\facade\Db; |
|
|
|
use think\facade\Request; |
|
|
|
@ -127,8 +128,8 @@ class AgentTeam extends BaseController |
|
|
|
$agentUser = $this->request->userInfo; |
|
|
|
|
|
|
|
validate(Agent::class)->scene('scores')->check($request); |
|
|
|
$checkCodeRes = validate(Agent::class)->validateUserInfo($agentUser['id'],$request['user_id']); |
|
|
|
if ($checkCodeRes !== true) return $this->renderError($checkCodeRes); |
|
|
|
$validateUserInfo = validate(Agent::class)->validateUserInfo($agentUser['id'],$request['user_id']); |
|
|
|
if ($validateUserInfo !== true) return $this->renderError($validateUserInfo); |
|
|
|
|
|
|
|
$user_id = $request['user_id']; # 用户id |
|
|
|
$quota = $request['quota']; # 额度 |
|
|
|
@ -177,8 +178,8 @@ class AgentTeam extends BaseController |
|
|
|
try { |
|
|
|
$agentUser = $this->request->userInfo; |
|
|
|
validate(Agent::class)->scene('scores')->check($request); |
|
|
|
$checkCodeRes = validate(Agent::class)->validateUserInfo($agentUser['id'],$request['user_id']); |
|
|
|
if ($checkCodeRes !== true) return $this->renderError($checkCodeRes); |
|
|
|
$validateUserInfo = validate(Agent::class)->validateUserInfo($agentUser['id'],$request['user_id']); |
|
|
|
if ($validateUserInfo !== true) return $this->renderError($validateUserInfo); |
|
|
|
|
|
|
|
$user_id = $request['user_id']; # 用户id |
|
|
|
$quota = $request['quota']; # 额度 |
|
|
|
@ -346,6 +347,79 @@ class AgentTeam extends BaseController |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 代理升级用户为代理 |
|
|
|
*/ |
|
|
|
public function upGradationAgent() |
|
|
|
{ |
|
|
|
$param = Request::param(); |
|
|
|
|
|
|
|
$connection = Db::connect(); |
|
|
|
try { |
|
|
|
|
|
|
|
$agentData = $this->request->userInfo; |
|
|
|
validate(Agent::class)->scene('promotion')->check($param); |
|
|
|
|
|
|
|
$user_id = $param['user_id']; |
|
|
|
$rebate_ratio = $param['rebate_ratio'] ?? 0; |
|
|
|
|
|
|
|
$validateUserInfo = validate(Agent::class)->validateUserInfo($agentData['id'],$user_id); |
|
|
|
if ($validateUserInfo !== true) throw new ValidateException($validateUserInfo); |
|
|
|
|
|
|
|
$validateUserIdentity = validate(UserValidate::class)->validateUserIdentity($user_id); |
|
|
|
if ($validateUserIdentity !== true) throw new ValidateException($validateUserIdentity); |
|
|
|
|
|
|
|
$validateRebateRatio = validate(Agent::class)->validateRebateRatio($agentData['id'],$rebate_ratio); |
|
|
|
if ($validateRebateRatio !== true) throw new ValidateException($validateRebateRatio); |
|
|
|
|
|
|
|
# 开启事务 |
|
|
|
$connection->startTrans(); |
|
|
|
# 创建代理信息 |
|
|
|
AgentInfo::createInfo($user_id,$rebate_ratio); |
|
|
|
# 升级为代理 |
|
|
|
User::changeIdentity($user_id,2,$agentData['id']); |
|
|
|
|
|
|
|
$connection->commit(); |
|
|
|
return $this->renderSuccess('成功'); |
|
|
|
} catch (ValidateException $validateException) { |
|
|
|
return $this->renderError($validateException->getMessage()); |
|
|
|
} catch (\Exception $e) { |
|
|
|
$connection->rollback(); |
|
|
|
return $this->renderError($e->getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 修改代理占比 |
|
|
|
*/ |
|
|
|
public function settingRebateRatio() |
|
|
|
{ |
|
|
|
$param = Request::param(); |
|
|
|
try { |
|
|
|
|
|
|
|
$agentData = $this->request->userInfo; |
|
|
|
validate()->rule([ |
|
|
|
'user_id|用户id' => 'require|number', |
|
|
|
'rebate_ratio|返点占比' => 'require|float' |
|
|
|
])->check($param); |
|
|
|
|
|
|
|
$user_id = $param['user_id']; |
|
|
|
$rebate_ratio = $param['rebate_ratio'] ?? 0; |
|
|
|
|
|
|
|
$validateUserInfo = validate(Agent::class)->validateUserInfo($agentData['id'],$user_id); |
|
|
|
if ($validateUserInfo !== true) throw new ValidateException($validateUserInfo); |
|
|
|
|
|
|
|
$validateRebateRatio = validate(Agent::class)->validateRebateRatio($agentData['id'],$rebate_ratio); |
|
|
|
if ($validateRebateRatio !== true) throw new ValidateException($validateRebateRatio); |
|
|
|
|
|
|
|
AgentInfo::updateRebateRatio($user_id,$rebate_ratio); |
|
|
|
|
|
|
|
return $this->renderSuccess('成功'); |
|
|
|
} catch (ValidateException $validateException) { |
|
|
|
return $this->renderError($validateException->getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 返回用户联系客服信息 |
|
|
|
* @return array |
|
|
|
|