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.
137 lines
4.0 KiB
137 lines
4.0 KiB
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\controller;
|
|
|
|
use app\BaseController;
|
|
use app\model\AgentUser;
|
|
use app\model\User as UserModel;
|
|
use think\exception\ValidateException;
|
|
use think\facade\Request;
|
|
use app\validate\User as UserValidate;
|
|
|
|
class AdminTeam extends BaseController
|
|
{
|
|
|
|
/**
|
|
* 获取用户列表
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function userList()
|
|
{
|
|
$request = Request::param();
|
|
|
|
$limit = $request['limit'] ?? 10;
|
|
|
|
$where = [];
|
|
|
|
$UserModel = new UserModel();
|
|
|
|
# 用户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,aid,phone,avatar,balance,withdrawal_balance,status';
|
|
$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]);
|
|
}
|
|
|
|
/**
|
|
* 编辑用户信息
|
|
*/
|
|
public function editUser()
|
|
{
|
|
$param = Request::param();
|
|
|
|
try {
|
|
|
|
validate(UserValidate::class)->scene('editUser')->check($param);
|
|
|
|
$UserModel = new UserModel();
|
|
$result = $UserModel->retrieve($param);
|
|
|
|
if (!$result['status']) throw new ValidateException($result['msg']);
|
|
|
|
return $this->renderSuccess($result['msg']);
|
|
} catch (ValidateException $validateException) {
|
|
return $this->renderError($validateException->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]);
|
|
}
|
|
}
|
|
|