优化支付逻辑,增加现金支付方式,修复支付状态判断

This commit is contained in:
mkm 2024-05-24 11:31:54 +08:00
parent f9fa105be6
commit adab9b2702
4 changed files with 82 additions and 36 deletions

View File

@ -41,22 +41,22 @@ class RetailOrderController extends BaseApiController
$number = $this->request->get('number');
$page_no = $this->request->get('page_no', 1);
$date = $this->request->get('date', date('Y-m-d'));
if(!$this->userInfo['merchant']['mer_id']){
if (!$this->userInfo['merchant']['mer_id']) {
return $this->fail('没有权限');
}
$where=[];
if($number){
$where = [];
if ($number) {
$where[] = ['number', 'like', '%' . $number . '%'];
}
$where[] = ['merchant', '=',$this->userInfo['merchant']['mer_id']];
$where[] = ['paid', '=',1];
$where[] = ['pay_type', '<>',9];
$where[] = ['is_opurchase', '=',0];
$where[] = ['merchant', '=', $this->userInfo['merchant']['mer_id']];
$where[] = ['paid', '=', 1];
$where[] = ['pay_type', '<>', 9];
$where[] = ['is_opurchase', '=', 0];
$res = Cashierclass::where($where)->page($page_no, 25)->whereDay('create_time', $date)
->order('address_id asc,id desc')
->select()->each(function($item){
$item['goods_list']=Cashierinfo::where('pid',$item['id'])->with('goodsName')->field('goods,nums,price sell')->limit(5)->select();
$item['goods_count']=count(explode(',',$item['cart_id']));
->select()->each(function ($item) {
$item['goods_list'] = Cashierinfo::where('pid', $item['id'])->with('goodsName')->field('goods,nums,price sell')->limit(5)->select();
$item['goods_count'] = count(explode(',', $item['cart_id']));
});
$data['count'] = Cashierclass::where($where)->whereDay('create_time', $date)->count();
$data['lists'] = $res?->toArray();
@ -70,10 +70,10 @@ class RetailOrderController extends BaseApiController
public function merchant_order_count()
{
$date = $this->request->get('date', date('Y-m-d'));
$where[] = ['merchant', '=',$this->userInfo['merchant']['mer_id']];
$where[] = ['paid', '=',1];
$where[] = ['pay_type', '<>',9];
$where[] = ['is_opurchase', '=',0];
$where[] = ['merchant', '=', $this->userInfo['merchant']['mer_id']];
$where[] = ['paid', '=', 1];
$where[] = ['pay_type', '<>', 9];
$where[] = ['is_opurchase', '=', 0];
$res = Cashierclass::where($where)->whereDay('create_time', $date)->count();
return $this->success('ok', ['order_count' => $res]);
}
@ -124,19 +124,19 @@ class RetailOrderController extends BaseApiController
$addressId = (int)$this->request->post('address_id');
$auth_code = $this->request->post('auth_code'); //微信支付条码
$params = $this->request->post();
if ($mer_id <= 0 && $pay_type!=9) {
if ($mer_id <= 0 && $pay_type != 9) {
return $this->fail('自提点不能为空');
}
if (count($cartId) > 100) {
return $this->fail('购物车商品不能超过100个');
}
if($pay_type==9){
if(empty($this->request->userInfo['merchant'])){
if ($pay_type == 9) {
if (empty($this->request->userInfo['merchant'])) {
return $this->fail('请先绑定商户');
}
$mer_id=$this->request->userInfo['merchant']['mer_id'];
$params['mer_id']=$mer_id;
$mer_id = $this->request->userInfo['merchant']['mer_id'];
$params['mer_id'] = $mer_id;
}
$order = OrderLogic::createOrder($cartId, $addressId, null, $params);
if ($order != false) {
@ -155,6 +155,11 @@ class RetailOrderController extends BaseApiController
return $this->success('余额支付成功');
}
break;
case PayEnum::CASH_PAY:
//现金支付
PayNotifyLogic::handle('cash_pay', $order['number']);
return $this->success('余额支付成功');
break;
case PayEnum::WECHAT_PAY:
//微信支付
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
@ -170,13 +175,13 @@ class RetailOrderController extends BaseApiController
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
if(isset($result['trade_state_desc']) && $result['trade_state_desc']=='支付成功'){
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
PayNotifyLogic::handle('cashierclass', $result['out_trade_no'], $result);
}else{
Redis::send('send-code-pay', ['number'=>$order['number']]);
} else {
Redis::send('send-code-pay', ['number' => $order['number']]);
return $this->success('用户支付中');
}
$result['create_time']=$order['create_time'];
$result['create_time'] = $order['create_time'];
return $this->success('', $result);
break;
default:
@ -204,7 +209,7 @@ class RetailOrderController extends BaseApiController
'paid' => 0,
];
$order = Cashierclass::where($where)->find();
if(!$order) return $this->fail('订单不存在或已支付');
if (!$order) return $this->fail('订单不存在或已支付');
switch ($pay_type) {
case PayEnum::BALANCE_PAY:
@ -213,11 +218,11 @@ class RetailOrderController extends BaseApiController
$res = RetailOrderLogic::payBalance($user, $order);
if (!RetailOrderLogic::hasError()) {
$res = RetailOrderLogic::paySuccess($order, ['money' => $order['actual']]);
if(RetailOrderLogic::hasError()){
if (RetailOrderLogic::hasError()) {
return $this->fail(RetailOrderLogic::getError());
}
return $this->success('余额支付成功');
}else{
} else {
return $this->fail(RetailOrderLogic::getError());
}
break;
@ -246,13 +251,13 @@ class RetailOrderController extends BaseApiController
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
if(isset($result['trade_state_desc']) && $result['trade_state_desc']=='支付成功'){
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
PayNotifyLogic::handle('cashierclass', $result['out_trade_no'], $result);
}else{
Redis::send('send-code-pay', ['number'=>$order['number']]);
} else {
Redis::send('send-code-pay', ['number' => $order['number']]);
return $this->success('用户支付中');
}
$result['create_time']=$order['create_time'];
$result['create_time'] = $order['create_time'];
return $this->success('', $result);
break;
default:

View File

@ -102,6 +102,9 @@ class OrderLogic extends BaseLogic
if($params['pay_type']==PayEnum::WECHAT_PAY_BARCODE){
$_order['source']=1;
}
if($params['pay_type']==PayEnum::CASH_PAY){
$_order['money']=$_order['total'];
}
Db::startTrans();
try {
$order = Cashierclass::create($_order);

View File

@ -30,6 +30,7 @@ class PayEnum
* @ALIPAY_QRCODE 支付宝二维码
* @GOODS_FIRST_PAYMENT_LATER 先货后款
* @CORPORATE_TRANSFER 对公转账
* @CASH_PAY 现金支付
*/
const BALANCE_PAY = 3;
const WECHAT_PAY = 1;
@ -47,6 +48,7 @@ class PayEnum
const ALIPAY_QRCODE = 14;
const GOODS_FIRST_PAYMENT_LATER = 15;
const CORPORATE_TRANSFER = 16;
const CASH_PAY = 17;
//支付状态
const UNPAID = 0; //未支付

View File

@ -63,14 +63,14 @@ class PayNotifyLogic extends BaseLogic
}
$financial_type = OrderEnum::USER_ORDER_PAY;
$financial_type2 = OrderEnum::MERCHANT_ORDER_OBTAINS;
if($order->pay_type !=10){
if ($order->pay_type != 10) {
$order->money = bcdiv($extra['amount']['payer_total'], 100, 2);
$order->paid = 1;
$order->status = 1;
$order->save();
}else{
} else {
$financial_type2 = OrderEnum::CASHIER_CASH_ORDER_PAY;
$extra['transaction_id']=time();
$extra['transaction_id'] = time();
}
if ($order->pay_type == 9) {
$order->status = 2;
@ -202,4 +202,40 @@ class PayNotifyLogic extends BaseLogic
// ];
(new FinancialRecord())->saveAll($record);
}
/**
* 现金支付
*/
public static function cash_pay($orderSn)
{
$order = Cashierclass::where('number', $orderSn)->findOrEmpty();
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
return true;
}
$order->paid = 1;
$order->status = 2;
$order->save();
if ($order['cart_id']) {
if (!is_array($order['cart_id'])) {
$cart_arr = explode(',', $order['cart_id']);
Cart::whereIn('cart_id', $cart_arr)->update(['is_pay' => 1]);
} else {
Cart::whereIn('cart_id', $order['cart_id'])->update(['is_pay' => 1]);
}
}
//商户获得流水
$record[] = [
'financial_record_sn' => time(),
'order_id' => $order['id'],
'number_sn' => $order['number'],
'user_id' => $order['uid'],
'financial_type' => OrderEnum::CASHIER_CASH_ORDER_PAY,
'financial_pm' => OrderEnum::INCOME,
'number' => $order['actual'],
'status' => 1,
'type' => OrderEnum::MERCHANT,
'mer_id' => $order['merchant'],
];
(new FinancialRecord())->saveAll($record);
}
}