刮刮后端接口
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.

219 lines
6.2 KiB

<?php
namespace app\controller;
use app\BaseController;
use app\model\CustomerService as CustomerServiceModel;
use app\model\User as UserModel;
use app\validate\User as UserValidate;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Request;
class User extends BaseController
{
/**
* 找回密码
* @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,$this->request->userInfo['id']);
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 = $this->request->userInfo;
$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 = $this->request->userInfo;
$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 = $this->request->userInfo;
$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 = $this->request->userInfo;
$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()
]);
}
/**
* 用户信息
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function userInfo()
{
$userData = $this->request->userInfo;
$UserModel = new UserModel();
$info = $UserModel->field('id,avatar,balance,withdrawal_balance')->where('id',$userData['id'])->find();
$info['avatar'] = get_image_url($info['avatar']);
return $this->renderSuccess('数据返回成功',['data' => $info]);
}
/**
* 返回用户联系客服信息
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCustomerServiceList()
{
$where = [];
$CustomerServiceModel = new CustomerServiceModel();
# 查询用户列表
$field = 'id,name,wx_number';
$list = $CustomerServiceModel->field($field)->where($where)->order('id desc')->select()->toArray();
return $this->renderSuccess('数据返回成功', ['list' => $list]);
}
/**
* 退出登陆
*/
public function LogOut()
{
$login_user_data = Cache::store('redis')->get('login_user_data');
if ($login_user_data) Cache::store('redis')->delete('login_user_data');
return $this->renderSuccess('退出登陆成功');
}
}