-
Notifications
You must be signed in to change notification settings - Fork 0
/
auction.php
498 lines (429 loc) · 16.5 KB
/
auction.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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<?php
/**
* ECSHOP 拍卖前台文件
* ============================================================================
* * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liubo $
* $Id: auction.php 17217 2011-01-19 06:29:08Z liubo $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
/*------------------------------------------------------ */
//-- act 操作项的初始化
/*------------------------------------------------------ */
if (empty($_REQUEST['act']))
{
$_REQUEST['act'] = 'list';
}
/*------------------------------------------------------ */
//-- 拍卖活动列表
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'list')
{
/* 取得拍卖活动总数 */
$count = auction_count();
if ($count > 0)
{
/* 取得每页记录数 */
$size = isset($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10;
/* 计算总页数 */
$page_count = ceil($count / $size);
/* 取得当前页 */
$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
$page = $page > $page_count ? $page_count : $page;
/* 缓存id:语言 - 每页记录数 - 当前页 */
$cache_id = $_CFG['lang'] . '-' . $size . '-' . $page;
$cache_id = sprintf('%X', crc32($cache_id));
}
else
{
/* 缓存id:语言 */
$cache_id = $_CFG['lang'];
$cache_id = sprintf('%X', crc32($cache_id));
}
/* 如果没有缓存,生成缓存 */
if (!$smarty->is_cached('auction_list.dwt', $cache_id))
{
if ($count > 0)
{
/* 取得当前页的拍卖活动 */
$auction_list = auction_list($size, $page);
$smarty->assign('auction_list', $auction_list);
/* 设置分页链接 */
$pager = get_pager('auction.php', array('act' => 'list'), $count, $page, $size);
$smarty->assign('pager', $pager);
}
/* 模板赋值 */
$smarty->assign('cfg', $_CFG);
assign_template();
$position = assign_ur_here();
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$smarty->assign('categories', get_categories_tree()); // 分类树
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('top_goods', get_top10()); // 销售排行
$smarty->assign('promotion_info', get_promotion_info());
$smarty->assign('feed_url', ($_CFG['rewrite'] == 1) ? "feed-typeauction.xml" : 'feed.php?type=auction'); // RSS URL
assign_dynamic('auction_list');
}
/* 显示模板 */
$smarty->display('auction_list.dwt', $cache_id);
}
/*------------------------------------------------------ */
//-- 拍卖商品 --> 商品详情
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'view')
{
/* 取得参数:拍卖活动id */
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
if ($id <= 0)
{
ecs_header("Location: ./\n");
exit;
}
/* 取得拍卖活动信息 */
$auction = auction_info($id);
if (empty($auction))
{
ecs_header("Location: ./\n");
exit;
}
/* 缓存id:语言,拍卖活动id,状态,如果是进行中,还要最后出价的时间(如果有的话) */
$cache_id = $_CFG['lang'] . '-' . $id . '-' . $auction['status_no'];
if ($auction['status_no'] == UNDER_WAY)
{
if (isset($auction['last_bid']))
{
$cache_id = $cache_id . '-' . $auction['last_bid']['bid_time'];
}
}
elseif ($auction['status_no'] == FINISHED && $auction['last_bid']['bid_user'] == $_SESSION['user_id']
&& $auction['order_count'] == 0)
{
$auction['is_winner'] = 1;
$cache_id = $cache_id . '-' . $auction['last_bid']['bid_time'] . '-1';
}
$cache_id = sprintf('%X', crc32($cache_id));
/* 如果没有缓存,生成缓存 */
if (!$smarty->is_cached('auction.dwt', $cache_id))
{
//取货品信息
if ($auction['product_id'] > 0)
{
$goods_specifications = get_specifications_list($auction['goods_id']);
$good_products = get_good_products($auction['goods_id'], 'AND product_id = ' . $auction['product_id']);
$_good_products = explode('|', $good_products[0]['goods_attr']);
$products_info = '';
foreach ($_good_products as $value)
{
$products_info .= ' ' . $goods_specifications[$value]['attr_name'] . ':' . $goods_specifications[$value]['attr_value'];
}
$smarty->assign('products_info', $products_info);
unset($goods_specifications, $good_products, $_good_products, $products_info);
}
$auction['gmt_end_time'] = local_strtotime($auction['end_time']);
$smarty->assign('auction', $auction);
/* 取得拍卖商品信息 */
$goods_id = $auction['goods_id'];
$goods = goods_info($goods_id);
if (empty($goods))
{
ecs_header("Location: ./\n");
exit;
}
$goods['url'] = build_uri('goods', array('gid' => $goods_id), $goods['goods_name']);
$smarty->assign('auction_goods', $goods);
/* 出价记录 */
$smarty->assign('auction_log', auction_log($id));
//模板赋值
$smarty->assign('cfg', $_CFG);
assign_template();
$position = assign_ur_here(0, $goods['goods_name']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$smarty->assign('categories', get_categories_tree()); // 分类树
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('top_goods', get_top10()); // 销售排行
$smarty->assign('promotion_info', get_promotion_info());
assign_dynamic('auction');
}
//更新商品点击次数
$sql = 'UPDATE ' . $ecs->table('goods') . ' SET click_count = click_count + 1 '.
"WHERE goods_id = '" . $auction['goods_id'] . "'";
$db->query($sql);
$smarty->assign('now_time', gmtime()); // 当前系统时间
$smarty->display('auction.dwt', $cache_id);
}
/*------------------------------------------------------ */
//-- 拍卖商品 --> 出价
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'bid')
{
include_once(ROOT_PATH . 'includes/lib_order.php');
/* 取得参数:拍卖活动id */
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
if ($id <= 0)
{
ecs_header("Location: ./\n");
exit;
}
/* 取得拍卖活动信息 */
$auction = auction_info($id);
if (empty($auction))
{
ecs_header("Location: ./\n");
exit;
}
/* 活动是否正在进行 */
if ($auction['status_no'] != UNDER_WAY)
{
show_message($_LANG['au_not_under_way'], '', '', 'error');
}
/* 是否登录 */
$user_id = $_SESSION['user_id'];
if ($user_id <= 0)
{
show_message($_LANG['au_bid_after_login']);
}
$user = user_info($user_id);
/* 取得出价 */
$bid_price = isset($_POST['price']) ? round(floatval($_POST['price']), 2) : 0;
if ($bid_price <= 0)
{
show_message($_LANG['au_bid_price_error'], '', '', 'error');
}
/* 如果有一口价且出价大于等于一口价,则按一口价算 */
$is_ok = false; // 出价是否ok
if ($auction['end_price'] > 0)
{
if ($bid_price >= $auction['end_price'])
{
$bid_price = $auction['end_price'];
$is_ok = true;
}
}
/* 出价是否有效:区分第一次和非第一次 */
if (!$is_ok)
{
if ($auction['bid_user_count'] == 0)
{
/* 第一次要大于等于起拍价 */
$min_price = $auction['start_price'];
}
else
{
/* 非第一次出价要大于等于最高价加上加价幅度,但不能超过一口价 */
$min_price = $auction['last_bid']['bid_price'] + $auction['amplitude'];
if ($auction['end_price'] > 0)
{
$min_price = min($min_price, $auction['end_price']);
}
}
if ($bid_price < $min_price)
{
show_message(sprintf($_LANG['au_your_lowest_price'], price_format($min_price, false)), '', '', 'error');
}
}
/* 检查联系两次拍卖人是否相同 */
if ($auction['last_bid']['bid_user'] == $user_id && $bid_price != $auction['end_price'])
{
show_message($_LANG['au_bid_repeat_user'], '', '', 'error');
}
/* 是否需要保证金 */
if ($auction['deposit'] > 0)
{
/* 可用资金够吗 */
if ($user['user_money'] < $auction['deposit'])
{
show_message($_LANG['au_user_money_short'], '', '', 'error');
}
/* 如果不是第一个出价,解冻上一个用户的保证金 */
if ($auction['bid_user_count'] > 0)
{
log_account_change($auction['last_bid']['bid_user'], $auction['deposit'], (-1) * $auction['deposit'],
0, 0, sprintf($_LANG['au_unfreeze_deposit'], $auction['act_name']));
}
/* 冻结当前用户的保证金 */
log_account_change($user_id, (-1) * $auction['deposit'], $auction['deposit'],
0, 0, sprintf($_LANG['au_freeze_deposit'], $auction['act_name']));
}
/* 插入出价记录 */
$auction_log = array(
'act_id' => $id,
'bid_user' => $user_id,
'bid_price' => $bid_price,
'bid_time' => gmtime()
);
$db->autoExecute($ecs->table('auction_log'), $auction_log, 'INSERT');
/* 出价是否等于一口价 */
if ($bid_price == $auction['end_price'])
{
/* 结束拍卖活动 */
$sql = "UPDATE " . $ecs->table('goods_activity') . " SET is_finished = 1 WHERE act_id = '$id' LIMIT 1";
$db->query($sql);
}
/* 跳转到活动详情页 */
ecs_header("Location: auction.php?act=view&id=$id\n");
exit;
}
/*------------------------------------------------------ */
//-- 拍卖商品 --> 购买
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'buy')
{
/* 查询:取得参数:拍卖活动id */
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
if ($id <= 0)
{
ecs_header("Location: ./\n");
exit;
}
/* 查询:取得拍卖活动信息 */
$auction = auction_info($id);
if (empty($auction))
{
ecs_header("Location: ./\n");
exit;
}
/* 查询:活动是否已结束 */
if ($auction['status_no'] != FINISHED)
{
show_message($_LANG['au_not_finished'], '', '', 'error');
}
/* 查询:有人出价吗 */
if ($auction['bid_user_count'] <= 0)
{
show_message($_LANG['au_no_bid'], '', '', 'error');
}
/* 查询:是否已经有订单 */
if ($auction['order_count'] > 0)
{
show_message($_LANG['au_order_placed']);
}
/* 查询:是否登录 */
$user_id = $_SESSION['user_id'];
if ($user_id <= 0)
{
show_message($_LANG['au_buy_after_login']);
}
/* 查询:最后出价的是该用户吗 */
if ($auction['last_bid']['bid_user'] != $user_id)
{
show_message($_LANG['au_final_bid_not_you'], '', '', 'error');
}
/* 查询:取得商品信息 */
$goods = goods_info($auction['goods_id']);
/* 查询:处理规格属性 */
$goods_attr = '';
$goods_attr_id = '';
if ($auction['product_id'] > 0)
{
$product_info = get_good_products($auction['goods_id'], 'AND product_id = ' . $auction['product_id']);
$goods_attr_id = str_replace('|', ',', $product_info[0]['goods_attr']);
$attr_list = array();
$sql = "SELECT a.attr_name, g.attr_value " .
"FROM " . $ecs->table('goods_attr') . " AS g, " .
$ecs->table('attribute') . " AS a " .
"WHERE g.attr_id = a.attr_id " .
"AND g.goods_attr_id " . db_create_in($goods_attr_id);
$res = $db->query($sql);
while ($row = $db->fetchRow($res))
{
$attr_list[] = $row['attr_name'] . ': ' . $row['attr_value'];
}
$goods_attr = join(chr(13) . chr(10), $attr_list);
}
else
{
$auction['product_id'] = 0;
}
/* 清空购物车中所有拍卖商品 */
include_once(ROOT_PATH . 'includes/lib_order.php');
clear_cart(CART_AUCTION_GOODS);
/* 加入购物车 */
$cart = array(
'user_id' => $user_id,
'session_id' => SESS_ID,
'goods_id' => $auction['goods_id'],
'goods_sn' => addslashes($goods['goods_sn']),
'goods_name' => addslashes($goods['goods_name']),
'market_price' => $goods['market_price'],
'goods_price' => $auction['last_bid']['bid_price'],
'goods_number' => 1,
'goods_attr' => $goods_attr,
'goods_attr_id' => $goods_attr_id,
'is_real' => $goods['is_real'],
'extension_code' => addslashes($goods['extension_code']),
'parent_id' => 0,
'rec_type' => CART_AUCTION_GOODS,
'is_gift' => 0
);
$db->autoExecute($ecs->table('cart'), $cart, 'INSERT');
/* 记录购物流程类型:团购 */
$_SESSION['flow_type'] = CART_AUCTION_GOODS;
$_SESSION['extension_code'] = 'auction';
$_SESSION['extension_id'] = $id;
/* 进入收货人页面 */
ecs_header("Location: ./flow.php?step=consignee\n");
exit;
}
/**
* 取得拍卖活动数量
* @return int
*/
function auction_count()
{
$now = gmtime();
$sql = "SELECT COUNT(*) " .
"FROM " . $GLOBALS['ecs']->table('goods_activity') .
"WHERE act_type = '" . GAT_AUCTION . "' " .
"AND start_time <= '$now' AND end_time >= '$now' AND is_finished < 2";
return $GLOBALS['db']->getOne($sql);
}
/**
* 取得某页的拍卖活动
* @param int $size 每页记录数
* @param int $page 当前页
* @return array
*/
function auction_list($size, $page)
{
$auction_list = array();
$auction_list['finished'] = $auction_list['finished'] = array();
$now = gmtime();
$sql = "SELECT a.*, IFNULL(g.goods_thumb, '') AS goods_thumb " .
"FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS a " .
"LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ON a.goods_id = g.goods_id " .
"WHERE a.act_type = '" . GAT_AUCTION . "' " .
"AND a.start_time <= '$now' AND a.end_time >= '$now' AND a.is_finished < 2 ORDER BY a.act_id DESC";
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
while ($row = $GLOBALS['db']->fetchRow($res))
{
$ext_info = unserialize($row['ext_info']);
$auction = array_merge($row, $ext_info);
$auction['status_no'] = auction_status($auction);
$auction['start_time'] = local_date($GLOBALS['_CFG']['time_format'], $auction['start_time']);
$auction['end_time'] = local_date($GLOBALS['_CFG']['time_format'], $auction['end_time']);
$auction['formated_start_price'] = price_format($auction['start_price']);
$auction['formated_end_price'] = price_format($auction['end_price']);
$auction['formated_deposit'] = price_format($auction['deposit']);
$auction['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$auction['url'] = build_uri('auction', array('auid'=>$auction['act_id']));
if($auction['status_no'] < 2)
{
$auction_list['under_way'][] = $auction;
}
else
{
$auction_list['finished'][] = $auction;
}
}
$auction_list = @array_merge($auction_list['under_way'], $auction_list['finished']);
return $auction_list;
}
?>