You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.6 KiB
117 lines
3.6 KiB
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\controller;
|
|
|
|
use app\BaseController;
|
|
use app\model\AgentDownScoresRecords;
|
|
use app\model\AgentUpScoresRecords;
|
|
use app\model\AgentUser;
|
|
use app\model\RechargeRecords;
|
|
use app\model\User;
|
|
use app\model\WithdrawalRecords;
|
|
use app\validate\Agent;
|
|
use think\exception\ValidateException;
|
|
use think\facade\Db;
|
|
use think\facade\Request;
|
|
use think\facade\Session;
|
|
|
|
class AgentTeam extends BaseController
|
|
{
|
|
|
|
/**
|
|
* 上分
|
|
* @return array
|
|
*/
|
|
public function upScores()
|
|
{
|
|
$request = Request::param();
|
|
|
|
$connection = Db::connect();
|
|
try {
|
|
$agentUser = Session::get('login_agent_user_data');
|
|
$agentUser['id'] = 1000;
|
|
|
|
validate(Agent::class)->scene('scores')->check($request);
|
|
|
|
$user_id = $request['user_id']; # 用户id
|
|
$quota = $request['quota']; # 额度
|
|
|
|
# 检测代理余额是否足够
|
|
$inspectRes = AgentUser::inspectBalance($agentUser['id'],$quota);
|
|
if (!$inspectRes['status']) throw new ValidateException($inspectRes['msg']);
|
|
|
|
# 开启事务
|
|
$connection->startTrans();
|
|
|
|
# 扣减代理余额
|
|
$agentBalance = AgentUser::decrBalance($agentUser['id'],$quota);
|
|
|
|
# 用户上分记录
|
|
AgentUpScoresRecords::createRecords($agentUser['id'],$user_id,$quota,$agentBalance);
|
|
|
|
# 用户上分
|
|
$userBalance = User::incrBalance($user_id,$quota);
|
|
|
|
# 用户充值记录-上分
|
|
RechargeRecords::createRecords($user_id,$quota,$userBalance,1);
|
|
|
|
$connection->commit();
|
|
return $this->renderSuccess('上分成功');
|
|
} catch (ValidateException $e) {
|
|
return $this->renderError($e->getMessage());
|
|
} catch (\Exception $exception) {
|
|
$connection->rollback();
|
|
return $this->renderError($exception->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 下分
|
|
* @return array|void
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function downScores()
|
|
{
|
|
$request = Request::param();
|
|
|
|
$connection = Db::connect();
|
|
try {
|
|
$agentUser = Session::get('login_agent_user_data');
|
|
$agentUser['id'] = 1000;
|
|
validate(Agent::class)->scene('scores')->check($request);
|
|
|
|
$user_id = $request['user_id']; # 用户id
|
|
$quota = $request['quota']; # 额度
|
|
|
|
# 检测代理余额是否足够
|
|
$inspectRes = User::inspectUserBalance($user_id,$quota);
|
|
if (!$inspectRes['status']) throw new ValidateException($inspectRes['msg']);
|
|
|
|
# 开启事务
|
|
$connection->startTrans();
|
|
|
|
# 增加代理余额
|
|
$agentBalance = AgentUser::incrWithdrawalBalance($agentUser['id'],$quota);
|
|
|
|
# 用户下分记录
|
|
AgentDownScoresRecords::createRecords($agentUser['id'],$user_id,$quota,$agentBalance);
|
|
|
|
# 用户下分
|
|
$userBalance = User::decrWithdrawalBalance($user_id,$quota);
|
|
|
|
# 用户提现记录-下分
|
|
WithdrawalRecords::createRecords($user_id,$quota,$userBalance,1);
|
|
|
|
$connection->commit();
|
|
return $this->renderSuccess('下分成功');
|
|
} catch (ValidateException $e) {
|
|
return $this->renderError($e->getMessage());
|
|
} catch (\Exception $exception) {
|
|
$connection->rollback();
|
|
return $this->renderError($exception->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|