feat: 修改支付逻辑增加充值功能

This commit is contained in:
mkm 2024-06-15 13:44:32 +08:00
parent e960f06837
commit e2c471c030
6 changed files with 99 additions and 68 deletions

View File

@ -17,6 +17,7 @@ use app\common\enum\user\UserTerminalEnum;
use app\common\logic\BaseLogic;
use app\common\model\user\User;
use app\common\model\user\UserAddress;
use app\common\model\user\UserRecharge;
use think\facade\Db;
use app\common\service\FileService;
use Webman\Config;

View File

@ -28,7 +28,7 @@ use Webman\RedisQueue\Redis;
class PayNotifyLogic extends BaseLogic
{
public static function handle($action, $orderSn, $extra = [])
public static function handle($action, $orderSn, $extra = [], $type = 'wechat')
{
Db::startTrans();
try {
@ -40,7 +40,7 @@ class PayNotifyLogic extends BaseLogic
$payNotifyLogLogic->insert($action, $extra);
}
}
self::$action($orderSn, $extra);
self::$action($orderSn, $extra, $type);
Db::commit();
return true;
} catch (\Exception $e) {
@ -115,7 +115,6 @@ class PayNotifyLogic extends BaseLogic
self::afterPay($order);
Redis::send('push-platform-print', ['id' => $order['id']], 60);
PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
}
/**
@ -150,11 +149,6 @@ class PayNotifyLogic extends BaseLogic
}
self::afterPay($order, $extra['transaction_id']);
//活动期间消费
$check = DictType::where('type', 'activities')->find();
if (isset($check) && $check['status'] == 1 && in_array($order->pay_type, [9, 17]) == false && $user['user_ship'] == 0) {
self::dealChange($order['uid']);
}
if ($order->pay_type == 9) {
$extra['create_time'] = $order['create_time'];
@ -191,13 +185,17 @@ class PayNotifyLogic extends BaseLogic
/**
* 充值
*/
public static function recharge($orderSn, $extra = [])
public static function recharge($orderSn, $extra = [], $type = 'wechat')
{
$order = UserRecharge::where('order_id', $orderSn)->findOrEmpty();
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
return true;
}
if ($type == 'wechat') {
$price = bcdiv($extra['amount']['payer_total'], 100, 2);
} else {
$price = $extra['buyer_pay_amount'];
}
$order->price = $price;
$order->paid = 1;
$order->pay_time = time();
@ -213,12 +211,15 @@ class PayNotifyLogic extends BaseLogic
}
bcscale(2);
// $user->now_money = bcadd($user->now_money, $price, 2);//v.1
//更新等级
if ($price >= 1000) {
$user->user_ship = 1; //v.1
}
$user->purchase_funds = bcadd($user->purchase_funds, $price, 2);
$user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2);
$user->save();
//更新等级
self::dealLevel($uid, $user->total_recharge_amount);
if (!empty($extra['payer']['openid'])) {
Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 5);
}
@ -375,31 +376,6 @@ class PayNotifyLogic extends BaseLogic
// }
}
//等级处理
public static function dealLevel($uid, $total_money)
{
$userShip = UserShip::where('limit', '<=', $total_money)
->field('id,title,limit')
->order('limit', 'desc')
->find();
$info = User::where('id', $uid)->findOrEmpty();
if ($info && $userShip) {
if ($info->user_ship != $userShip['id']) {
$info->user_ship = $userShip['id'];
$info->save();
}
}
return true;
}
//处理活动期间直接改用户的等级
public static function dealChange($uid)
{
User::where('id', $uid)->update(['user_ship' => UserShipEnum::LEVEL_ONE]);
return true;
}
/**
* 回调日志
* @param $order

View File

@ -30,7 +30,11 @@ class CodePaySend implements Consumer
];
$res = $pay->wechat->query($order);
if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') {
if(isset($data['pay_type']) && $data['pay_type']=='recharge'){
PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res);
}else{
PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res);
}
}else{
throw new BusinessException('订单支付中', 200);
}

View File

@ -13,6 +13,7 @@ use app\common\logic\SystemStoreStaffLogic;
use app\store\controller\BaseAdminController;
use app\common\logic\store_order\StoreOrderLogic;
use app\common\model\store_order\StoreOrder;
use app\common\model\user_recharge\UserRecharge;
use app\store\validate\store_order\StoreOrderValidate;
use support\Log;
use Webman\RedisQueue\Redis;
@ -290,6 +291,56 @@ class StoreOrderController extends BaseAdminController
return $this->success('ok',$data);
}
/**
* vip充值
*/
public function rechange_amount()
{
$pay_type = $this->request->post('pay_type');
$auth_code = $this->request->post('auth_code'); //微信支付条码
if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY) {
return $this->fail('支付条码不能为空');
}
$params = $this->request->post();
$data=[
'store_id'=>$this->adminInfo['store_id'],
'uid'=>$params['uid'],
'staff_id'=>$this->adminId,
'order_id'=>getNewOrderId('CZ'),
'price'=>$params['price'],
];
$order = UserRecharge::create($data);
switch ($pay_type) {
case PayEnum::WECHAT_PAY_BARCODE:
//微信条码支付
$result = PaymentLogic::codepay($auth_code, $order);
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result);
} else {
Redis::send('send-code-pay', ['order_id' => $order['order_id'],'pay_type'=>'recharge']);
return $this->success('用户支付中');
}
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]);
case PayEnum::ALIPAY_BARCODE:
//支付宝条码支付
$result = PaymentLogic::ali_auth_code($auth_code, $order);
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
if ($result['msg'] !== 'Success') {
return $this->success('用户支付中');
}
PayNotifyLogic::handle('recharge', $result['out_trade_no'], $result,'ali');
$result['create_time'] = $order['create_time'];
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::ALIPAY_BARCODE, 'transaction_id' => $result['trade_no']]);
default:
return $this->fail('支付方式错误');
}
return $this->fail('支付失败');
}
}

View File

@ -1,14 +1,14 @@
<?php
namespace app\api\controller\user;
namespace app\store\controller\user;
use app\api\controller\BaseApiController;
use app\store\controller\BaseAdminController;
use app\api\lists\user\UserAddressList;
use app\api\logic\user\AddressLogic;
use app\api\validate\UserAddressValidate;
class AddressController extends BaseApiController
class AddressController extends BaseAdminController
{
public function lists(){
return $this->dataLists(new UserAddressList());

View File

@ -30,7 +30,6 @@ class UserController extends BaseAdminController
}
public function detail()
{
$params = (new UserValidate())->goCheck('detail');