commit | author | age
|
19351a
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 评价插件 |
|
5 |
*/ |
|
6 |
|
|
7 |
if (!defined('IN_ECS')) |
|
8 |
{ |
|
9 |
die('Hacking attempt'); |
|
10 |
} |
|
11 |
|
|
12 |
function get_my_comments($goods_id, $type = 0, $page = 1, $c_tag) |
|
13 |
{ |
|
14 |
$res = $GLOBALS['db']->getAll("SELECT * FROM ".$GLOBALS['ecs']->table('goods_tag')." WHERE goods_id = '$goods_id' AND state = 1"); |
|
15 |
foreach ($res as $v) |
|
16 |
{ |
|
17 |
$tags[$v['tag_id']] = $v['tag_name']; |
|
18 |
} |
|
19 |
|
|
20 |
if ($type != 4) |
|
21 |
{ |
|
22 |
if ($type == 1) |
|
23 |
{ |
|
24 |
$where .= " AND c.comment_rank in (5,4)"; |
|
25 |
} |
|
26 |
if ($type == 2) |
|
27 |
{ |
|
28 |
$where .= " AND c.comment_rank in (3,2)"; |
|
29 |
} |
|
30 |
if ($type == 3) |
|
31 |
{ |
|
32 |
$where .= " AND c.comment_rank = 1"; |
|
33 |
} |
|
34 |
if ($type == 4) |
|
35 |
{ |
|
36 |
$where .= " AND s.shaidan_id > 0"; |
|
37 |
} |
|
38 |
|
|
39 |
$tag_name_c = $GLOBALS['db']->getOne("select tag_id from " . $GLOBALS['ecs']->table('goods_tag') . " where goods_id = " . $goods_id . " and tag_name = '" . $c_tag . "'"); |
|
40 |
if ($tag_name_c) |
|
41 |
{ |
|
42 |
$where .= " AND FIND_IN_SET('$tag_name_c',comment_tag)"; |
|
43 |
} |
|
44 |
|
|
45 |
$count = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM ".$GLOBALS['ecs']->table('comment')." AS c |
|
46 |
LEFT JOIN ".$GLOBALS['ecs']->table('shaidan')." AS s ON c.rec_id=s.rec_id |
|
47 |
WHERE c.id_value = '$goods_id' AND c.status = 1 AND c.comment_rank > 0 $where"); |
|
48 |
$size = !empty($GLOBALS['_CFG']['comments_number']) ? $GLOBALS['_CFG']['comments_number'] : 5; |
|
49 |
|
|
50 |
$page_count = ($count > 0) ? intval(ceil($count / $size)) : 1; |
|
51 |
|
|
52 |
$sql = "SELECT c.*, u.headimg, s.shaidan_id, s.status AS shaidan_status FROM ".$GLOBALS['ecs']->table('comment')." AS c |
|
53 |
LEFT JOIN ".$GLOBALS['ecs']->table('users')." AS u ON c.user_id=u.user_id |
|
54 |
LEFT JOIN ".$GLOBALS['ecs']->table('shaidan')." AS s ON c.rec_id=s.rec_id |
|
55 |
WHERE c.id_value = '$goods_id' AND c.status = 1 AND c.comment_rank > 0 $where ORDER BY c.add_time DESC"; |
|
56 |
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page-1) * $size); |
|
57 |
$points_list = array(); |
|
58 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
59 |
{ |
|
60 |
$row['add_time_str'] = local_date("Y-m-d", $row['add_time']); |
|
61 |
$row['buy_time_str'] = local_date("Y-m-d", $row['buy_time']); |
|
62 |
$row['user_rank'] = get_user_rank($row['user_id']); |
|
63 |
if ($row['shaidan_id'] > 0 && $row['shaidan_status'] == 1) |
|
64 |
{ |
|
65 |
$row['shaidan_imgs'] = $GLOBALS['db']->getAll("SELECT * FROM ".$GLOBALS['ecs']->table('shaidan_img')." WHERE shaidan_id = '$row[shaidan_id]'"); |
|
66 |
$row['shaidan_imgs_num'] = count($row['shaidan_imgs']); |
|
67 |
} |
|
68 |
if ($row['comment_tag']) |
|
69 |
{ |
|
70 |
$comment_tag = explode(',',$row['comment_tag']); |
|
71 |
foreach ($comment_tag as $tag_id) |
|
72 |
{ |
|
73 |
$row['tags'][] = $tags[$tag_id]; |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
$parent_res = $GLOBALS['db']->getAll("SELECT * FROM ".$GLOBALS['ecs']->table('comment')." WHERE parent_id = '$row[comment_id]'"); |
|
78 |
$row['comment_reps'] = $parent_res; |
|
79 |
|
|
80 |
$item_list[] = $row; |
|
81 |
} |
|
82 |
|
|
83 |
|
|
84 |
$arr = array(); |
|
85 |
$arr['item_list'] = $item_list; |
|
86 |
$arr['page'] = $page; |
|
87 |
$arr['count'] = $count; |
|
88 |
$arr['size'] = $size; |
|
89 |
$arr['page_count'] = $page_count; |
|
90 |
for ($i = 1 ; $i <= $page_count ; $i ++) |
|
91 |
{ |
|
92 |
$arr['page_number'][$i] = "ShowMyComments($goods_id,$type,$i)"; |
|
93 |
} |
|
94 |
|
|
95 |
return $arr; |
|
96 |
} |
|
97 |
else |
|
98 |
{ |
|
99 |
$count = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM ".$GLOBALS['ecs']->table('shaidan')." AS s |
|
100 |
WHERE s.goods_id = '$goods_id' AND s.status = 1"); |
|
101 |
$size = 20; |
|
102 |
$page_count = ($count > 0) ? intval(ceil($count / $size)) : 1; |
|
103 |
|
|
104 |
$sql = "SELECT s.*, u.user_name, u.headimg, c.comment_tag, c.comment_rank, c.comment_id FROM ".$GLOBALS['ecs']->table('shaidan')." AS s |
|
105 |
LEFT JOIN ".$GLOBALS['ecs']->table('users')." AS u ON s.user_id=u.user_id |
|
106 |
LEFT JOIN ".$GLOBALS['ecs']->table('comment')." AS c ON c.rec_id=s.rec_id |
|
107 |
WHERE s.goods_id = '$goods_id' AND s.status = 1 ORDER BY s.add_time DESC"; |
|
108 |
$res = $GLOBALS['db']->selectLimit($sql, $size, ($page-1) * $size); |
|
109 |
$points_list = array(); |
|
110 |
while ($row = $GLOBALS['db']->fetchRow($res)) |
|
111 |
{ |
|
112 |
$row['buy_time'] = $GLOBALS['db']->getOne("SELECT o.add_time FROM ".$GLOBALS['ecs']->table('order_info')." AS o |
|
113 |
LEFT JOIN ".$GLOBALS['ecs']->table('order_goods')." AS og ON o.order_id=og.order_id |
|
114 |
WHERE og.rec_id = '$row[rec_id]'"); |
|
115 |
$row['add_time_str'] = local_date("Y-m-d", $row['add_time']); |
|
116 |
$row['buy_time_str'] = local_date("Y-m-d", $row['buy_time']); |
|
117 |
$row['user_rank'] = get_user_rank($row['user_id']); |
|
118 |
if ($row['shaidan_id'] > 0) |
|
119 |
{ |
|
120 |
$row['shaidan_imgs'] = $GLOBALS['db']->getAll("SELECT * FROM ".$GLOBALS['ecs']->table('shaidan_img')." WHERE shaidan_id = '$row[shaidan_id]'"); |
|
121 |
$row['shaidan_imgs_num'] = count($row['shaidan_imgs']); |
|
122 |
} |
|
123 |
if ($row['comment_tag']) |
|
124 |
{ |
|
125 |
$comment_tag = explode(',',$row['comment_tag']); |
|
126 |
foreach ($comment_tag as $tag_id) |
|
127 |
{ |
|
128 |
$row['tags'][] = $tags[$tag_id]; |
|
129 |
} |
|
130 |
} |
|
131 |
$row['content'] = $row['message']; |
|
132 |
$row['hide_gnum'] = 1; |
|
133 |
if ($row['comment_id'] > 0) |
|
134 |
{ |
|
135 |
$parent_res = $GLOBALS['db']->getAll("SELECT * FROM ".$GLOBALS['ecs']->table('comment')." WHERE parent_id = '$row[comment_id]'"); |
|
136 |
$row['comment_reps'] = $parent_res; |
|
137 |
} |
|
138 |
$item_list[] = $row; |
|
139 |
} |
|
140 |
|
|
141 |
|
|
142 |
$arr = array(); |
|
143 |
$arr['item_list'] = $item_list; |
|
144 |
$arr['page'] = $page; |
|
145 |
$arr['count'] = $count; |
|
146 |
$arr['size'] = $size; |
|
147 |
$arr['page_count'] = $page_count; |
|
148 |
for ($i = 1 ; $i <= $page_count ; $i ++) |
|
149 |
{ |
|
150 |
$arr['page_number'][$i] = "ShowMyComments($goods_id,$type,$i)"; |
|
151 |
} |
|
152 |
|
|
153 |
return $arr; |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
|
|
158 |
function get_user_rank($user_id) |
|
159 |
{ |
|
160 |
if ($user_id <= 0) |
|
161 |
{ |
|
162 |
$arr['rank_id'] = 0; |
|
163 |
$arr['rank_name'] = '普通用户'; |
|
164 |
} |
|
165 |
else |
|
166 |
{ |
|
167 |
$infos = $GLOBALS['db']->getRow("select * from ".$GLOBALS['ecs']->table('users')." where user_id='$user_id'"); |
|
168 |
if ($infos['user_rank'] > 0) |
|
169 |
{ |
|
170 |
$sql = "SELECT rank_id, rank_name, discount FROM ".$GLOBALS['ecs']->table('user_rank') . " WHERE rank_id = '$infos[user_rank]'"; |
|
171 |
} |
|
172 |
else |
|
173 |
{ |
|
174 |
$sql = "SELECT rank_id, rank_name, discount, min_points FROM ".$GLOBALS['ecs']->table('user_rank') . |
|
175 |
" WHERE min_points<= " . intval($infos['rank_points']) . " ORDER BY min_points DESC"; |
|
176 |
} |
|
177 |
|
|
178 |
if ($row = $GLOBALS['db']->getRow($sql)) |
|
179 |
{ |
|
180 |
$rank_name = $row['rank_name']; |
|
181 |
} |
|
182 |
else |
|
183 |
{ |
|
184 |
$rank_name = $GLOBALS['_LANG']['undifine_rank']; |
|
185 |
} |
|
186 |
|
|
187 |
$arr['rank_id'] = $row['rank_id']; |
|
188 |
$arr['rank_name'] = $rank_name; |
|
189 |
} |
|
190 |
return $arr; |
|
191 |
} |
|
192 |
|
|
193 |
|
|
194 |
function array_sort($arr,$keys,$type='asc') |
|
195 |
{ |
|
196 |
$keysvalue = $new_array = array(); |
|
197 |
foreach ($arr as $k=>$v){ |
|
198 |
$keysvalue[$k] = $v[$keys]; |
|
199 |
} |
|
200 |
if($type == 'asc'){ |
|
201 |
asort($keysvalue); |
|
202 |
}else{ |
|
203 |
arsort($keysvalue); |
|
204 |
} |
|
205 |
reset($keysvalue); |
|
206 |
foreach ($keysvalue as $k=>$v){ |
|
207 |
$new_array[$k] = $arr[$k]; |
|
208 |
} |
|
209 |
return $new_array; |
|
210 |
} |
|
211 |
?> |