表有汇PC端购物车功能实现
加入购物车后的结算功能
购物车页面:
购物车页面html代码:
- <div class="cart_box">
- <!--购物车-->
- <h1 class="main_tit">
- <span><a onclick="DeleteClear(this,'/','0');" href="javascript:;">清空购物车</a></span>
- 我的购物车<strong>Shopping Cart</strong>
- </h1>
- <div class="cart_step">
- <ul>
- <li class="selected"><span>1</span>放进购物车</li>
- <li><span>2</span>填写订单信息</li>
- <li class="last"><span>3</span>支付/确定订单</li>
- </ul>
- </div>
- <div class="line20"></div>
- <table width="938" border="0" align="center" cellpadding="8" cellspacing="0" class="cart_table">
- <tbody><tr>
- <th width="64"></th>
- <th align="left">商品名称</th>
- <th width="110" align="center">颜色</th>
- <th width="80" align="center">积分</th>
- <th width="80" align="center">单价</th>
- <th width="80" align="center">数量</th>
- <!--<th width="80" align="center">优惠</th>-->
- <th width="100" align="center">金额小计</th>
- <th width="100" align="center">积分小计</th>
- <th width="50" align="center">操作</th>
- </tr>
- <tr>
- <td><a target="_blank" href="/goods/show-62.html"><img src="/upload/201505/04/201505041442488793.jpg" class="img"></a></td>
- <td><a target="_blank" href="/goods/show-62.html">韩国乐智迅时尚正品手表学生男表女表运动防水糖果色果冻表石英表</a></td>
- <!--颜色-->
- <td align="center">黑色<input name="goods_color" type="hidden" value="黑色"></td>
- <!--积分-->
- <td align="center">
- +
- 10
- </td>
- <!--价格-->
- <td align="center">¥2600.00<input name="goods_price" type="hidden" value="2600.00"></td><!-- value=用户价格 -->
- <!--数量-->
- <td align="center">
- <a href="javascript:;" class="reduce" title="减一" onclick="CartComputNum(this, '/', '62', -1);">减一</a>
- <input type="text" name="goods_quantity" class="input" style="width:30px;text-align:center;ime-mode:Disabled;" value="1" onblur="CartAmountTotal(this, '/', '62');" onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))">
- <a href="javascript:;" class="subjoin" title="加一" onclick="CartComputNum(this,'/', '62', 1);">加一</a>
- </td>
- <!--优惠-->
- <!--<td align="center">¥<label name="discount_amount"></label></td>-->
- <!--金额小记--> <!-- string转换成int -->
- <td align="center"><font color="#FF0000" size="2">¥<label name="real_amount">2600</label></font></td>
- <td align="center">
- <font color="#FF0000" size="2">
- +
- <label name="point_count">10</label>
- </font>
- </td>
- <td align="center"><a onclick="DeleteCart(this,'/','62');" href="javascript:;">删除</a></td>
- </tr>
- <tr>
- <th colspan="9" align="right">
- 商品件数:1 件 商品总金额(不含运费):<font color="#FF0000" size="2">¥2600</font>元 总积分:<font color="#FF0000" size="2">10分</font>
- </th>
- </tr>
- </tbody></table>
- <div class="line20"></div>
- <div class="right">
- <a class="btn" href="/index.html">继续购物</a>
- <a class="btn btn-success marL10" href="/shopping/confirm.html">马上去结算</a>
- </div>
- <div class="clear"></div>
- <!--/购物车-->
- </div>
对照一下商品的颜色、数量等是否选择正确,如果无误可以点击马上结算按钮,进入订单信息界面,填写信息
订单信息界面:
订单信息页面html代码:
- <div class="cart_box">
- <link rel="stylesheet" href="/css/validate.css">
- <script type="text/javascript" src="/scripts/jquery/jquery.form.min.js"></script>
- <script type="text/javascript" src="/scripts/jquery/Validform_v5.3.2_min.js"></script>
- <script type="text/javascript">
- $(function () {
- //表单提交
- AjaxInitForm('order_form', 'btnSubmit', 0);
- });
- </script>
- <!--结算中心-->
- <h1 class="main_tit">
- <span><a href="/shopping/cart.html">返回</a></span>
- 确认订单信息<strong>Confirm order</strong>
- </h1>
- <div class="cart_step">
- <ul>
- <li class="item"><span>1</span>放进购物车</li>
- <li class="selected"><span>2</span>填写订单信息</li>
- <li class="last"><span>3</span>支付/确定订单</li>
- </ul>
- </div>
- <div class="line20"></div>
- <form name="order_form" id="order_form" url="/tools/submit_ajax.ashx?action=order_save">
- <h3 class="bar_tit">1、收货信息</h3>
- <div class="form_box">
- <dl>
- <dt>收货人姓名:</dt>
- <dd><input name="accept_name" id="accept_name" type="text" class="input txt wide" value="发vdxgsd" datatype="s2-20" sucmsg=" "><span class="Validform_checktip">*收货人姓名</span></dd>
- </dl>
- <dl>
- <dt>收货地址:</dt>
- <dd><input name="address" id="address" type="text" class="input txt" value="广东省佛山市" datatype="*2-100" sucmsg=" " style="width:300px;"><span class="Validform_checktip">*收货人的详细地址</span></dd>
- </dl>
- <dl>
- <dt>邮政编码:</dt>
- <dd><input name="post_code" id="post_code" type="text" class="input txt"><span class="Validform_checktip">所在地区的邮政编码,非必填</span></dd>
- </dl>
- <dl>
- <dt>手机号码:</dt>
- <dd><input name="mobile" id="mobile" type="text" class="input txt" value="13256202154" datatype="m" sucmsg=" "><span class="Validform_checktip">*收货人的手机号码</span></dd>
- </dl>
- <dl>
- <dt>联系电话:</dt>
- <dd><input name="telphone" id="telphone" type="text" class="input txt" value=""><span class="Validform_checktip">收货人的联系电话,非必填</span></dd>
- </dl>
- </div>
- <div class="line20"></div>
- <h3 class="bar_tit">2、支付方式</h3>
- <ul class="item_box">
- <!--取得一个DataTable-->
- <li>
- <label><input name="payment_id" type="radio" onclick="PaymentAmountTotal(this);" value="1"><input name="payment_price" type="hidden" value="0.00">货到付款
- <em>手续费:0.00元</em></label>
- </li>
- <li>
- <label><input name="payment_id" type="radio" onclick="PaymentAmountTotal(this);" value="2"><input name="payment_price" type="hidden" value="0.00">账户余额
- <em>手续费:0.00元</em></label>
- </li>
- <li>
- <label><input name="payment_id" type="radio" onclick="PaymentAmountTotal(this);" value="3"><input name="payment_price" type="hidden" value="0.00">支付宝
- <em>手续费:0.00元</em></label>
- </li>
- <li>
- <label><input name="payment_id" type="radio" onclick="PaymentAmountTotal(this);" value="4" datatype="*" sucmsg=" "><input name="payment_price" type="hidden" value="0.00">财付通
- <em>手续费:0.00元</em><span class="Validform_checktip"></span></label>
- </li>
- </ul>
- <div class="line20"></div>
- <h3 class="bar_tit">3、配送方式</h3>
- <ul class="item_box">
- <!--取得一个DataTable-->
- <li>
- <label><input name="express_id" type="radio" onclick="FreightAmountTotal(this);" value="1"><input name="express_price" type="hidden" value="20.00">顺丰快递
- <em>费用:20.00元</em></label>
- </li>
- <li>
- <label><input name="express_id" type="radio" onclick="FreightAmountTotal(this);" value="2" datatype="*" sucmsg=" "><input name="express_price" type="hidden" value="14.00">韵达快递
- <em>费用:14.00元</em><span class="Validform_checktip"></span></label>
- </li>
- </ul>
- <div class="line20"></div>
- <h3 class="bar_tit">4、商品清单</h3>
- <table width="938" border="0" align="center" cellpadding="8" cellspacing="0" class="cart_table">
- <tbody><tr>
- <th width="64"></th>
- <th align="left">商品名称</th>
- <th width="110" align="center">颜色</th>
- <th width="80" align="center">积分</th>
- <th width="80" align="center">单价</th>
- <th width="80" align="center">数量</th>
- <th width="80" align="center">优惠</th>
- <th width="100" align="center">金额小计</th>
- <th width="100" align="center">积分小计</th>
- </tr>
- <tr>
- <td><a target="_blank" href="/goods/show-63.html"><img src="/upload/201505/04/201505041444321122.jpg" class="img"></a></td>
- <td><a target="_blank" href="/goods/show-63.html">卡帝仕正品超薄运动手表防水手表户外手表大表盘男表时装表</a></td>
- <!--颜色-->
- <td align="center"><input name="goods_color" type="hidden" value=""></td>
- <td align="center">
- +
- 10
- </td>
- <td align="center">¥5500.00<input name="goods_price" type="hidden" value="5500.00"></td>
- <td align="center">1</td>
- <td align="center">¥<label name="discount_amount">5500</label></td>
- <td align="center"><font color="#FF0000" size="2">¥<label name="real_amount">5500</label></font></td>
- <td align="center">
- <font color="#FF0000" size="2">
- +
- <label name="point_count">10</label>
- </font>
- </td>
- <td><input id="car_id" name="car_id" type="hidden" value="63"></td>
- </tr>
- </tbody></table>
- <div class="line20"></div>
- <h3 class="bar_tit">5、结算信息</h3>
- <div>
- <div class="left">
- <h4>订单留言<span>字数控制在100个字符内</span></h4>
- <textarea name="message" class="input" style="width:250px;height:35px;"></textarea>
- </div>
- <div class="right" style="text-align:right;line-height:40px;">
- 商品件数:<font color="#FF0000">1</font> 件 总积分:<font color="#FF0000">10</font> 分 商品金额:<font color="#FF0000">¥<label id="goods_amount">5500</label></font> + 运费:<font color="#FF0000">¥<label id="express_fee">0.00</label></font> + 支付手续费:<font color="#FF0000">¥<label id="payment_fee">0.00</label></font>
- <br>
- <b class="font18">应付总金额:<font color="#FF0000">¥<label id="order_amount">5500</label></font></b>
- </div>
- </div>
- <div class="line20"></div>
- <div class="right">
- <a class="btn" href="/shopping/cart.html">返回修改</a>
- <input id="btnSubmit" name="btnSubmit" type="submit" value="确认提交" class="btn btn-success marL10">
- </div>
- <div class="clear"></div>
- </form>
- <!--/结算中心-->
- </div>
填写好必要的信息(如:收货人姓名、地址、手机号码、快递、付款方式等),点击确认提交按钮进入支付界面;
支付界面:
支付页面html代码:
- <div class="cart_box">
- <h1 class="main_tit">
- 支付中心<strong>Payment</strong>
- </h1>
- <!--提交支付-->
- <form id="pay_form" name="pay_form" method="post" action="/api/payment/balance/index.aspx" target="_blank">
- <input id="pay_order_no" name="pay_order_no" type="hidden" value="b15061907244648"> <!--hidden-->
- <input id="pay_order_amount" name="pay_order_amount" type="hidden" value="2614.00">
- <input id="pay_user_name" name="pay_user_name" type="hidden" value="admin00">
- <div class="cart_step">
- <ul>
- <li><span>1</span>放进购物车</li>
- <li class="item"><span>2</span>填写订单信息</li>
- <li class="last selected"><span>3</span>支付/确定订单</li>
- </ul>
- </div>
- <div class="form_box">
- <dl>
- <dt>订单号:</dt>
- <dd>b15061907244648</dd>
- </dl>
- <dl>
- <dt>收货人姓名:</dt>
- <dd>发vdxgsd</dd>
- </dl>
- <dl>
- <dt>送货地址:</dt>
- <dd>广东省佛山市</dd>
- </dl>
- <dl>
- <dt>手机号码:</dt>
- <dd>13256202154</dd>
- </dl>
- <dl>
- <dt>固定电话:</dt>
- <dd></dd>
- </dl>
- <dl>
- <dt>备注留言:</dt>
- <dd>都很健康</dd>
- </dl>
- <dl>
- <dt>支付金额:</dt>
- <dd>2614.00</dd>
- </dl>
- <dl>
- <dt>支付方式:</dt>
- <dd>账户余额</dd>
- </dl>
- <dl>
- <dt></dt>
- <dd><input id="btnSubmit" name="btnSubmit" type="submit" class="btn_submit" value="确认支付"></dd>
- </dl>
- </div>
- <input id="pay_subject" name="pay_subject" type="hidden" value="购买商品">
- </form>
- <!--提交支付-->
- <div class="clear"></div>
- </div>
在确认信息无误后,点击确认支付按钮;如果正常,就会提示支付成功
成功提示:
提示html代码:
- <div class="cart_box">
- <h1 class="main_tit">
- 支付中心<strong>Payment</strong>
- </h1>
- <!--支付成功-->
- <div class="msg_tips">
- <div class="ico"></div>
- <div class="msg">
- <strong>支付成功啦!</strong>
- <p>恭喜您,您的支付已经成功!</p>
- <p>您可以点击这里进入<a href="/user/center/index.html">会员中心</a>查看订单状态!</p>
- <p>如有其它问题,请立即与我们客服人员联系。</p>
- </div>
- </div>
- <!--支付成功-->
- <div class="clear"></div>
- </div>
当然也可以在商品介绍页面点击立刻购买按钮,从而进入填写订单信息页面:(步骤同上)
商品介绍页html代码:
- <dl class="head green">
- <dt>购物商城</dt>
- <dd>
- <span>当前位置:<a href="<%linkurl("index","")%>">首页 </a>><a href="<%linkurl("goods","")%>">购物商城</a>{category_nav}</span>
- </dd>
- </dl>
- <div class="line20">
- </div>
- <!--商品图片-->
- <div class="left294">
- <!--幻灯片开始-->
- <div class="pictureDIV">
- <div id="preview" class="spec-preview">
- <span class="jqzoom">
- <img /></span>
- </div>
- <!--缩图开始-->
- <div class="spec-scroll">
- <a class="prev"><</a> <a class="next">></a>
- <div class="items">
- <ul>
- <%if(model.albums!=null)%>
- <%foreach(DTcms.Model.goods_albums modelt in model.albums)%>
- <li>
- <img bimg="{modelt.original_path}" src="{modelt.thumb_path}" onmousemove="preview(this);" /></li>
- <%/foreach%>
- <%/if%>
- </ul>
- </div>
- </div>
- <!--缩图结束-->
- </div>
- <!--幻灯片结束-->
- </div>
- <!--/商品图片-->
- <!--商品属性-->
- <div class="pro-attr right356">
- <h1>
- {model.title}</h1>
- <div class="pro-items">
- <dl>
- <dt>商品货号:</dt>
- <dd>
- {model.goods_no}
- </dd>
- </dl>
- <dl>
- <dt>销售价格:</dt>
- <dd><b class="red">¥{model.sell_price}</b></dd>
- </dl>
- <dl>
- <dt>颜色选择:</dt>
- <%if(yanse!=null)%>
- <dd>
- <%for(int i=0;i<yanse.Length;i++)%>
- <a id="<%=str[i]%>" href="javascript:void()" style="border: 1px solid #CCCCCC; margin-top:10px;"
- onclick="selected(this.id);">
- <b class="green" style="font-family:宋体; font-size:8;"><%=yanse[i]%></b>
- </a>
- <%/for%>
- </dd>
- <%else%>
- <dd><b class="red">抱歉,该商品没有颜色选择</b></dd>
- <%/if%>
- <script>
- var count = 0;
- function selected(id) {
- if (count != id) {
- $('#goods_color').val(id);
- var kk = document.getElementById(id);
- kk.style.border = "2px solid red";
- if (parseInt(count) != 0) {
- var hh = document.getElementById(count);
- hh.style.border = "1px solid #CCCCCC";
- }
- count = id;
- }
- else { }
- }
- </script>
- </dl>
- <!--<dl>
- <dt>会员价格:</dt>
- <dd>
- <%set decimal user_price=get_user_goods_price(model.id)%>
- <%if(user_price>-1)%>
- <b class="red">¥{user_price}</b>
- <%else%>
- 登录可见
- <%/if%>
- </dd>
- </dl>-->
- <dl>
- <dt>上架时间:</dt>
- <dd>
- {model.add_time}</dd>
- </dl>
- </div>
- <div class="pro-btns">
- <div class="input-box">
- 购买数量:<input name="goods_id" id="goods_id" type="hidden" value="{model.id}" /><input
- <input name="goods_color" id="goods_color" type="hidden" value="" />
- <input type="text" name="goods_quantity" id="goods_quantity" value="1" class="txt" style="ime-mode: disabled" />
- </div>
- <div class="btn-box">
- <%if({model.stock_quantity}>0)%>
- <a href="javascript:void(0);" class="add" onclick="CartAdd(this, '{config.webpath}', 0, '<%linkurl("shopping","cart")%>');">
- 加入购物车</a> <a href="javascript:void(0);" class="buy" onclick="CartAdd(this, '{config.webpath}', 1, '<%linkurl("shopping","confirm")%>');">
- 立即购买</a>
- <%else%>
- <a title="该商品供货紧张,无法加入购物车" class="add-over">加入购物车</a> <a title="该商品供货紧张,无法立即购买" class="buy-over">
- 立即购买</a>
- <%/if%>
- </div>
- </div>
- <div class="line10">
- </div>
- <!--分享-->
- <%template src="_share2_js.html"%>
- <!--/分享-->
- </div>
- <!--/商品属性-->
购物车的结算功能的表和表的关系
购物车商品结算涉及到的表有:订单表(dt_orders)、订单商品表(dt_order_goods)、购物车表(dt_shoppingCar)、用户表(dt_users)
订单表的字段有:订单id、订单号、交易号担保支付用到、用户ID、用户名、支付方式、支付手续费、支付状态1未支付2已支付、支付时间、快递ID、快递单号、物流费用、发货状态1未发货2已发货、发货时间、收货人姓名、邮政编码、联系电话、手机、所属省市区、收货地址、订单留言、订单备注/评估描述情况、应付商品总金额、实付商品总金额
列名
数据类型
主键/外键
说明
id
int
主键
订单id
order_no
nvarchar
订单号
trade_no
nvarchar
交易号担保支付用到
user_id
int
外键
用户id
user_name
nvarchar
用户名
payment_id
int
支付方式
payment_fee
decimal
支付手续费
payment_status
tinyint
支付状态1未支付2已支付
payment_time
datetime
支付时间
express_id
int
外键
快递id
express_no
nvarchar
快递单号
express_fee
decimal
物流费用
express_status
tinyint
发货状态1未发货2已发货
express_time
datetime
发货时间
accept_name
nvarchar
收货人姓名
post_code
nvarchar
邮政编码
telphone
nvarchar
联系电话
mobile
nvarchar
手机
area
nvarchar
所属省市区
address
nvarchar
收货地址
message
nvarchar
订单留言
remark
nvarchar
订单备注/评估描述情况
payable_amount
decimal
应付商品总金额
real_amount
decimal
实付商品总金额
order_amount
decimal
订单总金额
订单商品表的字段有:自增id、订单id、商品id、商品名称、商品价格、实际价格、数量、颜色、积分
列名 | 数据类型 | 主键/外键 | 说明 |
id | int | 主键 | 自增ID |
order_id | int | 外键 | 订单ID |
goods_id | int | 外键 | 商品ID |
goods_title | nvarchar |
| 商品标题 |
goods_price | decimal |
| 商品价格 |
real_price | nvarchar |
| 实际价格 |
quantity | nvarchar |
| 数量 |
color | decimal |
| 颜色 |
point | int |
| 积分 |
用户表的字段有:用户id、用户组id、用户名、密码、6位随机字符串,加密用到、电子邮箱、用户昵称、头像、性别、生日、联系电话、手机号码、QQ号码、联系地址、安全问题、问题答案、预存款、用户积分、经验值、用户状态、注册时间、注册IP、经度、纬度、城市、介绍、执照照片、场地照片、身份证号
列名
数据类型
主键/外键
说明
id
int
主键
用户id
group_id
int
外键
用户组id
user_name
nvarchar(100)
用户名
password
nvarchar(100)
密码
salt
nvarchar(20)
6位随机字符串加密用到
nvarchar(50)
电子邮箱
nick_name
nvarchar(100)
用户昵称
avatar
nvarchar(255)
头像
sex
nvarchar(20)
性别
birthday
datetime
生日
telphone
nvarchar(50)
联系电话
mobile
nvarchar(20)
手机号码
nvarchar(30)
QQ号码
address
nvarchar(255)
联系地址
safe_question
nvarchar(255)
安全问题
safe_answer
nvarchar(255)
问题答案
amount
decimal(9, 2)
预存款
point
int
用户积分
exp
int
经验值
status
tinyint
用户状态
reg_time
datetime
注册时间
reg_ip
nvarchar(30)
注册IP
longitude
nvarchar(100)
经度
latitude
nvarchar(100)
纬度
city
nvarchar(100)
城市
content
ntext
介绍
license_img
nvarchar(255)
执照照片
place_img
nvarchar(255)
场地照片
shenfenzheng
nvarchar(255)
身份证号
物流快递表的字段有:自增id、快递名称、物流编码、配送费用、快递网址、备注说明、排序、是否不显示
列名 | 数据类型 | 主键/外键 | 说明 |
id | int | 主键 | 自增ID |
title | nvarchar |
| 快递名称 |
express_code | nvarchar |
| 物流编码 |
express_fee | decimal |
| 配送费用 |
website | nvarchar |
| 快递网址 |
remark | ntext |
| 备注说明 |
sort_id | int |
| 排序 |
is_lock | tinyint |
| 是否不显示 |
关系图:
功能模块的具体实现:这个方式是利用dtcms3.0的二次开发,更多请浏览dtcms官方网站:http://www.dtcms.NET/news/show/97.aspx
购物车页面:‘马上结算’按钮
- <a class="btn btn-success marL10" href="<%linkurl("shopping","confirm")%>">马上去结算</a>
与form表单相对应的方法:
- #region 保存用户订单OK=============可以了,把cooke换过来了================
- private void order_save(HttpContext context)
- {
- //获得传参信息
- int payment_id = DTRequest.GetFormInt("payment_id"); //支付ID
- int express_id = DTRequest.GetFormInt("express_id"); //快递ID
- string accept_name = Utils.ToHtml(DTRequest.GetFormString("accept_name")); //收货人
- string post_code = Utils.ToHtml(DTRequest.GetFormString("post_code")); //邮政
- string telphone = Utils.ToHtml(DTRequest.GetFormString("telphone")); //电话
- string mobile = Utils.ToHtml(DTRequest.GetFormString("mobile")); //手机
- string address = Utils.ToHtml(DTRequest.GetFormString("address")); //地址
- string message = Utils.ToHtml(DTRequest.GetFormString("message")); //留言
- //获取订单配置信息
- Model.orderconfig orderConfig = new BLL.orderconfig().loadConfig();
- //检查物流方式
- if (express_id == 0)
- {
- context.Response.Write("{\"status\":0, \"msg\":\"对不起,请选择配送方式!\"}");
- return;
- }
- Model.express expModel = new BLL.express().GetModel(express_id);
- if (expModel == null)
- {
- context.Response.Write("{\"status\":0, \"msg\":\"对不起,配送方式不存在或已删除!\"}");
- return;
- }
- //检查支付方式
- if (payment_id == 0)
- {
- context.Response.Write("{\"status\":0, \"msg\":\"对不起,请选择支付方式!\"}");
- return;
- }
- Model.payment payModel = new BLL.payment().GetModel(payment_id);
- if (payModel == null)
- {
- context.Response.Write("{\"status\":0, \"msg\":\"对不起,支付方式不存在或已删除!\"}");
- return;
- }
- //检查收货人
- if (string.IsNullOrEmpty(accept_name))
- {
- context.Response.Write("{\"status\":0, \"msg\":\"对不起,请输入收货人姓名!\"}");
- return;
- }
- //检查手机和电话
- if (string.IsNullOrEmpty(telphone) && string.IsNullOrEmpty(mobile))
- {
- context.Response.Write("{\"status\":0, \"msg\":\"对不起,请输入收货人联系电话或手机!\"}");
- return;
- }
- //检查地址
- if (string.IsNullOrEmpty(address))
- {
- context.Response.Write("{\"status\":0, \"msg\":\"对不起,请输入详细的收货地址!\"}");
- return;
- }
- //如果开启匿名购物则不检查会员是否登录
- int user_id = 0;
- int user_group_id = 0;
- string user_name = string.Empty;
- //检查用户是否登录
- Model.users userModel = new BasePage().GetUserInfo();
- if (userModel != null)
- {
- user_id = userModel.id;
- user_group_id = userModel.group_id;
- user_name = userModel.user_name;
- bool kkk = new BLL.shoppingcar().updateQuantity(user_id);
- }
- if (orderConfig.anonymous == 0 && userModel == null)
- {
- context.Response.Write("{\"status\":0, \"msg\":\"对不起,用户尚未登录或已超时!\"}");
- return;
- }
- //检查购物车商品
- //IList<Model.cart_items> iList = DTcms.Web.UI.ShopCart.GetList(user_group_id);
- DataTable data = new BLL.shoppingcar().getList(user_id).Tables[0]; //查询购物车
- if (data.Rows.Count < 0)
- {
- context.Response.Write("{\"status\":0, \"msg\":\"对不起,购物车为空,无法结算!\"}");
- return;
- }
- //统计购物车
- Model.car_total carModel = new Model.car_total();
- BLL.shoppingcar carBll = new BLL.shoppingcar();
- string str = carBll.get_quantity(user_id);
- string[] ss = str.Split(';');//用;进行分割
- //判断数量、积分、金额判断是否为空,如果为空整型的转化就会出错
- if (Convert.ToInt32(ss[0]) > 0)
- {
- carModel.total_quantity = Convert.ToInt32(ss[0]); //查询购物车商品件数
- }
- if (Convert.ToInt32(ss[1]) > 0)
- {
- carModel.real_amount = Convert.ToInt32(ss[1]); //查询购物车商品总金额
- carModel.payable_amount = Convert.ToInt32(ss[1]); //查询购物车商品总金额
- }
- if (Convert.ToInt32(ss[2]) > 0)
- {
- carModel.total_point = Convert.ToInt32(ss[2]); //查询购物车商品总积分
- }
- //保存订单=======================================================================
- Model.orders model = new Model.orders();
- model.order_no = "B" + Utils.GetOrderNumber(); //订单号B开头为商品订单
- model.user_id = user_id; //用户id
- model.user_name = user_name; //用户名
- model.payment_id = payment_id; //支付方式id
- model.express_id = express_id; //快递id
- model.accept_name = accept_name; //收货人
- model.post_code = post_code; //邮编
- model.telphone = telphone; //电话
- model.mobile = mobile; //手机号码
- model.address = address; //地址
- model.message = message; //留言
- model.payable_amount = carModel.payable_amount; //总金额
- model.real_amount = carModel.real_amount; //实付金额
- model.express_status = 1;
- model.express_fee = expModel.express_fee; //物流费用
- //提交订单后,就修改的数据库购物车表的有效否,不让以购买的商品显示,自己修改的
- Model.shoppingcar carmodel = new Model.shoppingcar();
- carmodel.user_id = userModel.id;
- BLL.shoppingcar car = new BLL.shoppingcar();
- bool bi = car.submitDelete(carmodel);
- //如果是先款后货的话
- if (payModel.type == 1)
- {
- model.payment_status = 1; //标记未付款
- if (payModel.poundage_type == 1) //百分比
- {
- model.payment_fee = model.real_amount * payModel.poundage_amount / 100;
- }
- else //固定金额
- {
- model.payment_fee = payModel.poundage_amount;
- }
- }
- //订单总金额=实付商品金额+运费+支付手续费
- model.order_amount = model.real_amount + model.express_fee + model.payment_fee;
- //购物积分,可为负数
- model.point = carModel.total_point;
- model.add_time = DateTime.Now;
- //商品详细列表
- List<Model.order_goods> gls = new List<Model.order_goods>();
- for (int i = 0; i < data.Rows.Count; i++) //对购物车内的商品进行数量金额积分的计算,这里的数量金额应该不用进行判断了,出错再判断吧
- {
- int spID=Convert.ToInt32(data.Rows[i]["goods_id"]); //商品ID
- string title = data.Rows[i]["title"].ToString(); //商品名称
- decimal price = Convert.ToDecimal(data.Rows[i]["sell_price"]); //价格
- int quantity = Convert.ToInt32(data.Rows[i]["quantity"]); //数量
- string color = data.Rows[i]["color"].ToString();
- int point = Convert.ToInt32(data.Rows[i]["point"]); //积分
- gls.Add(new Model.order_goods { goods_id = spID, goods_title = title, goods_price = price, real_price = price, quantity = quantity,color = color, point = point });
- }
- //原来的
- //foreach (Model.cart_items item in data.Rows)
- //{
- // gls.Add(new Model.order_goods { goods_id = item.id, goods_title = item.title, goods_price = item.price, real_price = item.user_price, quantity = item.quantity, point = item.point });
- //}
- model.order_goods = gls;
- int result = new BLL.orders().Add(model); //保存订单
- if (result < 1)
- {
- context.Response.Write("{\"status\":0, \"msg\":\"订单保存过程中发生错误,请重新提交!\"}");
- return;
- }
- //扣除积分
- if (model.point < 0)
- {
- new BLL.user_point_log().Add(model.user_id, model.user_name, model.point, "积分换购,订单号:" + model.order_no, false);
- }
- //清空购物车
- //DTcms.Web.UI.ShopCart.Clear("0");
- //提交成功,返回URL
- context.Response.Write("{\"status\":1, \"url\":\"" + new Web.UI.BasePage().linkurl("payment", "confirm", model.order_no) + "\", \"msg\":\"恭喜您,订单已成功提交!\"}");
- return;
- }
- #endregion
快递BLL(payment.cs)层涉及到的方法:
- /// <summary>
- /// 得到一个对象实体
- /// </summary>
- public DTcms.Model.express GetModel(int id)
- {
- return dal.GetModel(id);
- }
- /// <summary>
- /// 得到一个对象实体
- /// </summary>
- public Model.express GetModel(int id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("select top 1 id,title,express_code,express_fee,website,remark,sort_id,is_lock from " + databaseprefix + "express ");
- strSql.Append(" where id=@id");
- SqlParameter[] parameters = {
- new SqlParameter("@id", SqlDbType.Int,4)};
- parameters[0].Value = id;
- Model.express model = new Model.express();
- DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
- if (ds.Tables[0].Rows.Count > 0)
- {
- if (ds.Tables[0].Rows[0]["id"].ToString() != "")
- {
- model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
- }
- model.title = ds.Tables[0].Rows[0]["title"].ToString();
- model.express_code = ds.Tables[0].Rows[0]["express_code"].ToString();
- if (ds.Tables[0].Rows[0]["express_fee"].ToString() != "")
- {
- model.express_fee = decimal.Parse(ds.Tables[0].Rows[0]["express_fee"].ToString());
- }
- model.website = ds.Tables[0].Rows[0]["website"].ToString();
- model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
- if (ds.Tables[0].Rows[0]["sort_id"].ToString() != "")
- {
- model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString());
- }
- if (ds.Tables[0].Rows[0]["is_lock"].ToString() != "")
- {
- model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString());
- }
- return model;
- }
- else
- {
- return null;
- }
- }
支付方式BLL(payment.cs)涉及到的方法:
- /// <summary>
- /// 得到一个对象实体
- /// </summary>
- public Model.payment GetModel(int id)
- {
- return dal.GetModel(id);
- }
与 支付方式BLL对应的DAL方法:
- /// <summary>
- /// 得到一个对象实体
- /// </summary>
- public Model.payment GetModel(int id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("select top 1 id,title,img_url,remark,type,poundage_type,poundage_amount,sort_id,is_lock,api_path from " + databaseprefix + "payment ");
- strSql.Append(" where id=@id");
- SqlParameter[] parameters = {
- new SqlParameter("@id", SqlDbType.Int,4)};
- parameters[0].Value = id;
- Model.payment model = new Model.payment();
- DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
- if (ds.Tables[0].Rows.Count > 0)
- {
- if (ds.Tables[0].Rows[0]["id"].ToString() != "")
- {
- model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
- }
- model.title = ds.Tables[0].Rows[0]["title"].ToString();
- model.img_url = ds.Tables[0].Rows[0]["img_url"].ToString();
- model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
- if (ds.Tables[0].Rows[0]["type"].ToString() != "")
- {
- model.type = int.Parse(ds.Tables[0].Rows[0]["type"].ToString());
- }
- if (ds.Tables[0].Rows[0]["poundage_type"].ToString() != "")
- {
- model.poundage_type = int.Parse(ds.Tables[0].Rows[0]["poundage_type"].ToString());
- }
- if (ds.Tables[0].Rows[0]["poundage_amount"].ToString() != "")
- {
- model.poundage_amount = decimal.Parse(ds.Tables[0].Rows[0]["poundage_amount"].ToString());
- }
- if (ds.Tables[0].Rows[0]["sort_id"].ToString() != "")
- {
- model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString());
- }
- if (ds.Tables[0].Rows[0]["is_lock"].ToString() != "")
- {
- model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString());
- }
- model.api_path = ds.Tables[0].Rows[0]["api_path"].ToString();
- return model;
- }
- else
- {
- return null;
- }
- }
购物车BLL(shoppingcar.cs)涉及到的方法:
- /// <summary>
- /// 提交购物车订单后,修改购物车表的有效否
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool submitDelete(Model.shoppingcar model)
- {
- int id = 0; //购物车id
- int k = 0;
- DataTable dt = getList(model.user_id).Tables[0];
- for (int i = 0; i < dt.Rows.Count; i++) //对购物车内的商品进行数量金额积分的计算
- {
- id = Convert.ToInt32(dt.Rows[i]["id"]);
- model.id = id;
- if (Delete(model))
- {
- k = 1;
- }
- }
- if (k > 0)
- {
- return true;
- }
- else { return false; }
- }
- /// <summary>
- /// 查询
- /// </summary>
- /// <param name="user_id"></param>
- /// <returns></returns>
- public DataSet getList(int user_id)
- {
- //get_quantity(user_id);
- //DataTable dt = dal.getList(user_id).Tables[0];
- return dal.getList(user_id);
- }
- /// <summary>
- /// 查询购物车的商品数量、积分、金额++
- /// </summary>
- /// <param name="user_id"></param>
- /// <returns></returns>
- public string get_quantity(int user_id)
- {
- DataTable dt = new DataTable();
- dt=dal.get_quantity(user_id).Tables[0];
- int quantity = 0;
- int sell_price = 0;
- int point = 0;
- for (int i = 0; i < dt.Rows.Count; i++) //对购物车内的商品进行数量金额积分的计算
- {
- if (dt.Rows[i]["quantity"] != Convert.DBNull) //如果dt.Rows[i]["quantity"]为空的话就转换不到整形,所以这里用Convert.DBNull进行判断
- {
- quantity += Convert.ToInt32(dt.Rows[i]["quantity"]);
- }
- if (dt.Rows[i]["sell_price"] != Convert.DBNull && dt.Rows[i]["quantity"] != Convert.DBNull)
- {
- sell_price += Convert.ToInt32(dt.Rows[i]["sell_price"]) * Convert.ToInt32(dt.Rows[i]["quantity"]);
- }
- if (dt.Rows[i]["point"] != Convert.DBNull && dt.Rows[i]["quantity"] != Convert.DBNull)
- {
- point += Convert.ToInt32(dt.Rows[i]["point"]) *Convert.ToInt32(dt.Rows[i]["quantity"]);
- }
- }
- string str = "";
- str = quantity + ";" + sell_price + ";" + point;
- return str;
- }
- /// <summary>
- /// 这个方法用于保存订单的时候,修改商品的数量
- /// </summary>
- /// <param name="user_id"></param>
- /// <returns></returns>
- public bool updateQuantity(int user_id)
- {
- DataTable dt = new DataTable();
- dt = dal.getList(user_id).Tables[0];
- int quantity = 0;
- for (int i = 0; i < dt.Rows.Count; i++) //进行遍历修改商品数量
- {
- quantity = Convert.ToInt32(dt.Rows[i]["quantity"]); //获取每一行的数量
- int goods_id = Convert.ToInt32(dt.Rows[i]["goods_id"]);
- BLL.goods goods = new goods();
- int goods_quantity = Convert.ToInt32(goods.GetQuantity(goods_id));
- if (goods_quantity >=quantity)
- {
- goods_quantity = goods_quantity - quantity; //数量运算
- }
- string str = "stock_quantity=" + goods_quantity;
- goods.UpdateField(goods_id, str);
- }
- return true;
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool Delete(Model.shoppingcar model)
- {
- return dal.Delete(model);
- }
与购物车BLL对应的DAL方法:
- /// <summary>
- /// 删除购物车,一行数据
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool Delete(Model.shoppingcar model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("update " + databaseprefix + "shoppingCar set youxiaofou=@youxiaofou where id=@id");
- SqlParameter[] parameters = {
- new SqlParameter("@id", SqlDbType.Int,4),
- new SqlParameter("@youxiaofou",SqlDbType.Bit)
- };
- parameters[0].Value = model.id;
- parameters[1].Value = false;
- int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
- if (rows > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 查询购物车
- /// </summary>
- /// <param name="user_id">根据当前‘用户ID’来查询该用户的购物车</param>
- /// <returns></returns>
- public DataSet getList(int user_id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("select a.*,b.sell_price,b.title,b.img_url,b.point FROM " + databaseprefix + "shoppingCar a left join dt_goods b on a.goods_id=b.id");
- strSql.Append(" where user_id=" + user_id + " and youxiaofou=1");
- strSql.Append(" order by a.id desc");
- return DbHelperSQL.Query(strSql.ToString());
- }
- /// <summary>
- /// 返回购物车商品数量、价格、积分总数
- /// </summary>
- /// <param name="user_id">根据用户ID来查询</param>
- /// <returns></returns>
- public DataSet get_quantity(int user_id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("select a.quantity,b.sell_price,b.point FROM " + databaseprefix + "shoppingCar a left join dt_goods b on a.goods_id=b.id");
- strSql.Append(" where user_id=" + user_id + " and youxiaofou=1");
- return DbHelperSQL.Query(strSql.ToString());
- }
另外购物车BLL(shoppingcar.cs)涉及到了商品BLL(goods.cs)里面的方法
- BLL里面的方法:
- /// <summary>
- /// 修改一列数据
- /// </summary>
- public void UpdateField(int id, string strValue)
- {
- dal.UpdateField(id, strValue);
- }
- DAL的方法:
- /// <summary>
- /// 修改一列数据
- /// </summary>
- public void UpdateField(int id, string strValue)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("update " + databaseprefix + "goods set " + strValue);
- strSql.Append(" where id=" + id);
- DbHelperSQL.ExecuteSql(strSql.ToString());
- }
订单信息BLL(orders.cs)涉及到的方法:
- /// <summary>
- /// 增加一条数据+++
- /// </summary>
- public int Add(Model.orders model)
- {
- return dal.Add(model);
- }
与订单信息BLL对应的DAL方法:
- /// <summary>
- /// 增加一条数据,及其子表数据
- /// </summary>
- public int Add(Model.orders model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("insert into " + databaseprefix + "orders(");
- strSql.Append("order_no,trade_no,user_id,user_name,payment_id,payment_fee,payment_status,payment_time,express_id,express_no,express_fee,express_status,express_time,accept_name,post_code,telphone,mobile,area,address,message,remark,payable_amount,real_amount,order_amount,point,status,add_time,confirm_time,complete_time)");
- strSql.Append(" values (");
- strSql.Append("@order_no,@trade_no,@user_id,@user_name,@payment_id,@payment_fee,@payment_status,@payment_time,@express_id,@express_no,@express_fee,@express_status,@express_time,@accept_name,@post_code,@telphone,@mobile,@area,@address,@message,@remark,@payable_amount,@real_amount,@order_amount,@point,@status,@add_time,@confirm_time,@complete_time)");
- strSql.Append(";set @ReturnValue= @@IDENTITY");
- SqlParameter[] parameters = {
- new SqlParameter("@order_no", SqlDbType.NVarChar,100),
- new SqlParameter("@trade_no", SqlDbType.NVarChar,100),
- new SqlParameter("@user_id", SqlDbType.Int,4),
- new SqlParameter("@user_name", SqlDbType.NVarChar,100),
- new SqlParameter("@payment_id", SqlDbType.Int,4),
- new SqlParameter("@payment_fee", SqlDbType.Decimal,5),
- new SqlParameter("@payment_status", SqlDbType.TinyInt,1),
- new SqlParameter("@payment_time", SqlDbType.DateTime),
- new SqlParameter("@express_id", SqlDbType.Int,4),
- new SqlParameter("@express_no", SqlDbType.NVarChar,100),
- new SqlParameter("@express_fee", SqlDbType.Decimal,5),
- new SqlParameter("@express_status", SqlDbType.TinyInt,1),
- new SqlParameter("@express_time", SqlDbType.DateTime),
- new SqlParameter("@accept_name", SqlDbType.NVarChar,50),
- new SqlParameter("@post_code", SqlDbType.NVarChar,20),
- new SqlParameter("@telphone", SqlDbType.NVarChar,30),
- new SqlParameter("@mobile", SqlDbType.NVarChar,20),
- new SqlParameter("@area", SqlDbType.NVarChar,100),
- new SqlParameter("@address", SqlDbType.NVarChar,500),
- new SqlParameter("@message", SqlDbType.NVarChar,500),
- new SqlParameter("@remark", SqlDbType.NVarChar,500),
- new SqlParameter("@payable_amount", SqlDbType.Decimal,5),
- new SqlParameter("@real_amount", SqlDbType.Decimal,5),
- new SqlParameter("@order_amount", SqlDbType.Decimal,5),
- new SqlParameter("@point", SqlDbType.Int,4),
- new SqlParameter("@status", SqlDbType.TinyInt,1),
- new SqlParameter("@add_time", SqlDbType.DateTime),
- new SqlParameter("@confirm_time", SqlDbType.DateTime),
- new SqlParameter("@complete_time", SqlDbType.DateTime),
- new SqlParameter("@ReturnValue",SqlDbType.Int)};
- parameters[0].Value = model.order_no;
- parameters[1].Value = model.trade_no;
- parameters[2].Value = model.user_id;
- parameters[3].Value = model.user_name;
- parameters[4].Value = model.payment_id;
- parameters[5].Value = model.payment_fee;
- parameters[6].Value = model.payment_status;
- parameters[7].Value = model.payment_time;
- parameters[8].Value = model.express_id;
- parameters[9].Value = model.express_no;
- parameters[10].Value = model.express_fee;
- parameters[11].Value = model.express_status;
- parameters[12].Value = model.express_time;
- parameters[13].Value = model.accept_name;
- parameters[14].Value = model.post_code;
- parameters[15].Value = model.telphone;
- parameters[16].Value = model.mobile;
- parameters[17].Value = model.area;
- parameters[18].Value = model.address;
- parameters[19].Value = model.message;
- parameters[20].Value = model.remark;
- parameters[21].Value = model.payable_amount;
- parameters[22].Value = model.real_amount;
- parameters[23].Value = model.order_amount;
- parameters[24].Value = model.point;
- parameters[25].Value = model.status;
- parameters[26].Value = model.add_time;
- parameters[27].Value = model.confirm_time;
- parameters[28].Value = model.complete_time;
- parameters[29].Direction = ParameterDirection.Output;
- List<CommandInfo> sqllist = new List<CommandInfo>();
- CommandInfo cmd = new CommandInfo(strSql.ToString(), parameters);
- sqllist.Add(cmd);
- //订单商品列表
- if (model.order_goods != null)
- {
- StringBuilder strSql2;
- foreach (Model.order_goods models in model.order_goods)
- {
- strSql2 = new StringBuilder();
- strSql2.Append("insert into " + databaseprefix + "order_goods(");
- strSql2.Append("order_id,goods_id,goods_title,goods_price,real_price,quantity,color,point)");
- strSql2.Append(" values (");
- strSql2.Append("@order_id,@goods_id,@goods_title,@goods_price,@real_price,@quantity,@color,@point)");
- SqlParameter[] parameters2 = {
- new SqlParameter("@order_id", SqlDbType.Int,4),
- new SqlParameter("@goods_id", SqlDbType.Int,4),
- new SqlParameter("@goods_title", SqlDbType.NVarChar,100),
- new SqlParameter("@goods_price", SqlDbType.Decimal,5),
- new SqlParameter("@real_price", SqlDbType.Decimal,5),
- new SqlParameter("@quantity", SqlDbType.Int,4),
- new SqlParameter("@color", SqlDbType.NVarChar,150),
- new SqlParameter("@point", SqlDbType.Int,4)};
- parameters2[0].Direction = ParameterDirection.InputOutput;
- parameters2[1].Value = models.goods_id;
- parameters2[2].Value = models.goods_title;
- parameters2[3].Value = models.goods_price;
- parameters2[4].Value = models.real_price;
- parameters2[5].Value = models.quantity;
- parameters2[6].Value = models.color;
- parameters2[7].Value = models.point;
- cmd = new CommandInfo(strSql2.ToString(), parameters2);
- sqllist.Add(cmd);
- }
- }
- DbHelperSQL.ExecuteSqlTranWithIndentity(sqllist);
- return (int)parameters[29].Value;
- }
仅供学习,禁止商业用途