2db47680
hexiaodong
chore: 初始提交 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
|
<?php
namespace app\admin\controller\antis\customer;
use addons\antis\model\Staff;
use app\admin\controller\antis\Base;
use addons\antis\model\Comment as CommentModel;
use addons\antis\model\Record;
use addons\antis\model\Message;
use think\DB;
use function EasyWeChat\Kernel\Support\get_client_ip;
/**
* 客户评论
*/
class Comment extends Base {
public function _initialize() {
parent::_initialize();
$this->model = new CommentModel();
}
/**
* 评论列表
*/
public function index() {
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
//0:全部 1:我负责的 2:下属负责的
$type = input('type',0);
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
switch($type){
case 1:
$staff = Staff::info();
$wheres['staff_id'] = $staff->id;
break;
case 2:
$wheres['staff_id'] = array('in',Staff::getLowerStaffId());
break;
default:
$wheres['staff_id'] = array('in',Staff::getMyStaffIds());
break;
}
$wheres['relation_type'] = 1;
$list = $this->model->where($where)->where($wheres)->with(['staff','record'])->order($sort, $order)->paginate($limit);
$row = $list->items();
$result = array("total" => $list->total(), "rows" => $row);
return json($result);
}
return $this->view->fetch();
}
/**
* 添加评论
* @param null $ids
* @return string
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public function add($ids=null) {
if ($this->request->isPost()) {
$content = input('content');
if (empty($content)) {
$this->error('评论内容不能为空');
}
$record = Record::get($ids);
$data = [
'relation_type' => $record['relation_type'],
'relation_id' => $ids,
'staff_id' => $this->_staff->id,
'content' => $content,
'status' => 1,
'ip' => get_client_ip(),
];
$commentModel = new CommentModel();
$commentModel->save($data);
Message::addMessage(Message::COMMENT_TYPE, $ids, $record['create_staff_id'], $this->_staff->id);
$staff_ids = $commentModel->where(['relation_type' => $record['relation_type'], 'relation_id' => $ids])->group('staff_id')->column('staff_id');
foreach ($staff_ids as $staff_id) {
//发送通知
if ($staff_id != $this->_staff->id) {
Message::addMessage(Message::COMMENT_TYPE, $ids, $staff_id, $this->_staff->id);
}
}
$this->success('评论成功');
}
return $this->view->fetch();
}
}
|