Browse Source

order_add

master
ZLW-PC\Administrator 7 years ago
parent
commit
78872e1037
  1. 66
      app/Http/Controllers/Api/OrderController.php
  2. 48
      app/Http/Controllers/Weixin/CartController.php
  3. 2
      app/Http/Model/UserBonus.php
  4. 78
      resources/views/weixin/cart/cartCheckout.blade.php
  5. 4
      routes/web.php

66
app/Http/Controllers/Api/OrderController.php

@ -0,0 +1,66 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Common\Token;
use App\Http\Model\Order;
class OrderController extends CommonController
{
public function __construct()
{
parent::__construct();
}
//订单列表
public function orderList(Request $request)
{
//参数
$data['user_id'] = Token::$uid;
$res = Order::getList($data);
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//生成订单
public function orderAdd(Request $request)
{return ReturnData::create(ReturnData::SUCCESS);
//参数
$data['goods_number'] = $request->input('goods_number','');
$data['goods_id'] = $request->input('goods_id','');
if($request->input('goods_attr', '') != ''){$data['goods_attr'] = $request->input('goods_attr');}
if($request->input('shop_id', '') != ''){$data['shop_id'] = $request->input('shop_id');}
$data['add_time'] = time();
$data['user_id'] = Token::$uid;
if($data['goods_number']=='' || $data['goods_id']=='')
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
return Order::cartAdd($data);
}
//删除订单
public function cartDelete(Request $request)
{
$id = $request->input('id','');
if($id=='')
{
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);
}
}

48
app/Http/Controllers/Weixin/CartController.php

@ -3,6 +3,7 @@ namespace App\Http\Controllers\Weixin;
use App\Http\Controllers\Weixin\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnData;
class CartController extends CommonController
{
@ -94,8 +95,53 @@ class CartController extends CommonController
);
$url = env('APP_API_URL')."/user_available_bonus_list";
$res = curl_request($url,$postdata,'GET');
$data['bonus_list'] = $res['data'];
$data['bonus_list'] = $res['data']['list'];
return view('weixin.cart.cartCheckout', $data);
}
//生成订单
public function cartDone(Request $request)
{
$cartids = $request->input('cartids',''); //购物车商品id,8_9
$default_address_id = $request->input('default_address_id',''); //收货地址id
$payid = $request->input('payid',''); //支付方式:1余额支付,2微信,3支付宝
$user_bonus_id = $request->input('user_bonus_id',0); //优惠券id,0没有优惠券
$shipping_costs = $request->input('shipping_costs',''); //运费
$message = $request->input('message',''); //买家留言
if($default_address_id==''){$this->error_jump('请选择收货地址');}
if($payid==''){$this->error_jump('请选择支付方式');}
if($cartids==''){$this->error_jump(ReturnData::PARAMS_ERROR);}
//订单提交
$postdata = array(
'cartids' => $cartids,
'default_address_id' => $default_address_id,
'payid' => $payid,
'user_bonus_id' => $user_bonus_id,
'shipping_costs' => $shipping_costs,
'message' => $message,
'access_token' => $_SESSION['weixin_user_info']['access_token']
);
$url = env('APP_API_URL')."/order_add";
$res = curl_request($url,$postdata,'POST');
if($res['code'] == ReturnData::SUCCESS)
{
/* $url = U('Order/orderlist');
header("Location: $url");
exit(); */
}
else
{
$ReturnMsg = '生成订单失败';
if($res['msg'])
{
$ReturnMsg = $res['msg'];
}
$this->error_jump($ReturnMsg);
}
}
}

2
app/Http/Model/UserBonus.php

@ -110,7 +110,7 @@ class UserBonus extends BaseModel
if(isset($status)){$where['bonus.status'] = 0;}
$model = new UserBonus;
if(isset($min_amount)){$model = $model->where('bonus.min_amount', '<=', $min_amount);} //满多少使用
if(isset($min_amount)){$model = $model->where('bonus.min_amount', '<=', $min_amount)->where('bonus.money', '<=', $min_amount);} //满多少使用
if(isset($bonus_end_time)){$model = $model->where('bonus.end_time', '>=', date('Y-m-d H:i:s'));} //有效期
$bonus_list = $model->join('bonus', 'bonus.id', '=', 'user_bonus.bonus_id')->where($where)

78
resources/views/weixin/cart/cartCheckout.blade.php

