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.

217 lines
6.5 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. namespace App\Controller\v3;
  3. use App\Constants\v3\OrderState;
  4. use App\Controller\BaseController;
  5. use App\Exception\BusinessException;
  6. use App\Model\v3\CcbPayment;
  7. use App\Model\v3\Order;
  8. use App\Service\v3\CcbPaymentService;
  9. use App\Service\v3\Interfaces\BadgeServiceInterface;
  10. use App\Service\v3\Interfaces\CouponRebateServiceInterface;
  11. use App\Service\v3\Interfaces\DeviceServiceInterface;
  12. use App\Service\v3\Interfaces\FeiePrintServiceInterface;
  13. use App\Service\v3\Interfaces\MiniprogramServiceInterface;
  14. use App\Service\v3\Interfaces\MqttServiceInterface;
  15. use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
  16. use App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
  17. use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
  18. use Hyperf\Di\Annotation\Inject;
  19. use Hyperf\Logger\LoggerFactory;
  20. use Hyperf\Utils\ApplicationContext;
  21. class CcbNotifyController extends BaseController
  22. {
  23. /**
  24. * @var \Psr\Log\LoggerInterface
  25. */
  26. private $logger;
  27. /**
  28. * @Inject
  29. * @var MqttServiceInterface
  30. */
  31. protected $mqttService;
  32. /**
  33. * @Inject
  34. * @var DeviceServiceInterface
  35. */
  36. protected $deviceService;
  37. /**
  38. * @Inject
  39. * @var MiniprogramServiceInterface
  40. */
  41. protected $miniprogramService;
  42. /**
  43. * @Inject
  44. * @var FeiePrintServiceInterface
  45. */
  46. protected $feiePrintService;
  47. /**
  48. * @Inject
  49. * @var CouponRebateServiceInterface
  50. */
  51. protected $couponRebateService;
  52. /**
  53. * @Inject
  54. * @var OrderOnlineServiceInterface
  55. */
  56. protected $orderOnlineService;
  57. /**
  58. * @Inject
  59. * @var SeparateAccountsServiceInterface
  60. */
  61. protected $separateAccountsService;
  62. /**
  63. * @Inject
  64. * @var BadgeServiceInterface
  65. */
  66. protected $badgeService;
  67. /**
  68. * @Inject
  69. * @var OrderStatisticsServiceInterface
  70. */
  71. protected $orderStatisticsService;
  72. public function __construct(LoggerFactory $loggerFactory)
  73. {
  74. parent::__construct();
  75. $this->logger = $loggerFactory->get('ccb.notify');
  76. }
  77. private function saveLog($func, $content)
  78. {
  79. $this->logger->info($func."\n".$content."\n");
  80. }
  81. public function pay()
  82. {
  83. try {
  84. $this->saveLog(__FUNCTION__, $this->request->getBody()->getContents());
  85. $data = $this->request->all();
  86. if (!isset($data['Main_Ordr_No'], $data['Sign_Inf'])) {
  87. throw new BusinessException(500, '缺少参数');
  88. }
  89. $ccb = ApplicationContext::getContainer()->get(CcbPaymentService::class);
  90. if (!$ccb->verifySign($ccb->createSign($data), $data['Sign_Inf'])) {
  91. throw new BusinessException(500, '验签失败');
  92. }
  93. $model = CcbPayment::where('main_ordr_no', $data['Main_Ordr_No'])->first();
  94. if (!$model) {
  95. throw new BusinessException(500, '下单记录不存在');
  96. }
  97. $payResult = $ccb->gatherEnquireOrder($data['Main_Ordr_No']);
  98. if ($payResult['Ordr_Stcd'] != $data['Ordr_Stcd']) {
  99. throw new BusinessException(500, '订单状态不一致');
  100. }
  101. // 状态已同步
  102. if ($model->ordr_stcd == $data['Ordr_Stcd']) {
  103. return $this->response->json([
  104. 'Svc_Rsp_St' => '00',
  105. ]);
  106. }
  107. $model->ordr_stcd = $data['Ordr_Stcd'];
  108. $model->pay_time = $data['Pay_Time'];
  109. $model->pay_type = $data['TYPE'];
  110. $model->pay_channel = $data['PAY_CHANNEL'];
  111. $model->debit_credit_type = $data['DEBIT_CREDIT_TYPE'];
  112. $model->save();
  113. if ($payResult['Ordr_Stcd'] == '2') {
  114. $orderMain = $model->orderMain;
  115. if ($orderMain->state != OrderState::UNPAID) {
  116. throw new BusinessException(500, '订单状态异常');
  117. }
  118. $this->orderOnlineService->doByPaid($orderMain->global_order_id);
  119. $this->separateAccountsService->orderOnlinePaid($orderMain->global_order_id);
  120. //记录当前市场的当天外卖订单数
  121. $this->orderStatisticsService->setForMarket($orderMain->market_id);
  122. // 优惠券返券
  123. $this->couponRebateService->couponRebateInTask($orderMain->global_order_id);
  124. // 喇叭通知,兼容旧音响,MQTT+IOT
  125. $res = $this->mqttService->speakToStore($orderMain->global_order_id);
  126. $res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMain->global_order_id);
  127. // 打印订单,自动打印
  128. $res = $this->feiePrintService->feiePrint($orderMain->global_order_id);
  129. // 记录badge
  130. $orderChildIds = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->pluck('store_id');
  131. $this->badgeService->doByOrder($orderMain->user_id, $orderChildIds, $orderMain->global_order_id, OrderState::PAID);
  132. // 公众号模板消息
  133. $res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMain->global_order_id);
  134. }
  135. return $this->response->json([
  136. 'Svc_Rsp_St' => '00',
  137. ]);
  138. } catch (\Exception $e) {
  139. return $this->response->json([
  140. 'Svc_Rsp_St' => '01',
  141. 'Rsp_Inf' => $e instanceof BusinessException ? $e->getMessage() : '内部错误'
  142. ]);
  143. }
  144. }
  145. public function refund()
  146. {
  147. $this->saveLog(__FUNCTION__, $this->request->getBody()->getContents());
  148. return $this->response->json([
  149. 'Svc_Rsp_St' => '00',
  150. ]);
  151. }
  152. public function merchant()
  153. {
  154. $this->saveLog(__FUNCTION__, $this->request->getBody()->getContents());
  155. return $this->response->json([
  156. 'Svc_Rsp_St' => '00',
  157. ]);
  158. }
  159. public function accounting()
  160. {
  161. $this->saveLog(__FUNCTION__, $this->request->getBody()->getContents());
  162. return $this->response->json([
  163. 'Svc_Rsp_St' => '00',
  164. ]);
  165. }
  166. public function bill()
  167. {
  168. $this->saveLog(__FUNCTION__, $this->request->getBody()->getContents());
  169. return $this->response->json([
  170. 'Svc_Rsp_St' => '00',
  171. ]);
  172. }
  173. public function platform()
  174. {
  175. $this->saveLog(__FUNCTION__, $this->request->getBody()->getContents());
  176. return $this->response->json([
  177. 'Svc_Rsp_St' => '00',
  178. ]);
  179. }
  180. }