bhq@iemsoft.cn
2018-11-27 e2b48dac099e43f4b3243cdf19a7522e4b5eccbe
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
<?php
 
/**
  评价插件
*/
 
if (!defined('IN_ECS'))
{
    die('Hacking attempt');
}
 
function get_my_comments($goods_id, $type = 0, $page = 1, $c_tag)
{
    $res = $GLOBALS['db']->getAll("SELECT * FROM ".$GLOBALS['ecs']->table('goods_tag')." WHERE goods_id = '$goods_id' AND state = 1");    
    foreach ($res as $v)
    {
        $tags[$v['tag_id']] = $v['tag_name'];    
    }
    
    if ($type != 4)
    {
        if ($type == 1)
        {
            $where .= " AND c.comment_rank in (5,4)";    
        }
        if ($type == 2)
        {
            $where .= " AND c.comment_rank in (3,2)";    
        }
        if ($type == 3)
        {
            $where .= " AND c.comment_rank = 1";    
        }
        if ($type == 4)
        {
            $where .= " AND s.shaidan_id > 0";    
        }
        
        $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 . "'");
        if ($tag_name_c)
        {
            $where .= " AND FIND_IN_SET('$tag_name_c',comment_tag)";            
        }
 
        $count = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM ".$GLOBALS['ecs']->table('comment')." AS c 
                                         LEFT JOIN ".$GLOBALS['ecs']->table('shaidan')." AS s ON c.rec_id=s.rec_id
                                         WHERE c.id_value = '$goods_id' AND c.status = 1 AND c.comment_rank > 0 $where");
        $size  = empty($GLOBALS['_CFG']['comments_number'])?10:$GLOBALS['_CFG']['comments_number'];
        $page_count = ($count > 0) ? intval(ceil($count / $size)) : 1;
    
        $sql = "SELECT c.*, u.headimg, s.shaidan_id, s.status AS shaidan_status,s.title,s.message FROM ".$GLOBALS['ecs']->table('comment')." AS c 
                LEFT JOIN ".$GLOBALS['ecs']->table('users')." AS u ON c.user_id=u.user_id
                LEFT JOIN ".$GLOBALS['ecs']->table('shaidan')." AS s ON c.rec_id=s.rec_id
                WHERE c.id_value = '$goods_id' AND c.status = 1 AND c.comment_rank > 0 $where ORDER BY c.add_time DESC";
        $res = $GLOBALS['db']->selectLimit($sql, $size, ($page-1) * $size);
        $points_list = array();
        while ($row = $GLOBALS['db']->fetchRow($res))
        {
            $row['add_time_str'] = local_date("Y-m-d", $row['add_time']);
            $row['buy_time_str'] = local_date("Y-m-d", $row['buy_time']);
            $row['user_rank'] = get_user_rank($row['user_id']);
            if ($row['shaidan_id'] > 0 && $row['shaidan_status'] == 1)
            {
                $row['shaidan_imgs'] = $GLOBALS['db']->getAll("SELECT * FROM ".$GLOBALS['ecs']->table('shaidan_img')." WHERE shaidan_id = '$row[shaidan_id]'");    
                $row['shaidan_imgs_num'] = count($row['shaidan_imgs']);
            }
            if ($row['comment_tag'])
            {
                $comment_tag = explode(',',$row['comment_tag']);    
                foreach ($comment_tag as $tag_id)
                {
                    $row['tags'][] = $tags[$tag_id];
                }
            }
            
            $parent_res = $GLOBALS['db']->getAll("SELECT * FROM ".$GLOBALS['ecs']->table('comment')." WHERE parent_id = '$row[comment_id]'");    
            $row['comment_reps'] = $parent_res;
            
            $item_list[] = $row;
        }
        
        
        $arr = array();
        $arr['item_list'] = $item_list;
        $arr['page'] = $page;
        $arr['count'] = $count;
        $arr['size'] = $size;
        $arr['page_count'] = $page_count;
                $next = $page+1;
                $prev = $page-1;
                $arr['page_prev'] =  "ShowMyComments($goods_id,$type,$prev)";
                $arr['page_next'] =  "ShowMyComments($goods_id,$type,$next)";
//        for ($i = 1 ; $i <= $page_count ; $i ++)
//        {
//            $arr['page_number'][$i] = "ShowMyComments($goods_id,$type,$i)";
//        }
//        
        return $arr;
    }
    else
    {
        $count = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM ".$GLOBALS['ecs']->table('shaidan')." AS s 
                                         WHERE s.goods_id = '$goods_id' AND s.status = 1");
        $size  = 10;
        $page_count = ($count > 0) ? intval(ceil($count / $size)) : 1;
    
        $sql = "SELECT s.*, u.user_name, c.comment_tag, c.comment_rank, c.comment_id FROM ".$GLOBALS['ecs']->table('shaidan')." AS s 
                LEFT JOIN ".$GLOBALS['ecs']->table('users')." AS u ON s.user_id=u.user_id
                LEFT JOIN ".$GLOBALS['ecs']->table('comment')." AS c ON c.rec_id=s.rec_id
                WHERE s.goods_id = '$goods_id' AND s.status = 1 ORDER BY s.add_time DESC";
        $res = $GLOBALS['db']->selectLimit($sql, $size, ($page-1) * $size);
        $points_list = array();
        while ($row = $GLOBALS['db']->fetchRow($res))
        {
            $row['buy_time'] = $GLOBALS['db']->getOne("SELECT o.add_time FROM ".$GLOBALS['ecs']->table('order_info')." AS o
                                                       LEFT JOIN ".$GLOBALS['ecs']->table('order_goods')." AS og ON o.order_id=og.order_id
                                                       WHERE og.rec_id = '$row[rec_id]'");
            $row['add_time_str'] = local_date("Y-m-d", $row['add_time']);
            $row['buy_time_str'] = local_date("Y-m-d", $row['buy_time']);
            $row['user_rank'] = get_user_rank($row['user_id']);
            if ($row['shaidan_id'] > 0)
            {
                $row['shaidan_imgs'] = $GLOBALS['db']->getAll("SELECT * FROM ".$GLOBALS['ecs']->table('shaidan_img')." WHERE shaidan_id = '$row[shaidan_id]'");    
                $row['shaidan_imgs_num'] = count($row['shaidan_imgs']);
            }
            if ($row['comment_tag'])
            {
                $comment_tag = explode(',',$row['comment_tag']);    
                foreach ($comment_tag as $tag_id)
                {
                    $row['tags'][] = $tags[$tag_id];
                }
            }
            $row['content'] = $row['message'];
            $row['hide_gnum'] = 1;
            if ($row['comment_id'] > 0)
            {
                $parent_res = $GLOBALS['db']->getAll("SELECT * FROM ".$GLOBALS['ecs']->table('comment')." WHERE parent_id = '$row[comment_id]'");    
                $row['comment_reps'] = $parent_res;
            }
            $item_list[] = $row;
        }
        
        
        $arr = array();
        $arr['item_list'] = $item_list;
        $arr['page'] = $page;
        $arr['count'] = $count;
        $arr['size'] = $size;
        $arr['page_count'] = $page_count;
        for ($i = 1 ; $i <= $page_count ; $i ++)
        {
            $arr['page_number'][$i] = "ShowMyComments($goods_id,$type,$i)";
        }
 
        return $arr;
    }
}
 
 
function get_user_rank($user_id)
{
    if ($user_id <= 0)
    {
        $arr['rank_id'] = 0;
        $arr['rank_name'] = '游客';
    }
    else
    {
        $infos = $GLOBALS['db']->getRow("select * from ".$GLOBALS['ecs']->table('users')." where user_id='$user_id'");
        if ($infos['user_rank'] > 0)
        {
            $sql = "SELECT rank_id, rank_name, discount FROM ".$GLOBALS['ecs']->table('user_rank') . " WHERE rank_id = '$infos[user_rank]'";
        }
        else
        {
            $sql = "SELECT rank_id, rank_name, discount, min_points FROM ".$GLOBALS['ecs']->table('user_rank') .
                   " WHERE min_points<= " . intval($infos['rank_points']) . " ORDER BY min_points DESC";
        }
    
        if ($row = $GLOBALS['db']->getRow($sql))
        {
            $rank_name     = $row['rank_name'];
        }
        else
        {
            $rank_name = $GLOBALS['_LANG']['undifine_rank'];
        }
        
        $arr['rank_id'] = $row['rank_id'];
        $arr['rank_name'] = $rank_name;
    }
    return $arr;
}
 
 
function array_sort($arr,$keys,$type='asc')
    $keysvalue = $new_array = array();
    foreach ($arr as $k=>$v){
        $keysvalue[$k] = $v[$keys];
    }
    if($type == 'asc'){
        asort($keysvalue);
    }else{
        arsort($keysvalue);
    }
    reset($keysvalue);
    foreach ($keysvalue as $k=>$v){
        $new_array[$k] = $arr[$k];
    }
    return $new_array; 
}
?>