更新收银支付

This commit is contained in:
mkm 2024-05-09 17:44:27 +08:00
parent 73a1b79a04
commit df2bf1d143
5 changed files with 196 additions and 130 deletions

View File

@ -31,11 +31,6 @@ class PayController extends BaseApiController
$attach = $ciphertext['attach']; $attach = $ciphertext['attach'];
switch ($attach) { switch ($attach) {
case 'cashierclass': case 'cashierclass':
$order = Cashierclass::where(['number' => $ciphertext['out_trade_no']])->findOrEmpty();
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
return true;
}
PayNotifyLogic::handle('cashierclass', $ciphertext['out_trade_no'], $ciphertext); PayNotifyLogic::handle('cashierclass', $ciphertext['out_trade_no'], $ciphertext);
$app->wechat->success(); $app->wechat->success();
break; break;

View File

@ -24,35 +24,38 @@ class RetailOrderController extends BaseApiController
/** /**
* 订单列表 * 订单列表
*/ */
public function order_list(){ public function order_list()
{
return $this->dataLists(new RetailOrderList()); return $this->dataLists(new RetailOrderList());
} }
public function order_count(){ public function order_count()
$userId=$this->request->userId; {
$where=['uid'=>$userId,'paid'=>0]; $userId = $this->request->userId;
$no_pay=Cashierclass::where($where)->count(); $where = ['uid' => $userId, 'paid' => 0];
$where['paid']=1; $no_pay = Cashierclass::where($where)->count();
$where['status']=0; $where['paid'] = 1;
$waiting=Cashierclass::where($where)->count(); $where['status'] = 0;
$where['status']=1; $waiting = Cashierclass::where($where)->count();
$receiving=Cashierclass::where($where)->count(); $where['status'] = 1;
return $this->success('ok',['no_pay'=>$no_pay,'waiting'=>$waiting,'receiving'=>$receiving]); $receiving = Cashierclass::where($where)->count();
return $this->success('ok', ['no_pay' => $no_pay, 'waiting' => $waiting, 'receiving' => $receiving]);
} }
/** /**
* @notes 检测零售订单 * @notes 检测零售订单
*/ */
public function checkOrder(){ public function checkOrder()
$cartId = (Array)$this->request->post('cart_id', []); {
$cartId = (array)$this->request->post('cart_id', []);
$addressId = (int)$this->request->post('address_id'); $addressId = (int)$this->request->post('address_id');
$pay_type = (int)$this->request->post('pay_type'); // $pay_type = (int)$this->request->post('pay_type');
$auth_code = $this->request->post('auth_code'); //微信支付条码 // $auth_code = $this->request->post('auth_code'); //微信支付条码
$params=$this->request->post(); $params = $this->request->post();
$res=OrderLogic::cartIdByOrderInfo($cartId,$addressId,null,$params); $res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, null, $params);
if($res==false){ if ($res == false) {
$msg=OrderLogic::getError(); $msg = OrderLogic::getError();
if($msg=='购物车为空'){ if ($msg == '购物车为空') {
return $this->data([]); return $this->data([]);
} }
return $this->fail(OrderLogic::getError()); return $this->fail(OrderLogic::getError());
@ -63,46 +66,59 @@ class RetailOrderController extends BaseApiController
/** /**
* @notes 创建零售订单 * @notes 创建零售订单
*/ */
public function createOrder(){ public function createOrder()
{
// d(WeChatConfigService::getPayConfigByTerminal(1)); // d(WeChatConfigService::getPayConfigByTerminal(1));
$user=User::where('id',$this->request->userId)->find(); $user = User::where('id', $this->request->userId)->find();
$cartId = (Array)$this->request->post('cart_id', []); $cartId = (array)$this->request->post('cart_id', []);
$mer_id = (Array)$this->request->post('mer_id', 0); $mer_id = (array)$this->request->post('mer_id', 0);
if($mer_id<=0){ if ($mer_id <= 0) {
return $this->fail('自提点不能为空'); return $this->fail('自提点不能为空');
} }
if(count($cartId)>100){ if (count($cartId) > 100) {
return $this->fail('购物车商品不能超过100个'); return $this->fail('购物车商品不能超过100个');
} }
$addressId = (int)$this->request->post('address_id'); $addressId = (int)$this->request->post('address_id');
$pay_type = (int)$this->request->post('pay_type'); $pay_type = (int)$this->request->post('pay_type');
$auth_code = $this->request->post('auth_code'); //微信支付条码 $auth_code = $this->request->post('auth_code'); //微信支付条码
$params=$this->request->post(); $params = $this->request->post();
$order=OrderLogic::createOrder($cartId,$addressId,null,$params); $order = OrderLogic::createOrder($cartId, $addressId, null, $params);
if($order!=false){ if ($order != false) {
if($pay_type==PayEnum::BALANCE_PAY){ switch ($pay_type) {
$user=User::where('id',$this->request->userId)->find(); case PayEnum::WECHAT_PAY:
$res=RetailOrderLogic::payBalance($user,$order); $user = User::where('id', $this->request->userId)->find();
if($res==true){ $res = RetailOrderLogic::payBalance($user, $order);
$res=RetailOrderLogic::paySuccess($order, ['money'=>$order['actual']]); if (RetailOrderLogic::hasError()) {
if($res){ $res = RetailOrderLogic::paySuccess($order, ['money' => $order['actual']]);
}else{ if (RetailOrderLogic::hasError()) {
} else {
return $this->fail(RetailOrderLogic::getError());
}
} else {
return $this->fail(RetailOrderLogic::getError()); return $this->fail(RetailOrderLogic::getError());
} }
}else{ break;
return $this->fail(RetailOrderLogic::getError()); case PayEnum::WECHAT_PAY:
} $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
}elseif($pay_type==PayEnum::WECHAT_PAY){ $result = PaymentLogic::pay($pay_type, 'cashierclass', $order, $this->userInfo['terminal'], $redirectUrl);
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; if (PaymentLogic::hasError()) {
$result = PaymentLogic::pay($pay_type,'cashierclass', $order, $this->userInfo['terminal'], $redirectUrl); return $this->fail(PaymentLogic::getError(), $params);
if (false === $result) { }
return $this->fail(PaymentLogic::getError(), $params); return $this->success('', $result);
} break;
return $this->success('', $result); case PayEnum::WECHAT_PAY_BARCODE:
$result = PaymentLogic::codepay($auth_code, $order);
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
return $this->success('', $result);
break;
default:
return $this->fail('支付方式错误');
} }
return $this->data(['order_id'=>$order->id]); return $this->data(['order_id' => $order->id]);
}else{ } else {
return $this->fail(OrderLogic::getError()); return $this->fail(OrderLogic::getError());
} }
} }
@ -110,61 +126,75 @@ class RetailOrderController extends BaseApiController
/** /**
* 重新支付 * 重新支付
*/ */
public function Repayment(){ public function Repayment()
{
$order_id = (int)$this->request->post('order_id'); $order_id = (int)$this->request->post('order_id');
$addressId = (int)$this->request->post('address_id'); $addressId = (int)$this->request->post('address_id');
$pay_type = (int)$this->request->post('pay_type'); $pay_type = (int)$this->request->post('pay_type');
$params=$this->request->post(); $auth_code = $this->request->post('auth_code'); //微信支付条码
$where=[ $params = $this->request->post();
'id'=>$order_id, $where = [
'uid'=>$this->userId, 'id' => $order_id,
'paid'=>0, 'uid' => $this->userId,
'paid' => 0,
]; ];
$order=Cashierclass::where($where)->find(); $order = Cashierclass::where($where)->find();
if($pay_type==PayEnum::BALANCE_PAY){ switch ($pay_type) {
$user=User::where('id',$this->request->userId)->find(); case PayEnum::BALANCE_PAY:
$res=RetailOrderLogic::payBalance($user,$order); $user = User::where('id', $this->request->userId)->find();
if($res==true){ $res = RetailOrderLogic::payBalance($user, $order);
$res=RetailOrderLogic::paySuccess($order, ['money'=>$order['actual']]); if (!RetailOrderLogic::hasError()) {
if($res){ $res = RetailOrderLogic::paySuccess($order, ['money' => $order['actual']]);
if(RetailOrderLogic::hasError()){
return $this->fail(RetailOrderLogic::getError());
}
return $this->success('余额支付成功');
}else{ }else{
return $this->fail(RetailOrderLogic::getError()); return $this->fail(RetailOrderLogic::getError());
} }
}else{ break;
return $this->fail(RetailOrderLogic::getError()); case PayEnum::WECHAT_PAY:
} $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
}elseif($pay_type==PayEnum::WECHAT_PAY){ if ($addressId != $order['address_id']) {
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; $address = UserAddress::where(['address_id' => $addressId, 'uid' => Request()->userId])->find();
if($addressId!=$order['address_id']){ if ($address) {
$address=UserAddress::where(['address_id'=>$addressId,'uid'=>Request()->userId])->find(); $_order['real_name'] = $address['real_name'];
if($address){ $_order['user_phone'] = $address['phone'];
$_order['real_name'] = $address['real_name']; $_order['user_address'] = $address['detail'];
$_order['user_phone'] = $address['phone']; $_order['address_id'] = $addressId;
$_order['user_address'] = $address['detail']; Cashierclass::where(['id' => $order_id, 'uid' => Request()->userId])->update($_order);
$_order['address_id'] = $addressId; }
Cashierclass::where(['id'=>$order_id,'uid'=>Request()->userId])->update($_order);
} }
} $result = PaymentLogic::pay($pay_type, 'cashierclass', $order, $this->userInfo['terminal'], $redirectUrl);
$result = PaymentLogic::pay($pay_type,'cashierclass', $order, $this->userInfo['terminal'], $redirectUrl); if (PaymentLogic::hasError()) {
if (false === $result) { return $this->fail(PaymentLogic::getError());
return $this->fail(PaymentLogic::getError()); }
} return $this->success('', $result);
return $this->success('', $result); break;
case PayEnum::WECHAT_PAY_BARCODE:
$result = PaymentLogic::codepay($auth_code, $order);
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
return $this->success('', $result);
break;
default:
return $this->fail('支付方式错误');
} }
return $this->fail('支付失败'); return $this->fail('支付失败');
} }
public function detail(){ public function detail()
{
$order_id = (int)$this->request->get('order_id'); $order_id = (int)$this->request->get('order_id');
$where=[ $where = [
'id'=>$order_id, 'id' => $order_id,
'uid'=>$this->userId, 'uid' => $this->userId,
]; ];
$order=CashierclassLogic::detail($where); $order = CashierclassLogic::detail($where);
if($order){ if ($order) {
return $this->data($order); return $this->data($order);
}else{ } else {
return $this->fail('订单不存在'); return $this->fail('订单不存在');
} }
} }
@ -172,12 +202,13 @@ class RetailOrderController extends BaseApiController
/** /**
* 获取用户常用购买记录 * 获取用户常用购买记录
*/ */
public function frequently_purchase(){ public function frequently_purchase()
$params=$this->request->get(); {
$res=RetailOrderLogic::frequentlyPurchase($params); $params = $this->request->get();
if(RetailOrderLogic::hasError()){ $res = RetailOrderLogic::frequentlyPurchase($params);
if (RetailOrderLogic::hasError()) {
return $this->fail(RetailOrderLogic::getError()); return $this->fail(RetailOrderLogic::getError());
}else{ } else {
return $this->data($res); return $this->data($res);
} }
} }
@ -185,17 +216,18 @@ class RetailOrderController extends BaseApiController
/** /**
* 取消订单 * 取消订单
*/ */
public function cancel_order(){ public function cancel_order()
{
$order_id = (int)$this->request->post('order_id'); $order_id = (int)$this->request->post('order_id');
$value = (int)$this->request->post('value'); $value = (int)$this->request->post('value');
$where=[ $where = [
'id'=>$order_id, 'id' => $order_id,
'uid'=>$this->userId, 'uid' => $this->userId,
'paid'=>0, 'paid' => 0,
]; ];
$order=Cashierclass::where($where)->find(); $order = Cashierclass::where($where)->find();
if($order){ if ($order) {
$data=['data'=>$value,'delete_time'=>time()]; $data = ['data' => $value, 'delete_time' => time()];
Cashierclass::where($where)->update($data); Cashierclass::where($where)->update($data);
return $this->success('取消成功'); return $this->success('取消成功');
} }
@ -205,36 +237,36 @@ class RetailOrderController extends BaseApiController
/** /**
* 确认收货 * 确认收货
*/ */
public function confirm_receipt(){ public function confirm_receipt()
{
$order_id = (int)$this->request->post('order_id'); $order_id = (int)$this->request->post('order_id');
$where=[ $where = [
'id'=>$order_id, 'id' => $order_id,
'uid'=>$this->userId, 'uid' => $this->userId,
'paid'=>1, 'paid' => 1,
'status'=>1, 'status' => 1,
]; ];
$order=Cashierclass::where($where)->find(); $order = Cashierclass::where($where)->find();
if($order){ if ($order) {
$data=['status'=>2]; $data = ['status' => 2];
Cashierclass::where($where)->update($data); Cashierclass::where($where)->update($data);
return $this->success('确认成功'); return $this->success('确认成功');
} }
return $this->fail('确认失败'); return $this->fail('确认失败');
} }
/** /**
* 再次购买 * 再次购买
*/ */
public function purchase_again(){ public function purchase_again()
{
$order_id = (int)$this->request->get('order_id'); $order_id = (int)$this->request->get('order_id');
$res=RetailOrderLogic::purchaseAgain($order_id); $res = RetailOrderLogic::purchaseAgain($order_id);
if($res==false){ if ($res == false) {
return $this->fail('添加失败'); return $this->fail('添加失败');
}else{ } else {
return $this->success('添加成功'); return $this->success('添加成功');
} }
} }
} }

View File

@ -50,8 +50,11 @@ class PayNotifyLogic extends BaseLogic
*/ */
public static function cashierclass($orderSn, $extra = []) public static function cashierclass($orderSn, $extra = [])
{ {
$order = Cashierclass::where('number', $orderSn)->findOrEmpty(); $order = Cashierclass::where('number', $orderSn)->findOrEmpty();
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
return true;
}
$order->money = bcdiv($extra['amount']['payer_total'],100,2); $order->money = bcdiv($extra['amount']['payer_total'],100,2);
$order->paid = 1; $order->paid = 1;
$order->status = 1; $order->status = 1;

View File

@ -50,7 +50,7 @@ class PaymentLogic extends BaseLogic
], ],
'attach' => $from 'attach' => $from
]; ];
$wechat=new PayService(1); $wechat = new PayService(1);
$result = $wechat->wechat->mini($order)->toArray(); $result = $wechat->wechat->mini($order)->toArray();
break; break;
default: default:
@ -59,4 +59,40 @@ class PaymentLogic extends BaseLogic
} }
return $result; return $result;
} }
/**
* 微信条码支付
*/
public static function codepay($auth_code, $order)
{
$pattern = '/^(10|11|12|13|14|15)\d{16}$/';
if (!preg_match($pattern, (string)$auth_code)) {
self::$error = '请使用正确的微信收付款条码';
return false;
}
$order = [
'description' => '条码商品',
'out_trade_no' => $order['number'],
'payer' => [
'auth_code' => $auth_code
],
'amount' => [
'total' => intval($order['actual'] * 100),
],
'scene_info' => [
"store_info" => [
'id' => $order['mer_id']
]
],
];
$wechat = new PayService(1);
try {
$result = $wechat->wechat->pot($order)->toArray();
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
return $result;
}
} }

