From 4bc80929311dc59abfe207e5f349beaa2b6ef078 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 31 Jul 2024 11:11:49 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(ExceptionHandler):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E4=BB=A5=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ExceptionHandler.php | 4 +--- app/common/cache/UserAccountSafeCache.php | 2 +- config/log.php | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/ExceptionHandler.php b/app/ExceptionHandler.php index 8cfa3719a..179dd0a7f 100644 --- a/app/ExceptionHandler.php +++ b/app/ExceptionHandler.php @@ -20,9 +20,7 @@ class ExceptionHandler extends Handler { if ($exception instanceof Dumper) { return \response(self::convertToHtml($exception)); - } elseif ($exception instanceof ErrorException) { - return response($exception->getMessage(), 401); - } elseif ($exception instanceof BusinessException) { + }elseif ($exception instanceof BusinessException) { return response($exception->getMessage()); } elseif ($exception instanceof \Exception) { $isDebug = config('app.debug'); diff --git a/app/common/cache/UserAccountSafeCache.php b/app/common/cache/UserAccountSafeCache.php index 2061ecb39..53cc1d5a2 100644 --- a/app/common/cache/UserAccountSafeCache.php +++ b/app/common/cache/UserAccountSafeCache.php @@ -20,7 +20,7 @@ class UserAccountSafeCache extends BaseCache public function __construct() { parent::__construct(); - $ip = \request()->getLocalIp(); + $ip = \request()->getRealIp(); $this->key = $this->tagName . $ip; } diff --git a/config/log.php b/config/log.php index 59727598f..b6c0e6c59 100644 --- a/config/log.php +++ b/config/log.php @@ -20,7 +20,7 @@ return [ 'constructor' => [ runtime_path() . '/logs/'.date('Ym').'/.log', 2048, - Monolog\Logger::NOTICE, + Monolog\Logger::INFO, true, 0755 ], From 27a71efb076d868097b6e5d791c4ff3566a9c438 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 31 Jul 2024 11:25:55 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E6=94=AF=E4=BB=98=E7=A0=81=E6=94=AF=E4=BB=98=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/order/OrderController.php | 1 + app/common/logic/PayNotifyLogic.php | 5 ++- .../store_order/StoreOrderController.php | 3 ++ process/Task.php | 44 +++++++++---------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 3fbb8e1fb..68b9790db 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -292,6 +292,7 @@ class OrderController extends BaseApiController if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result); } else { + Db::name('wechat_micropay')->insert(['order_id'=>$order['order_id'],'create_time'=>time(),'update_time'=>time()]); Redis::send('send-code-pay', ['order_id' => $order['order_id']]); return $this->success('用户支付中'); } diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index e37f97f22..10792981a 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -280,6 +280,9 @@ class PayNotifyLogic extends BaseLogic if (!empty($extra['payer']['openid']) && $order->pay_type == 7) { Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid']], 4); } + if($order['pay_type']==9){ + Db::name('wechat_micropay')->where(['order_id'=>$order['order_id']])->delete(); + } return true; } @@ -461,12 +464,12 @@ class PayNotifyLogic extends BaseLogic $uid = $order['other_uid']; } - PushService::push('wechat_mmp_' . $uid, $uid, ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]); PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]); if (!empty($extra['payer']['openid'])) { Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 4); } + Db::name('wechat_micropay')->where(['order_id'=>$order['order_id']])->delete(); return true; } diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 5cf8e9560..37b1bd220 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -29,6 +29,7 @@ use app\store\validate\store_order\StoreOrderValidate; use support\Cache; use support\Log; use think\Exception; +use think\facade\Db; use Webman\RedisQueue\Redis; /** @@ -246,6 +247,7 @@ class StoreOrderController extends BaseAdminController Log::error(json_encode($result)); PayNotifyLogic::handle('wechat_common', $result['out_trade_no'], $result); } else { + Db::name('wechat_micropay')->insert(['order_id'=>$order['order_id'],'create_time'=>time(),'update_time'=>time()]); Redis::send('send-code-pay', ['order_id' => $order['order_id']]); return $this->success('用户支付中'); } @@ -318,6 +320,7 @@ class StoreOrderController extends BaseAdminController PayNotifyLogic::handle('wechat_common', $result['out_trade_no'], $result); } else { Redis::send('send-code-pay', ['order_id' => $order['order_id']]); + Db::name('wechat_micropay')->insert(['order_id'=>$order['order_id'],'create_time'=>time(),'update_time'=>time()]); return $this->success('用户支付中'); } return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id'], 'id' => $order['id']]); diff --git a/process/Task.php b/process/Task.php index 0d5b35169..70503c56f 100644 --- a/process/Task.php +++ b/process/Task.php @@ -63,27 +63,27 @@ class Task } }); //每10秒执行一次 - // new Crontab('*/10 * * * * *', function () { - // $select=Db::name('wechat_micropay')->limit(100)->select(); - // $pay = new PayService(); - // foreach ($select as $k=>$v) { - // $time = time(); - // if ($time - $v['create_time'] > 60){ - // Db::name('wechat_micropay')->where('id',$v['id'])->delete(); - // continue; - // } - // $order = [ - // 'out_trade_no' => $v['order_id'], - // ]; - // $res = $pay->wechat->query($order); - // if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') { - // if(isset($data['pay_type']) && $data['pay_type']=='recharge'){ - // PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res); - // }else{ - // PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res); - // } - // } - // } - // }); + new Crontab('*/10 * * * * *', function () { + $select=Db::name('wechat_micropay')->limit(100)->select(); + $pay = new PayService(); + foreach ($select as $k=>$v) { + $time = time(); + if ($time - $v['create_time'] > 60){ + Db::name('wechat_micropay')->where('id',$v['id'])->delete(); + continue; + } + $order = [ + 'out_trade_no' => $v['order_id'], + ]; + $res = $pay->wechat->query($order); + if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') { + if(isset($data['pay_type']) && $data['pay_type']=='recharge'){ + PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res); + }else{ + PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res); + } + } + } + }); } } From 64821a9a3b4cf9c12db96a85e7c3310cd9c6e7aa Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 31 Jul 2024 11:44:39 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat(PayNotifyLogic):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=94=AF=E4=BB=98=E6=88=90=E5=8A=9F=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E9=80=9A=E7=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/PayNotifyLogic.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 10792981a..9184b6019 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -282,6 +282,7 @@ class PayNotifyLogic extends BaseLogic } if($order['pay_type']==9){ Db::name('wechat_micropay')->where(['order_id'=>$order['order_id']])->delete(); + PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); } return true; } From 1df7f8740a657f492e36b759afda9a5c41708b7d Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 31 Jul 2024 11:59:49 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat(store=5Forder):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AE=A2=E5=8D=95=E6=94=AF=E4=BB=98=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store_order/StoreOrderController.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 37b1bd220..d5b269ac7 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -25,6 +25,7 @@ use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStoreStaff; use app\common\model\user_recharge\UserRecharge; +use app\common\service\pay\PayService; use app\store\validate\store_order\StoreOrderValidate; use support\Cache; use support\Log; @@ -504,4 +505,41 @@ class StoreOrderController extends BaseAdminController } return $this->success('获取成功', $find?->toArray()); } + + /** + * @notes 查询订单支付状态 + */ + public function wechatQuery() + { + $order_no = $this->request->get('order_no'); + $order = [ + 'out_trade_no' => $order_no, + ]; + $app = new PayService(0); + + try { + $res = $app->wechat->query($order); + } catch (\Exception $e) { + return $this->fail($e->extra['message'] ?? $e->getMessage()); + } + if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') { + $attach = $res['attach']; + switch ($attach) { + case 'recharge': + PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res); + $app->wechat->success(); + break; + case 'wechat_common': + PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res); + $app->wechat->success(); + break; + default: + Log::error('支付回调失败,订单号:' . $res['out_trade_no'], $res); + break; + } + return $this->success('支付成功'); + } else { + return $this->fail('订单支付中'); + } + } }