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/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/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/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index e37f97f22..9184b6019 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -280,6 +280,10 @@ 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(); + PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'cash_register', 'msg' => '您有一笔订单已支付', 'data' => $extra]); + } return true; } @@ -461,12 +465,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..d5b269ac7 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -25,10 +25,12 @@ 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; use think\Exception; +use think\facade\Db; use Webman\RedisQueue\Redis; /** @@ -246,6 +248,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 +321,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']]); @@ -501,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('订单支付中'); + } + } } 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 ], 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); + } + } + } + }); } }