提交
This commit is contained in:
@@ -4,6 +4,7 @@ declare (strict_types=1);
|
||||
namespace app\miniapi\controller;
|
||||
|
||||
use app\miniapi\service\Order\OrderService;
|
||||
use app\miniapi\service\Order\UnpaidOrderPolicy;
|
||||
use app\miniapi\service\Payment\MiniPayService;
|
||||
|
||||
class Order extends Base
|
||||
@@ -89,6 +90,9 @@ class Order extends Base
|
||||
}
|
||||
|
||||
$money = $service->payMoney($order);
|
||||
if ($error = UnpaidOrderPolicy::paymentError($order)) {
|
||||
return $this->fail($error);
|
||||
}
|
||||
if ($money === '') {
|
||||
return $this->fail('订单金额异常');
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace app\miniapi\controller;
|
||||
|
||||
use app\miniapi\service\Payment\MiniPayService;
|
||||
use app\miniapi\service\Order\UnpaidOrderPolicy;
|
||||
use app\miniapi\service\VisaApplication\VisaApplicationService;
|
||||
|
||||
final class VisaApplication extends Base
|
||||
@@ -40,7 +41,7 @@ final class VisaApplication extends Base
|
||||
if ($appPayment !== []) $data['app_payment'] = $appPayment;
|
||||
else $data['payment_message'] = '当前服务暂不支持 App 支付,请稍后重试';
|
||||
} else {
|
||||
$pay = $this->paymentParameters($data, $input);
|
||||
$pay = $this->paymentParameters($data, $input, $userId);
|
||||
if ((int)($pay['code'] ?? 0) === 1) $data['pay'] = $pay['data'];
|
||||
else $data['payment_message'] = (string)($pay['msg'] ?? '支付参数暂不可用');
|
||||
}
|
||||
@@ -63,15 +64,22 @@ final class VisaApplication extends Base
|
||||
$appPayment = $this->appPaymentParameters($data, $this->safePublicBusiness((string)($input['business'] ?? '')));
|
||||
return $appPayment !== [] ? $this->ok(['order_sn' => $appPayment['order_sn'], 'app_payment' => $appPayment]) : $this->fail('当前服务暂不支持 App 支付,请稍后重试');
|
||||
}
|
||||
$pay = $this->paymentParameters($data, $input);
|
||||
$pay = $this->paymentParameters($data, $input, $userId);
|
||||
return (int)($pay['code'] ?? 0) === 1 ? $this->ok(['pay' => $pay['data']]) : $this->fail((string)($pay['msg'] ?? '支付参数暂不可用'));
|
||||
}
|
||||
private function paymentParameters(array $data, array $input): array
|
||||
private function paymentParameters(array $data, array $input, int $userId): array
|
||||
{
|
||||
$target = VisaApplicationService::nativePaymentForCheck($data);
|
||||
$openid = trim((string)($input['openid'] ?? ''));
|
||||
if (!$target || $openid === '') return ['code' => 0, 'msg' => $openid === '' ? '请重新登录后到我的申请支付' : '支付订单信息需核对'];
|
||||
try {
|
||||
// Check persisted order time, including retries of an already-submitted application.
|
||||
$detail = (new VisaApplicationService())->orderDetail($userId, [
|
||||
'business' => (string)($data['payment_business'] ?? $input['business'] ?? ''),
|
||||
'order_sn' => $target['order_sn'],
|
||||
]);
|
||||
if ((int)($detail['code'] ?? 0) !== 1) return ['code' => 0, 'msg' => '订单信息暂不可核验,请稍后重试'];
|
||||
if ($error = UnpaidOrderPolicy::paymentError((array)($detail['data'] ?? []))) return ['code' => 0, 'msg' => $error];
|
||||
return (new MiniPayService())->requestForTarget($this->currentMiniAppContext('visa'), $target['order_sn'], $target['money'], $openid, $target['target_table'], 'miniapi visa mini pay');
|
||||
} catch (\Throwable $e) { return ['code' => 0, 'msg' => '支付参数暂不可用,请到我的申请继续支付']; }
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace app\miniapi\service\CustomerCenter;
|
||||
|
||||
use api\Httpcurl;
|
||||
use app\miniapi\service\Order\UnpaidOrderPolicy;
|
||||
use think\facade\Log;
|
||||
|
||||
final class CustomerCenterService
|
||||
@@ -27,7 +28,7 @@ final class CustomerCenterService
|
||||
'pay_status' => $payStatus,
|
||||
'page' => max(1, $page),
|
||||
'page_size' => max(1, min(50, $pageSize)),
|
||||
]);
|
||||
] + ($payStatus === 'nopay' ? ['unpaid_since' => UnpaidOrderPolicy::cutoff()] : []));
|
||||
}
|
||||
|
||||
public function applicant(
|
||||
|
||||
38
app/miniapi/service/Order/UnpaidOrderPolicy.php
Normal file
38
app/miniapi/service/Order/UnpaidOrderPolicy.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\miniapi\service\Order;
|
||||
|
||||
final class UnpaidOrderPolicy
|
||||
{
|
||||
public static function cutoff(?\DateTimeImmutable $now = null): string
|
||||
{
|
||||
$now = ($now ?? new \DateTimeImmutable())->setTimezone(new \DateTimeZone('Asia/Shanghai'));
|
||||
// Match the legacy website list: include midnight fifteen calendar days ago.
|
||||
return $now->setTime(0, 0)->modify('-15 days')->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
public static function paymentError(array $detail, ?\DateTimeImmutable $now = null): string
|
||||
{
|
||||
$order = array_replace((array)($detail['order'] ?? []), $detail);
|
||||
if (in_array((string)($order['pay_status'] ?? ''), ['1', 'pay'], true)) {
|
||||
return '订单已支付,请刷新查看办理进度';
|
||||
}
|
||||
$raw = $order['reg_time'] ?? $order['order_created_at'] ?? $order['create_time'] ?? '';
|
||||
$text = is_scalar($raw) ? trim((string)$raw, " \t\r\n") : '';
|
||||
$timezone = new \DateTimeZone('Asia/Shanghai');
|
||||
if (preg_match('/^\d{10}(?:\d{3})?$/D', $text)) {
|
||||
$date = (new \DateTimeImmutable('@' . substr($text, 0, 10)))->setTimezone($timezone);
|
||||
} else {
|
||||
if (!preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/D', $text)) {
|
||||
return '订单时间异常,请联系客服核对';
|
||||
}
|
||||
$date = \DateTimeImmutable::createFromFormat('!Y-m-d H:i:s', $text, $timezone);
|
||||
if (!$date || $date->format('Y-m-d H:i:s') !== $text) {
|
||||
return '订单时间异常,请联系客服核对';
|
||||
}
|
||||
}
|
||||
return $date->format('Y-m-d H:i:s') < self::cutoff($now)
|
||||
? '订单已超过15天支付有效期,请重新提交申请' : '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user