Solution.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\controller\api;
  3. use app\extra\basic\Base;
  4. use app\extra\dyLife\Token;
  5. use app\extra\dyMini\Relation;
  6. use app\extra\tools\CodeExtend;
  7. use app\middleware\AuthMiddleware;
  8. use app\model\saas\SaasGoods;
  9. use app\model\saas\SaasOrder;
  10. use LinFly\Annotation\Attributes\Route\Controller;
  11. use LinFly\Annotation\Attributes\Route\GetMapping;
  12. use LinFly\Annotation\Attributes\Route\RequestMapping;
  13. use support\Request;
  14. use support\Response;
  15. /**
  16. * 解决方案回传
  17. */
  18. #[Controller("/solution")]
  19. class Solution extends Base
  20. {
  21. #[RequestMapping(path: "notify")]
  22. public function getSolutionData(Request $request): Response
  23. {
  24. try {
  25. $data = $request->all();
  26. echo getDateFull()."===扩展回调\n";
  27. print_r($data);
  28. if (isset($data['operate_type'])) {
  29. if ($data['status'] == "PASS") { // 创建商品回调
  30. $goods = (new SaasGoods)->where("goods_id",$data['product_id'])->findOrEmpty();
  31. if ($goods->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
  32. $goods->status = 1;
  33. $goods->save();
  34. }
  35. }
  36. if (isset($data['type']))
  37. {
  38. $msgData = json_decode($data['msg'],true);
  39. switch ($data['type'])
  40. {
  41. case "pre_create_order": // 预下单
  42. if (!isset($msgData['item_order_info_list'][0]['goods_id'])) return json(['err_no' => 0,"err_tips" => "success"]);
  43. $goods = (new SaasGoods)->where("goods_id",$msgData['item_order_info_list'][0]['goods_id'])->findOrEmpty();
  44. if ($goods->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
  45. $order = (new SaasOrder)->where("order_sn",$msgData['order_id'])->findOrEmpty();
  46. if (!$order->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
  47. $orderSn = "AL".CodeExtend::uniqidDate(18).rand(100,999);
  48. $goodsImg = is_string($goods['image_list'])?json_decode($goods['image_list'],true):[];
  49. $order->insertGetId([
  50. "out_order_no" => $orderSn,
  51. "order_sn" => $msgData['order_id'],
  52. "openid" => $msgData['open_id'],
  53. "goods_id" => $goods['id'],
  54. "life_goods_id" => $goods['goods_id'],
  55. "product_id" => $goods['product_id'],
  56. "sku_id" => "",
  57. "number" => $msgData['goods'][0]['quantity']??1,
  58. "price" => $msgData['item_order_info_list'][0]['price']?:$goods['price'],
  59. "line_price" => $goods['line_price']*100,
  60. "poi_id" => $goods['poi_id'],
  61. "img" => $goodsImg[0]['url'],
  62. "sku_name" => "",
  63. "mobile" => $msgData['phone_num']??'',
  64. "pay_money" => $msgData['total_amount']??0,
  65. ]);
  66. return json(['err_no' => 0,"err_tips" => "success","data" => [
  67. "order_entry_schema" => [
  68. "path" => "page/order/detail",
  69. "params" => json_encode([
  70. "order" => $orderSn
  71. ])
  72. ],
  73. "out_order_no" => $orderSn,
  74. "pay_expire_seconds" => 300,
  75. "pay_notify_url" => "https://tran.jsshuita.cn/notify/douyin"
  76. ]]);
  77. break;
  78. default:
  79. break;
  80. }
  81. }
  82. return json(['err_no' => 0,"err_tips" => "success"]);
  83. } catch (\Throwable $throwable) {
  84. return error($throwable->getMessage());
  85. }
  86. }
  87. #[GetMapping("token")]
  88. public function setTestToken(Request $request): Response
  89. {
  90. try {
  91. $param = $this->_valid([
  92. "code.require" => ""
  93. ]);
  94. if (!is_array($param)) return error($param);
  95. $data = (new Token)->config($this->getDyConfig())->token()->getAccessTokenUser($param['code']);
  96. return success("ok",$data);
  97. } catch (\Throwable $throwable) {
  98. return error($throwable->getMessage());
  99. }
  100. }
  101. #[GetMapping("test")]
  102. public function setTest()
  103. {
  104. try {
  105. $data = (new Relation)->config($this->getDyConfig())->token()->createOrderFirst(['1865253598118939']);
  106. return success("ok",$data);
  107. } catch (\Throwable $throwable) {
  108. return error($throwable->getMessage());
  109. }
  110. }
  111. }