Comment.php
8.24 KB
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
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* 评论管理控制器
* Date: 2015-10-20
*/
namespace app\admin\controller;
use think\AjaxPage;
use think\Page;
class Comment extends Base {
public function index(){
$day = trim(I('day',""));
$ishf = trim(I('ishf'));
$this->assign('day',$day);
$this->assign('ishf',$ishf);
return $this->fetch('',getAdmStoId());
}
public function detail(){
$id = I('get.id/d');
$res = M('comment')->alias('a')->join('users b',' a.user_id=b.user_id','left')->where(array('comment_id'=>$id))->find();
if(!$res){
exit($this->error('不存在该评论'));
}
if(IS_POST){
$add['parent_id'] = $id;
$add['content'] = I('post.content');
$add['goods_id'] = $res['goods_id'];
$add['add_time'] = time();
$add['username'] = 'admin';
$add['store_id'] =getAdmStoId();
$add['is_show'] = 1;
$row = M('comment')->add($add);
if($row){
// upload_ylp_log('评论回复');
$this->success('添加成功');
}else{
$this->error('添加失败');
}
exit;
}
$reply = M('comment')->where(array('parent_id'=>$id))->select(); // 评论回复列表
if($res['source_type']==0){
if($res['img']) $res['s_mg']=unserialize($res['img']);
}else{
if($res['weapp_img']) $res['s_mg']= json_decode($res['weapp_img'],true);
}
$this->assign('comment',$res);
$this->assign('reply',$reply);
return $this->fetch('',getAdmStoId());
}
public function del(){
$id = I('get.id/d');
$row = M('comment')->where(array('comment_id'=>$id))->delete();
if($row){
// upload_ylp_log('删除订单评价');//记录事件日志
$this->success('删除成功');
}else{
$this->error('删除失败');
}
}
public function op(){
$type = I('post.type');
$selected_id = I('post.selected/a');
if(!in_array($type,array('del','show','hide')) || !$selected_id)
$this->error('非法操作');
$where['comment_id'] = array('IN', $selected_id);
if($type == 'del'){
//删除回复
$where['parent_id'] = ['IN',$selected_id];
$row = M('comment')->whereOr($where)->delete();
// exit(DB::getLastSql());
}
if($type == 'show'){
$row = M('comment')->where($where)->save(array('is_show'=>1));
}
if($type == 'hide'){
$row = M('comment')->where($where)->save(array('is_show'=>0));
}
if(!$row){
$this->error('操作失败');
}else{
// upload_ylp_log('评价操作');
$this->success('操作成功');
}
}
public function ajaxindex(){
$model = M('comment');
$username = I('nickname','','trim');
$content = I('content','','trim');
$ishow=I('is_show');
$isauto=I('isauto');
$day = trim(I('day',""));
$today = strtotime(date('Y-m-d'));
$where['parent_id'] = 0;
$getAdmStoId=getAdmStoId();
$where['store_id']=$getAdmStoId;
if($username){
$where['username'] = $username;
}
if ($content) {
$where['content'] = ['like', '%' . $content . '%'];
}
$where1="";
$ishf=I('ishf');
if ($ishf==1)
{
$where1=" comment_id not in(select parent_id from wxd_comment where store_id=".$getAdmStoId." and parent_id<>0) ";
}
if($ishow>-1){
$where['is_show']=$ishow;
}
if($isauto>-1){
$where['isauto']=$isauto;
}
//
//
if ($day=="1") $where['add_time']=array('egt',$today);
$count = $model->where($where)->where($where1)->count();
$Page = $pager = new AjaxPage($count,16);
$show = $Page->show();
$comment_list = $model->where($where)->where($where1)->order('add_time DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
if(!empty($comment_list))
{
$goods_id_arr = get_arr_column($comment_list, 'goods_id');
$goods_list = M('Goods')->where("goods_id", "in" , implode(',', $goods_id_arr))->getField("goods_id,goods_name");
}
$this->assign('goods_list',$goods_list);
$this->assign('comment_list',$comment_list);
$this->assign('page',$show);// 赋值分页输出
$this->assign('pager',$pager);// 赋值分页输出
upload_ylp_log('B17评价管理查询/搜索');
return $this->fetch('',getAdmStoId());
}
public function ask_list(){
return $this->fetch('',getAdmStoId());
}
public function ajax_ask_list(){
$model = M('goods_consult');
$username = I('nickname','','trim');
$content = I('content','','trim');
$where=' parent_id = 0';
if($username){
$where .= " AND username='$username'";
}
if($content){
$where .= " AND content like '%{$content}%'";
}
$count = $model->where($where)->count();
$Page = $pager = new AjaxPage($count,10);
$show = $Page->show();
$comment_list = $model->where($where)->order('add_time DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
if(!empty($comment_list))
{
$goods_id_arr = get_arr_column($comment_list, 'goods_id');
$goods_list = M('Goods')->where("goods_id", "in", implode(',', $goods_id_arr))->getField("goods_id,goods_name");
}
$consult_type = array(0=>'默认咨询',1=>'商品咨询',2=>'支付咨询',3=>'配送',4=>'售后');
$this->assign('consult_type',$consult_type);
$this->assign('goods_list',$goods_list);
$this->assign('comment_list',$comment_list);
$this->assign('page',$show);// 赋值分页输出
$this->assign('pager',$pager);// 赋值分页输出
return $this->fetch('',getAdmStoId());
}
public function consult_info(){
$id = I('get.id/d');
$res = M('goods_consult')->where(array('id'=>$id))->find();
if(!$res){
exit($this->error('不存在该咨询'));
}
if(IS_POST){
$add['parent_id'] = $id;
$add['content'] = I('post.content');
$add['goods_id'] = $res['goods_id'];
$add['consult_type'] = $res['consult_type'];
$add['add_time'] = time();
$add['is_show'] = 1;
$row = M('goods_consult')->add($add);
if($row){
$this->success('添加成功');
}else{
$this->error('添加失败');
}
exit;
}
$reply = M('goods_consult')->where(array('parent_id'=>$id))->select(); // 咨询回复列表
$this->assign('comment',$res);
$this->assign('reply',$reply);
return $this->fetch('',getAdmStoId());
}
public function ask_handle()
{
$type = I('post.type');
$selected_id = I('post.selected/a');
if (!in_array($type, array('del', 'show', 'hide')) || !$selected_id)
$this->error('操作完成');
$selected_id = implode(',', $selected_id);
if ($type == 'del') {
//删除咨询
$row = M('goods_consult')->where('id', 'IN', $selected_id)->whereOr('parent_id', 'IN', $selected_id)->delete();
}
if ($type == 'show') {
$row = M('goods_consult')->where('id', 'IN', $selected_id)->save(array('is_show' => 1));
}
if ($type == 'hide') {
$row = M('goods_consult')->where('id', 'IN', $selected_id)->save(array('is_show' => 0));
}
$this->success('操作完成');
}
}