Payment.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\api\service;
  3. use app\api\model\Wxapp as WxappModel;
  4. //use app\api\model\WxappPrepayId as WxappPrepayIdModel;
  5. use app\common\library\wechat\WxPay;
  6. use app\common\enum\OrderType as OrderTypeEnum;
  7. use app\common\enum\order\PayType as PayTypeEnum;
  8. class Payment
  9. {
  10. /**
  11. * 构建订单支付参数
  12. * @param $user
  13. * @param $order
  14. * @param $payType
  15. * @return array
  16. * @throws \app\common\exception\BaseException
  17. * @throws \think\exception\DbException
  18. */
  19. public static function orderPayment($user, $order, $payType)
  20. {
  21. if ($payType == PayTypeEnum::WECHAT) {
  22. return self::wechat(
  23. $user,
  24. $order['order_id'],
  25. $order['order_no'],
  26. $order['pay_price'],
  27. OrderTypeEnum::MASTER
  28. );
  29. }
  30. return [];
  31. }
  32. /**
  33. * 构建微信支付
  34. * @param \app\api\model\User $user
  35. * @param $orderId
  36. * @param $orderNo
  37. * @param $payPrice
  38. * @param int $orderType
  39. * @return array
  40. * @throws \app\common\exception\BaseException
  41. * @throws \think\exception\DbException
  42. */
  43. public static function wechat(
  44. $user,
  45. $orderId,
  46. $orderNo,
  47. $payPrice,
  48. $orderType = OrderTypeEnum::MASTER
  49. )
  50. {
  51. // 统一下单API
  52. $wxConfig = WxappModel::getWxappCache($user['wxapp_id']);
  53. $WxPay = new WxPay($wxConfig);
  54. $payment = $WxPay->unifiedorder($orderNo, $user['open_id'], $payPrice, $orderType);
  55. // // 记录prepay_id
  56. // $model = new WxappPrepayIdModel;
  57. // $model->add($payment['prepay_id'], $orderId, $user['user_id'], $orderType);
  58. return $payment;
  59. }
  60. }