Browse Source

orderWxpay

master
ZLW-PC\Administrator 7 years ago
parent
commit
047b64aa96
  1. 25
      app/Http/Controllers/Api/OrderController.php
  2. 5
      app/Http/Controllers/Weixin/CartController.php
  3. 135
      app/Http/Controllers/Weixin/OrderController.php
  4. 2
      app/Http/Controllers/Weixin/UserController.php
  5. 63
      resources/views/weixin/order/orderWxpay.blade.php
  6. 62
      resources/views/weixin/order/pay.blade.php
  7. 1
      routes/web.php

25
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);
}
}

5
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
{

135
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 .= '<li><a href="'.$v['goods']['goods_detail_url'].'"><span class="goods_thumb"><img alt="'.$v['goods']['title'].'" src="'.env('APP_URL').$v['goods']['litpic'].'"></span></a>';
$html .= '<div class="goods_info"><p class="goods_tit">'.$v['goods']['title'].'</p>';
$html .= '<p class="goods_price">¥<b>'.$v['goods']['price'].'</b></p>';
$html .= '<p class="goods_des fr"><span id="del_history" onclick="delconfirm(\''.route('weixin_user_goods_history_delete',array('id'=>$v['id'])).'\')">删除</span></p>';
$html .= '</div></li>';
}
}
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);
}
}

2
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();

63
resources/views/weixin/order/orderWxpay.blade.php

@ -0,0 +1,63 @@
<!DOCTYPE html><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>订单-微信支付</title><meta name="keywords" content="关键词"><meta name="description" content="描述"><meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
<link href="<?php echo env('APP_URL'); ?>/css/weixin/style.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/weixin/mobile.js"></script>
<script>
//调用微信JS api 支付
function jsApiCall()
{
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
<?php echo $jsApiParameters; ?>,
function(res){
WeixinJSBridge.log(res.err_msg);
//alert(res.err_code+res.err_desc+res.err_msg);
if(res.err_msg=='get_brand_wcpay_request:ok')
{
alert('支付成功!');
}
else
{
alert('支付失败!');
}
setTimeout("location.href = '<?php echo $returnUrl; ?>'",2000);
}
);
}
function callpay()
{
if (typeof WeixinJSBridge == "undefined"){
if( document.addEventListener ){
document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
}else if (document.attachEvent){
document.attachEvent('WeixinJSBridgeReady', jsApiCall);
document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
}
}else{
jsApiCall();
}
}
</script>
</head><body onload="callpay();">
<div class="classreturn loginsignup">
<div class="ds-in-bl return"><a href="javascript:history.back(-1);"><img src="<?php echo env('APP_URL'); ?>/images/weixin/return.png" alt="返回"></a></div>
<div class="ds-in-bl tit center"><span>订单微信支付</span></div>
</div>
<style>
.bottoma{display:block;font-size:18px;padding:10px;border-radius:2px;}
</style>
<div class="floor">
<div style="margin:10px;text-align:left;">
<p>订单已于 <b style="color:#fea700;"><?php echo date('Y-m-d H:is',$order_detail['add_time']); ?></b> 提交成功,请您尽快付款!</p>
订单号:<?php echo $order_detail['id']; ?><br>
应付金额:<strong style="color:#D03737;"><?php echo $order_detail['order_amount']; ?></strong> 元
</div>
<a style="margin:0 10px 10px 10px;background-color:#1aad19;text-align:center;color:#fff;border:1px solid #179e16;" class="bottoma" href="javascript:callpay();">去支付</a>
</div>
</body></html>

62
resources/views/weixin/order/pay.blade.php

