reimAction.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. class reimClassAction extends apiAction
  3. {
  4. /**
  5. * 获取聊天记录
  6. */
  7. public function getrecordAction()
  8. {
  9. $uid = $this->adminid;
  10. $type = $this->post('type');
  11. $gid = (int)$this->post('gid');
  12. $minid = (int)$this->post('minid');
  13. $lastdt = (int)$this->post('lastdt');
  14. $lastdts = '';
  15. if($lastdt>0)$lastdts = date('Y-m-d H:i:s', $lastdt);
  16. $arr = m('reim')->getrecord($type, $uid, $gid, $minid, $lastdts);
  17. $this->showreturn($arr);
  18. }
  19. /**
  20. * 获取会话的信息
  21. */
  22. public function getreceinforAction()
  23. {
  24. $uid = $this->adminid;
  25. $type = $this->post('type');
  26. $gid = (int)$this->post('gid');
  27. $reimdb = m('reim');
  28. $arr['receinfor'] = $reimdb->getreceinfor($type, $gid);
  29. $reimdb->setallyd($type, $uid, $gid);
  30. $this->showreturn($arr);
  31. }
  32. /**
  33. * 发消息
  34. */
  35. public function sendinforAction()
  36. {
  37. $uid = $this->adminid;
  38. $type = $this->post('type');
  39. $gid = (int)$this->post('gid');
  40. $lx = 0;
  41. if($this->cfrom=='reim')$lx=1;
  42. if($type=='group'){
  43. $tos = m('im_groupuser')->rows("`gid`='$gid' and `uid`='$uid'");
  44. if($tos==0)$this->showreturn('','您不在此会话中,不允许发送', 201);
  45. }
  46. $cont = $this->post('cont');
  47. $cont = $this->jm->base64decode($cont);
  48. $cont = str_replace('<br>','[BR]', $cont);
  49. $cont = str_replace(array('<','>'),array('&lt;','&gt;'), $cont);
  50. $cont = $this->jm->base64encode(str_replace('[BR]','<br>',$cont));
  51. $arr = m('reim')->sendinfor($type, $uid, $gid, array(
  52. 'optdt' => $this->now,
  53. 'cont' => $cont,
  54. 'fileid'=> (int)$this->post('fileid')
  55. ), $lx);
  56. $arr['sendname'] = $this->adminname;
  57. $this->showreturn($arr);
  58. }
  59. /**
  60. * 标识已读
  61. */
  62. public function yiduAction()
  63. {
  64. $id = $this->post('id');
  65. m('reim')->setyd($id, $this->adminid);
  66. $this->showreturn($id);
  67. }
  68. //将会话标识已读
  69. public function yiduallAction()
  70. {
  71. $type = $this->post('type');
  72. $gid = (int)$this->post('gid');
  73. m('reim')->setallyd($type, $this->adminid, $gid);
  74. $this->showreturn('');
  75. }
  76. /**
  77. * 创建讨论组
  78. */
  79. public function createtaolunAction()
  80. {
  81. $name = $this->post('title');
  82. $explain= $this->post('content');
  83. $receid = $this->post('receid');
  84. if($name==''||$receid=='')$this->showreturn('','not data',201);
  85. $arr = m('reim')->creategroup($name, $receid.','.$this->adminid, 1, $explain);
  86. $this->showreturn($arr);
  87. }
  88. /**
  89. * 获取会话上人员
  90. */
  91. public function getgroupuserAction()
  92. {
  93. $gid = (int)$this->post('gid');
  94. $type = $this->post('type');
  95. $arr = m('reim')->getgroupuser($gid, $type);
  96. $this->showreturn($arr);
  97. }
  98. /**
  99. * 下载聊天记录
  100. */
  101. public function downrecordAction()
  102. {
  103. $minid = floatval($this->post('minid','999999999'));
  104. $maxid = floatval($this->post('maxid','0'));
  105. $arr = m('reim')->downrecord($this->adminid, $maxid, $minid);
  106. $this->showreturn($arr);
  107. }
  108. /**
  109. * 删除历史会话
  110. */
  111. public function delhistoryAction()
  112. {
  113. $gid = (int)$this->post('gid');
  114. $type = $this->post('type');
  115. $arr = m('reim')->delhistory($type,$gid,$this->adminid);
  116. $this->showreturn('');
  117. }
  118. //邀请人员
  119. public function yaoqinguidAction()
  120. {
  121. $gid = (int)$this->post('gid');
  122. $val = $this->post('val');
  123. $ids = m('reim')->adduserchat($gid, $val, true);
  124. $msg = 'success'.$ids.'';
  125. $this->showreturn($msg);
  126. }
  127. //修改会话名称
  128. public function editnameAction()
  129. {
  130. $gid = (int)$this->post('gid');
  131. $val = $this->post('val');
  132. if(isempt($val))return returnerror('不能为空');
  133. m('reim')->editname($gid, $val);
  134. $this->showreturn('');
  135. }
  136. //邀请人员
  137. public function yaoqingnameAction()
  138. {
  139. $gid = (int)$this->post('gid');
  140. $val = $this->post('val');
  141. if(isempt($val))return returnerror('不能为空');
  142. $urs = m('admin')->geturs($val);
  143. if(!$urs)return returnerror('“'.$val.'”不存在');
  144. $uids = ''.$urs['id'].'';
  145. $ids = m('reim')->adduserchat($gid, $uids, true);
  146. $msg = 'success'.$ids.'';
  147. $this->showreturn('ok');
  148. }
  149. //退出讨论组
  150. public function exitgroupAction()
  151. {
  152. $aid = (int)$this->post('aid');
  153. if($aid==0)$aid = $this->adminid;
  154. $gid = (int)$this->post('gid');
  155. m('reim')->exitchat($gid, $aid);
  156. $this->showreturn('success');
  157. }
  158. public function createlunAction()
  159. {
  160. $val = $this->getvals('val');
  161. $isadd = m('view')->isadd('huihua', $this->adminid);
  162. if(!$isadd)return returnerror('无权限创建会话');
  163. m('reim')->createchat($val, $this->adminid,$this->adminid, $this->adminname,'', true);
  164. $this->showreturn('success');
  165. }
  166. //清除历史记录
  167. public function clearrecordAction()
  168. {
  169. $gid = (int)$this->post('gid');
  170. $type = $this->post('type');
  171. $ids = c('check')->onlynumber($this->post('ids'));
  172. $day = (int)$this->post('day');
  173. $arr = m('reim')->clearrecord($type,$gid,$this->adminid, $ids, $day);
  174. $this->showreturn('');
  175. }
  176. //上传头像
  177. public function changefaceAction()
  178. {
  179. $fid = (int)$this->post('id');
  180. $uid = $this->adminid;
  181. $face = m('admin')->changeface($uid, $fid);
  182. if(!$face)$this->showreturn('','fail changeface',201);
  183. $this->showreturn($face);
  184. }
  185. //下载文件
  186. public function downfileAction()
  187. {
  188. $id = (int)$this->post('id');
  189. m('file')->download($id);
  190. }
  191. //修改会话头像
  192. public function editfaceAction()
  193. {
  194. $gid = (int)$this->get('gid');
  195. $fileid = (int)$this->get('fileid');
  196. if($gid<=0)return returnerror('error');
  197. m('reim')->editface($gid, $fileid);
  198. $this->showreturn('');
  199. }
  200. /**
  201. * 文件转发发送给对应人员
  202. */
  203. public function forwardAction()
  204. {
  205. $fid = (int)$this->post('fileid');
  206. $tuid= $this->post('tuid');
  207. $msg = m('reim')->forward($tuid, 'user', $this->post('cont'), $fid);
  208. if($msg!='ok')$this->showreturn('', $msg, 201);
  209. $this->showreturn('');
  210. }
  211. /**
  212. * 消息撤回
  213. */
  214. public function chehuimessAction()
  215. {
  216. $gid = (int)$this->post('gid');
  217. $type = $this->post('type');
  218. $ids = (int)$this->post('ids');
  219. $barr = m('reim')->chehuimess($type, $gid, $ids);
  220. if(is_array($barr))$this->showreturn($barr);
  221. $this->showreturn('', $barr, 201);
  222. }
  223. public function saveoutunumAction()
  224. {
  225. $unum = $this->get('unum');
  226. $num = 'outunum'.$this->adminid.'';
  227. $this->option->setval($num, $unum);
  228. return returnsuccess();
  229. }
  230. /**
  231. * 收藏使用
  232. */
  233. public function savestarAction()
  234. {
  235. $content = $this->post('content');
  236. $kev = $this->post('kev');
  237. $id = (int)$this->post('id','0');
  238. $num = 'reimstar_'.$this->adminid.'';
  239. $this->option->setval($num,'收藏消息');
  240. $pid = $this->option->getpids($num);
  241. $snum = ''.$num.'_'.$kev.'';
  242. $sid = $this->option->getpids($snum);
  243. if($sid>0)$id = $sid;
  244. $uarr = array(
  245. 'value' => $content,
  246. 'pid' => $pid,
  247. 'num' => $snum,
  248. 'optdt' => $this->now,
  249. 'optid' => $this->adminid,
  250. );
  251. if($id==0){
  252. $id = $this->option->insert($uarr);
  253. }else{
  254. $this->option->update($uarr, $id);
  255. }
  256. return returnsuccess(array(
  257. 'id' => $id
  258. ));
  259. }
  260. public function getstarAction()
  261. {
  262. $num = 'reimstar_'.$this->adminid.'';
  263. $pid = $this->option->getpids($num);
  264. $data = $this->option->getall('`pid`='.$pid.'','id,value','optdt desc');
  265. return returnsuccess($data);
  266. }
  267. public function delstarAction()
  268. {
  269. $id = (int)$this->get('id');
  270. $this->option->delete('`id`='.$id.' and `optid`='.$this->adminid.'');
  271. return returnsuccess();
  272. }
  273. public function rockkefuAction()
  274. {
  275. $barr = c('rockkefu')->getdata('openkefu','exists', array(
  276. 'user' => $this->userrs['user']
  277. ));
  278. $msg = 'err';
  279. if($barr['success'])$msg='ok';
  280. return returnsuccess($msg);
  281. }
  282. /**
  283. * 读取消息情况
  284. */
  285. public function getxqkkdAction()
  286. {
  287. $barr = array();
  288. $id = (int)$this->get('id');
  289. $mrs = m('im_mess')->getone($id);
  290. $type = $mrs['type'];
  291. $receuid = $mrs['receuid'];
  292. $recearr = explode(',', $receuid);
  293. //$barr['mrs'] = $mrs;
  294. $yiduids = '';
  295. $widuids = '';
  296. if($type=='user'){
  297. if($mrs['zt']==1){
  298. $yiduids = $mrs['receid'];
  299. }else{
  300. $widuids = $mrs['receid'];
  301. }
  302. }else{
  303. $rows = m('im_messzt')->getall('mid='.$id.'');
  304. foreach($rows as $k=>$rs)$widuids.=','.$rs['uid'].'';
  305. if($widuids){
  306. $widuids = substr($widuids, 1);
  307. $widuar = explode(',', $widuids);
  308. foreach($recearr as $sid)if(!in_array($sid, $widuar))$yiduids.=','.$sid.'';
  309. if($yiduids)$yiduids = substr($yiduids, 1);
  310. }else{
  311. $yiduids = $receuid;
  312. }
  313. }
  314. $ydarr = $wdarr = array();
  315. $dbs = m('admin');
  316. if($yiduids){
  317. $rows = $dbs->getall('`id` in('.$yiduids.')','name,face,id','sort asc');
  318. foreach($rows as $k=>$rs){
  319. $ydarr[] = array(
  320. 'name' => $rs['name'],
  321. 'id' => $rs['id'],
  322. 'face' => $dbs->getface($rs['face']),
  323. );
  324. }
  325. }
  326. if($widuids){
  327. $rows = $dbs->getall('`id` in('.$widuids.')','name,face,id','sort asc');
  328. foreach($rows as $k=>$rs){
  329. $wdarr[] = array(
  330. 'name' => $rs['name'],
  331. 'id' => $rs['id'],
  332. 'face' => $dbs->getface($rs['face']),
  333. );
  334. }
  335. }
  336. $barr['ydarr'] = $ydarr;
  337. $barr['wdarr'] = $wdarr;
  338. return returnsuccess($barr);
  339. }
  340. }
粤ICP备19079148号