You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.5 KiB

6 years ago
  1. <?php
  2. namespace App\Controller;
  3. use App\Constants\LogLabel;
  4. use App\Model\OrderMain;
  5. use EasyWeChat\Factory;
  6. use Hyperf\Guzzle\CoroutineHandler;
  7. class NotifyController extends BaseController
  8. {
  9. public function wxminiOnline()
  10. {
  11. $config = config('wxpay');
  12. $app = Factory::payment($config);
  13. $app['guzzle_handler'] = CoroutineHandler::class;
  14. // 通知回调,进行业务处理
  15. $response = $app->handlePaidNotify(function ($message, $fail) use ($app) {
  16. $this->log->event(
  17. LogLabel::PAY_NOTIFY_WXMINI,
  18. $message
  19. );
  20. // 查询订单
  21. $orderMain = OrderMain::query()
  22. ->where(['global_order_id' => $message['out_trade_no'], 'type' => OrderMain::ORDER_TYPE_ONLINE, 'state' => OrderMain::ORDER_STATE_UNPAY])
  23. ->where('time', '>=', date('Y-m-d H:i:s', (time()-900)))
  24. ->first();
  25. if (empty($orderMain)) {
  26. // 去查一下微信订单
  27. $wxOrder = $app->order->queryByOutTradeNumber($orderMain->global_order_id);
  28. $this->log->event(
  29. LogLabel::PAY_NOTIFY_WXMINI,
  30. $wxOrder
  31. );
  32. // return true;
  33. }
  34. // 修改订单、子订单状态
  35. // 更新销量、商品库存,新增月销数据
  36. });
  37. $response->send();
  38. }
  39. public function wxminiOffline()
  40. {
  41. $config = config('wxpay');
  42. $app = Factory::payment($config);
  43. $app['guzzle_handler'] = CoroutineHandler::class;
  44. // 通知回调,进行业务处理
  45. $response = $app->handlePaidNotify(function ($message, $fail) use ($app) {
  46. $this->log->event(
  47. LogLabel::PAY_NOTIFY_WXMINI,
  48. $message
  49. );
  50. // 查询订单
  51. $orderMain = OrderMain::query()
  52. ->where(['global_order_id' => $message['out_trade_no'], 'type' => OrderMain::ORDER_TYPE_OFFLINE, 'state' => OrderMain::ORDER_STATE_UNPAY])
  53. ->where('time', '>=', date('Y-m-d H:i:s', (time()-900)))
  54. ->first();
  55. if (empty($orderMain)) {
  56. // 去查一下微信订单
  57. $wxOrder = $app->order->queryByOutTradeNumber($orderMain->global_order_id);
  58. $this->log->event(
  59. LogLabel::PAY_NOTIFY_WXMINI,
  60. $wxOrder
  61. );
  62. // return true;
  63. }
  64. });
  65. $response->send();
  66. }
  67. }