Comment.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\admin\controller\qingdong\customer;
  3. use addons\qingdong\model\Staff;
  4. use app\admin\controller\qingdong\Base;
  5. use addons\qingdong\model\Comment as CommentModel;
  6. use addons\qingdong\model\Record;
  7. use addons\qingdong\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. Message::addMessage(Message::COMMENT_TYPE, $ids, $record['create_staff_id'], $this->_staff->id);
  72. $staff_ids = $commentModel->where(['relation_type' => $record['relation_type'], 'relation_id' => $ids])->group('staff_id')->column('staff_id');
  73. foreach ($staff_ids as $staff_id) {
  74. //发送通知
  75. if ($staff_id != $this->_staff->id) {
  76. Message::addMessage(Message::COMMENT_TYPE, $ids, $staff_id, $this->_staff->id);
  77. }
  78. }
  79. $this->success('评论成功');
  80. }
  81. return $this->view->fetch();
  82. }
  83. }