Notify.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace app\controller\mini;
  3. use app\extra\basic\Base;
  4. use app\model\saas\SaasGoods;
  5. use app\model\saas\SaasOrderLife;
  6. use LinFly\Annotation\Route\Controller;
  7. use LinFly\Annotation\Route\Route;
  8. use support\Request;
  9. use support\Response;
  10. #[Controller(prefix: "/notify")]
  11. class Notify extends Base
  12. {
  13. /**
  14. * 核销工具解决方案-spi
  15. * @param Request $request
  16. * @return Response
  17. */
  18. #[Route(path: "pay",methods: "post")]
  19. public function getPayStatue(Request $request): Response
  20. {
  21. try {
  22. $param = $request->post();
  23. echo getDateFull()."==支付结果回调==\n";
  24. print_r($param);
  25. return json([
  26. "err_no" => 0,
  27. "err_tips" => "success"
  28. ]);
  29. } catch (\Throwable $throwable) {
  30. return error($throwable->getMessage());
  31. }
  32. }
  33. /**
  34. * 核销工具解决方案-spi
  35. * @param Request $request
  36. * @return Response
  37. */
  38. #[Route(path: "mini",methods: "post")]
  39. public function getSpiData(Request $request): Response
  40. {
  41. try {
  42. $param = $request->post();
  43. echo getDateFull()."=={$param['type']}==\n";
  44. print_r($param);
  45. return json([
  46. "err_no" => 0,
  47. "err_tips" => "success"
  48. ]);
  49. } catch (\Throwable $throwable) {
  50. return error($throwable->getMessage());
  51. }
  52. }
  53. /**
  54. * 核销工具解决方案-扩展点-spi
  55. * @param Request $request
  56. * @return Response
  57. */
  58. #[Route(path: "expand",methods: "post")]
  59. public function getExpandData(Request $request): Response
  60. {
  61. try {
  62. $param = $request->post();
  63. switch ($param['type'])
  64. {
  65. case "pre_create_order": // 预下单回调
  66. $orderData = json_decode($param['msg']);
  67. $orderGoods = (new SaasGoods)->where("out_id",$orderData['goods'][0]['goods_id'])->findOrEmpty();
  68. if ($orderGoods->isEmpty()) return json([
  69. "err_no" => 0,
  70. "err_tips" => "success"
  71. ]);
  72. (new SaasOrderLife)->insertGetId([
  73. "open_id" => $orderData['open_id'],
  74. "agent_id" => $orderGoods['agent_id'],
  75. "store_id" => $orderGoods['agent_id'],
  76. "order_id" => $orderData['order_id'],
  77. "product_name" => $orderData['goods'][0]['title'],
  78. "product_img" => $orderData['goods'][0]['img_url'],
  79. "out_id" => $orderData['goods'][0]['goods_id'],
  80. "order_amount" => $orderData['goods'][0]['price'],
  81. "pay_amount" => $orderData['goods'][0]['price'],
  82. "count" => $orderData['goods'][0]['quantity'],
  83. "status" => 0
  84. ]);
  85. return json([
  86. "out_order_no" => $orderData['order_id'],
  87. "order_entry_schema" => [
  88. "path" => "page/order/detail",
  89. "params" => ['order' => $orderData['order_id']]
  90. ],
  91. "pay_notify_url" => "https://hx-mini-api.jsshuita.com.cn/notify/pay"
  92. ]);
  93. break;
  94. case "pre_create_refund": // 退款审核回调
  95. break;
  96. }
  97. echo getDateFull()."=={$param['type']}==\n";
  98. print_r($param);
  99. return json([
  100. "err_no" => 0,
  101. "err_tips" => "success"
  102. ]);
  103. } catch (\Throwable $throwable) {
  104. return error($throwable->getMessage());
  105. }
  106. }
  107. }