链街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.

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