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.

86 lines
2.2 KiB

  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Commons\Log;
  4. use App\Constants\v3\ErrorCode;
  5. use App\Exception\ErrorCodeException;
  6. use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
  7. use Hyperf\DbConnection\Db;
  8. use Hyperf\RpcServer\Annotation\RpcService;
  9. use Hyperf\Di\Annotation\Inject;
  10. use App\Constants\v3\LogLabel;
  11. /**
  12. * @RpcService(name="OrderOnlineService", protocol="jsonrpc-http", server="jsonrpc-http", publishTo="")
  13. */
  14. class OrderOnlineService implements OrderOnlineServiceInterface
  15. {
  16. /**
  17. * @Inject
  18. * @var Log
  19. */
  20. protected $log;
  21. /**
  22. * @Inject
  23. * @var \App\Service\v3\Interfaces\OrderOnlineServiceInterface
  24. */
  25. protected $orderOnlineService;
  26. /**
  27. * @Inject
  28. * @var SeparateAccountsServiceInterface
  29. */
  30. protected $separateAccountsService;
  31. public function onlineComplete($orderMainId, $userId)
  32. {
  33. Db::beginTransaction();
  34. try {
  35. $this->orderOnlineService->doComplete($orderMainId, $userId);
  36. $this->separateAccountsService->orderOnlineCompleted($orderMainId, $userId);
  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::ORDER_COMPLETE_LOG, ['exception' => $e->getMessage()]);
  47. throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL, $e->getMessage());
  48. }
  49. }
  50. /**
  51. * 线上订单退款
  52. * 申请退款 state = 8
  53. * 退款成功 state = 9
  54. */
  55. public function onlineRefund($global_order_id){
  56. $result = [
  57. "status" => 200,
  58. "code" => ErrorCode::ORDER_FAILURE,
  59. "result" => [],
  60. "message" => ''
  61. ];
  62. $res = $this->orderOnlineService->onlineRefund($global_order_id);
  63. if($res['code'] > 0){
  64. $result['result'] = $res;
  65. $result['message'] = '退款失败';
  66. }else{
  67. $result['code'] = 0;
  68. $result['result'] = $res;
  69. $result['message'] = '退款成功';
  70. };
  71. return $result;
  72. }
  73. }