结算到提交订单

 public function create()   //点击结算查询地址表信息
    {
        if(!session('?info')){  
            session('back_url','home/cart/index');//检测登录
            $this->redirect('home/login/login');
        }
        $info = session('info');
        $address = Address::where('user_id',$info)->select();
//查询选中的商品记录以及商品信息和SKU规格商品信息
        $cart_data = \app\common\model\Cart::with('goods,spec_goods')->where('is_selected',1)->where('user_id',$info)->select();
        $cart_data = (new \think\Collection($cart_data))->toArray();
        $total_price = 0;   //累加总数量和价格
        $total_number = 0;
        foreach($cart_data as &$v){
            if(isset($v['price']) && $v['price']>0){
                $v['goods_price'] = $v['price'];
            }
            if(isset($v['cost_price2']) && $v['cost_price2']>0){
                $v['cost_price'] = $v['cost_price2'];
            }
           //库存处理
            if(isset($v['store_count']) && $v['store_count']>0){
                $v['goods_number'] = $v['store_count'];
            }
            if(isset($v['store_frozen']) && $v['store_frozen']>0){
                $v['frozen_number'] = $v['store_frozen'];
            }
            $total_number += $v['number'];//累加总数量和价格
            $total_price += $v['number'] * $v['goods_price'];
        }
        unset($v);
        $res = \app\home\logic\OrderLogic::getCarDataWithGoods();//调用封装方法查询购物记录
        $cart_data = $res['cart_data'];
        $total_number = $res['total_number'];
        $total_price = $res['total_price'];
        //dump($total_price);die();
        return view('order/getOrderInfo',['address'=>$address,'cart_data'=>$cart_data,
            'total_number'=>$total_number,'total_price'=>$total_price]);
    }
地址表信息循环展示
<ul class="addr-detail">
   {foreach $address as $v}
   <li class="addr-item">
      <div address_id="{$v.id}" class="con name {if($v.is_default)}selected{/if}"><a href="javascript:;" ><em>{$v.consignee}</em><span title="点击取消选择">&nbsp;</span></a></div>
      <div class="con address">
         <span class="consignee_name">{$v.consignee}</span>
         <span class="consignee_address">{$v.area} {$v.address}</span>
         <span class="consignee_phone">{$v.phone}</span>
         <span class="base">默认地址</span>
         <span class="edittext">
               <a class="edit_address" data-toggle="modal" data-target=".edit" data-keyboard="false" >编辑</a>&nbsp;&nbsp;
               <a class="delete_address" href="javascript:;">删除</a>
            </span>
      </div>
      <div class="clearfix"></div>
   </li>
   {/foreach}
</ul>
关联模型,绑定字段
public function goods(){
   return $this->belongsTo('Goods','goods_id','id')->bind('goods_name,goods_price,goods_logo,goods_number,frozen_number,cost_price');
}
public function specGoods(){
   return $this->belongsTo('SpecGoods','spec_goods_id','id')->bind(['value_ids','value_names','price','cost_price2'=>'cost_price','store_count','store_frozen']);
}
商品信息循环展示
<div class="sendGoods">
   <span>商品清单:</span>
   {foreach $cart_data as $v}
   <ul class="yui3-g">
      <li class="yui3-u-1-6">
         <span><img src="{$v.goods_logo}"/></span>
      </li>
      <li class="yui3-u-7-12">
         <div class="desc">{$v.goods_name}<br>{$v.value_names}</div>
         <div class="seven">7天无理由退货</div>
      </li>
      <li class="yui3-u-1-12">
         <div class="price">¥{$v.goods_price}</div>
      </li>
      <li class="yui3-u-1-12">
         <div class="num">X{$v.number}</div>
      </li>
      <li class="yui3-u-1-12">
         <div class="exit">{if($v.goods_number >= $v.number)}有货{else/}无货{/if}</div>
      </li>
   </ul>
   {/foreach}
</div>
<div class="list">   //商品金额及购买商品数量
   <span><i class="number">{$total_number}</i>件商品,总商品金额</span>
   <em class="allprice">¥{$total_price}</em>
</div>
<div class="clearfix trade">
   <div class="fc-price">应付金额: <span class="price">¥{$total_price}</span></div>
   <div class="fc-receiverInfo">寄送至:北京市海淀区三环内 中关村软件园9号楼 收货人:某某某 159****3201</div>
</div>
$(function(){
   //封装函数 将选中的地址,放到页面右下角展示
   var show_address = function(element){
      //获取到选中的地址信息
      if(element){
         var li = $(element).closest('li');
      }else{
         var li = $('.addressInfo').find('.name.selected').closest('li');
      }
      var consignee_address = li.find('.consignee_address').html();
      var consignee_phone = li.find('.consignee_phone').html();
      var consignee_name = li.find('.consignee_name').html();
      //展示到页面右下角
      $('.fc-receiverInfo').html('寄送至:' + consignee_address +' 收货人:' + consignee_name + ' ' + consignee_phone);
   };
   show_address();
//点击地址 切换右下角的地址
   $('.addressInfo').find('.name').click(function(){show_address(this);});
});
提交订单传递地址
<div class="submit"><a class="sui-btn btn-danger btn-xlarge" href="javascript:;">提交订单</a></div>
<form id="orderForm" action="{:url('home/order/save')}" method="post" style="display: none;">
<input type="hidden" name="address_id" value=""></form>
提交订单
$('.submit').click(function(){
   //获取选中的收货地址id
   var address_id = $('.addressInfo').find('.name.selected').attr('address_id');
   //将地址id放到表单中
   $('input[name=address_id]').val(address_id);
   //提交表单
   $('#orderForm').submit();
});

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值