Comment.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\admin\controller\qingdongams\customer;
  3. use addons\qingdongams\model\Staff;
  4. use app\admin\controller\qingdongams\Base;
  5. use addons\qingdongams\model\Comment as CommentModel;
  6. use addons\qingdongams\model\Record;
  7. use addons\qingdongams\model\Message;
  8. use think\DB;
  9. use function EasyWeChat\Kernel\Support\get_client_ip;
  10. /**
  11. * 客户评论
  12. */
  13. class Comment extends Base {
  14. public function _initialize() {
  15. parent::_initialize();
  16. $this->model = new CommentModel();
  17. }
  18. /**
  19. * 评论列表
  20. */
  21. public function index() {
  22. $this->request->filter(['strip_tags']);
  23. if ($this->request->isAjax()) {
  24. //0:全部 1:我负责的 2:下属负责的
  25. $type = input('type',0);
  26. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  27. switch($type){
  28. case 1:
  29. $staff = Staff::info();
  30. $wheres['staff_id'] = $staff->id;
  31. break;
  32. case 2:
  33. $wheres['staff_id'] = array('in',Staff::getLowerStaffId());
  34. break;
  35. default:
  36. $wheres['staff_id'] = array('in',Staff::getMyStaffIds());
  37. break;
  38. }
  39. $wheres['relation_type'] = 1;
  40. $list = $this->model->where($where)->where($wheres)->with(['staff','record'])->order($sort, $order)->paginate($limit);
  41. $row = $list->items();
  42. $result = array("total" => $list->total(), "rows" => $row);
  43. return json($result);
  44. }
  45. return $this->view->fetch();
  46. }
  47. /**
  48. * 添加评论
  49. * @param null $ids
  50. * @return string
  51. * @throws \think\Exception
  52. * @throws \think\exception\DbException
  53. */
  54. public function add($ids=null) {
  55. if ($this->request->isPost()) {
  56. $content = input('content');
  57. if (empty($content)) {
  58. $this->error('评论内容不能为空');
  59. }
  60. $record = Record::get($ids);
  61. $data = [
  62. 'relation_type' => $record['relation_type'],
  63. 'relation_id' => $ids,
  64. 'staff_id' => $this->_staff->id,
  65. 'content' => $content,
  66. 'status' => 1,
  67. 'ip' => get_client_ip(),
  68. ];
  69. $commentModel = new CommentModel();
  70. $commentModel->save($data);
  71. $lastId= $commentModel->getLastInsID();
  72. //修改跟进状态
  73. Record::where(array('id'=>$ids))->update(array('status'=>1,'updatetime'=>time()));
  74. Message::addMessage(Message::COMMENT_TYPE, $lastId, $record['create_staff_id'], $this->_staff->id);
  75. $staff_ids = $commentModel->where(['relation_type' => $record['relation_type'], 'relation_id' => $ids])->group('staff_id')->column('staff_id');
  76. foreach ($staff_ids as $staff_id) {
  77. //发送通知
  78. if ($staff_id != $this->_staff->id) {
  79. Message::addMessage(Message::COMMENT_TYPE, $lastId, $staff_id, $this->_staff->id);
  80. }
  81. }
  82. $this->success('评论成功');
  83. }
  84. return $this->view->fetch();
  85. }
  86. }