From 047b64aa96cfda61dc0ca01dcd13fe24f0246f70 Mon Sep 17 00:00:00 2001
From: "ZLW-PC\\Administrator" <374861669@qq.com>
Date: Tue, 28 Nov 2017 17:34:55 +0800
Subject: [PATCH] orderWxpay
---
app/Http/Controllers/Api/OrderController.php | 25 ++--
.../Controllers/Weixin/CartController.php | 5 +-
.../Controllers/Weixin/OrderController.php | 135 ++++++++++++++++++
.../Controllers/Weixin/UserController.php | 2 +-
.../views/weixin/order/orderWxpay.blade.php | 63 ++++++++
resources/views/weixin/order/pay.blade.php | 62 ++++----
routes/web.php | 1 +
7 files changed, 245 insertions(+), 48 deletions(-)
create mode 100644 resources/views/weixin/order/orderWxpay.blade.php
diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php
index accf2e7..42162ee 100644
--- a/app/Http/Controllers/Api/OrderController.php
+++ b/app/Http/Controllers/Api/OrderController.php
@@ -19,10 +19,9 @@ class OrderController extends CommonController
{
//参数
$data['user_id'] = Token::$uid;
+ $data['status'] = $request->input('status','');
- $res = Order::getList($data);
-
- return ReturnData::create(ReturnData::SUCCESS,$res);
+ return Order::getList($data);
}
//订单详情
@@ -30,10 +29,14 @@ class OrderController extends CommonController
{
//参数
$data['user_id'] = Token::$uid;
+ $data['order_id'] = $request->input('order_id','');
- $res = Order::getList($data);
-
- return ReturnData::create(ReturnData::SUCCESS,$res);
+ if($data['order_id']=='')
+ {
+ return ReturnData::create(ReturnData::PARAMS_ERROR);
+ }
+
+ return Order::getUnpaidOrder($data);
}
//生成订单
@@ -60,7 +63,7 @@ class OrderController extends CommonController
}
//删除订单
- public function cartDelete(Request $request)
+ public function orderDelete(Request $request)
{
$id = $request->input('id','');
@@ -69,12 +72,6 @@ class OrderController extends CommonController
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
- $res = Cart::remove($id,Token::$uid);
- if($res === true)
- {
- return ReturnData::create(ReturnData::SUCCESS,$res);
- }
-
- return ReturnData::create(ReturnData::SYSTEM_FAIL);
+ return Order::remove($id,Token::$uid);
}
}
\ No newline at end of file
diff --git a/app/Http/Controllers/Weixin/CartController.php b/app/Http/Controllers/Weixin/CartController.php
index 3c9f794..c9bbfcb 100644
--- a/app/Http/Controllers/Weixin/CartController.php
+++ b/app/Http/Controllers/Weixin/CartController.php
@@ -129,9 +129,8 @@ class CartController extends CommonController
if($res['code'] == ReturnData::SUCCESS)
{
- /* $url = U('Order/orderlist');
- header("Location: $url");
- exit(); */
+ header("Location: ".route('weixin_order_wxpay',array('order_id'=>$res['data'])));
+ exit;
}
else
{
diff --git a/app/Http/Controllers/Weixin/OrderController.php b/app/Http/Controllers/Weixin/OrderController.php
index 2cb9b49..8584a23 100644
--- a/app/Http/Controllers/Weixin/OrderController.php
+++ b/app/Http/Controllers/Weixin/OrderController.php
@@ -11,6 +11,50 @@ class OrderController extends CommonController
{
parent::__construct();
}
+
+ //订单列表
+ public function orderList(Request $request)
+ {
+ $pagesize = 10;
+ $offset = 0;
+
+ if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
+
+ $status = $request->input('status','');
+
+ $postdata = array(
+ 'limit' => $pagesize,
+ 'offset' => $offset,
+ 'status' => $status, //0或者不传表示全部,1待付款,2待发货,3待收货,4待评价,5退款/售后
+ 'access_token' => $_SESSION['weixin_user_info']['access_token']
+ );
+ $url = env('APP_API_URL')."/order_list";
+ $res = curl_request($url,$postdata,'GET');
+ $data['list'] = $res['data']['list'];
+
+ $data['totalpage'] = ceil($res['data']['count']/$pagesize);
+
+ if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
+ {
+ $html = '';
+
+ if($res['data']['list'])
+ {
+ foreach($res['data']['list'] as $k => $v)
+ {
+ $html .= '
';
+ $html .= ''.$v['goods']['title'].'
';
+ $html .= '
¥'.$v['goods']['price'].'
';
+ $html .= '
删除
';
+ $html .= '
';
+ }
+ }
+
+ exit(json_encode($html));
+ }
+
+ return view('weixin.order.orderList', $data);
+ }
//订单支付
public function pay($id)
@@ -25,6 +69,7 @@ class OrderController extends CommonController
$data['order_detail'] = $res['data'];
$data['order_id'] = $id;
+ /* if(!$res['code']!=0){$this->error_jump('订单不存在或已过期');} */
//获取会员信息
$postdata = array(
@@ -41,4 +86,94 @@ class OrderController extends CommonController
return view('weixin.order.pay', $data);
}
+
+ public function dopay(Request $request)
+ {
+ $order_id = $request->input('order_id','');
+ $payment_id = $request->input('payment_id','');
+
+ if($order_id == '' || $order_id == '')
+ {
+ $this->error_jump(ReturnData::PARAMS_ERROR);
+ }
+
+ $url = '';
+
+ if($payment_id == 1) //余额支付
+ {
+ $url = '';
+ }
+ elseif($payment_id == 2) //微信支付
+ {
+ $url = route('weixin_order_wxpay',array('order_id'=>$order_id));
+ }
+
+ if($url == '')
+ {
+ $this->error_jump('订单不存在或已过期');
+ }
+ else
+ {
+ header('Location: '.$url);
+ exit;
+ }
+ }
+
+ public function orderWxpay(Request $request)
+ {
+ $order_id = $request->input('order_id','');
+
+ //获取订单详情
+ $postdata = array(
+ 'order_id' => $order_id, //要支付的订单id
+ 'access_token' => $_SESSION['weixin_user_info']['access_token']
+ );
+ $url = env('APP_API_URL')."/order_detail";
+ $res = curl_request($url,$postdata,'GET');
+ $data['order_detail'] = $res['data'];
+ $data['order_id'] = $order_id;
+
+ if(!$res['code']!=0){$this->error_jump('订单不存在或已过期');}
+
+ //微信支付-start
+ require_once(resource_path('org/wxpay/WxPayConfig.php')); // 导入微信配置类
+ require_once(resource_path('org/wxpay/WxPayPubHelper.class.php')); // 导入微信支付类
+
+ $body = '订单支付';//订单详情
+ $out_trade_no = $data['order_detail']['order_sn'];//订单号
+ $total_fee = floatval($data['order_detail']['order_amount']*100);//价格0.01
+ $attach = 'pay_type=2'; //pay_type=2订单支付
+ $notify_url = route('weixin_wxpay_notify');//通知地址
+ $wxconfig= \WxPayConfig::wxconfig();
+
+ //=========步骤1:网页授权获取用户openid============
+ $jsApi = new \JsApi_pub($wxconfig);
+ $openid = $jsApi->getOpenid();
+ //=========步骤2:使用统一支付接口,获取prepay_id============
+ //使用统一支付接口
+ $unifiedOrder = new \UnifiedOrder_pub($wxconfig);
+ //设置统一支付接口参数
+ //设置必填参数
+ //appid已填,商户无需重复填写
+ //mch_id已填,商户无需重复填写
+ //noncestr已填,商户无需重复填写
+ //spbill_create_ip已填,商户无需重复填写
+ //sign已填,商户无需重复填写
+ $unifiedOrder->setParameter("openid","$openid");//微信用户
+ $unifiedOrder->setParameter("body","$body");//商品描述
+ $unifiedOrder->setParameter("out_trade_no","$out_trade_no");//商户订单号
+ $unifiedOrder->setParameter("total_fee","$total_fee");//总金额
+ $unifiedOrder->setParameter("attach","$attach"); //附加数据,选填,在查询API和支付通知中原样返回,可作为自定义参数使用,示例:a=1&b=2
+ $unifiedOrder->setParameter("notify_url","$notify_url");//通知地址
+ $unifiedOrder->setParameter("trade_type","JSAPI");//交易类型
+ $prepay_id = $unifiedOrder->getPrepayId();
+ //=========步骤3:使用jsapi调起支付============
+ $jsApi->setPrepayId($prepay_id);
+ $jsApiParameters = $jsApi->getParameters();
+
+ $data['jsApiParameters'] = $jsApiParameters;
+ $data['returnUrl'] = route('weixin_order_list'); //支付完成要跳转的url,跳转到用户订单列表页面
+
+ return view('weixin.order.orderWxpay', $data);
+ }
}
\ No newline at end of file
diff --git a/app/Http/Controllers/Weixin/UserController.php b/app/Http/Controllers/Weixin/UserController.php
index f8fb25d..c2795de 100644
--- a/app/Http/Controllers/Weixin/UserController.php
+++ b/app/Http/Controllers/Weixin/UserController.php
@@ -125,7 +125,7 @@ class UserController extends CommonController
$body = '充值';//订单详情
$out_trade_no = '20177878738';//订单号
$total_fee = floatval(0.01*100);//价格0.01
- $attach = 'pay_type=1';
+ $attach = 'pay_type=1'; //pay_type=1充值支付
$notify_url = route('weixin_wxpay_notify');//通知地址
$wxconfig= \WxPayConfig::wxconfig();
diff --git a/resources/views/weixin/order/orderWxpay.blade.php b/resources/views/weixin/order/orderWxpay.blade.php
new file mode 100644
index 0000000..e111a42
--- /dev/null
+++ b/resources/views/weixin/order/orderWxpay.blade.php
@@ -0,0 +1,63 @@
+
+订单-微信支付
+
+
+
+
+
+
+
+
+
+
+
+
订单已于 提交成功,请您尽快付款!
+ 订单号:
+ 应付金额:
¥ 元
+
+
去支付
+
+
\ No newline at end of file
diff --git a/resources/views/weixin/order/pay.blade.php b/resources/views/weixin/order/pay.blade.php
index 3408d80..10c50a4 100644
--- a/resources/views/weixin/order/pay.blade.php
+++ b/resources/views/weixin/order/pay.blade.php
@@ -12,37 +12,39 @@
@include('weixin.common.headerNav')