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

282 lines
8.4 KiB

<?php
namespace app\controller;
use app\BaseController;
use app\middleware\CheckUser;
use app\model\ConsumptionRecords;
use app\model\CustomerService as CustomerServiceModel;
use app\model\RechargeRecords;
use app\model\Setting as SettingModel;
use app\model\User as UserModel;
use app\model\ZoneGoods;
use app\validate\User as UserValidate;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Request;
use think\facade\Session;
class User extends BaseController
{
protected $middleware = [CheckUser::class];
/**
* 找回密码
* @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,trade_type')
->order('id' ,'desc')
->paginate($limit);
$listArr = $list->items();
$trade_type = [1 => '代理下分', 2 => '管理员下分', 3 => '支付宝'];
foreach ($listArr as &$item) {
$item['trade_type'] = $trade_type[$item['trade_type']];
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,trade_type,recharge_time')
->order('id' ,'desc')
->paginate($limit);
$listArr = $list->items();
$RechargeRecords = new RechargeRecords();
$trade_type = $RechargeRecords->tradeType;
foreach ($listArr as &$item) {
give_symbol($item['recharge_amount']);
$item['trade_type'] = $trade_type[$item['trade_type']];
$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']])
->field('zone_goods_id,actual_price,residue_amount,create_time,actual_type')
->order('id' ,'desc')
->paginate($limit);
$listArr = $list->items();
foreach ($listArr as &$item) {
$ZoneGoods = ZoneGoods::find($item['zone_goods_id']);
$Zone = \app\model\Zone::find($ZoneGoods->zone_id);
$item['zone_title'] = $Zone->title;
give_symbol($item['actual_price'],'-');
$item['create_time'] = date("m月d日 H:i",strtotime($item['create_time']));
$item['actual_type'] = $item['actual_type'] == 2 ? '可提余额' : '余额';
}
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('cr_id,awards_amount,withdrawal_balance,create_time')
->order('id' ,'desc')
->paginate($limit);
$listArr = $list->items();
foreach ($listArr as &$item) {
$ConsumptionRecords = ConsumptionRecords::find($item['cr_id']);
$ZoneGoods = ZoneGoods::find($ConsumptionRecords->zone_goods_id);
$Zone = \app\model\Zone::find($ZoneGoods->zone_id);
$item['zone_title'] = $Zone->title;
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']);
$info['recharge'] = SettingModel::settingLoad('user_recharge_set') ?: 0;
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]);
}
/**
*
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function transferBalance()
{
$userData = $this->request->userInfo;
$connection = Db::connect();
try {
# 开启事务
$connection->startTrans();
$result = UserModel::transferBalance($userData['id']);
if (!$result['status']) return $this->renderError($result['msg']);
$connection->commit();
return $this->renderSuccess('成功');
} catch (\Exception $e) {
$connection->rollback();
return $this->renderError('操作失败');
}
}
/**
* 下载安装包链接
* @return array
*/
public function downloadApp()
{
$apk_filename = get_new_apk_filename();
$file_url = get_image_url('download/'.$apk_filename);//文件路径
return $this->renderSuccess('成功',['app_url' => $file_url]);
}
/**
* 退出登陆
*/
public function LogOut()
{
Session::delete('login_user_data');
return $this->renderSuccess('退出登陆成功');
}
}