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.

93 lines
2.4 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. $result = [
  61. "status" => 200,
  62. "code" => ErrorCode::ORDER_FAILURE,
  63. "result" => [],
  64. "message" => ''
  65. ];
  66. try{
  67. $res = $this->orderService->onlineRefund($global_order_id);
  68. if($res){
  69. $result['code'] = 0;
  70. $result['result'] = $res;
  71. $result['message'] = '退款成功';
  72. }else{
  73. $result['result'] = $res;
  74. $result['message'] = '退款失败';
  75. };
  76. } catch (\Exception $e){
  77. $result['message'] = $e->getMessage();
  78. }
  79. return $result;
  80. }
  81. }