Recharge.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\Recharge as RechargeService;
  15. /**
  16. * 用户余额充值管理
  17. * Class Recharge
  18. * @package app\api\controller
  19. */
  20. class Recharge extends Controller
  21. {
  22. /**
  23. * 充值中心页面数据
  24. * @param string $client 当前客户端
  25. * @return Json
  26. * @throws \cores\exception\BaseException
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\DbException
  29. * @throws \think\db\exception\ModelNotFoundException
  30. */
  31. public function center(string $client): Json
  32. {
  33. $RechargeService = new RechargeService;
  34. $data = $RechargeService->center($client);
  35. return $this->renderSuccess($data);
  36. }
  37. /**
  38. * 确认充值订单
  39. * @return Json
  40. * @throws \cores\exception\BaseException
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. */
  45. public function submit(): Json
  46. {
  47. $data = $this->postForm();
  48. $RechargeService = new RechargeService;
  49. $data = $RechargeService->setMethod($data['method'])
  50. ->setClient($data['client'])
  51. ->orderPay($data['planId'], $data['customMoney'], $data['extra']);
  52. return $this->renderSuccess($data, $RechargeService->getMessage() ?: '下单成功');
  53. }
  54. /**
  55. * 交易查询
  56. * @param string $outTradeNo 商户订单号
  57. * @param string $method 支付方式
  58. * @param string $client 指定的客户端
  59. * @return Json
  60. * @throws \cores\exception\BaseException
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\DbException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. */
  65. public function tradeQuery(string $outTradeNo, string $method, string $client): Json
  66. {
  67. $RechargeService = new RechargeService;
  68. $result = $RechargeService->setMethod($method)->setClient($client)->tradeQuery($outTradeNo);
  69. $message = $result ? '恭喜您,余额充值成功' : ($RechargeService->getError() ?: '很抱歉,订单未支付,请重新发起');
  70. return $this->renderSuccess(['isPay' => $result], $message);
  71. }
  72. }