EmptyPaymentService.php 1.9 KB

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