添加:兑换添加消费者查询接口

This commit is contained in:
wuhui_zzw 2024-01-16 13:49:30 +08:00
parent c4287d37ca
commit 59c49dea4e
2 changed files with 66 additions and 4 deletions

View File

@ -11,6 +11,7 @@ use app\common\model\user\User;
use app\common\repositories\user\ExchangePickupPointRepository;
use app\common\repositories\user\ExchangePickupRecordRepository;
use app\common\repositories\user\ExchangeQuotaRepository;
use app\common\repositories\user\UserRepository;
use crmeb\basic\BaseController;
use crmeb\services\QrcodeService;
use crmeb\services\wechat\MiniProgram;
@ -32,7 +33,10 @@ class Exchange extends BaseController{
* @return mixed
*/
public function getUserHold(){
$params = $this->request->params(['consume_uid']);
$uid = $this->request->uid();
// 判断:是否存在指定消费者,不存在则使用当前登录用户
$uid = (int)$params['consume_uid'] > 0 ? (int)$params['consume_uid'] : $uid;
// 获取额度
$info = app()->make(ExchangeQuotaRepository::class)
->getSearch([])
@ -43,7 +47,8 @@ class Exchange extends BaseController{
])
->where('uid',$uid)
->findOrEmpty();
$info->available_integral = $this->user->exchange_integral;
$info->available = (float)$info->available;
$info->available_integral = (float)$this->user->exchange_integral;
$info->diff_rate = 30;// 差价 应补金额默认为30%
return app('json')->success($info);
@ -71,10 +76,12 @@ class Exchange extends BaseController{
public function exchangeHandle(){
// 参数获取
$uid = $this->request->uid();
$data = $this->request->params(['total_money','use_integral','diff_money','diff_money_pay','point_id','staff_uid']);
$data = $this->request->params(['total_money','use_integral','diff_money','diff_money_pay','point_id','staff_uid','consume_uid']);
if ((float)$data['total_money'] <= 0) return app('json')->fail('价值必须大于0');
if ((float)$data['point_id'] <= 0) return app('json')->fail('请选择提货点!');
if ((float)$data['staff_uid'] <= 0) return app('json')->fail('请选择操作员!');
// 判断:是否存在指定消费者,不存在则使用当前登录用户
$uid = (int)$data['consume_uid'] > 0 ? (int)$data['consume_uid'] : $uid;
if ($data['staff_uid'] == $uid) return app('json')->fail('操作员和消费用户不能是同一人!');
// 添加兑换记录
try{
@ -149,6 +156,33 @@ class Exchange extends BaseController{
return app('json')->success($data);
}
/**
* Common: 获取消费者列表
* Author: wu-hui
* Time: 2024/01/16 11:16
* @return mixed
*/
public function getConsumeList(){
$search = $this->request->params(['search_text', 'default_consume_id']);
$list = app()->make(UserRepository::class)
->getSearch([])
->field(['uid','real_name','nickname','avatar','phone'])
->where(function($query) use ($search){
// 用户ID/用户昵称/真实姓名/联系电话
$query->where('uid',$search['search_text'])
->whereOr('nickname','like',"%{$search['search_text']}%")
->whereOr('real_name','like',"%{$search['search_text']}%")
->whereOr('phone','like',"%{$search['search_text']}%");
})
->when(isset($search['default_consume_id']) && $search['default_consume_id'] > 0,function($query) use ($search){
$query->where('uid',$search['default_consume_id']);
})
->page(1, 30)
->select()
->toArray();
return app('json')->success($list);
}
/**
@ -181,7 +215,7 @@ class Exchange extends BaseController{
return app('json')->success($data);
}
/**
* Common: 获取兑换二维码显示
* Common: 获取兑换二维码显示(操作员二维码)
* Author: wu-hui
* Time: 2024/01/15 14:37
* @return mixed
@ -210,7 +244,34 @@ class Exchange extends BaseController{
return app('json')->fail('小程序码生成失败!');
}
/**
* Common: 获取兑换二维码(用户二维码)
* Author: wu-hui
* Time: 2024/01/16 10:17
* @return mixed
*/
public function userQrCode(){
// 参数获取
$uid = $this->request->uid();
if((int)$uid > 0){
try{
$valueData = 'consume_uid=' . $uid;
$name = md5('consume_qrcode_'.$valueData) . '.jpg';
$qrcode = app()->make(QrcodeService::class)->getRoutineQrcodePath($name, 'pages/users/online_payment/exchange/index', $valueData);
if (!$qrcode) throw new \Exception('二维码生成失败');
return app('json')->success([
'qr_code' => $qrcode
]);
}catch(\Exception $e){
return app('json')->fail($e->getMessage());
}catch(\Throwable $e){
return app('json')->fail($e->getMessage());
}
}
return app('json')->fail('小程序码生成失败!');
}
}

View File

@ -353,11 +353,12 @@ Route::group('api/', function () {
Route::get('userHold', 'Exchange/getUserHold');
Route::get('exchangeHandle', 'Exchange/exchangeHandle');
Route::get('exchangeRecord', 'Exchange/exchangeRecord');
Route::get('consumeList', 'Exchange/getConsumeList');
// 站点管理相关
Route::get('site_list', 'Exchange/siteList');
Route::get('site_exchange_record', 'Exchange/siteExchangeRecord');
Route::get('site_qr_code', 'Exchange/siteQrCode');
Route::get('user_qr_code', 'Exchange/userQrCode');
})->prefix('api.user.');