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.

91 lines
2.3 KiB

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