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.

96 lines
2.4 KiB

5 years ago
5 years ago
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Commons\Log;
  4. use App\Constants\ErrorCode;
  5. use App\Service\SeparateAccountsServiceInterface;
  6. use App\Service\v3\SfExpress;
  7. use Hyperf\DbConnection\Db;
  8. use Hyperf\RpcServer\Annotation\RpcService;
  9. use Hyperf\Di\Annotation\Inject;
  10. use App\Constants\LogLabel;
  11. /**
  12. * @RpcService(name="OrderService", protocol="jsonrpc-http", server="jsonrpc-http", publishTo="")
  13. */
  14. class OrderService implements OrderServiceInterface
  15. {
  16. /**
  17. * @Inject
  18. * @var Log
  19. */
  20. protected $log;
  21. /**
  22. * @Inject
  23. * @var \App\Service\OrderServiceInterface
  24. */
  25. protected $orderService;
  26. /**
  27. * @Inject
  28. * @var SeparateAccountsServiceInterface
  29. */
  30. protected $separateAccountsService;
  31. public function onlineComplete($global_order_id)
  32. {
  33. Db::beginTransaction();
  34. try {
  35. $this->orderService->onlineCompleted($global_order_id);
  36. $this->separateAccountsService->orderOnlineCompleted($global_order_id);
  37. Db::commit();
  38. return [
  39. "status" => 200,
  40. "code" => 0,
  41. "result" => [],
  42. "message" => '调用成功'
  43. ];
  44. } catch (\Exception $e) {
  45. Db::rollBack();
  46. $this->log->event(LogLabel::ONLINE_COMPLETE_LOG, ['exception' => $e->getMessage()]);
  47. return [
  48. "status" => 200,
  49. "code" =>ErrorCode::SEPARATE_ACCOUNTS_ERROR,
  50. "result" => [],
  51. "message" => ErrorCode::getMessage(ErrorCode::SEPARATE_ACCOUNTS_ERROR)
  52. ];
  53. }
  54. }
  55. /**
  56. * 线上订单退款
  57. * 申请退款 state = 8
  58. * 退款成功 state = 9
  59. */
  60. public function onlineRefund($global_order_id){
  61. $result = [
  62. "status" => 200,
  63. "code" => ErrorCode::ORDER_FAILURE,
  64. "result" => [],
  65. "message" => ''
  66. ];
  67. # 取消顺丰配送
  68. go(function () use ($global_order_id) {
  69. SfExpress::getInstance()->cancelOrder(['order_id' => $global_order_id]);
  70. });
  71. $res = $this->orderService->onlineRefund($global_order_id);
  72. if($res['code'] > 0){
  73. $result['result'] = $res;
  74. $result['message'] = '退款失败';
  75. }else{
  76. $result['code'] = 0;
  77. $result['result'] = $res;
  78. $result['message'] = '退款成功';
  79. };
  80. return $result;
  81. }
  82. }