链街Dcat后台
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.

167 lines
5.3 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Admin\Common;
  3. use Graze\GuzzleHttp\JsonRpc\Client;
  4. class Rpc
  5. {
  6. const SEPARATE_ACCOUNTS = "/orders/onlineComplete";//订单完成
  7. const ORDER_REFUND = "/orders/onlineRefund";//整笔订单退款
  8. const ORDER_SINGLE_REFUND = "/orders/onlineSingleRefund";//订单单个商品退款
  9. const GET_DISTANCE = "/location/getDistanceByTencent";//获取骑行距离
  10. const DO_BY_ORDER = "/badge/doByOrder";//订单状态变更
  11. const ALI_SMS_SENT = "/alisms/sent";//发短信
  12. const FEI_E_PRINT = '/feie/doPrint';//订单打印
  13. const ORDER_DELIVERY_START= '/orders/onlineDeliveryStart';//订单打印
  14. /**
  15. * 订单完成时分账流水
  16. * @param $oid
  17. * @param $uid
  18. * @return string
  19. */
  20. public static function doByOrder($userId, $storeIds, $globalOrderId, $orderState){
  21. $client = Client::factory(env('RPC_SITE_HOST'));
  22. $request = $client->request(
  23. uniqid(),
  24. self::DO_BY_ORDER,
  25. ['userId' => $userId,'storeIds'=>$storeIds,'globalOrderId'=>$globalOrderId,'orderState'=>$orderState]);
  26. $response = $client->send($request);
  27. return $response->getBody()->getContents();
  28. }
  29. /**
  30. * 订单完成时分账流水
  31. * @param $oid
  32. * @param $uid
  33. * @return string
  34. */
  35. public static function separateAccounts($global_order_id,$uid){
  36. $client = Client::factory(env('RPC_SITE_HOST'));
  37. $request = $client->request(
  38. uniqid(),
  39. self::SEPARATE_ACCOUNTS,
  40. ['global_order_id' => $global_order_id,'user_id'=>$uid]);
  41. $response = $client->send($request);
  42. return $response->getBody()->getContents();
  43. }
  44. /**
  45. * 订单整笔退款
  46. * @param $global_order_id
  47. * @param $uid
  48. * @return string
  49. */
  50. public static function orderRefund($global_order_id,$uid){
  51. $client = Client::factory(env('RPC_SITE_HOST'));
  52. $request = $client->request(
  53. uniqid(),
  54. self::ORDER_REFUND,
  55. ['global_order_id' => $global_order_id,'user_id'=>$uid]);
  56. $response = $client->send($request);
  57. return $response->getBody()->getContents();
  58. }
  59. /**
  60. * @param $lng1
  61. * @param $lat1
  62. * @param $lng2
  63. * @param $lat2
  64. * @return mixed
  65. */
  66. public static function getDistance($lng1, $lat1, $lng2, $lat2){
  67. $client = Client::factory(env('RPC_SITE_HOST'));
  68. $request = $client->request(
  69. uniqid(),
  70. self::GET_DISTANCE,
  71. ['lng1' => $lng1,'lat1'=>$lat1,'lng2'=>$lng2,'lat2'=>$lat2]);
  72. $response = $client->send($request);
  73. return json_decode($response->getBody()->getContents(),true);
  74. }
  75. /**
  76. * 线上订单单笔退款,主要用于后台强行操作退单退款
  77. * 支持单商品、单店、整单
  78. * 按比例计算红包进行退款
  79. * 比如:两个子订单和子订单商品,分别是2元,98元,使用了10元优惠券
  80. * 退2元商品时,退款金额为
  81. * 红包 (2/(98+2)*10 = 0.2
  82. * 退款:2-0.2=1.8
  83. * @param $user_id
  84. * @param $note
  85. * @param $global_order_id
  86. * @param null $order_child_id
  87. * @param null $order_goods_id
  88. * @return mixed
  89. */
  90. public static function onlineSingleRefund($user_id, $note, $global_order_id, $order_child_id=null, $order_goods_id=null){
  91. $client = Client::factory(env('RPC_SITE_HOST'));
  92. $request = $client->request(
  93. uniqid(),
  94. self::ORDER_SINGLE_REFUND,
  95. [
  96. 'user_id' => $user_id,
  97. 'note'=>$note,
  98. 'global_order_id'=>$global_order_id,
  99. 'order_child_id'=>$order_child_id,
  100. 'order_goods_id'=>$order_goods_id
  101. ]);
  102. $response = $client->send($request);
  103. return json_decode($response->getBody()->getContents(),true);
  104. }
  105. /**
  106. * 阿里大于
  107. * @param $phone
  108. * @param $template
  109. * @param $templateParams
  110. * @param string $signName
  111. * @return string
  112. */
  113. public static function alisSmsSent($phone, $template, $templateParams, $signName='懒族生活'){
  114. $client = Client::factory(env('RPC_SITE_HOST'));
  115. $request = $client->request(uniqid(),
  116. self::ALI_SMS_SENT,
  117. [
  118. 'phone' => $phone,
  119. 'template'=>$template,
  120. 'templateParams'=> json_encode($templateParams),
  121. 'signName'=>$signName,
  122. ]);
  123. $response = $client->send($request);
  124. return $response->getBody()->getContents();
  125. }
  126. /**
  127. * 订单打印
  128. * @param $oid
  129. * @return string
  130. */
  131. public static function doPrint($oid)
  132. {
  133. $client = Client::factory(env('RPC_SITE_HOST'));
  134. $request = $client->request(uniqid(),
  135. self::FEI_E_PRINT,
  136. ['oid' => $oid]
  137. );
  138. $response = $client->send($request);
  139. return $response->getBody()->getContents();
  140. }
  141. public static function onlineDeliveryStart($global_order_id)
  142. {
  143. $client = Client::factory(env('RPC_SITE_HOST'));
  144. $request = $client->request(uniqid(),
  145. self::ORDER_DELIVERY_START,
  146. ['global_order_id' => $global_order_id]
  147. );
  148. $response = $client->send($request);
  149. return $response->getBody()->getContents();
  150. }
  151. }