commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 报价单 |
|
5 |
*/ |
|
6 |
define('IN_ECS', true); |
|
7 |
|
|
8 |
require(dirname(__FILE__) . '/includes/init.php'); |
|
9 |
|
|
10 |
$action = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default'; |
|
11 |
if ($action == 'print_quotation') |
|
12 |
{ |
|
13 |
$smarty->template_dir = DATA_DIR; |
|
14 |
$smarty->assign('shop_name', $_CFG['shop_title']); |
|
15 |
$smarty->assign('cfg', $_CFG); |
|
16 |
$where = get_quotation_where($_POST); |
|
17 |
$sql = "SELECT g.goods_id, g.goods_name, g.shop_price, g.goods_number, c.cat_name AS goods_category,p.product_id,p.product_number,p.goods_attr". |
|
18 |
" FROM " . $ecs->table('goods') . " AS g LEFT JOIN " . $ecs->table('category') . " AS c ON g.cat_id = c.cat_id LEFT JOIN ".$ecs->table('products')."as p On g.goods_id=p.goods_id" . $where . " AND is_on_sale = 1 AND is_alone_sale = 1 "; |
|
19 |
$goods_list = $db->getAll($sql); |
|
20 |
|
|
21 |
foreach($goods_list as $key=>$val) |
|
22 |
{ |
|
23 |
if(!empty($val['product_id'])) |
|
24 |
{ |
|
25 |
$goods_list[$key]['goods_number']=$val['product_number']; |
|
26 |
$product_info=product_info($val['goods_attr'],$val['goods_id']); |
|
27 |
$goods_list[$key]['members_price'] = $val['shop_price']; |
|
28 |
$goods_list[$key]['shop_price'] += $product_info['attr_price']; |
|
29 |
$goods_list[$key]['product_name']=$product_info['attr_value']; |
|
30 |
$goods_list[$key]['attr_price'] =$product_info['attr_price']; |
|
31 |
} |
|
32 |
else |
|
33 |
{ |
|
34 |
$goods_list[$key]['members_price'] = $val['shop_price']; |
|
35 |
$goods_list[$key]['product_name']=' '; |
|
36 |
$goods_list[$key]['product_price']=0; |
|
37 |
} |
|
38 |
$goods_list[$key]['goods_key']=$key; |
|
39 |
} |
|
40 |
$user_rank = $db->getAll("SELECT * FROM " .$ecs->table('user_rank') . "WHERE show_price = 1 OR rank_id = '$_SESSION[user_rank]'"); |
|
41 |
$rank_point = 0; |
|
42 |
if (!empty($_SESSION['user_id'])) |
|
43 |
{ |
|
44 |
$rank_point = $db->getOne("SELECT rank_points FROM " . $ecs->table('users') . " WHERE user_id = '$_SESSION[user_id]'"); |
|
45 |
} |
|
46 |
$user_rank = calc_user_rank($user_rank, $rank_point); |
|
47 |
$user_men = serve_user($goods_list); |
|
48 |
$smarty->assign('extend_price', $user_rank['ext_price']); |
|
49 |
$smarty->assign('extend_rank', $user_men); |
|
50 |
$smarty->assign('goods_list', $goods_list); |
|
51 |
|
|
52 |
$html = $smarty->fetch('quotation_print.html'); |
|
53 |
exit($html); |
|
54 |
} |
|
55 |
|
|
56 |
assign_template(); |
|
57 |
|
|
58 |
$position = assign_ur_here(0, $_LANG['quotation']); |
|
59 |
$smarty->assign('page_title', $position['title']); // 页面标题 |
|
60 |
$smarty->assign('ur_here', $position['ur_here']); // 当前位置 |
|
61 |
|
|
62 |
$smarty->assign('cat_list', cat_list()); |
|
63 |
$smarty->assign('brand_list', get_brand_list()); |
|
64 |
|
|
65 |
if (is_null($smarty->get_template_vars('helps'))) |
|
66 |
{ |
|
67 |
$smarty->assign('helps', get_shop_help()); // 网店帮助 |
|
68 |
} |
|
69 |
|
|
70 |
$smarty->display('quotation.dwt'); |
|
71 |
|
|
72 |
function get_quotation_where($filter) |
|
73 |
{ |
|
74 |
include_once(ROOT_PATH . ADMIN_PATH . '/includes/lib_main.php'); |
|
75 |
$_filter = new StdClass(); |
|
76 |
$_filter->cat_id = $filter['cat_id']; |
|
77 |
$_filter->brand_id = $filter['brand_id']; |
|
78 |
$where = get_where_sql($_filter); |
|
79 |
$_filter->keyword = $filter['keyword']; |
|
80 |
$where .= isset($_filter->keyword) && trim($_filter->keyword) != '' ? " AND (g.goods_name LIKE '%" . mysql_like_quote($_filter->keyword) . "%' OR g.goods_sn LIKE '%" . mysql_like_quote($_filter->keyword) . "%' OR g.goods_id LIKE '%" . mysql_like_quote($_filter->keyword) . "%') " : ''; |
|
81 |
return $where; |
|
82 |
} |
|
83 |
|
|
84 |
function calc_user_rank($rank, $rank_point) |
|
85 |
{ |
|
86 |
$_tmprank = array(); |
|
87 |
foreach($rank as $_rank) |
|
88 |
{ |
|
89 |
if ($_rank['show_price']) |
|
90 |
{ |
|
91 |
$_tmprank['ext_price'][] = $_rank['rank_name']; |
|
92 |
$_tmprank['ext_rank'][] = $_rank['discount']; |
|
93 |
} |
|
94 |
else |
|
95 |
{ |
|
96 |
if (!empty($_SESSION['user_id']) && ($rank_point >= $_rank['min_points'])) |
|
97 |
{ |
|
98 |
$_tmprank['ext_price'][] = $_rank['rank_name']; |
|
99 |
$_tmprank['ext_rank'][] = $_rank['discount']; |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
return $_tmprank; |
|
104 |
} |
|
105 |
|
|
106 |
function serve_user($goods_list) |
|
107 |
{ |
|
108 |
foreach ( $goods_list as $key=> $all_list ) |
|
109 |
{ |
|
110 |
$goods_id = $all_list['goods_id']; |
|
111 |
$goods_key =$all_list['goods_key']; |
|
112 |
$price = $all_list['members_price']; |
|
113 |
$sql = "SELECT rank_id, IFNULL(mp.user_price, r.discount * $price / 100) AS price, r.rank_name, r.discount " . |
|
114 |
'FROM ' . $GLOBALS['ecs']->table('user_rank') . ' AS r ' . |
|
115 |
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . " AS mp ". |
|
116 |
"ON mp.goods_id = '$goods_id' AND mp.user_rank = r.rank_id " . |
|
117 |
"WHERE r.show_price = 1 OR r.rank_id = '$_SESSION[user_rank]'"; |
|
118 |
$res = $GLOBALS['db']->getAll($sql); |
|
119 |
|
|
120 |
foreach ( $res as $row ) |
|
121 |
{ |
|
122 |
$arr[$row['rank_id']] = array( |
|
123 |
'rank_name' => htmlspecialchars($row['rank_name']), |
|
124 |
'price' => price_format($row['price']+$all_list['attr_price'])); |
|
125 |
|
|
126 |
} |
|
127 |
$arr_list[$goods_key] = $arr; |
|
128 |
} |
|
129 |
return $arr_list; |
|
130 |
} |
|
131 |
function product_info($goods_attr,$goods_id) |
|
132 |
{ |
|
133 |
$goods_attr=str_replace('|',' OR goods_attr_id=',$goods_attr); |
|
134 |
$sql="SELECT attr_value,attr_price FROM ". $GLOBALS['ecs']->table('goods_attr') ." WHERE goods_id='$goods_id' AND (goods_attr_id = $goods_attr)"; |
|
135 |
$result =$GLOBALS['db']->getAll($sql); |
|
136 |
$i=1; |
|
137 |
$count=count($result); |
|
138 |
foreach ($result as $val) |
|
139 |
{ |
|
140 |
$i==$count?$f='':$f='<br/>'; |
|
141 |
$product_info['attr_value'].=$val['attr_value'].$f; |
|
142 |
$product_info['attr_price']+=$val['attr_price']; |
|
143 |
$i++; |
|
144 |
} |
|
145 |
return($product_info); |
|
146 |
} |
|
147 |
?> |