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.
223 lines
6.2 KiB
223 lines
6.2 KiB
<?php
|
|
namespace app\controller;
|
|
|
|
use app\BaseController;
|
|
use app\model\User as UserModel;
|
|
use app\validate\User as UserValidate;
|
|
use think\exception\ValidateException;
|
|
use think\facade\Db;
|
|
use think\facade\Request;
|
|
use think\facade\Session;
|
|
|
|
class User extends BaseController
|
|
{
|
|
|
|
/**
|
|
* 获取用户列表
|
|
* @param Request $request
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
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;
|
|
}
|
|
}
|
|
# 代理id查询
|
|
if ($agentData = Session::get('login_agent_user_data')) {
|
|
$where['aid'] = $agentData['id'];
|
|
}
|
|
|
|
# 查询用户列表
|
|
$field = 'id,aid,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']);
|
|
}
|
|
|
|
return $this->renderSuccess('数据返回成功',['list' => $list, 'total' => $total]);
|
|
}
|
|
|
|
/**
|
|
* 找回密码
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function modifyPassword()
|
|
{
|
|
$data = Request::param();
|
|
|
|
try {
|
|
// 验证用户输入
|
|
validate(UserValidate::class)->scene('modifyPassword')->check($data);
|
|
|
|
$userModel = new UserModel();
|
|
|
|
$user = $userModel->modifyPassword($data);
|
|
|
|
if ($user['status']) {
|
|
return $this->renderSuccess('修改成功');
|
|
} else {
|
|
return $this->renderError($user['msg']);
|
|
}
|
|
} catch (ValidateException $exception) {
|
|
return $this->renderError($exception->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 提现记录
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function withdrawalRecords()
|
|
{
|
|
$userData = Session::get('login_user_data');
|
|
|
|
$data = Request::param();
|
|
|
|
$limit = $data['limit'] ?: 10;
|
|
|
|
$list = Db::name('withdrawal_records')
|
|
->where(['user_id' => $userData['id'], 'status' => 1])
|
|
->field('withdrawal_amount,withdrawal_balance,apply_time')
|
|
->order('id' ,'desc')
|
|
->paginate($limit);
|
|
|
|
$listArr = $list->items();
|
|
|
|
foreach ($listArr as &$item) {
|
|
give_symbol($item['withdrawal_amount'],'-');
|
|
$item['apply_time'] = date("m月d日 H:i",strtotime($item['apply_time']));
|
|
}
|
|
|
|
return $this->renderSuccess('数据获取成功',[
|
|
'list' => $listArr,
|
|
'total' => $list->total()
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 充值记录
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function rechargeRecords()
|
|
{
|
|
$userData = Session::get('login_user_data');
|
|
|
|
$data = Request::param();
|
|
|
|
$limit = $data['limit'] ?: 10;
|
|
|
|
$list = Db::name('recharge_records')
|
|
->where('user_id',$userData['id'])
|
|
->field('recharge_amount,residue_amount,recharge_time')
|
|
->order('id' ,'desc')
|
|
->paginate($limit);
|
|
|
|
$listArr = $list->items();
|
|
|
|
foreach ($listArr as &$item) {
|
|
give_symbol($item['recharge_amount']);
|
|
$item['recharge_time'] = date("m月d日 H:i",strtotime($item['recharge_time']));
|
|
}
|
|
|
|
return $this->renderSuccess('数据获取成功',[
|
|
'list' => $listArr,
|
|
'total' => $list->total()
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 消费记录
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function consumptionRecords()
|
|
{
|
|
$userData = Session::get('login_user_data');
|
|
|
|
$data = Request::param();
|
|
|
|
$limit = $data['limit'] ?: 10;
|
|
|
|
$list = Db::name('consumption_records')
|
|
->where(['user_id' => $userData['id'],'status' => 1])
|
|
->field('actual_price,residue_amount,create_time')
|
|
->order('id' ,'desc')
|
|
->paginate($limit);
|
|
|
|
$listArr = $list->items();
|
|
|
|
foreach ($listArr as &$item) {
|
|
give_symbol($item['actual_price'],'-');
|
|
$item['create_time'] = date("m月d日 H:i",strtotime($item['create_time']));
|
|
}
|
|
|
|
return $this->renderSuccess('数据获取成功',[
|
|
'list' => $listArr,
|
|
'total' => $list->total()
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 中奖记录
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function awardsRecords()
|
|
{
|
|
$userData = Session::get('login_user_data');
|
|
|
|
$data = Request::param();
|
|
|
|
$limit = $data['limit'] ?: 10;
|
|
|
|
$list = Db::name('awards_records')
|
|
->where('user_id',$userData['id'])
|
|
->field('awards_amount,withdrawal_balance,create_time')
|
|
->order('id' ,'desc')
|
|
->paginate($limit);
|
|
|
|
$listArr = $list->items();
|
|
|
|
foreach ($listArr as &$item) {
|
|
give_symbol($item['awards_amount']);
|
|
$item['create_time'] = date("m月d日 H:i",strtotime($item['create_time']));
|
|
}
|
|
|
|
return $this->renderSuccess('数据获取成功',[
|
|
'list' => $listArr,
|
|
'total' => $list->total()
|
|
]);
|
|
}
|
|
}
|