userInfo['openid']; $data['fromname'] = empty($this->userInfo['nickname']) ? '匿名用户' : $this->userInfo['nickname']; $data['fromavatar'] = empty($this->userInfo['avatar']) ? $kefuconfig['defaultavatar'] : $this->userInfo['avatar']; if (empty($data['toname'])) { $seating = Seating::field('uid,chatid,title,touxiang')->where('chatid', $data['toid'])->find(); $data['toname'] = $seating['title']; } } else { $fromid = input('post.fromid', '', 'serach_in'); $seating = Seating::field('uid,chatid,title,touxiang')->where('chatid', $fromid)->find(); $data['fromid'] = $fromid; $data['fromname'] = $seating['title']; $data['fromavatar'] = empty($seating['touxiang']) ? $kefuconfig['defaultavatar'] : $seating['touxiang']; } if ($is_group == 1 || is_numeric($data['toid'])) { $chatgroupid = $data['toid']; $grouptopid = Chat::getcrowd($data['toid']); $grouptopid = str_replace($data['fromid'] . ',', "", $grouptopid); $grouptopid = str_replace(',' . $data['fromid'], "", $grouptopid); $grouptopid = str_replace($data['fromid'], "", $grouptopid); $grouptopid = explode(",", $grouptopid); } if (empty($chatgroupid)) { $chatgroupid = Chat::getchatid($data['fromid'], $data['toid']); } $data['chatgroupid'] = $chatgroupid; $ret = Chatlog::create($data); $url = gethost() . scriptPath() . '/public/h5-im/?openid=' . $data['toid'] . '&toid=' . $data['fromid'] . '&xmtoken=xmtokenvalue'; $app = \app\samos\wechat\Wechatmp::makemp(); if (!empty($app)) { $kefudata['username'] = $data['fromname']; $kefudata['kefu'] = $data['toname']; $kefudata['time'] = date('Y-m-d H:i:s', $data['time']); $kefudata['content'] = $content; $message['data']['thing3']['value'] = $kefudata['username']; $message['data']['thing2']['value'] = mb_substr($kefudata['content'], 0, 20); $app->template_message->send([ 'touser' => $data['toid'], 'template_id' => trim($messagetpl['kefu_tpl']), 'url' => $url, 'data' => $message['data'], ]); //$ret = $ret->toArray(); $ret['grouptopid'] = $grouptopid; $ret['is_group'] = $is_group; } return $this->json(['data' => $ret]); } function log() { $toid = input('post.toid', '', 'serach_in'); $fromid = $this->userInfo['openid']; $chatgroupid = Chat::getchatid($fromid, $toid); if (!empty($chatgroupid)) { $chantcon = Chatlog::where(['chatgroupid' => $chatgroupid])->select(); $msgList = []; foreach ($chantcon as $kk => $vo) { $msgList[$kk]['id'] = $vo['id']; $msgList[$kk]['avatarUrl'] = $vo['fromavatar']; $msgList[$kk]['fromid'] = $vo['fromid']; $msgList[$kk]['fromname'] = $vo['fromname']; $msgList[$kk]['chattype'] = $vo['chattype']; $msgList[$kk]['content'] = $vo['content']; $msgList[$kk]['contentType'] = $vo['contentType']; $msgList[$kk]['createTime'] = date('Y-m-d H:i', $vo['time']); if ($vo['fromid'] == $fromid) { $msgList[$kk]['role'] = 'right'; } else { $msgList[$kk]['role'] = 'left'; } } } $data['msgList'] = $msgList; return $this->json(['data' => $data]); } function chatlist() { $fromid = input('post.fromid', '', 'serach_in'); $data = []; if (!empty($fromid)) { $mychatlist = Chat::field('id,crowd,title,is_group,time')->where(['weid' => weid()])->where('crowd', 'find in set', $fromid)->select(); if (!empty($mychatlist)) { $mychatlist = $mychatlist->toArray(); $k = 0; foreach ($mychatlist as $v) { $crowd = explode(',', $v['crowd']); $chantcon = []; if (!empty($crowd[1])) { $chantcon = []; $chantcon = Chatlog::where(['chatgroupid' => $v['id']])->select()->toArray(); if (!empty($chantcon)) { $data[$k]['is_group'] = 0; $msgList = []; foreach ($chantcon as $kk => $vo) { $msgList[$kk]['avatarUrl'] = $vo['fromavatar']; $msgList[$kk]['content'] = $vo['content']; $msgList[$kk]['contentType'] = $vo['contentType']; $msgList[$kk]['createTime'] = date('Y-m-d H:i', $vo['time']); $data[$k]['accessTime'] = date('Y-m-d H:i', $vo['time']); $data[$k]['inputContent'] = ''; $data[$k]['isFollow'] = false; $data[$k]['lastMsgContent'] = $vo['content']; $data[$k]['lastMsgShowTime'] = date('Y-m-d H:i', $vo['time']); $data[$k]['lastMsgTime'] = date('Y-m-d H:i', $vo['time']); $data[$k]['state'] = 'on'; $data[$k]['newMsgCount'] = ''; if ($vo['fromid'] == $fromid) { $msgList[$kk]['role'] = 'server'; $data[$k]['clientChatId'] = $vo['toid']; $data[$k]['clientChatName'] = $vo['toname']; } else { $msgList[$kk]['role'] = 'client'; $data[$k]['clientChatId'] = $vo['fromid']; $data[$k]['clientChatName'] = $vo['fromname']; } $data[$k]['msgList'] = $msgList; } if ($v['is_group'] == 1) { $data[$k]['accessTime'] = date('Y-m-d H:i', $v['time']); $data[$k]['clientChatId'] = $v['id']; $data[$k]['is_group'] = 1; $data[$k]['clientChatName'] = $v['title']; $data[$k]['inputContent'] = ''; $data[$k]['isFollow'] = false; $data[$k]['lastMsgContent'] = ''; $data[$k]['lastMsgShowTime'] = date('Y-m-d H:i', $v['time']); $data[$k]['lastMsgTime'] = date('Y-m-d H:i', $v['time']); $data[$k]['msgList'] = $msgList; $data[$k]['state'] = 'on'; $data[$k]['newMsgCount'] = ''; } $k++; } } } } } return $this->json(['data' => $data]); } }