99 lines
2.8 KiB
PHP
99 lines
2.8 KiB
PHP
<?php
|
|
|
|
|
|
namespace app\common\logic;
|
|
|
|
|
|
use app\common\enum\PayEnum;
|
|
use app\common\model\user\UserAuth;
|
|
use app\common\service\pay\PayService;
|
|
|
|
/**
|
|
* 支付逻辑
|
|
* Class PaymentLogic
|
|
* @package app\common\logic
|
|
*/
|
|
class PaymentLogic extends BaseLogic
|
|
{
|
|
|
|
/**
|
|
* @notes 支付
|
|
* @param $payWay
|
|
* @param $from
|
|
* @param $order
|
|
* @param $terminal
|
|
* @param $redirectUrl
|
|
* @return array|false|mixed|string
|
|
* @author 段誉
|
|
* @date 2023/2/28 12:15
|
|
*/
|
|
public static function pay($payWay, $from, $order, $terminal, $redirectUrl)
|
|
{
|
|
// 支付编号-仅为微信支付预置(同一商户号下不同客户端支付需使用唯一订单号)
|
|
$paySn = $order['number'];
|
|
if ($order['actual'] == 0) {
|
|
PayNotifyLogic::handle($from, $order['number']);
|
|
return ['pay_way' => PayEnum::BALANCE_PAY];
|
|
}
|
|
switch ($payWay) {
|
|
case PayEnum::WECHAT_PAY:
|
|
$auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty();
|
|
$order = [
|
|
'out_trade_no' => $paySn,
|
|
'description' => '商品',
|
|
'amount' => [
|
|
'total' => intval($order['actual'] * 100),
|
|
'currency' => 'CNY',
|
|
],
|
|
"payer" => [
|
|
"openid" => $auth['openid'] ?? 0
|
|
],
|
|
'attach' => $from
|
|
];
|
|
$wechat = new PayService(1);
|
|
$result = $wechat->wechat->mini($order)->toArray();
|
|
break;
|
|
default:
|
|
self::$error = '订单异常';
|
|
$result = false;
|
|
}
|
|
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['merchant']
|
|
]
|
|
],
|
|
];
|
|
$wechat = new PayService(1);
|
|
try {
|
|
$result = $wechat->wechat->pot($order)->toArray();
|
|
} catch (\Exception $e) {
|
|
self::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
return $result;
|
|
}
|
|
}
|