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

116 lines
3.6 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
  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. /**
  12. * 订单完成时分账流水
  13. * @param $oid
  14. * @param $uid
  15. * @return string
  16. */
  17. public static function doByOrder($userId, $storeIds, $globalOrderId, $orderState){
  18. $client = Client::factory(env('RPC_SITE_HOST'));
  19. $request = $client->request(
  20. uniqid(),
  21. self::DO_BY_ORDER,
  22. ['userId' => $userId,'storeIds'=>$storeIds,'globalOrderId'=>$globalOrderId,'orderState'=>$orderState]);
  23. $response = $client->send($request);
  24. return $response->getBody()->getContents();
  25. }
  26. /**
  27. * 订单完成时分账流水
  28. * @param $oid
  29. * @param $uid
  30. * @return string
  31. */
  32. public static function separateAccounts($global_order_id,$uid){
  33. $client = Client::factory(env('RPC_SITE_HOST'));
  34. $request = $client->request(
  35. uniqid(),
  36. self::SEPARATE_ACCOUNTS,
  37. ['global_order_id' => $global_order_id,'user_id'=>$uid]);
  38. $response = $client->send($request);
  39. return $response->getBody()->getContents();
  40. }
  41. /**
  42. * 订单整笔退款
  43. * @param $global_order_id
  44. * @param $uid
  45. * @return string
  46. */
  47. public static function orderRefund($global_order_id,$uid){
  48. $client = Client::factory(env('RPC_SITE_HOST'));
  49. $request = $client->request(
  50. uniqid(),
  51. self::ORDER_REFUND,
  52. ['global_order_id' => $global_order_id,'user_id'=>$uid]);
  53. $response = $client->send($request);
  54. return $response->getBody()->getContents();
  55. }
  56. /**
  57. * @param $lng1
  58. * @param $lat1
  59. * @param $lng2
  60. * @param $lat2
  61. * @return mixed
  62. */
  63. public static function getDistance($lng1, $lat1, $lng2, $lat2){
  64. $client = Client::factory(env('RPC_SITE_HOST'));
  65. $request = $client->request(
  66. uniqid(),
  67. self::GET_DISTANCE,
  68. ['lng1' => $lng1,'lat1'=>$lat1,'lng2'=>$lng2,'lat2'=>$lat2]);
  69. $response = $client->send($request);
  70. return json_decode($response->getBody()->getContents(),true);
  71. }
  72. /**
  73. * 线上订单单笔退款,主要用于后台强行操作退单退款
  74. * 支持单商品、单店、整单
  75. * 按比例计算红包进行退款
  76. * 比如:两个子订单和子订单商品,分别是2元,98元,使用了10元优惠券
  77. * 退2元商品时,退款金额为
  78. * 红包 (2/(98+2)*10 = 0.2
  79. * 退款:2-0.2=1.8
  80. * @param $user_id
  81. * @param $note
  82. * @param $global_order_id
  83. * @param null $order_child_id
  84. * @param null $order_goods_id
  85. * @return mixed
  86. */
  87. public static function onlineSingleRefund($user_id, $note, $global_order_id, $order_child_id=null, $order_goods_id=null){
  88. $client = Client::factory(env('RPC_SITE_HOST'));
  89. $request = $client->request(
  90. uniqid(),
  91. self::ORDER_SINGLE_REFUND,
  92. [
  93. 'user_id' => $user_id,
  94. 'note'=>$note,
  95. 'global_order_id'=>$global_order_id,
  96. 'order_child_id'=>$order_child_id,
  97. 'order_goods_id'=>$order_goods_id
  98. ]);
  99. $response = $client->send($request);
  100. return json_decode($response->getBody()->getContents(),true);
  101. }
  102. }