View File

@ -9,9 +9,9 @@ return [
'alipay' => [ 'alipay' => [
'default' => [ 'default' => [
// 必填-支付宝分配的 app_id // 必填-支付宝分配的 app_id
'app_id' => '20160909004708941', 'app_id' => '2021004140622055',
// 必填-应用私钥 字符串或路径 // 必填-应用私钥 字符串或路径
'app_secret_cert' => 'MIIEpAIBAAKCxxxxxxxxxxxxxxP4r3m4OUmD/+XDgCg==', 'app_secret_cert' => 'MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDJBRXcWRsuH9h+FC7annXOqroHkkLNQhAbMqyKEG4S6v5d8W/h+7icuL7FtoeBn6PFXwrOqvb6dgARriMooJxTsxZmCqyrfB9C9JpMUhvfuvVOw2kZm34b642ovgsAfyO0Bs7+s8iakg2twdPXG1+LhLQZQI0Mm8G1buN60JnieyyWINgnzbDDRjrqBSmjGF+xjoy6zXV4LkthMPGx/KAXXm3OAb/eqhR2b3B1uv4TCFWr9ILGaU8H0cgOXOguznQrcBDJOjPLUZkpcDuxs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YsPUK/9A7s0zUlUveaa14OKmTTahbUXmjlSzP33GNLF8M66E2PdR5XvIRQKBgQCig9ffDup8An/Gyt//mFySiKW014EWQmetyPtecb2h7qknD2G4Vy3hvG7aJeEbaqEve2Y13JP4yQhtcgoPAX0GTzRc4Fd4MuZmWWlZYlZfgCQOJy5zEwTidjPMrEOsTvVQvWOOLuFS+PigVK7fz/YEsPXx61zkGPcuwQvNhQtOLA==',
// 必填-应用公钥证书 路径 // 必填-应用公钥证书 路径
'app_public_cert_path' => base_path() . '/payment/appCertPublicKey_2016090900470841.crt', 'app_public_cert_path' => base_path() . '/payment/appCertPublicKey_2016090900470841.crt',
// 必填-支付宝公钥证书 路径 // 必填-支付宝公钥证书 路径
@ -19,13 +19,13 @@ return [
// 必填-支付宝根证书 路径 // 必填-支付宝根证书 路径
'alipay_root_cert_path' => base_path() . '/payment/alipayRootCert.crt', 'alipay_root_cert_path' => base_path() . '/payment/alipayRootCert.crt',
// 选填-同步回调地址 // 选填-同步回调地址
'return_url' => 'https://webman.tinywan.cn/payment/alipay-return', 'return_url' => 'https://erp.lihaink.cn/api/pay/alipay-return',
// 选填-异步回调地址 // 选填-异步回调地址
'notify_url' => 'https://webman.tinywan.cn/payment/alipay-notify', 'notify_url' => 'https://erp.lihaink.cn/api/pay/alipay-notify',
// 选填-服务商模式下的服务商 id当 mode 为 Pay::MODE_SERVICE 时使用该参数 // 选填-服务商模式下的服务商 id当 mode 为 Pay::MODE_SERVICE 时使用该参数
'service_provider_id' => '', 'service_provider_id' => '',
// 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SANDBOX, MODE_SERVICE // 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SANDBOX, MODE_SERVICE
'mode' => \Yansongda\Pay\Pay::MODE_SANDBOX, 'mode' => \Yansongda\Pay\Pay::MODE_NORMAL,
] ]
], ],
'wechat' => [ 'wechat' => [