添加:菜卡兑换功能
This commit is contained in:
parent
62145d52ea
commit
ee4e2a07ca
|
|
@ -129,7 +129,9 @@ class ExchangePickupPointRepository extends BaseRepository{
|
|||
// 积分&额度变更数量
|
||||
$changeNum = (float)sprintf("%.2f",$pickupRecordInfo['total_money'] - $pickupRecordInfo['diff_money_pay']);
|
||||
// 变更额度
|
||||
$userHoldInfo = ExchangeQuota::where('uid',$pickupRecordInfo['uid'])->findOrEmpty();
|
||||
$userHoldInfo = app()->make(ExchangeQuotaRepository::class)
|
||||
->searchModel(['uid'=>$pickupRecordInfo['uid'],'quota_type'=>$pickupRecordInfo['quota_type']])
|
||||
->findOrEmpty();
|
||||
$changeFront = (float)$userHoldInfo->surplus_quota;
|
||||
$userHoldInfo->use_quota += (float)$changeNum;
|
||||
$userHoldInfo->surplus_quota -= (float)$changeNum;
|
||||
|
|
@ -145,6 +147,7 @@ class ExchangePickupPointRepository extends BaseRepository{
|
|||
'change_after' => (float)$userHoldInfo->surplus_quota,
|
||||
'remark' => "兑换消费",
|
||||
'source' => 2,
|
||||
'quota_type' => $pickupRecordInfo['quota_type'],
|
||||
]);
|
||||
// 变更积分
|
||||
$userInfo = User::where('uid',$pickupRecordInfo['uid'])->findOrEmpty();
|
||||
|
|
|
|||
|
|
@ -141,6 +141,9 @@ class Service extends BaseController{
|
|||
$service = $this->repository->getWith($id,[
|
||||
'user' => function($query){
|
||||
$query->field('avatar,uid');
|
||||
},
|
||||
'merchant' => function($query){
|
||||
$query->field('mer_id,mer_name,mer_avatar')->bind(['mer_name','mer_avatar']);
|
||||
}
|
||||
])->toArray();
|
||||
if($service['user'] ?? null){
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use app\common\model\user\ExchangeQuotaRecord;
|
|||
use app\common\model\user\User;
|
||||
use app\common\repositories\store\order\StoreOrderCreateRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\store\service\StoreServiceRepository;
|
||||
use app\common\repositories\user\ExchangeIntegralRecordRepository;
|
||||
use app\common\repositories\user\ExchangePickupPointRepository;
|
||||
use app\common\repositories\user\ExchangePickupRecordRepository;
|
||||
|
|
@ -81,8 +82,34 @@ class Exchange extends BaseController{
|
|||
*/
|
||||
public function exchangeHandle(StoreOrderCreateRepository $orderCreateRepository){
|
||||
// 参数获取
|
||||
$data = $this->request->params([
|
||||
'total_money',
|
||||
'use_integral',
|
||||
'diff_money',
|
||||
'diff_money_pay',
|
||||
'point_id',
|
||||
'staff_uid',
|
||||
'consume_uid',
|
||||
'service_id',
|
||||
'quota_type'
|
||||
]);
|
||||
$quotaType = $data['quota_type'] ?? 1;// 存在指定类型则使用指定类型,否则使用默认类型(默认酒卡)
|
||||
$data['quota_type'] = in_array((int)$quotaType,[1,2]) ? $quotaType : 1;// 类型非法,使用默认类型
|
||||
|
||||
|
||||
if($data['quota_type'] == 2) return $this->createOrderTwo($data, $orderCreateRepository);
|
||||
else return $this->createOrder($data, $orderCreateRepository);
|
||||
}
|
||||
/**
|
||||
* Common: 酒卡兑换下单
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/03 17:16
|
||||
* @param $data
|
||||
* @param $orderCreateRepository
|
||||
* @return mixed
|
||||
*/
|
||||
private function createOrder($data, $orderCreateRepository){
|
||||
$uid = $this->request->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('请选择操作员!');
|
||||
|
|
@ -144,6 +171,79 @@ class Exchange extends BaseController{
|
|||
return app('json')->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Common: 菜卡兑换下单
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/03 17:16
|
||||
* @param $data
|
||||
* @param $orderCreateRepository
|
||||
* @return mixed
|
||||
*/
|
||||
private function createOrderTwo($data, $orderCreateRepository){
|
||||
$uid = $this->request->uid();
|
||||
if ((float)$data['total_money'] <= 0) return app('json')->fail('价值必须大于0!');
|
||||
if ((float)$data['service_id'] <= 0) return app('json')->fail('兑换信息不存在!');
|
||||
$service = app()->make(StoreServiceRepository::class)
|
||||
->getSearch([])
|
||||
->where('service_id',$data['service_id'])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
// 判断:是否存在指定消费者,不存在则使用当前登录用户
|
||||
if ($service['uid'] == $uid) return app('json')->fail('操作员和消费用户不能是同一人!');
|
||||
// 支付信息
|
||||
$payInfo = $this->request->params(['pay_type', 'return_url']);
|
||||
$payInfo['money'] = (float)$data['diff_money_pay'];
|
||||
if((float)$payInfo['money'] > 0) if (!in_array($payInfo['pay_type'], StoreOrderRepository::PAY_TYPE, true)) return app('json')->fail('请选择正确的支付方式');
|
||||
// 添加兑换记录
|
||||
try{
|
||||
return Db::transaction(function () use ($data, $uid, $payInfo, $orderCreateRepository, $service) {
|
||||
// 添加兑换记录
|
||||
$pickupRecordId = ExchangePickupRecord::insertGetId([
|
||||
'uid' => $uid,
|
||||
'point_id' => $service['mer_id'],
|
||||
'staff_uid' => $service['uid'],
|
||||
'total_money' => $data['total_money'],
|
||||
'use_integral' => $data['use_integral'],
|
||||
'diff_money' => $data['diff_money'],
|
||||
'diff_money_pay' => $data['diff_money_pay'],
|
||||
'quota_type' => $data['quota_type']
|
||||
]);
|
||||
// 判断:如果【差价应支付金额】大于0 生成支付订单
|
||||
if((float)$payInfo['money'] > 0){
|
||||
$userInfo = User::where('uid',$uid)->findOrEmpty();
|
||||
$payInfo['pickup_record_id'] = $pickupRecordId;
|
||||
// 发起支付
|
||||
$groupOrder = app()->make(LockService::class)
|
||||
->exec('online_order.create',function() use ($payInfo,$orderCreateRepository, $userInfo){
|
||||
$payType = array_search($payInfo['pay_type'],StoreOrderRepository::PAY_TYPE);
|
||||
|
||||
return $orderCreateRepository->exchangeGoods($payType,$payInfo,$userInfo);
|
||||
});
|
||||
|
||||
if ($groupOrder['pay_price'] == 0) {
|
||||
app()->make(StoreOrderRepository::class)->paySuccess($groupOrder);
|
||||
return app('json')->status('success', '支付成功', ['order_id' => $groupOrder['group_order_id']]);
|
||||
}
|
||||
try {
|
||||
|
||||
return app()->make(StoreOrderRepository::class)
|
||||
->pay($payInfo['pay_type'], $userInfo, $groupOrder, $payInfo['return_url'], $this->request->isApp());
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return app('json')->status('error', $e->getMessage(), ['order_id' => $groupOrder->group_order_id]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
app()->make(ExchangePickupPointRepository::class)->exchangeSuccessHandle($pickupRecordId);
|
||||
|
||||
return app('json')->success('success');
|
||||
}
|
||||
});
|
||||
}catch(\Exception $e){
|
||||
|
||||
return app('json')->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Common: 取货记录
|
||||
* Author: wu-hui
|
||||
|
|
@ -235,27 +335,45 @@ class Exchange extends BaseController{
|
|||
public function siteQrCode(){
|
||||
// 参数获取
|
||||
$uid = $this->request->uid();
|
||||
$params = $this->request->params(['point_id',['total_money',0]]);
|
||||
if((int)$params['point_id'] > 0){
|
||||
try{
|
||||
// 由于微信长度限制问题 suid=staff_id;pid=point_id;tmy=total_money
|
||||
$params = $this->request->params(['point_id','mer_id','quota_type',['total_money',0]]);
|
||||
$quotaType = $params['quota_type'] ?? 1;// 存在指定类型则使用指定类型,否则使用默认类型(默认酒卡)
|
||||
$quotaType = in_array((int)$quotaType,[1,2]) ? $quotaType : 1;// 类型非法,使用默认类型
|
||||
// 参数验证
|
||||
if((int)$params['point_id'] <= 0 && $quotaType == 1) return app('json')->fail('小程序码生成失败,不存在的酒道馆!');
|
||||
if((int)$params['mer_id'] <= 0 && $quotaType == 2) return app('json')->fail('小程序码生成失败,不存在的商户!');
|
||||
// 二维码生成
|
||||
try{
|
||||
if($quotaType == 1){
|
||||
// 酒卡兑换 由于微信长度限制问题 suid=staff_id;pid=point_id;tmy=total_money
|
||||
$valueData = 'suid=' . $uid . '&pid=' . $params['point_id'] . '&tmy=' . $params['total_money'];
|
||||
$name = md5($valueData) . '.jpg';
|
||||
// pages/users/online_payment/exchange/index
|
||||
$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());
|
||||
$path = 'pages/users/online_payment/exchange/index';
|
||||
}else if($quotaType == 2){
|
||||
// 菜卡兑换 由于微信长度限制问题 sid=service_id;tmy=total_money
|
||||
$service = app()->make(StoreServiceRepository::class)
|
||||
->getSearch([])
|
||||
->where('mer_id',$params['mer_id'])
|
||||
->where('uid',$uid)
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$valueData = 'sid=' . $service['service_id'] . '&tmy=' . $params['total_money'];
|
||||
$name = md5($valueData) . '.jpg';
|
||||
$path = 'pages/users/online_payment/exchange/vegetable';
|
||||
}else{
|
||||
throw new \Exception('二维码生成失败,类型不明确!');
|
||||
}
|
||||
}
|
||||
// 生成二维码
|
||||
$qrcode = app()->make(QrcodeService::class)->getRoutineQrcodePath($name, $path, $valueData);
|
||||
if (!$qrcode) throw new \Exception('二维码生成失败');
|
||||
|
||||
return app('json')->fail('小程序码生成失败!');
|
||||
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());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Common: 获取兑换二维码(用户二维码)
|
||||
|
|
|
|||
Loading…
Reference in New Issue