ChatController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\index\controller\kefu;
  3. use think\exception\ValidateException;
  4. use app\model\kefu\Chat;
  5. use app\model\kefu\Seating;
  6. use app\model\kefu\Seatinggroups;
  7. use app\model\kefu\Contacts;
  8. class ChatController extends Base
  9. {
  10. function uslist()
  11. {
  12. $where['status'] = 1;
  13. $field = 'id,title,chatid';
  14. $query = Seating::where($where);
  15. $res = $query->field($field)
  16. ->order('id desc')
  17. ->select()
  18. ->toArray();
  19. $res2 = Contacts::where($where)->field($field)
  20. ->order('id desc')
  21. ->select()
  22. ->toArray();
  23. $data['data'] = array_merge($res, $res2);
  24. return $this->json($data);
  25. }
  26. function add()
  27. {
  28. $ChatId = input('post.ChatId', '', 'serach_in');
  29. $fromid = input('post.fromid', '', 'serach_in');
  30. if (!empty($ChatId)) {
  31. $ChatId = implode(',', $ChatId);
  32. }
  33. $chat = Chat::create(['weid' => weid(), 'title' => '群聊', 'is_group' => 1, 'crowd' => $ChatId, 'time' => time()]);
  34. $chat->title = $chat->title . $chat->id;
  35. Chat::update(['id' => $chat->id, 'title' => $chat->title]);
  36. $grouptopid = $chat->crowd;
  37. $grouptopid = str_replace($fromid . ',', "", $grouptopid);
  38. $grouptopid = str_replace(',' . $fromid, "", $grouptopid);
  39. $grouptopid = str_replace($fromid, "", $grouptopid);
  40. if(!empty($grouptopid)){
  41. $grouptopid = explode(",", $grouptopid);
  42. }
  43. $chat = $chat->toArray();
  44. $chat['grouptopid'] = $grouptopid;
  45. return $this->json($chat);
  46. }
  47. }