Cashier.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\api\service;
  13. use app\api\service\cashier\Payment;
  14. use app\api\service\cashier\Payment as PaymentService;
  15. use app\common\service\BaseService;
  16. use cores\exception\BaseException;
  17. /**
  18. * 余额充值服务类 (收银台)
  19. * Class Cashier
  20. * @package app\api\controller
  21. */
  22. class Cashier extends BaseService
  23. {
  24. // 提示信息
  25. private string $message = '';
  26. // 订单ID
  27. private int $orderId;
  28. // 支付方式 (微信支付、支付宝)
  29. private string $method;
  30. // 下单的客户端
  31. private string $client;
  32. /**
  33. * 设置支付的订单ID
  34. * @param int $orderId 订单ID
  35. * @return $this
  36. */
  37. public function setOrderId(int $orderId): Cashier
  38. {
  39. $this->orderId = $orderId;
  40. return $this;
  41. }
  42. /**
  43. * 设置当前支付方式
  44. * @param string $method 支付方式
  45. * @return $this
  46. */
  47. public function setMethod(string $method): Cashier
  48. {
  49. $this->method = $method;
  50. return $this;
  51. }
  52. /**
  53. * 设置下单的客户端
  54. * @param string $client 客户端
  55. * @return $this
  56. */
  57. public function setClient(string $client): Cashier
  58. {
  59. $this->client = $client;
  60. return $this;
  61. }
  62. /**
  63. * 获取支付订单的信息
  64. * @param int $orderId 订单ID
  65. * @param string $client 指定的客户端
  66. * @return array
  67. * @throws \cores\exception\BaseException
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. public function orderInfo(): array
  73. {
  74. $PaymentService = new PaymentService;
  75. return $PaymentService->setOrderId($this->orderId)
  76. ->setClient($this->client)
  77. ->orderInfo();
  78. }
  79. /**
  80. * 确认订单支付事件
  81. * @param array $extra 附加数据
  82. * @return array[]
  83. * @throws BaseException
  84. * @throws \think\db\exception\DataNotFoundException
  85. * @throws \think\db\exception\DbException
  86. * @throws \think\db\exception\ModelNotFoundException
  87. */
  88. public function orderPay(array $extra = []): array
  89. {
  90. $PaymentService = new PaymentService;
  91. $result = $PaymentService->setOrderId($this->orderId)
  92. ->setMethod($this->method)
  93. ->setClient($this->client)
  94. ->orderPay($extra);
  95. $this->message = $PaymentService->getMessage();
  96. return $result;
  97. }
  98. /**
  99. * 交易查询
  100. * 查询第三方支付订单是否付款成功
  101. * @param string $outTradeNo 商户订单号
  102. * @return bool
  103. * @throws BaseException
  104. * @throws \think\db\exception\DataNotFoundException
  105. * @throws \think\db\exception\DbException
  106. * @throws \think\db\exception\ModelNotFoundException
  107. */
  108. public function tradeQuery(string $outTradeNo): bool
  109. {
  110. $PaymentService = new PaymentService;
  111. return $PaymentService->setMethod($this->method)->setClient($this->client)->tradeQuery($outTradeNo);
  112. }
  113. /**
  114. * 返回消息提示
  115. * @return string
  116. */
  117. public function getMessage(): string
  118. {
  119. return $this->message;
  120. }
  121. }