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.

112 lines
3.1 KiB

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\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. {
  66. Db::beginTransaction();
  67. try {
  68. $this->orderOnlineService->doRefund($global_order_id, $user_id);
  69. Db::commit();
  70. return [
  71. "status" => 200,
  72. "code" => 0,
  73. "result" => [],
  74. "message" => '处理成功'
  75. ];
  76. } catch (\Exception $e) {
  77. Db::rollBack();
  78. $this->log->event(LogLabel::ORDER_REFUND_LOG, ['jsonrpc_order_service_exception_onlineRefund' => $e->getMessage(), 'params' => json([$global_order_id, $user_id])]);
  79. throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL);
  80. }
  81. }
  82. /**
  83. * 线上订单单笔退款
  84. * 支持单商品、单店、整单
  85. * @param $user_id *用户ID
  86. * @param $global_order_id *全局总订单ID
  87. * @param $child_order_id *主订单ID,
  88. * @param $order_goods_id *订单商品ID
  89. * @param $note
  90. */
  91. public function onlineSingleRefund($user_id, $global_order_id, $child_order_id, $order_goods_id, $note)
  92. {
  93. }
  94. }