|
|
|
@ -4,11 +4,18 @@ declare (strict_types = 1); |
|
|
|
namespace app\controller; |
|
|
|
|
|
|
|
use app\BaseController; |
|
|
|
use app\model\AdminDownScoresRecords; |
|
|
|
use app\model\AdminUpScoresRecords; |
|
|
|
use app\model\AgentRechargeRecords; |
|
|
|
use app\model\AgentUser; |
|
|
|
use app\model\User; |
|
|
|
use app\model\User as UserModel; |
|
|
|
use think\exception\ValidateException; |
|
|
|
use think\facade\Db; |
|
|
|
use think\facade\Request; |
|
|
|
use think\facade\Session; |
|
|
|
use app\validate\Admin; |
|
|
|
use app\validate\User as UserValidate; |
|
|
|
use think\exception\ValidateException; |
|
|
|
|
|
|
|
class AdminTeam extends BaseController |
|
|
|
{ |
|
|
|
@ -134,4 +141,83 @@ class AdminTeam extends BaseController |
|
|
|
|
|
|
|
return $this->renderSuccess('数据返回成功', ['list' => $list, 'total' => $total]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 代理上分 |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public function upScores() |
|
|
|
{ |
|
|
|
$request = Request::param(); |
|
|
|
|
|
|
|
$connection = Db::connect(); |
|
|
|
try { |
|
|
|
$adminUser = Session::get('login_admin_user_data'); |
|
|
|
|
|
|
|
validate(Admin::class)->scene('scores')->check($request); |
|
|
|
|
|
|
|
$aid = $request['aid']; # 代理id |
|
|
|
$quota = $request['quota']; # 额度 |
|
|
|
|
|
|
|
# 开启事务 |
|
|
|
$connection->startTrans(); |
|
|
|
|
|
|
|
# 增加代理余额 |
|
|
|
$agentBalance = AgentUser::incrBalance($aid,$quota); |
|
|
|
# 代理上分记录 |
|
|
|
AdminUpScoresRecords::createRecords($aid,$adminUser['id'],$quota,$agentBalance,2); |
|
|
|
# 代理充值记录 |
|
|
|
AgentRechargeRecords::createRecords($aid,$quota,$agentBalance,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 { |
|
|
|
$adminUser = Session::get('login_admin_user_data'); |
|
|
|
validate(Admin::class)->scene('scores')->check($request); |
|
|
|
|
|
|
|
$aid = $request['aid']; # 用户id |
|
|
|
$quota = $request['quota']; # 额度 |
|
|
|
|
|
|
|
# 检测代理可提余额是否足够 |
|
|
|
$inspectRes = AgentUser::inspectWithdrawalBalance($aid,$quota); |
|
|
|
if (!$inspectRes['status']) throw new ValidateException($inspectRes['msg']); |
|
|
|
|
|
|
|
# 开启事务 |
|
|
|
$connection->startTrans(); |
|
|
|
|
|
|
|
# 扣减代理可提余额 |
|
|
|
$agentBalance = AgentUser::decrWithdrawalBalance($aid,$quota); |
|
|
|
|
|
|
|
# 代理下分记录 |
|
|
|
AdminDownScoresRecords::createRecords($aid,10010,$quota,$agentBalance,2); |
|
|
|
|
|
|
|
$connection->commit(); |
|
|
|
return $this->renderSuccess('下分成功'); |
|
|
|
} catch (ValidateException $e) { |
|
|
|
return $this->renderError($e->getMessage()); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
$connection->rollback(); |
|
|
|
return $this->renderError($exception->getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|