123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace app\admin\controller\qingdongams\customer;
- use addons\qingdongams\model\Staff;
- use app\admin\controller\qingdongams\Base;
- use addons\qingdongams\model\Comment as CommentModel;
- use addons\qingdongams\model\Record;
- use addons\qingdongams\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);
- $lastId= $commentModel->getLastInsID();
- //修改跟进状态
- Record::where(array('id'=>$ids))->update(array('status'=>1,'updatetime'=>time()));
- Message::addMessage(Message::COMMENT_TYPE, $lastId, $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, $lastId, $staff_id, $this->_staff->id);
- }
- }
- $this->success('评论成功');
- }
- return $this->view->fetch();
- }
- }
|