diff --git a/app/controller/AdminAgentTeam.php b/app/controller/AdminAgentTeam.php new file mode 100644 index 0000000..08e758c --- /dev/null +++ b/app/controller/AdminAgentTeam.php @@ -0,0 +1,147 @@ +whereOr(['phone' => $request['title'], 'id' => $request['title']]) + ->field('id') + ->select() + ->toArray(); + if ($queryUser) { + foreach ($queryUser as $queryUserRow) { + $where['id'][] = $queryUserRow['id']; + } + } else { + $where['id'] = 0; + } + } + + # 查询用户列表 + $field = 'id,phone,avatar,balance,withdrawal_balance'; + $userRes = $UserModel->field($field)->where($where)->order('id desc')->paginate($limit); + + $list = $userRes->items(); + $total = $userRes->total(); + + foreach ($list as &$item) { + + $item['phone'] = format_phone_number($item['phone']); + $item['avatar'] = get_image_url($item['avatar']); + $item['status'] = $item['status'] == 1 ? '正常' : '停用'; + } + + return $this->renderSuccess('数据返回成功', ['list' => $list, 'total' => $total]); + } + + /** + * 代理上分 + * @return array + */ + public function agentUpScores() + { + $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 agentDownScores() + { + $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()); + } + } +} diff --git a/app/controller/AdminTeam.php b/app/controller/AdminUserTeam.php similarity index 57% rename from app/controller/AdminTeam.php rename to app/controller/AdminUserTeam.php index a0302cf..e650fda 100644 --- a/app/controller/AdminTeam.php +++ b/app/controller/AdminUserTeam.php @@ -6,8 +6,6 @@ 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\RechargeRecords; use app\model\User; use app\model\WithdrawalRecords; @@ -18,7 +16,7 @@ use app\validate\Admin; use app\validate\User as UserValidate; use think\exception\ValidateException; -class AdminTeam extends BaseController +class AdminUserTeam extends BaseController { /** @@ -198,133 +196,4 @@ class AdminTeam extends BaseController return $this->renderError($exception->getMessage()); } } - - /** - * 代理列表 - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function agentList() - { - $request = Request::param(); - - $limit = $request['limit'] ?? 10; - - $where = []; - - $UserModel = new AgentUser(); - - # 用户id / 手机号码查询 - if (isset($request['title']) && !empty($request['title'])) { - $queryUser = $UserModel - ->whereOr(['phone' => $request['title'], 'id' => $request['title']]) - ->field('id') - ->select() - ->toArray(); - if ($queryUser) { - foreach ($queryUser as $queryUserRow) { - $where['id'][] = $queryUserRow['id']; - } - } else { - $where['id'] = 0; - } - } - - # 查询用户列表 - $field = 'id,phone,avatar,balance,withdrawal_balance'; - $userRes = $UserModel->field($field)->where($where)->order('id desc')->paginate($limit); - - $list = $userRes->items(); - $total = $userRes->total(); - - foreach ($list as &$item) { - - $item['phone'] = format_phone_number($item['phone']); - $item['avatar'] = get_image_url($item['avatar']); - $item['status'] = $item['status'] == 1 ? '正常' : '停用'; - } - - return $this->renderSuccess('数据返回成功', ['list' => $list, 'total' => $total]); - } - - /** - * 代理上分 - * @return array - */ - public function agentUpScores() - { - $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 agentDownScores() - { - $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()); - } - } } diff --git a/route/app.php b/route/app.php index f3f12d9..41cd2f4 100644 --- a/route/app.php +++ b/route/app.php @@ -58,15 +58,17 @@ Route::group('agentTeam',function(){ # 总后台 -Route::group('adminTeam',function() { - Route::post('userList','adminTeam/userList')->middleware(CheckAdmin::class)->allowCrossDomain(); - Route::post('editUser','adminTeam/editUser')->middleware(CheckAdmin::class)->allowCrossDomain(); - Route::post('deleteUser','adminTeam/deleteUser')->middleware(CheckAdmin::class)->allowCrossDomain(); - Route::post('agentList','adminTeam/agentList')->middleware(CheckAdmin::class)->allowCrossDomain(); - Route::post('agentUpScores','adminTeam/agentUpScores')->middleware(CheckAdmin::class)->allowCrossDomain(); - Route::post('agentDownScores','adminTeam/agentDownScores')->middleware(CheckAdmin::class)->allowCrossDomain(); - Route::post('upScores','adminTeam/upScores')->middleware(CheckAdmin::class)->allowCrossDomain(); - Route::post('downScores','adminTeam/downScores')->middleware(CheckAdmin::class)->allowCrossDomain(); +Route::group('adminUserTeam',function() { + Route::post('userList','adminUserTeam/userList')->middleware(CheckAdmin::class)->allowCrossDomain(); + Route::post('editUser','adminUserTeam/editUser')->middleware(CheckAdmin::class)->allowCrossDomain(); + Route::post('deleteUser','adminUserTeam/deleteUser')->middleware(CheckAdmin::class)->allowCrossDomain(); + Route::post('upScores','adminUserTeam/upScores')->middleware(CheckAdmin::class)->allowCrossDomain(); + Route::post('downScores','adminUserTeam/downScores')->middleware(CheckAdmin::class)->allowCrossDomain(); +}); +Route::group('adminAgentTeam',function() { + Route::post('agentList','adminAgentTeam/agentList')->middleware(CheckAdmin::class)->allowCrossDomain(); + Route::post('agentUpScores','adminAgentTeam/agentUpScores')->middleware(CheckAdmin::class)->allowCrossDomain(); + Route::post('agentDownScores','adminAgentTeam/agentDownScores')->middleware(CheckAdmin::class)->allowCrossDomain(); }); # 支付(待开发)