@ -12,37 +12,39 @@
@include('weixin.common.headerNav')
<div class="floor">
<form action="<?php echo route('weixin_order_dopay'); ?>" method="POST" id="goto_pay">
<input type="hidden" name="order_id" value="<?php echo $order_id; ?>">
<div class="step_main">
<div class="clue_on"><p>您的订单已成功生成,选择您想用的支付方式进行支付。</p></div>
<div class="order_info">
<p>订单编号:<span><?php echo $order_id; ?></span></p>
<p>应付金额:<span>¥608.00</span></p>
</div>
<div class="payment mt10">
<h3>选择支付方式付款</h3>
<dl class="defray">
<dd>
<p class="radio"><input id="payment_yuer" name="payment_id" value="4" type="radio"></p>
<label for="payment_yuer"><p class="logo"><img src="<?php echo env('APP_URL'); ?>/images/weixin/yuepay_icon.png"></p>
<p class="explain">余额支付</p></label>
</dd>
<dd>
<p class="radio"><input id="payment_wxpay" name="payment_id" value="3" type="radio" checked="checked"></p>
<label for="payment_wxpay"><p class="logo"><img src="<?php echo env('APP_URL'); ?>/images/weixin/wxpay_icon.png"></p>
<p class="explain">微信支付</p></label>
</dd>
</dl>
<div class="cl"></div>
</div>
<a href="javascript:$('#goto_pay').submit();" class="bottoma" style="margin-top:10px;margin-bottom:15px;background-color:#1aad19;border:1px solid #179e16;color:white;border-radius:2px;text-align:center;">确认支付</a>
<div class="remark" style="color:#666;">
您可以在 <a href="<?php echo route('weixin_order_list'); ?>">我的订单</a> 中查看或取消您的订单。<br>
如果您现在不方便支付,可以随后到 <a href="<?php echo route('weixin_order_list'); ?>">我的订单</a>完成支付,我们会在48小时内为您保留未支付的订单。
</div>
<form action="<?php echo route('weixin_order_dopay'); ?>" method="POST" id="goto_pay">
<input type="hidden" name="order_id" value="<?php echo $order_id; ?>">
<div class="step_main">
<div class="clue_on"><p>您的订单已成功生成,选择您想用的支付方式进行支付。</p></div>
<div class="order_info">
<p>订单编号:<span><?php echo $order_id; ?></span></p>
<p>应付金额:<span>¥<?php echo $order_detail['order_amount']; ?></span></p>
</div>
</form>
<div class="payment mt10">
<h3>选择支付方式付款</h3>
<dl class="defray">
<?php if($is_balance_enough){ ?>
<dd>
<p class="radio"><input id="payment_yuer" name="payment_id" value="1" type="radio"></p>
<label for="payment_yuer"><p class="logo"><img src="<?php echo env('APP_URL'); ?>/images/weixin/yuepay_icon.png"></p>
<p class="explain">余额支付</p></label>
</dd>
<?php } ?>
<dd>
<p class="radio"><input id="payment_wxpay" name="payment_id" value="2" type="radio" checked="checked"></p>
<label for="payment_wxpay"><p class="logo"><img src="<?php echo env('APP_URL'); ?>/images/weixin/wxpay_icon.png"></p>
<p class="explain">微信支付</p></label>
</dd>
</dl>
<div class="cl"></div>
</div>
<a href="javascript:$('#goto_pay').submit();" class="bottoma" style="margin-top:10px;margin-bottom:15px;background-color:#1aad19;border:1px solid #179e16;color:white;border-radius:2px;text-align:center;">确认支付</a>
<div class="remark" style="color:#666;">
您可以在 <a href="<?php echo route('weixin_order_list'); ?>">我的订单</a> 中查看或取消您的订单。<br>
如果您现在不方便支付,可以随后到 <a href="<?php echo route('weixin_order_list'); ?>">我的订单</a>完成支付,我们会在48小时内为您保留未支付的订单。
</div>
</div>
</form>
</div>
<style>

1
routes/web.php

@ -103,6 +103,7 @@ Route::group(['prefix' => 'weixin', 'namespace' => 'Weixin', 'middleware' => ['w
Route::get('/order_pay/{id}', 'OrderController@pay')->name('weixin_order_pay'); //订单支付
Route::post('/order_dopay', 'OrderController@dopay')->name('weixin_order_dopay'); //订单支付
Route::get('/order_list', 'OrderController@orderList')->name('weixin_order_list'); //全部订单列表
Route::get('/order_wxpay', 'OrderController@orderWxpay')->name('weixin_order_wxpay'); //订单微信支付
//收货地址
Route::get('/user_address', 'AddressController@index')->name('weixin_user_address_list');
Route::get('/user_address_add', 'AddressController@userAddressAdd')->name('weixin_user_address_add');

Loading…
Cancel
Save