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

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