Cashier.php 3.2 KB

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