EmptyPaymentService.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\data\service\payment;
  3. use app\data\service\PaymentService;
  4. use think\admin\extend\CodeExtend;
  5. use think\Exception;
  6. /**
  7. * 空支付通道
  8. * Class EmptyPaymentService
  9. * @package app\data\service\payment
  10. */
  11. class EmptyPaymentService extends PaymentService
  12. {
  13. /**
  14. * 订单主动查询
  15. * @param string $orderNo
  16. * @return array
  17. */
  18. public function query(string $orderNo): array
  19. {
  20. return [];
  21. }
  22. /**
  23. * 支付通知处理
  24. * @return string
  25. */
  26. public function notify(): string
  27. {
  28. return '';
  29. }
  30. /**
  31. * 创建支付订单
  32. * @param string $openid 会员OPENID
  33. * @param string $orderNo 交易订单单号
  34. * @param string $paymentAmount 交易订单金额(元)
  35. * @param string $paymentTitle 交易订单名称
  36. * @param string $paymentRemark 交易订单描述
  37. * @param string $paymentReturn 支付回跳地址
  38. * @return array
  39. * @throws Exception
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. */
  44. public function create(string $openid, string $orderNo, string $paymentAmount, string $paymentTitle, string $paymentRemark, string $paymentReturn = ''): array
  45. {
  46. $order = $this->app->db->name('ShopOrder')->where(['order_no' => $orderNo])->find();
  47. if (empty($order)) throw new Exception("订单不存在");
  48. if ($order['status'] !== 2) throw new Exception("不可发起支付");
  49. // 创建支付行为
  50. $this->createPaymentAction($orderNo, $paymentTitle, $paymentAmount);
  51. // 更新支付行为
  52. $this->updatePaymentAction($orderNo, CodeExtend::uniqidDate(20), $paymentAmount, '无需支付');
  53. return ['info' => '无需支付'];
  54. }
  55. }