Pay.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace addons\service\library;
  3. use think\db\exception\DataNotFoundException;
  4. use think\db\exception\ModelNotFoundException;
  5. use think\exception\DbException;
  6. use think\Request;
  7. use think\Exception;
  8. class Pay
  9. {
  10. /**
  11. * @throws DataNotFoundException
  12. * @throws ModelNotFoundException
  13. * @throws DbException
  14. * @throws Exception
  15. */
  16. public static function payOrder($order, $paytype, $uid, $types)
  17. {
  18. switch ($paytype) {
  19. case 0:
  20. $method='miniapp';
  21. $type = 'wechat';
  22. break;
  23. case 1:
  24. $method='app';
  25. $type = 'wechat';
  26. break;
  27. case 2:
  28. $method='mp';
  29. $type = 'wechat';
  30. break;
  31. case 3:
  32. $method='app';
  33. $type = 'alipay';
  34. break;
  35. default:
  36. $method='miniapp';
  37. $type = 'wechat';
  38. }
  39. $order['type'] = $type;
  40. $request = Request::instance();
  41. $domain=$request->domain();
  42. if($types == 0){
  43. $order['notifyurl'] = $domain.'/addons/service/notify/notifyx/paytype/'.$type;
  44. }else{
  45. $order['notifyurl'] = $domain.'/addons/service/notify/notify/paytype/'.$type;
  46. }
  47. $order['returnurl'] = $domain.'/addons/service/notify/returnx/paytype/'.$type;
  48. $order['method'] = $method;
  49. $userInfo = \app\api\model\service\UserInfo::where('user_id',$uid)->field('id,user_openid,skill_openid,shop_openid,is_skill,is_shop')->find();
  50. switch ($types){
  51. case 0:
  52. $openid = $userInfo['user_openid'];
  53. break;
  54. case 1:
  55. $openid = $userInfo['skill_openid'];
  56. break;
  57. case 2:
  58. $openid = $userInfo['shop_openid'];
  59. break;
  60. default:
  61. $openid = $userInfo['user_openid'];
  62. }
  63. $order['openid'] = $openid;
  64. $info = get_addon_info('epay');
  65. if (!$info || !$info['state']) {
  66. throw new Exception("请确保微信支付宝整合插件已安装并启用");
  67. }
  68. if($types == 0){
  69. $re = \addons\epay\library\Service::submitOrder($order);
  70. }else{
  71. $wxPay = new WxPay();
  72. $re = $wxPay->pay(['type'=>$types,'body'=>$order['title'],'out_trade_no'=>$order['orderid'],'total_fee'=>intval($order['amount']*100),'notify_url'=>$order['notifyurl'],'openid'=>$openid]);
  73. }
  74. return $re;
  75. }
  76. }