OrderData.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. namespace app\extra\dyLife\data;
  3. use app\extra\dyLife\BasicLife;
  4. /**
  5. * 订单相关
  6. */
  7. class OrderData extends BasicLife
  8. {
  9. /**
  10. * 通过订单ID获取 encrypted_code
  11. * https://developer.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/general-capabilities/life.capacity.fulfilment/certificate.query
  12. * @param string $orderId
  13. * @param string $accountId
  14. * data['certificates'][0]['encrypted_code']
  15. * @return array
  16. */
  17. public function getCertificate(string $orderId = "",string $accountId = ""): array
  18. {
  19. $param = [
  20. "account_id" => $accountId,
  21. "order_id" => $orderId
  22. ];
  23. return $this->curlPostApi("goodlife/v1/fulfilment/certificate/query/",$param);
  24. }
  25. /**
  26. * 查询订单详情
  27. * @param string $orderId
  28. * @return array
  29. */
  30. public function getOrderData(string $orderId = ""): array
  31. {
  32. $param = [
  33. "account_id" => $this->baseAccountId,
  34. "order_id" => $orderId,
  35. "page_num" => 1,
  36. "page_size" => 10
  37. ];
  38. return $this->curlPostApi("goodlife/v1/trade/order/query/",$param);
  39. }
  40. /**
  41. * 发起核销
  42. * https://developer.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/general-capabilities/life.capacity.fulfilment/certificate.verify
  43. * @param array $data
  44. * data['verify_results'][0]
  45. * certificate_id、verify_id
  46. * @return array
  47. */
  48. public function verifyCertificate(array $data = []): array
  49. {
  50. $param = [
  51. "account_id" => $data['account_id'],
  52. "verify_token" => $data['pay_sn'],
  53. "encrypted_codes" => $data['encrypted_code'],
  54. "order_id" => $data['order_id'],
  55. "poi_id" => $data['poi_id']
  56. ];
  57. return $this->curlPostApi("goodlife/v1/fulfilment/certificate/verify/",$param);
  58. }
  59. /**
  60. * 撤销核销
  61. * https://developer.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/general-capabilities/life.capacity.fulfilment/certificate.cancel
  62. * @param array $data
  63. * data['cancel_results'][0]
  64. * result_code
  65. * @return array
  66. */
  67. public function cancelCertificate(array $data = []): array
  68. {
  69. $param = [
  70. "certificate_id" => $data['certificate_id'],
  71. "verify_id" => $data['verify_id'],
  72. "account_id" => $data['account_id']
  73. ];
  74. return $this->curlPostApi("goodlife/v1/fulfilment/certificate/verify/",$param);
  75. }
  76. /**
  77. * 订单退款
  78. * https://developer.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/general-capabilities/groupon-refund/order-refund-apply
  79. * @param string $orderId
  80. * @param array $codeList
  81. * @return array
  82. */
  83. public function cancelOrder(string $orderId = "",array $codeList = []): array
  84. {
  85. $param = [
  86. "refund_reason_code" => [305],
  87. "order_id" => $orderId,
  88. "certificate_id_list" => $codeList,
  89. "account_id" => $this->baseAccountId
  90. ];
  91. echo "手动退款参数\n";
  92. print_r($param);
  93. return $this->curlPostApi("goodlife/v1/groupon/order/refund/apply/",$param);
  94. }
  95. /**
  96. * 开发者发起退款
  97. * https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/locallife/general-ability/agency-trade-system/refund/apply
  98. */
  99. public function refundOrderOp(array $data = []): array
  100. {
  101. $param = [
  102. "out_order_no" => $data['out_order_no'], // AL开头订单号
  103. "out_refund_no" => $data['out_order_no']."1",
  104. "order_entry_schema" => [
  105. "path" => "pages/order/detail",
  106. "params" => json_encode(['order' => $data['out_order_no']])
  107. ],
  108. "notify_url" => "https://tran.jsshuita.cn/notify/refund",
  109. "item_order_detail" => [
  110. [
  111. "item_order_id" => $data['item_order_id'],
  112. ]
  113. ]
  114. ];
  115. return $this->curlPostApi("api/apps/trade/v2/refund/create_refund",$param);
  116. }
  117. /**
  118. * 小程序版核销 - 三方码
  119. * https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/locallife/general-ability/agency-trade-system/fulfillment/third-code/push-delivery
  120. * @param array $data
  121. * @return array
  122. * {
  123. * "data": {
  124. * "verify_results": [
  125. * {
  126. * "certificate_id": "7676385765337382962",
  127. * "item_order_id": "800014550969473945813031711",
  128. * "verify_id": "7676388522927933482",
  129. * "verify_time": 1787298487000
  130. * }
  131. * ],
  132. * "error_code": 0,
  133. * "description": ""
  134. * },
  135. * }
  136. */
  137. public function verifyOrder(array $data = []): array
  138. {
  139. $param = [
  140. "delivery_status" => 2,
  141. "item_order_list" => [
  142. [
  143. "item_order_id" => $data['item_order_id'],
  144. ]
  145. ],
  146. "poi_info" => json_encode([
  147. "shop_name" => $data['poi']['poi_name'],
  148. "ext_valid_shop_id" => $data['poi']['poi_id'],
  149. "valid_poi_id_str" => $data['poi']['poi_id'],
  150. ]),
  151. "out_order_no" => $data['out_order_no'],
  152. "use_all" => true
  153. ];
  154. return $this->curlPostApi("api/apps/trade/v2/fulfillment/push_delivery/",$param);
  155. }
  156. /**
  157. * 退款审核推送
  158. * https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/locallife/general-ability/agency-trade-system/refund/audit-callback
  159. * @param array $data
  160. * @return array
  161. */
  162. public function auditOrder(array $data = []): array
  163. {
  164. $param = [
  165. "out_refund_no" => "R".$data['out_order_no'],
  166. "refund_audit_status" => 1
  167. ];
  168. return $this->curlPostApi("api/apps/trade/v2/refund/merchant_audit_callback",$param);
  169. }
  170. }