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.

97 lines
2.6 KiB

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