forked from gaozhifeng/PHPMyWind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.php
403 lines (363 loc) · 10.9 KB
/
order.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<?php require_once(dirname(__FILE__).'/include/config.inc.php');
/*
**************************
(C)2010-2015 phpMyWind.com
update: 2013-1-14 13:23:24
person: Feng
**************************
*/
//初始化购物车字符串
if(empty($_COOKIE['shoppingcart']))
{
header('location:shoppingcart.php');
exit();
}
//不允许游客下单跳转登录
if(empty($_COOKIE['username']))
{
header('location:member.php?c=login');
exit();
}
//初始化参数
$action = isset($action) ? $action : '';
$username = AuthCode($_COOKIE['username']);
$shoppingcart = unserialize(AuthCode($_COOKIE['shoppingcart']));
$totalprice = '';
$totalweight = '';
$datagroup = isset($datagroup) ? $datagroup : '';
$level = isset($level) ? intval($level) : '';
$v = isset($areaval) ? $areaval : '0';
//获取级联
if($action == 'getarea')
{
$str = '<option value="-1">--</option>';
$sql = "SELECT * FROM `#@__cascadedata` WHERE level=$level And ";
if($v == 0)
$sql .= "datagroup='$datagroup'";
else if($v % 500 == 0)
$sql .= "datagroup='$datagroup' AND datavalue>'$v' AND datavalue<'".($v + 500)."'";
else
$sql .= "datavalue LIKE '$v.%%%' AND datagroup='$datagroup'";
$sql .= " ORDER BY orderid ASC, datavalue ASC";
$dosql->Execute($sql);
while($row = $dosql->GetArray())
{
$str .= '<option value="'.$row['datavalue'].'">'.$row['dataname'].'</option>';
}
if($str == '') $str .= '<option value="-1">--</option>';
echo $str;
exit();
}
//保存订单
if($action == 'save')
{
//检测数据完整性
if($username == '' or
$truename == '' or
$telephone == '' or
$zipcode == '' or
$postarea_prov == '-1' or
$address == '' or
$idcard == '' or
$postmode == '-1' or
$paymode == '-1' or
$getmode == '-1'
)
{
header('location:order.php');
exit();
}
//HTML转义变量
$username = htmlspecialchars($username);
$truename = htmlspecialchars($truename);
$idcard = htmlspecialchars($idcard);
$telephone = htmlspecialchars($telephone);
$zipcode = htmlspecialchars($zipcode);
$address = htmlspecialchars($address);
$buyremark = htmlspecialchars($buyremark);
$posttime = time();
$postarea_prov = empty($postarea_prov) ? '-1' : $postarea_prov;
$postarea_city = empty($postarea_city) ? '-1' : $postarea_city;
$postarea_country = empty($postarea_country) ? '-1' : $postarea_country;
$orderinfo = array('truename' => $truename,
'telephone' => $telephone,
'zipcode' => $zipcode,
'postarea_prov' => $postarea_prov,
'postarea_city' => $postarea_city,
'postarea_country' => $postarea_country,
'address' => $address,
'idcard' => $idcard,
'postmode' => $postmode,
'paymode' => $paymode,
'getmode' => $getmode,
'buyremark' => $buyremark,
'posttime' => $posttime);
//存入COOKIE
setcookie('orderinfo', AuthCode(serialize($orderinfo),'ENCODE'));
header('location:orderenter.php');
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php echo GetHeader(0,0,'商品订单'); ?>
<link href="templates/default/style/webstyle.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="templates/default/js/jquery.min.js"></script>
<script type="text/javascript" src="templates/default/js/getarea.js"></script>
<script type="text/javascript" src="templates/default/js/top.js"></script>
<script type="text/javascript">
$(function(){
$("input").focus(function(){
$(this).attr("class", "class_input_on");
}).blur(function(){
$(this).attr("class", "class_input");
});
$("textarea").focus(function(){
$(this).attr("class", "class_areatext_on");
}).blur(function(){
$(this).attr("class", "class_areatext");
});
$("#truename").focus();
})
/*验证订单表单*/
function CheckOrder()
{
if($("#truename").val() == "")
{
alert("请填写收货人姓名!");
$("#truename").focus();
return false;
}
if($("#telephone").val() == "")
{
alert("请填写电话!");
$("#telephone").focus();
return false;
}
if($("#zipcode").val() == "")
{
alert("请填写邮编!");
$("#zipcode").focus();
return false;
}
if($("#postarea_prov").val() == "-1")
{
alert("请选择所在省份!");
$("#postarea_prov").focus();
return false;
}
if($("#postarea_city").val() == "-1")
{
alert("请选择所在城市!");
$("#postarea_city").focus();
return false;
}
if($("#address").val() == "")
{
alert("请填写详细地址!");
$("#address").focus();
return false;
}
if($("#idcard").val() == "")
{
alert("请填写身份证号码!");
$("#idcard").focus();
return false;
}
if($("#postmode").val() == "-1")
{
alert("请选择配送方式!");
$("#postmode").focus();
return false;
}
if($("#paymode").val() == "-1")
{
alert("请选择支付方式!");
$("#paymode").focus();
return false;
}
if($("#getmode").val() == "-1")
{
alert("请选择货到方式!");
$("#getmode").focus();
return false;
}
$("#form").submit();
return false;
}
</script>
</head>
<body>
<!-- header-->
<?php require_once('header.php'); ?>
<!-- /header-->
<!-- banner-->
<div class="subBanner"> <img src="templates/default/images/banner-ir.png" /> </div>
<!-- /banner-->
<!-- notice-->
<div class="subnotice"><strong>网站公告:</strong> <?php echo Info(1); ?> </div>
<!-- /notice-->
<!-- mainbody-->
<div class="subBody">
<div class="subTitle" style="margin:0;"> <span class="catname shopcart">商品订单</span>
<div class="cl"></div>
</div>
<form name="form" id="form" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="shoppingcart">
<tr>
<td colspan="2" height="30" class="thead"> 收货人信息</td>
</tr>
<tr>
<td colspan="2" height="15"></td>
</tr>
<tr>
<td width="80" height="40" align="right">收货人姓名: </td>
<td><input name="truename" type="text" class="class_input" id="truename" /></td>
</tr>
<tr>
<td height="40" align="right">电 话:</td>
<td><input name="telephone" type="text" class="class_input" id="telephone" /></td>
</tr>
<tr>
<td height="40" align="right">邮 编: </td>
<td><input name="zipcode" type="text" class="class_input" id="zipcode" /></td>
</tr>
<tr>
<td height="40" align="right">地 址:</td>
<td><select name="postarea_prov" id="postarea_prov" onchange="SelProv(this.value,'postarea');">
<option value="-1">请选择</option>
<?php
$dosql->Execute("SELECT * FROM `#@__cascadedata` WHERE `datagroup`='area' AND level=0 ORDER BY orderid ASC, datavalue ASC");
while($row = $dosql->GetArray())
{
echo '<option value="'.$row['datavalue'].'">'.$row['dataname'].'</option>';
}
?>
</select>
<select name="postarea_city" id="postarea_city" onchange="SelCity(this.value,'postarea');">
<option value="-1">--</option>
</select>
<select name="postarea_country" id="postarea_country">
<option value="-1">--</option>
</select></td>
</tr>
<tr>
<td height="40" align="right"> </td>
<td><input name="address" type="text" class="class_input" id="address" /></td>
</tr>
<tr>
<td height="40" align="right">身份证号:</td>
<td><input type="text" name="idcard" id="idcard" class="class_input" /></td>
</tr>
<tr>
<td colspan="2" height="30"> </td>
</tr>
<tr>
<td colspan="2" height="30" class="thead"> 订单信息</td>
</tr>
<tr>
<td colspan="2" height="15"></td>
</tr>
<tr>
<td height="40" align="right">配送方式:</td>
<td><select name="postmode" id="postmode">
<option value="-1">请选择配送方式</option>
<?php GetTopType('#@__postmode','#@__goodsorder','postmode'); ?>
</select></td>
</tr>
<tr>
<td height="40" align="right">支付方式:</td>
<td><select name="paymode" id="paymode">
<option value="-1">请选择支付方式</option>
<?php GetTopType('#@__paymode','#@__goodsorder','paymode'); ?>
</select></td>
</tr>
<tr>
<td height="40" align="right">货到方式:</td>
<td><select name="getmode" id="getmode">
<option value="-1">请选择货到方式</option>
<?php GetTopType('#@__getmode','#@__goodsorder','getmode'); ?>
</select></td>
</tr>
<tr>
<td height="120" align="right">购物备注:</td>
<td><textarea name="buyremark" class="class_areatext" id="buyremark"></textarea></td>
</tr>
<tr>
<td height="60" colspan="2" align="right" valign="bottom">
<?php
//显示订单列表
foreach($shoppingcart as $k=>$goods)
{
//获取数据库中商品信息
$r = $dosql->GetOne("SELECT * FROM `#@__goods` WHERE `id`=".intval($goods[0]));
//计算订单总价
$totalprice += $r['salesprice']*$goods[1];
//计算订单总重
$totalweight += $r['weight']*$goods[1];
}
?>
<strong class="total">总计:</strong><span class="totalprice"><?php echo $totalprice; ?></span><a href="shoppingcart.php" class="next">上一步</a><a href="javascript:;" onclick="CheckOrder();return false;" class="next">提 交</a></td>
</tr>
</table>
<input type="hidden" name="username" id="username" value="<?php echo $username; ?>" />
<input type="hidden" name="amount" id="amount" value="<?php echo $totalprice; ?>" />
<input type="hidden" name="weight" id="weight" value="<?php echo $totalweight; ?>" />
<input type="hidden" name="action" id="action" value="save" />
</form>
</div>
<?php
/*
* 展示自定义类别(无下级)
*
* @access public
* @param $tbname string 显示分类的表名称
* @param $tbname2 string 使用分类的表名称
* @param $colname string 使用分类的表字段
* @param $id int 区别记录集的ID
* @param $i int option缩进位数
* @return string 输出<select>
*/
function GetTopType($tbname='', $tbname2='', $colname='', $id=0, $i=0)
{
global $dosql;
if(isset($_GET['id']))
{
$r = $dosql->GetOne("SELECT `$colname` FROM `$tbname2` WHERE `id`=".intval($_GET['id']));
}
$dosql->Execute("SELECT * FROM `$tbname` ORDER BY `orderid` ASC",$id);
$i++;
while($row = $dosql->GetArray($id))
{
$selected = '';
if(isset($r) && is_array($r))
{
if($row['id'] == $r["$colname"])
$selected = 'selected="selected"';
}
echo '<option value="'.$row['id'].'"'.$selected.'>'.$row["classname"].'</option>';
}
}
/*
* 获取排列序号
*
* @access public
* @param $tbname string 获取该表的最大ID
* @return $orderid int 返回当前ID
*/
function GetOrderID($tbname)
{
global $dosql;
$r = $dosql->GetOne("SELECT MAX(orderid) AS orderid FROM `$tbname`");
$orderid = (empty($r['orderid']) ? 1 : ($r['orderid'] + 1));
return $orderid;
}
?>
<!-- /mainbody-->
<!-- footer-->
<?php require_once('footer.php'); ?>
<!-- /footer-->
</body>
</html>