更新收银支付

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,12 +24,14 @@ 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; $userId = $this->request->userId;
$where = ['uid' => $userId, 'paid' => 0]; $where = ['uid' => $userId, 'paid' => 0];
$no_pay = Cashierclass::where($where)->count(); $no_pay = Cashierclass::where($where)->count();
@ -43,11 +45,12 @@ class RetailOrderController extends BaseApiController
/** /**
* @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) {
@ -63,12 +66,13 @@ 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('自提点不能为空');
} }
@ -81,25 +85,37 @@ class RetailOrderController extends BaseApiController
$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) {
case PayEnum::WECHAT_PAY:
$user = User::where('id', $this->request->userId)->find(); $user = User::where('id', $this->request->userId)->find();
$res = RetailOrderLogic::payBalance($user, $order); $res = RetailOrderLogic::payBalance($user, $order);
if($res==true){ if (RetailOrderLogic::hasError()) {
$res = RetailOrderLogic::paySuccess($order, ['money' => $order['actual']]); $res = RetailOrderLogic::paySuccess($order, ['money' => $order['actual']]);
if($res){ if (RetailOrderLogic::hasError()) {
} else { } else {
return $this->fail(RetailOrderLogic::getError()); return $this->fail(RetailOrderLogic::getError());
} }
} else { } else {
return $this->fail(RetailOrderLogic::getError()); return $this->fail(RetailOrderLogic::getError());
} }
}elseif($pay_type==PayEnum::WECHAT_PAY){ break;
case PayEnum::WECHAT_PAY:
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
$result = PaymentLogic::pay($pay_type, 'cashierclass', $order, $this->userInfo['terminal'], $redirectUrl); $result = PaymentLogic::pay($pay_type, 'cashierclass', $order, $this->userInfo['terminal'], $redirectUrl);
if (false === $result) { if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params); return $this->fail(PaymentLogic::getError(), $params);
} }
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->data(['order_id' => $order->id]); return $this->data(['order_id' => $order->id]);
} else { } else {
@ -110,10 +126,12 @@ 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');
$auth_code = $this->request->post('auth_code'); //微信支付条码
$params = $this->request->post(); $params = $this->request->post();
$where = [ $where = [
'id' => $order_id, 'id' => $order_id,
@ -121,19 +139,21 @@ class RetailOrderController extends BaseApiController
'paid' => 0, 'paid' => 0,
]; ];
$order = Cashierclass::where($where)->find(); $order = Cashierclass::where($where)->find();
if($pay_type==PayEnum::BALANCE_PAY){ switch ($pay_type) {
case PayEnum::BALANCE_PAY:
$user = User::where('id', $this->request->userId)->find(); $user = User::where('id', $this->request->userId)->find();
$res = RetailOrderLogic::payBalance($user, $order); $res = RetailOrderLogic::payBalance($user, $order);
if($res==true){ if (!RetailOrderLogic::hasError()) {
$res = RetailOrderLogic::paySuccess($order, ['money' => $order['actual']]); $res = RetailOrderLogic::paySuccess($order, ['money' => $order['actual']]);
if($res){ 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:
}
}elseif($pay_type==PayEnum::WECHAT_PAY){
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
if ($addressId != $order['address_id']) { if ($addressId != $order['address_id']) {
$address = UserAddress::where(['address_id' => $addressId, 'uid' => Request()->userId])->find(); $address = UserAddress::where(['address_id' => $addressId, 'uid' => Request()->userId])->find();
@ -146,16 +166,26 @@ class RetailOrderController extends BaseApiController
} }
} }
$result = PaymentLogic::pay($pay_type, 'cashierclass', $order, $this->userInfo['terminal'], $redirectUrl); $result = PaymentLogic::pay($pay_type, 'cashierclass', $order, $this->userInfo['terminal'], $redirectUrl);
if (false === $result) { if (PaymentLogic::hasError()) {
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,
@ -172,7 +202,8 @@ class RetailOrderController extends BaseApiController
/** /**
* 获取用户常用购买记录 * 获取用户常用购买记录
*/ */
public function frequently_purchase(){ public function frequently_purchase()
{
$params = $this->request->get(); $params = $this->request->get();
$res = RetailOrderLogic::frequentlyPurchase($params); $res = RetailOrderLogic::frequentlyPurchase($params);
if (RetailOrderLogic::hasError()) { if (RetailOrderLogic::hasError()) {
@ -185,7 +216,8 @@ 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 = [
@ -205,7 +237,8 @@ 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,
@ -220,13 +253,13 @@ class RetailOrderController extends BaseApiController
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);
@ -235,6 +268,5 @@ class RetailOrderController extends BaseApiController
} 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

@ -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/eqhR2b3B1uv4TCFWr9ILGaU8H0cgOXOguznQrcBDJOjPLUZkpcDuxsyqzSaUnUfuw30HA9pQO8ssjxaVjdiOOH/cftQZJD4lTXub/vvi6hwzSHz9UAOIPDl4ZAgMBAAECggEAQxfxbfRHwCNc7Ofro4hUJcCSCsjkhwHPwmQtdn95XdMVR2G4SCLuQVDgS7lajQctcEkCoGwrtvj/mOcYUQ0aYE1b4n8Zlrr87Cob/fFB4HDUQ4+xWpytgMAkLfgQUAAfeIz1Ncnn4L9y1VXmUNuQDk8ilXMYIOczxkzWnD1Xv2FpBFEJRYcIuIFQbAU7HicMuYYf6tqm8FF5epRioci19qujlYg7wNZs7bgxVonIbT9aVhI173c47jrJ2j0S5LGK0IgALnLQE76cK4jvH+YSVUbfnsfz8QEmWGNofo7XWgGE3qfTdc+STzpg9m0xs5pjeU3nhk5efnEkZkLG8wOuiQKBgQD7zxNouoI8+NRAP9tUEg3OlW3sufx6Tn+IPeftzZNK0RPL/zqzbJ4BPZBtS9sdTUFQKipY9MQSxx7xG7o0o9NZUZ7LxDCCJMcMfCQ8XxWl2j7L/lpk4kR2b/r5gep3m3enWIpOOqKujMUaZGulMf8pQ4bXoXl87tlHwV8NQ89PkwKBgQDMXZqzNNWAq4BFFSjudIekdefqusbNNDX8UenCQfPhfQtuRpNZ9Mudk/UMloQEvJrDn6Z9yGjdWDnHXsmXFT1aElvUVYuqaU0PluI24XPyHkn3Q+PTR2rvWEPlneqlxiKb/VZPNaI3ziv1Jx0XB+IIu/IWJBorQKWw5CrpHQuvIwKBgQCJhX5EJBgc1IiWzkkqkPGZcWKndqu84EImVijkZvGaWrVFJA8bDqb8ZnMKPfNc/WQ+M8kM7CBpYPY1F7+KIC69CSaAgpU7fnp3BxWDIyrfeWHyZudXUXuyc1XODnXO/MlMS769GqjeS2MaFt3zSmrgTlDGUxnWcVuZJLKUvAPsoQKBgQC20J1M5lx/Z+us4Mrm1TNp+VdncYHZm3UXrCcScXE7K2MIWPYDqKpk4jB5/ENJAXbovG5xYs/8AapeIPrwvj1Nz9J51bTE0sHuyii+s1vHITVFjmPFYsPUK/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' => [