@ -64,7 +64,7 @@ function selectaddress()
<div class="ui-list-info">
<h4 class="ui-nowrap">支付方式</h4>
<div class="ui-txt-info"><span id="paytext">微信支付</span> &nbsp;</div>
<input type="hidden" name="payment" id="payid" value="2">
<input type="hidden" name="payid" id="payid" value="2">
</div>
<i class="fa fa-angle-right" aria-hidden="true"></i>
</li></a>
@ -83,13 +83,74 @@ function selectaddress()
$("#payid").val(id);
}
</script>
<a href="javascript:update_username();"><li>
<a href="javascript:select_bonus_layer();"><li>
<div class="ui-list-info">
<h4 class="ui-nowrap">优惠券</h4>
<div class="ui-txt-info">请选择优惠券 &nbsp;</div>
<div class="ui-txt-info"><span id="bonustext">请选择优惠券</span> &nbsp;</div>
<input type="hidden" name="user_bonus_id" id="user_bonus_id" value="0">
</div>
<i class="fa fa-angle-right" aria-hidden="true"></i>
</li></a>
<script>
function select_bonus_layer()
{
//询问框
layer.open({
title: [
'请选择优惠券',
'background-color: #FF4351; color:#fff;'
]
,content: '<div><?php if($bonus_list){foreach($bonus_list as $k=>$v){ ?><a style="margin-bottom:10px;background-color:#1aad19;border:1px solid #179e16;color:white;border-radius:2px;text-align:center;" class="bottoma" onclick="layer.closeAll();" href="javascript:select_bonus(<?php echo $v['user_bonus_id']; ?>,\'省<?php echo $v['money']; ?>元\',<?php echo $v['money']; ?>);">省<?php echo $v['money']; ?>元</a><?php }} ?><a style="background-color:#ea5a3d;border:1px solid #dd2727;color:white;border-radius:2px;text-align:center;" class="bottoma" onclick="layer.closeAll();" href="javascript:select_bonus(0,\'不使用优惠\',0);">不使用优惠</a></div>'
});
}
function select_bonus(id,name,money)
{
$("#bonustext").html(name);
$("#user_bonus_id").val(id);
//更改总计价格
change_totalamount(money);
}
function change_totalamount(discount)
{
totalamount = $("#product_total_price").val(); //商品总价
shipping_costs = $("#shipping_costs").val(); //运费
totalamount = totalamount + shipping_costs - discount;
$("#totalamount").html(totalamount.toFixed(2));
}
function submit_form()
{
payid = $("#payid").val();
default_address_id = $("#default_address_id").val();
if(payid==''){alert("请选择支付方式");}
if(default_address_id==''){alert("请选择收货地址");}
var re = /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字
if (!re.test(payid))
{
alert("支付方式格式不正确");
return false;
}
if (!re.test(default_address_id))
{
alert("收货地址格式不正确");
return false;
}
//询问框
layer.open({
content: '您确定要提交吗?'
,btn: ['确定', '取消']
,yes: function(index){
document.getElementById("myform").submit();
}
});
}
</script>
</ul></div>
<div class="floor" style="background-color:#fff;margin-top:10px;padding:10px;">
@ -99,10 +160,10 @@ function selectaddress()
</div>
<div class="order_check_info">
<p><?php echo $checkout_goods['total_goods']; ?>件商品</p>
<p>运费:¥0</p>
<p>满¥15.00减¥1.00</p>
<p>商品总价:¥<?php echo $checkout_goods['total_price']; ?></span></p>
<p>应付款金额:<span class="red">¥<i id="totalamount">99</i></span></p>
<!-- <p>运费:¥0</p> -->
<input type="hidden" name="shipping_costs" id="shipping_costs" value="0">
<input type="hidden" name="product_total_price" id="product_total_price" value="<?php echo $checkout_goods['total_price']; ?>">
<p>应付款金额:<span class="red">¥<i id="totalamount"><?php echo $checkout_goods['total_price']; ?></i></span></p>
</div>
</div>
<style>
@ -113,7 +174,7 @@ function selectaddress()
.order_check_info p .red{color:#ff5500;font-size:18px;}
</style>
<div class="setting"><div class="close"><a href="<?php echo route('weixin_user_logout'); ?>" id="logout">提交</a></div></div>
<div class="setting"><div class="close"><a href="javascript:submit_form();" id="logout">提交</a></div></div>
</form>
</div>
<!-- 订单确认信息-end -->
@ -165,7 +226,6 @@ function selectaddress()
}
}, 'json');
}
</script>
<!-- 收货地址列表-start -->
<div class="address_list mt10">

4
routes/web.php

@ -158,7 +158,6 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web
Route::post('/user_goods_history_delete', 'UserGoodsHistoryController@userGoodsHistoryDelete'); //我的足迹删除一条
Route::post('/user_goods_history_clear', 'UserGoodsHistoryController@userGoodsHistoryClear'); //我的足迹清空
Route::post('/user_goods_history_add', 'UserGoodsHistoryController@userGoodsHistoryAdd'); //我的足迹添加
//商品评价
Route::get('/goods_comment_list', 'CommentController@goodsCommentList'); //商品评价列表
Route::post('/goods_comment_add', 'CommentController@goodsCommentAdd'); //商品评价添加
@ -169,7 +168,8 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web
Route::post('/collect_goods_add', 'CollectGoodsController@collectGoodsAdd'); //收藏商品
Route::post('/collect_goods_delete', 'CollectGoodsController@collectGoodsDelete'); //取消收藏商品
//订单
Route::post('/order_add', 'OrderController@orderAdd'); //生成订单
Route::get('/order_list', 'OrderController@orderList'); //订单列表
//购物车
Route::get('/cart_list', 'CartController@cartList'); //购物车列表
Route::post('/cart_clear', 'CartController@cartClear'); //清空购物车

Loading…
Cancel
Save