| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- /**
- * 支付
- * @author wesmiler
- */
- namespace app\api\controller;
- use app\weixin\model\Address;
- use app\weixin\model\Books;
- use app\weixin\model\Goods;
- use app\weixin\model\Member;
- use app\weixin\model\Payment;
- use app\weixin\model\Wechat;
- use app\weixin\service\PRedis;
- use think\Controller;
- use think\Db;
- class PaymentController extends Controller
- {
- /**
- * 获取调起支付参数
- * @author wesmiler
- */
- public function index()
- {
- $userInfo = session('userInfo');
- $userId = isset($userInfo['id']) ? intval($userInfo['id']) : 0;
- if (empty($userInfo) || !$userId) {
- $url = url('','','', true);
- showJson(1006, 1014, ['url' => Wechat::makeRedirectUrl($url)]);
- }
- // 订单信息验证
- $bookId = input('id', 0);
- $orderInfo = Books::getInfo(['id'=> $bookId]);
- $orderStatus = isset($orderInfo['status']) ? intval($orderInfo['status']) : 0;
- if ($orderStatus != 1) {
- showJson(1004, 5007);
- }
- // 验证用户
- $orderUserId = isset($orderInfo['uid']) ? intval($orderInfo['uid']) : 0;
- if ($orderUserId != $userId) {
- showJson(1004, 2009);
- }
- $orderSn = isset($orderInfo['order_sn'])? $orderInfo['order_sn'] : '';
- if(empty($orderSn)){
- showJson(1004, 1012);
- }
- // 支付金额
- $orderMoney = isset($orderInfo['money']) ? moneyFormat($orderInfo['money']) : 0.00;
- if ($orderMoney <= 0) {
- showJson(1004, 5008);
- }
- // 支付方式
- $payType = input('payType', 1);
- switch ($payType) {
- case 1: // 微信支付
- $result = Payment::wechatPay($bookId, $orderInfo, $userInfo);
- if(!is_array($result)){
- showJson(1004, $result? $result : 5011);
- }
- showJson(1005, 5010, $result);
- break;
- default:
- showJson(1004, 4003);
- break;
- }
- }
- }
- ?>
|