Cashier.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\controller;
  13. use think\response\Json;
  14. use app\api\service\Cashier as CashierService;
  15. use app\api\service\recharge\Payment as PaymentService;
  16. /**
  17. * 订单付款控制器 (收银台)
  18. * Class Cashier
  19. * @package app\api\controller
  20. */
  21. class Cashier extends Controller
  22. {
  23. /**
  24. * 获取支付订单的信息
  25. * @param int $orderId 订单ID
  26. * @param string $client 指定的客户端
  27. * @return Json
  28. * @throws \cores\exception\BaseException
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function orderInfo(int $orderId, string $client): Json
  34. {
  35. $CashierService = new CashierService;
  36. $data = $CashierService->setOrderId($orderId)->setClient($client)->orderInfo();
  37. return $this->renderSuccess($data);
  38. }
  39. /**
  40. * 确认订单支付事件
  41. * @param int $orderId 订单ID
  42. * @param string $method 支付方式
  43. * @param string $client 指定的客户端
  44. * @param array $extra 附加数据
  45. * @return Json
  46. * @throws \cores\exception\BaseException
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function orderPay(int $orderId, string $method, string $client, array $extra = []): Json
  52. {
  53. $CashierService = new CashierService;
  54. $data = $CashierService->setOrderId($orderId)
  55. ->setMethod($method)
  56. ->setClient($client)
  57. ->orderPay($extra);
  58. return $this->renderSuccess($data, $CashierService->getMessage() ?: '下单成功');
  59. }
  60. /**
  61. * 交易查询
  62. * @param string $outTradeNo 商户订单号
  63. * @param string $method 支付方式
  64. * @param string $client 指定的客户端
  65. * @return Json
  66. * @throws \cores\exception\BaseException
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\DbException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. */
  71. public function tradeQuery(string $outTradeNo, string $method, string $client): Json
  72. {
  73. $CashierService = new CashierService;
  74. $result = $CashierService->setMethod($method)->setClient($client)->tradeQuery($outTradeNo);
  75. $message = $result ? '恭喜您,订单已付款成功' : ($CashierService->getError() ?: '很抱歉,订单未支付,请重新发起');
  76. return $this->renderSuccess(['isPay' => $result], $message);
  77. }
  78. }