reimModel.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. <?php
  2. class reimClassModel extends Model
  3. {
  4. private $groupname = '';
  5. public $serverrecid = 'rockreim';
  6. public $serverpushurl = '';
  7. public $serverhosturl = '';
  8. public $servertitle = '';
  9. private $hisobj,$option,$optiondb;
  10. public function initModel()
  11. {
  12. // 设置表名为 'im_mess'
  13. $this->settable('im_mess');
  14. // 实例化 'im_history' 模型并赋值给属性 'hisobj'
  15. $this->hisobj = m('im_history');
  16. // 实例化 'option' 模型并赋值给属性 'option'
  17. $this->option = m('option');
  18. // 调用 'inithost' 方法进行初始化
  19. $this->inithost();
  20. }
  21. private function inithost()
  22. {
  23. if($this->serverpushurl!='')return;
  24. $dbs = $this->option;
  25. $this->optiondb = $dbs;
  26. $this->serverrecid = $dbs->getval('reimrecidsystem','rockxinhu');
  27. $this->serverpushurl = $dbs->getval('reimpushurlsystem');
  28. $this->serverhosturl = $dbs->getval('reimhostsystem');
  29. $this->servertitle = $dbs->getval('reimtitlesystem');
  30. $this->serverpushurl = getconfig('reim_push', $this->serverpushurl);
  31. $this->serverhosturl = getconfig('reim_host', $this->serverhosturl);
  32. if($this->isempt($this->servertitle))$this->servertitle='信呼';
  33. }
  34. public function isanwx()
  35. {
  36. $bo = false;
  37. return $bo;
  38. }
  39. /**
  40. * 返回判断是否有安装微信企业号/企业微信 $lx=0企业号,1企业微信,2钉钉,3微信公众号号,4是否微信模版消息
  41. */
  42. public function installwx($lx=0)
  43. {
  44. if($lx==0)return $this->isanwx();
  45. $bo = false;
  46. if($lx==1){
  47. if(!isempt($this->optiondb->getval('weixinqy_corpid')))$bo=true;
  48. return $bo;
  49. }
  50. if($lx==2){
  51. if(!isempt($this->optiondb->getval('dingding_token0')))$bo=true;
  52. return $bo;
  53. }
  54. if($lx==3){
  55. if(!isempt($this->optiondb->getval('wxgzh_appid')))$bo=true;
  56. return $bo;
  57. }
  58. if($lx==4){
  59. if($this->optiondb->getval('wxgzh_tplmess')=='1')$bo=true;
  60. return $bo;
  61. }
  62. if($lx==5){
  63. if(!isempt($this->optiondb->getval('reimplat_cnum')))$bo=true;
  64. return $bo;
  65. }
  66. return false;
  67. }
  68. public function getreims()
  69. {
  70. $this->inithost();
  71. $chehui = (int)$this->optiondb->getval('reimchehuisystem',0);
  72. if($chehui<0)$chehui = 0;
  73. return array(
  74. 'recid' => $this->serverrecid,
  75. 'title' => $this->servertitle,
  76. 'chehui'=> $chehui * 60,
  77. 'appwx' => $this->optiondb->getval('reimappwxsystem'),
  78. 'wsurl' => $this->rock->jm->base64encode($this->serverhosturl)
  79. );
  80. }
  81. private function getgroupid($gname)
  82. {
  83. $agesta = explode(',', $gname);
  84. $name = $agesta[0];
  85. $sid = (int)$this->db->getmou('[Q]im_group','id', "`name`='$name' and `type`=2");
  86. if($sid==0 && count($agesta)>1)$sid = $this->getgroupid($agesta[1]);
  87. $this->groupname = $name;
  88. return $sid;
  89. }
  90. /**
  91. * REIM推送的
  92. */
  93. public function sendsystem($sendid, $receid, $gname, $cont, $table='',$mid='', $url='')
  94. {
  95. $gid = $this->getgroupid($gname);
  96. $gname = $this->groupname;
  97. if($gid==0)return false;
  98. if($this->isempt($receid))return 'not receuid';
  99. $receids = $receid;
  100. $wheres = " and `id` in($receid)";
  101. if($receid=='all')$wheres='';
  102. $allsid = '';
  103. $recrarr = $this->db->getall("select id from [Q]admin where `status`=1 $wheres");
  104. foreach($recrarr as $k=>$rs){
  105. $allsid.=','.$rs['id'].'';
  106. }
  107. $messid = 0;
  108. if($allsid != ''){
  109. $allsid = substr($allsid, 1);
  110. $this->insert(array(
  111. 'type' => 'agent',
  112. 'optdt' => $this->rock->now,
  113. 'zt' => 0,
  114. 'cont' => $this->rock->jm->base64encode($cont),
  115. 'sendid'=> $sendid,
  116. 'receid'=> $gid,
  117. 'optid' => $sendid,
  118. 'receuid' => $allsid,
  119. 'table' => $table,
  120. 'mid' => $mid,
  121. 'url' => $url
  122. ));
  123. $messid = $this->db->insert_id();
  124. $this->db->insert('[Q]im_messzt','`mid`,`uid`,`gid`','select '.$messid.',id,'.$gid.' from `[Q]admin` where id in('.$allsid.') and `status`=1 ', true);
  125. }
  126. $resid = $receids;
  127. if($resid!='all')$resid = m('admin')->getonline($resid);
  128. if($resid!='' && $messid>0)$this->sendpush($sendid, $resid, array(
  129. 'agent' => $gname,
  130. 'optdt' => $this->rock->now,
  131. 'type' => 'agent',
  132. 'messid' => $messid,
  133. 'agentid' => $gid,
  134. 'cont' => $this->rock->jm->base64encode($cont),
  135. 'table' => $table,
  136. 'mid' => $mid,
  137. 'url' => $url
  138. ));
  139. //if($messid>0)$this->addhistory('agent', $gid, $allsid);
  140. return true;
  141. }
  142. /**
  143. * 应用信息推送
  144. * $slx 0,1发送给pc,0,2发送给移动端,3不发送
  145. * $xgurl 相关地址,一般是单据详情:模块编号|id
  146. */
  147. public function pushagent($receid, $gname, $cont, $title='', $url='', $wxurl='', $slx=0, $xgurl='')
  148. {
  149. if($slx==3 || isempt($receid))return false;
  150. $cont = str_replace(array("\n",'\n','<br>'),' ', $cont);
  151. $gid = $this->getgroupid($gname);
  152. $grs = $this->getgroupxinxi($gid);
  153. $gname = $this->groupname;
  154. $admdb = m('admin');
  155. $sarr = array(
  156. 'gname' => $gname,
  157. 'optdt' => $this->rock->now,
  158. 'type' => 'agent',
  159. 'pushtype' => 'agent',
  160. 'title' => $title,
  161. 'gface' => arrvalue($grs,'face'),
  162. 'gid' => $gid,
  163. 'cont' => $this->rock->jm->base64encode($cont),
  164. 'url' => $url
  165. );
  166. if($title=='')$title = $gname;
  167. //保存到推送会话列表上历史记录上
  168. if($gid>0){
  169. $receids = $admdb->gjoins($receid);
  170. if($receids!='all' &&
  171. !isempt($receids)
  172. )$this->addhistory($sarr['type'], $gid, $receids, $sarr['optdt'], $sarr['cont'], $this->adminid, $title, $xgurl);
  173. }
  174. $resid = $receid;
  175. if($slx == 0 || $slx==1){
  176. if($resid != 'all')$resid = $admdb->getonline($resid);
  177. if($resid != '')$this->sendpush($this->adminid, $resid, $sarr);//PC端
  178. }
  179. //推送到APP上
  180. if($slx == 0 || $slx==2){
  181. if($wxurl!='')$sarr['url'] = $wxurl;
  182. $this->pushapp($receid, $title, $sarr, $slx);
  183. }
  184. }
  185. //获取REIM未读的
  186. public function getwdarr($mid=0, $ldt='')
  187. {
  188. $rows = array();
  189. if($mid==0)$mid = $this->adminid;
  190. $whes = $this->rock->dbinstr('receuid', $mid);
  191. $wher = '';
  192. if(!$this->isempt($ldt))$wher=" and `optdt`>='$ldt' ";
  193. $arr = $this->getall("`zt`=0 and receid='$mid' and `type`='user' $wher group by `sendid`", "`sendid`,count(1) as stotal,max(optdt) as optdts,cont");
  194. foreach($arr as $k=>$rs){
  195. $uid = $rs['sendid'];
  196. $urs = $this->db->getone('[Q]admin',"`id`='$uid'",'`name`,`face`');
  197. if($urs){
  198. $rows[] = array(
  199. 'type' => 'user',
  200. 'id' => $uid,
  201. 'stotal'=> $rs['stotal'],
  202. 'optdt' => $rs['optdts'],
  203. 'name' => $urs['name'],
  204. 'cont' => $rs['cont'],
  205. 'face' => $this->getface($urs['face'])
  206. );
  207. }
  208. }
  209. // 讨论组 群
  210. $groupa = $this->db->getarr('[Q]im_group','1=1','`name`,`face`,`type`');
  211. $gid = '0';
  212. foreach($groupa as $_gid=>$kvs)$gid.=','.$_gid.'';
  213. $arr = $this->getall("`type`='group' and `receid` in($gid) and $whes $wher and id in(select mid from [Q]im_messzt where uid='$mid') group by `receid`", "`receid`,count(1) as stotal,max(optdt) as optdts,cont");
  214. $typea = array('group','group');
  215. foreach($arr as $k=>$rs){
  216. $grs = $groupa[$rs['receid']];
  217. $typ = $typea[$grs['type']];
  218. $rows[] = array(
  219. 'type' => 'group',
  220. 'id' => $rs['receid'],
  221. 'stotal'=> $rs['stotal'],
  222. 'optdt' => $rs['optdts'],
  223. 'name' => $grs['name'],
  224. 'cont' => $rs['cont'],
  225. 'face' => $this->getface($grs['face'],'images/'.$typ.'.png')
  226. );
  227. }
  228. //应用的信息
  229. $arr = $this->getall("`type`='agent' and `receid` in($gid) and $whes $wher and id in(select mid from [Q]im_messzt where uid='$mid') group by `receid`", "`receid`,count(1) as stotal,max(optdt) as optdts,cont");
  230. foreach($arr as $k=>$rs){
  231. $grs = $groupa[$rs['receid']];
  232. $rows[] = array(
  233. 'type' => 'agent',
  234. 'id' => $rs['receid'],
  235. 'stotal'=> $rs['stotal'],
  236. 'optdt' => $rs['optdts'],
  237. 'cont' => $rs['cont'],
  238. 'name' => $grs['name'],
  239. 'face' => $this->getface($grs['face'])
  240. );
  241. }
  242. return $rows;
  243. }
  244. public function getweitotal($uid, $type, $sid=0, $blx=0)
  245. {
  246. $whes = $this->rock->dbinstr('receuid', $uid);
  247. $where = "`type`='$type' and `receid` ='$sid' and $whes and id in(select mid from [Q]im_messzt where uid='$uid')";
  248. if($type == 'user'){
  249. $where = "`zt`=0 and `receid`='$uid' and `type`='user' and $whes";
  250. }
  251. if($blx==1)return $where;
  252. $to = $this->rows($where);
  253. return $to;
  254. }
  255. /**
  256. * 获取未读的会话消息数量
  257. */
  258. public function getreimwd($uid)
  259. {
  260. $to = $this->db->getmou('[Q]im_history','sum(stotal)','uid='.$uid.'');
  261. if(isempt($to))$to = '0';
  262. return $to;
  263. }
  264. /**
  265. * 获取人员所在的会话上
  266. */
  267. public function getgroup($uid)
  268. {
  269. $ids = '0';
  270. $idrsa = m('im_groupuser')->getall("uid='$uid'",'gid');
  271. foreach($idrsa as $k=>$rs){
  272. $ids.=','.$rs['gid'];
  273. }
  274. $sql = "select a.gid,count(1)utotal from `[Q]im_groupuser` a left join `[Q]admin` b on a.uid=b.id where a.gid in($ids) and b.status=1 group by a.gid";
  275. $urows = $this->db->getall($sql);
  276. $ugarr = array();
  277. foreach($urows as $k=>$rs)$ugarr[$rs['gid']] = $rs['utotal'];
  278. $rows = m('im_group')->getall("`id`>0 and ((`type` in(0,1) and `id` in($ids) ) ) order by `type`,`sort` ",'`id`,`type`,`name`,`face`,`sort`,`deptid`');
  279. $facarr = array('images/group.png','images/group.png','images/system.png');
  280. foreach($rows as $k=>$rs){
  281. $rows[$k]['face'] = $this->getface($rs['face'], $facarr[$rs['type']]);
  282. $rows[$k]['utotal'] = arrvalue($ugarr,$rs['id'], '0');
  283. }
  284. return $rows;
  285. }
  286. public function getgroupuser($gid, $type)
  287. {
  288. $sql = "select b.id,b.name,b.face from `[Q]im_groupuser` a left join `[Q]admin` b on a.uid=b.id where a.gid='$gid' and b.status=1";
  289. if($type=='user')$sql = "select id,name,face from `[Q]admin` where id in(".$gid.",".$this->adminid.")";
  290. $rows = $this->db->getall($sql);
  291. foreach($rows as $k=>$rs){
  292. $rows[$k]['face'] = $this->getface($rs['face']);
  293. }
  294. $arr['uarr'] = $rows;
  295. if($type=='user'){
  296. $arr['infor'] = array();
  297. }else{
  298. $arr['infor'] = $this->getgroupxinxi($gid);
  299. }
  300. return $arr;
  301. }
  302. public function getgroupxinxi($gid)
  303. {
  304. $rs = m('im_group')->getone($gid,'`id`,`type`,`name`,`face`,`deptid`,`createname`,`createid`');
  305. $facarr = array('images/group.png','images/group.png','images/todo.png');
  306. if(!$rs){
  307. $rs = array(
  308. 'face' => '',
  309. 'type' => 2,
  310. 'name' => '',
  311. 'id' => $gid,
  312. );
  313. }
  314. $rs['face'] = $this->getface($rs['face'], $facarr[$rs['type']]);
  315. $rs['utotal'] = $this->db->rows('[Q]im_groupuser','gid='.$gid.'');
  316. $rs['innei'] = $this->db->rows('[Q]im_groupuser','gid='.$gid.' and uid='.$this->adminid.''); //是否在会话中
  317. return $rs;
  318. }
  319. private function getface($face, $mr='')
  320. {
  321. if($mr=='')$mr = 'images/noface.png';
  322. $url = URL;
  323. if(!$url)$url = getconfig('outurl');
  324. if(substr((string)$mr,0,4)!='http')$mr = $url.''.$mr.'';
  325. if(substr((string)$face,0,4)!='http' && !$this->isempt($face))$face = $url.''.$face.'';
  326. $face = $this->rock->repempt($face, $mr);
  327. return $face;
  328. }
  329. /**
  330. 设置已读
  331. */
  332. public function setyd($ids, $receid)
  333. {
  334. $this->update("`zt`=1", "`id` in($ids) and receid='$receid' and `type` ='user' ");
  335. m('im_messzt')->delete("uid='$receid' and `mid` in($ids)");
  336. }
  337. public function setallyd($type,$uid, $gid)
  338. {
  339. if($type=='user'){
  340. $this->update("`zt`=1", "`sendid` ='$gid' and receid='$uid' and `type`='user'");
  341. }else{
  342. m('im_messzt')->delete("uid='$uid' and `gid`=$gid");
  343. }
  344. $this->hisobj->update('stotal=0', "`type`='$type' and `uid`='$uid' and `receid`='$gid'");
  345. }
  346. /**
  347. * 桌面版PC客户端获取应用
  348. */
  349. public function getagent($uid=0, $whe='', $pid=0)
  350. {
  351. if($uid==0)$uid = $this->adminid;
  352. $yylx = '2';
  353. if($this->rock->get('cfrom')=='reim')$yylx='1';
  354. $dboaj = m('admin');
  355. $where = $dboaj->getjoinstr('receid', $this->adminid);
  356. $rows = $this->db->getrows('[Q]im_group',"`valid`=1 and `type`=2 and `yylx` in(0,".$yylx.") $where $whe",'`id`,`name`,`url`,`face`,`num`,`pid`,`iconfont`,`iconcolor`,`types`,`urlpc`,`urlm`','`sort`');
  357. $dbs = m('im_menu');
  358. $mdbs = m('menu');
  359. $barr = $carr = array();
  360. $mids = '0';
  361. foreach($rows as $k=>$rs)$mids.=','.$rs['id'].'';
  362. $allmenu = $cmenu = array();
  363. $allmenua = $dbs->getall("`mid` in($mids)",'`pid`,`mid`,`id`,`name`,`type`,`url`,`num`,`color`,`receid`','`sort`');
  364. foreach($allmenua as $k1=>$rs1){
  365. if(isempt($rs1['receid'])){
  366. $allmenu[] = $rs1;
  367. }else{
  368. $bo = $dboaj->containjoin($rs1['receid'], $uid);
  369. if($bo)$allmenu[] = $rs1;
  370. }
  371. }
  372. foreach($allmenu as $k=>$rs){
  373. if($rs['pid']=='0'){
  374. $submenu = array();
  375. foreach($allmenu as $k1=>$rs1){
  376. if($rs1['pid']==$rs['id'])$submenu[] = $rs1;
  377. }
  378. $rs['submenu'] = $submenu;
  379. $cmenu[$rs['mid']][] = $rs;
  380. }
  381. }
  382. foreach($rows as $k=>$rs){
  383. if(isempt($rs['num']))continue;
  384. $rs['face'] = $this->getface($rs['face']);
  385. $stotal = 0;
  386. $btosr = m('agent:'.$rs['num'].'')->gettotal();
  387. $stotal = $btosr['stotal'];
  388. $rs['titles'] = $btosr['titles'];
  389. $menu = array();
  390. if(isset($cmenu[$rs['id']]))$menu = $cmenu[$rs['id']];
  391. $rs['menu'] = $menu;
  392. $rs['stotal'] = $stotal;
  393. $rs['totals'] = 0;
  394. //连接地址转化
  395. if($rs['url']=='link' || $rs['url']=='linko'){
  396. $urlpc = $rs['urlpc'];
  397. if(!isempt($urlpc) && $mrs = $mdbs->getone("`num`='$urlpc'")){
  398. $urlpc = 'index.php?m=index&homeurl='.$this->rock->jm->base64encode($mrs['url']).'&homename='.$this->rock->jm->base64encode($mrs['name']).'&menuid='.$this->rock->jm->base64encode($mrs['id']).'';
  399. $rs['urlpc'] = $urlpc;
  400. }
  401. }
  402. $barr[] = $rs;
  403. }
  404. foreach($barr as $k=>$rs){
  405. $types = $rs['types'];
  406. if(isempt($types))$types='应用';
  407. if(!isset($carr[$types]))$carr[$types]=array();
  408. $rs['types'] = $types;
  409. $carr[$types][] = $rs;
  410. }
  411. //应用统计
  412. $gcarr = array();
  413. foreach($carr as $types=>$rows){
  414. $ntypes = $types.'('.count($rows).')';
  415. foreach($rows as $k=>$rs)$rows[$k]['types'] = $ntypes;
  416. $gcarr[$ntypes] = $rows;
  417. }
  418. $barr = array();
  419. foreach($gcarr as $types=>$rs){
  420. $barr = array_merge($barr, $rs);
  421. }
  422. return $barr;
  423. }
  424. /**
  425. * 手机app/手机网页版上获取应用
  426. */
  427. public function getappagent($uid=0)
  428. {
  429. $uid = $this->adminid;
  430. $where = m('admin')->getjoinstr('receid', $this->adminid);
  431. $rows = $this->db->getrows('[Q]im_group',"`valid`=1 and `type`=2 and `yylx` in(0,2) $where ",'`id`,`name`,`url`,`face`,`num`,`types`,`urlm`','`sort`');
  432. $dbs = m('im_menu');
  433. $barr = $carr = array();
  434. $stotalt= 0;
  435. foreach($rows as $k=>$rs){
  436. if(isempt($rs['num']))continue;
  437. $rs['face'] = $this->getface($rs['face']);
  438. $stotal = 0;
  439. $btosr = m('agent:'.$rs['num'].'')->gettotal(); //统计红点数
  440. $stotal = $btosr['stotal'];
  441. $stotalt+=$stotal;
  442. $rs['titles'] = $btosr['titles'];
  443. $rs['stotal'] = $stotal;
  444. $barr[] = $rs;
  445. }
  446. foreach($barr as $k=>$rs){
  447. $types = $rs['types'];
  448. if(isempt($types))$types='应用';
  449. if(!isset($carr[$types]))$carr[$types]=array();
  450. $rs['types'] = $types;
  451. $carr[$types][] = $rs;
  452. }
  453. //应用统计
  454. $gcarr = array();
  455. foreach($carr as $types=>$rows){
  456. $ntypes = $types.'('.count($rows).')';
  457. foreach($rows as $k=>$rs)$rows[$k]['types'] = $ntypes;
  458. $gcarr[$ntypes] = $rows;
  459. }
  460. $barr = array();
  461. foreach($gcarr as $types=>$rs){
  462. $barr = array_merge($barr, $rs);
  463. }
  464. return array(
  465. 'rows' => $barr,
  466. 'stotal' => $stotalt,
  467. );
  468. }
  469. /**
  470. * 获取历史记录
  471. */
  472. public function gethistory($uid=0, $optdt='', $whes='')
  473. {
  474. if($uid==0)$uid = $this->adminid;
  475. $where = $whes;
  476. if($optdt!='')$where = "and `optdt`>'$optdt'";
  477. $rows = $this->db->getall("select * from `[Q]im_history` where `uid`=$uid $where order by `optdt` desc");
  478. $dt = $this->rock->date;
  479. foreach($rows as $k=>$rs){
  480. $rows[$k]['optdts'] = substr($rs['optdt'],11,5);
  481. if(!contain($rs['optdt'], $dt))$rows[$k]['optdts'] = substr($rs['optdt'],5,5);
  482. $rows[$k]['id'] = $rs['receid'];
  483. $name = '';
  484. $rson = false;
  485. if($rs['type']=='user'){
  486. $rson = $this->db->getone('[Q]admin', $rs['receid'], 'name,face');
  487. $face = 'images/noface.png';
  488. }else{
  489. $face = 'images/group.png';
  490. $rows[$k]['gid'] = $rs['receid'];
  491. $rson = $this->db->getone('[Q]im_group', $rs['receid'], 'name,face,deptid');
  492. if(!isempt($rs['title']) && $rson)$rson['name'] = $rs['title'];
  493. }
  494. if($rson){
  495. $name = $rson['name'];
  496. $face = $this->getface($rson['face'], $face);
  497. if($rs['type']=='group')$rows[$k]['deptid'] = $rson['deptid'];
  498. }
  499. $rows[$k]['face'] = $face;
  500. $rows[$k]['name'] = $name;
  501. }
  502. return $rows;
  503. }
  504. /**
  505. * 微信上获取未读消息
  506. */
  507. public function getuntodo($uid)
  508. {
  509. $rows = $this->gethistory($uid, '', 'and `stotal`>0');
  510. $str = '';
  511. foreach($rows as $k=>$rs){
  512. if($k>0)$str.= "\n";
  513. $str.=''.($k+1).'、'.$rs['name'].':'.$rs['stotal'].'条';
  514. }
  515. return $str;
  516. }
  517. /**
  518. * 添加到历史记录,用户不显示历史记录让从新显示
  519. */
  520. public function addhistory($type, $receid, $uids,$optdt, $cont,$sendid=0, $title='', $xgurl='',$messid=0)
  521. {
  522. $uidsas = explode(',', $uids);
  523. $db = $this->hisobj;
  524. $isuar = array();
  525. $uarrs = $db->getrows("`type`='$type' and `receid`='$receid' and `uid` in($uids)", '`uid`,`id`');
  526. foreach($uarrs as $k=>$rs)$isuar[$rs['uid']]=$rs['id'];
  527. $iarr = $garr = array();
  528. $gids = '';
  529. foreach($uidsas as $uid){
  530. $where = '';
  531. if(isset($isuar[$uid]))$where = $isuar[$uid];
  532. $arr = array();
  533. $arr['optdt'] = $optdt;
  534. $arr['cont'] = substr($cont, 0, 190);
  535. $arr['sendid'] = $sendid;
  536. $arr['title'] = $title;
  537. $arr['xgurl'] = $xgurl;
  538. $arr['messid'] = $messid;
  539. if($where==''){
  540. $arr['type'] = $type;
  541. $arr['receid'] = $receid;
  542. $arr['uid'] = $uid;
  543. $arr['stotal'] = 1;
  544. }else{
  545. $arr['stotal'] = '(&;)`stotal`+1';
  546. }
  547. if($where==''){
  548. $iarr[] = $arr;
  549. }else{
  550. if(!$garr)$garr = $arr;
  551. $gids.=','.$where.'';
  552. }
  553. }
  554. if($iarr)$db->insertAll($iarr);
  555. if($gids!='')$db->update($garr,'`id` in('.substr($gids,1).')');
  556. $db->update('`stotal`=0',"`type`='$type' and `receid`='$receid' and `uid`='$this->adminid'");
  557. }
  558. public function delhistory($type, $receid, $uid=0)
  559. {
  560. $where = "`type`='$type' and `receid`='$receid'";
  561. if($uid>0)$where.=" and `uid`='$uid'";
  562. if($type=='all'){
  563. $where = "`uid`='$uid'";
  564. }
  565. $this->hisobj->delete($where);
  566. }
  567. /**
  568. * 获取聊天会话记录
  569. */
  570. public function getrecord($type, $uid, $gid, $minid=0, $lastdt='')
  571. {
  572. $arr = array();
  573. $rows= array();
  574. $loadci = (int)$this->rock->get('loadci','0');
  575. if($type == 'user'){
  576. $arr = $this->getuserinfor($uid, $gid, $minid, $lastdt);
  577. }
  578. if($type=='group'){
  579. $arr = $this->getgroupinfor($uid, $gid, $minid, $lastdt);
  580. }
  581. $arr['receinfor'] = $this->getreceinfor($type, $gid);
  582. $arr['nowdt'] = time();
  583. $arr['servernow'] = $this->rock->now;
  584. if($loadci==0){
  585. $arr['sendinfo'] = m('admin')->getinfor($uid);
  586. }
  587. if(isset($arr['rows']))$arr['rows'] = $this->replacefileid($arr['rows']);
  588. $this->hisobj->update('stotal=0',"`type`='$type' and `receid`='$gid' and `uid`='$uid'");
  589. return $arr;
  590. }
  591. public function getreceinfor($type, $gid)
  592. {
  593. $info = array();
  594. if($type == 'user'){
  595. $info = m('admin')->getinfor($gid);
  596. }
  597. if($type=='group'){
  598. $info = $this->getgroupxinxi($gid);
  599. }
  600. $bsear = $this->getreims();
  601. $info['type'] = $type;
  602. $info['gid'] = $gid;
  603. $info['chehui'] = $bsear['chehui'];
  604. return $info;
  605. }
  606. private function replacefileid($rows)
  607. {
  608. $fileids = '0';
  609. if($rows)foreach($rows as $k=>$rs){
  610. if($rs['fileid'])$fileids.=','.$rs['fileid'].'';
  611. }
  612. $imgext = ',gif,png,jpg,jpeg,bmp,';
  613. $fobj = m('file');
  614. if($fileids!='0'){
  615. $farr = array();
  616. $frows = $fobj->getrows("id in ($fileids)", 'id,fileext,filenum,filepath,filename,thumbpath,filetype,filesizecn,optid,optname,adddt,filesize,thumbplat');
  617. foreach($frows as $k=>$rs)$farr[$rs['id']]=$rs;
  618. if($farr)foreach($rows as $k=>$rs){
  619. $frs = array();
  620. $fid = $rs['fileid'];
  621. if(isset($farr[$fid]))$frs=$farr[$fid];
  622. if($frs){
  623. $type = $frs['fileext'];
  624. $path = $frs['filepath'];
  625. $boc = false;
  626. if(substr($path,0,4)=='http' || !isempt($frs['filenum'])){
  627. $boc = true;
  628. }else{
  629. if(file_exists($path))$boc = true;
  630. }
  631. if($boc){
  632. if($this->contain($imgext, ','.$type.',')){
  633. $frs['thumbpath'] = $fobj->getthumbpath($frs);
  634. //$cont = '<img fid="'.$fid.'" src="'.$frs['thumbpath'].'">';
  635. //$rows[$k]['cont'] = $this->rock->jm->base64encode($cont);
  636. }else{
  637. }
  638. $frs['fileid'] = $fid;
  639. $rows[$k]['filers'] = $frs;
  640. }else{
  641. $rows[$k]['fileid'] = 0;
  642. }
  643. }
  644. }
  645. }
  646. return $rows;
  647. }
  648. /**
  649. * 获取人员信息
  650. * $uid 当前用户
  651. */
  652. public function getuserinfor($uid, $receid, $minid=0, $lastdt='')
  653. {
  654. $type = 'user';
  655. $whes = $this->rock->dbinstr('receuid', $uid);
  656. $soulx = $this->rock->get('soulx');
  657. $soukey = $this->rock->get('soukey');
  658. $wdtotal= 0;
  659. $where1 = "`type`='$type' and `zt`=0 and `receid`='$uid' and `sendid`='$receid' and $whes";
  660. if($lastdt=='' && $this->rock->get('laiyuan')!='not')$wdtotal= $this->rows($where1);
  661. if($wdtotal > 0){
  662. $where = "$where1 order by `id` desc limit 10";
  663. }else{
  664. $where = "`type`='$type' and ((`receid`='$uid' and `sendid`='$receid') or (`sendid`='$uid' and `receid`='$receid')) and $whes ";
  665. if($lastdt != ''){
  666. $where .= " and `optdt`>'$lastdt'";
  667. if($this->rock->get('laiyuan')!='new')$where .=' and `sendid`<>'.$uid.'';
  668. }
  669. if($soulx=='sou0' | $soulx=='sou1')$where.= " and `fileid`>0 ";
  670. if($soukey)$where.=" and `cont` like '%".$soukey."%'";
  671. if($minid==0){
  672. $where .= ' order by `id` desc limit 5';
  673. }else{
  674. $where .= ' and `id`<'.$minid.' order by `id` desc limit 10';
  675. }
  676. }
  677. $rows = $this->getall($where, 'SQL_CALC_FOUND_ROWS optdt,zt,id,cont,sendid,fileid,type');
  678. $total = $this->db->found_rows();
  679. $len = 0;
  680. $suids = '0';
  681. $ids = '0';
  682. foreach($rows as $k=>$rs){
  683. $len++;
  684. if($rs['zt']==0)$ids .= ','.$rs['id'].'';
  685. $suids.= ','.$rs['sendid'];
  686. $wdtotal--;
  687. }
  688. $rows = $this->ivaregarr($suids, $rows);
  689. if($ids!='0')$this->setyd($ids, $uid);
  690. if($wdtotal<0)$wdtotal=0;
  691. $total = $total-$len;
  692. if($total<=0)$total = 0;
  693. return array(
  694. 'rows' => $rows,
  695. 'wdtotal' => $wdtotal,
  696. 'systotal' => $total,
  697. );
  698. }
  699. public function getgroupinfor($uid, $receid, $minid=0, $lastdt='')
  700. {
  701. $whes = $this->rock->dbinstr('receuid', $uid);
  702. $order = '';
  703. $type = 'group';
  704. $wdtotal = 0;
  705. if($lastdt=='' && $this->rock->get('laiyuan')!='not')$wdtotal = $this->getweitotal($uid, $type, $receid);
  706. $soulx = $this->rock->get('soulx');
  707. $soukey = $this->rock->get('soukey');
  708. if($wdtotal > 0){
  709. $wdwhere = $this->getweitotal($uid, $type, $receid, 1);
  710. $zwhere = " $wdwhere order by `id` desc limit 10";
  711. }else{
  712. $zwhere = " `receid`='$receid' and `type`='$type' and $whes";
  713. if($lastdt != ''){
  714. $zwhere .= " and `optdt`>'$lastdt'";
  715. if($this->rock->get('laiyuan')!='new')$zwhere .=' and `sendid`<>'.$uid.'';
  716. }
  717. if($soulx=='sou0' | $soulx=='sou1')$zwhere.= " and `fileid`>0 ";
  718. if($soukey)$zwhere.=" and `cont` like '%".$soukey."%'";
  719. if($minid==0){
  720. $zwhere .= ' order by `id` desc limit 5';
  721. }else{
  722. $zwhere .= ' and `id`<'.$minid.' order by `id` desc limit 10';
  723. }
  724. }
  725. $rows = $this->getall($zwhere, 'SQL_CALC_FOUND_ROWS optdt,zt,id,cont,sendid,fileid');
  726. $total = $this->db->found_rows();
  727. $ids = '0';
  728. $suids = '0';
  729. $len = 0;
  730. foreach($rows as $k=>$rs){
  731. $len++;
  732. $ids .= ','.$rs['id'].'';
  733. $suids.= ','.$rs['sendid'];
  734. $wdtotal--;
  735. }
  736. $rows = $this->ivaregarr($suids, $rows);
  737. if($ids!='0')$this->setyd($ids, $uid);
  738. if($wdtotal<0)$wdtotal=0;
  739. $total = $total-$len;
  740. if($total<=0)$total = 0;
  741. return array(
  742. 'rows' => $rows,
  743. 'wdtotal' => $wdtotal,
  744. 'systotal' => $total,
  745. );
  746. }
  747. public function ivaregarr($suids,$rows,$fid='')
  748. {
  749. if($suids=='' || $suids=='0')return $rows;
  750. if($fid=='')$fid='sendid';
  751. $farr = $this->db->getarr('[Q]admin', "`id` in($suids)",'`face`,`name`');
  752. foreach($rows as $k=>$rs){
  753. $face = $name = '';
  754. if(isset($farr[$rs[$fid]])){
  755. $face = $farr[$rs[$fid]]['face'];
  756. $name = $farr[$rs[$fid]]['name'];
  757. }
  758. $rows[$k]['face'] = $this->getface($face);
  759. $rows[$k]['sendname'] = $name;
  760. }
  761. return $rows;
  762. }
  763. private function ivarggarr($sgids,$rows, $fid='')
  764. {
  765. if($sgids=='' || $sgids=='0')return $rows;
  766. if($fid=='')$fid='receid';
  767. $farr = $this->db->getarr('[Q]im_group', "`id` in($suids)",'`face`,`name`');
  768. foreach($rows as $k=>$rs){
  769. $face = $name = '';
  770. if(isset($farr[$rs[$fid]])){
  771. $face = $farr[$rs[$fid]]['face'];
  772. $name = $farr[$rs[$fid]]['name'];
  773. }
  774. $rows[$k]['face'] = $this->getface($face);
  775. $rows[$k]['sendname'] = $name;
  776. }
  777. return $rows;
  778. }
  779. /**
  780. 发送单人信息
  781. $lx = 0 app发送 1web客户端
  782. */
  783. public function senduser($sendid,$receid, $cans=array(), $lx=0)
  784. {
  785. $cont = '';
  786. if(isset($cans['cont']))$cont=$cans['cont'];
  787. $optdt = $this->rock->now;
  788. $fileid = 0;
  789. $msgid = '';
  790. if(isset($cans['optdt']))$optdt=$cans['optdt'];
  791. if(isset($cans['sendid']))$sendid=$cans['sendid'];
  792. if(isset($cans['fileid']))$fileid=$cans['fileid'];
  793. if(isset($cans['msgid']))$msgid=$cans['msgid'];
  794. $pushcont = arrvalue($cans, 'pushcont');
  795. $arr = array(
  796. 'cont' => $cont,
  797. 'sendid' => $sendid,
  798. 'receid' => $receid,
  799. 'type' => 'user',
  800. 'optdt' => $optdt,
  801. 'zt' => '0',
  802. 'fileid' => $fileid,
  803. 'msgid' => $msgid
  804. );
  805. $arr['receuid'] = $arr['sendid'].','.$arr['receid'];
  806. $bo = $this->insert($arr);
  807. $arr['id'] = $this->db->insert_id();
  808. $arr['nuid'] = $this->rock->request('nuid');
  809. $farr = array();
  810. if($fileid>0){
  811. m('file')->addfile($fileid, 'im_mess', $arr['id']);
  812. $farr = m('file')->getone($fileid,'filesizecn,fileext,thumbpath,filename');
  813. if($farr)foreach($farr as $fk=>$fv)$arr[$fk] = $fv;
  814. }
  815. //给服务端发送0
  816. if($lx==0){
  817. $receids = m('admin')->getonline($arr['receid']);
  818. if($receids != ''){
  819. $pusharr = array(
  820. 'cont' => $cont,
  821. 'type' => 'user',
  822. 'optdt' => $optdt,
  823. 'messid' => $arr['id'],
  824. 'fileid' => $fileid
  825. );
  826. if($farr)foreach($farr as $fk=>$fv)$pusharr[$fk] = $fv;
  827. $this->sendpush($arr['sendid'], $receids , $pusharr);
  828. }
  829. }
  830. //告诉app端也有推送,因为app也用到websocket连接服务端
  831. $this->addhistory('user', $receid, $sendid, $optdt, $cont, $sendid,'','', $arr['id']);
  832. if($sendid!=$receid)$this->addhistory('user', $sendid, $receid, $optdt, $cont, $sendid,'','', $arr['id']);
  833. //推送的原生App上(使用异步推送哦)
  834. $tuicont['sendid'] = $arr['sendid'];
  835. $tuicont['sendname'] = $this->adminname;
  836. $tuicont['name'] = $this->adminname;
  837. $tuicont['cont'] = $cont;
  838. $tuicont['pushcont'] = $pushcont;
  839. $tuicont['pushtype'] = 'chat'; //推送消息类型
  840. $tuicont['receid'] = $receid;
  841. $tuicont['fileid'] = $fileid;
  842. $tuicont['type'] = 'user';
  843. $tuicont['id'] = $arr['id'];
  844. $tuicont['optdt'] = $optdt;
  845. $tuicont['optdts'] = substr($optdt,11,5);
  846. $this->pushapp($receid, '['.$this->adminname.']发来一条消息', $tuicont, $lx);
  847. /*
  848. $last = date('Y-m-d H:i:s', time()-15);
  849. $where = "`uid`='$receid' and `online`=1 and `cfrom` in('appandroid','appios') and `moddt`<'$last'";
  850. $tos = m('logintoken')->rows($where);
  851. if($tos>0){//没有打开应用
  852. $conts = substr($this->rock->jm->base64decode($cont),0,99);
  853. c('JPush')->send($receid,'['.$this->adminname.']发来一条消息', ''.$this->adminname.':'.$conts, 1);
  854. }*/
  855. return $arr;
  856. }
  857. /**
  858. 发送群讨论信息
  859. $lx = 0 app发送 1web客户端
  860. */
  861. public function sendgroup($sendid, $gid, $cans=array(), $lx=0)
  862. {
  863. $cont = '';
  864. if(isset($cans['cont']))$cont=$cans['cont'];
  865. $receid = $gid;
  866. $grs = $this->getgroupxinxi($gid);
  867. $gname = $grs['name'];
  868. $type = 'group';
  869. $fileid = 0;
  870. $msgid = '';
  871. $optdt = $this->rock->now;
  872. if(isset($cans['optdt']))$optdt=$cans['optdt'];
  873. if(isset($cans['type']))$type=$cans['type'];
  874. if(isset($cans['sendid']))$sendid=$cans['sendid'];
  875. if(isset($cans['fileid']))$fileid=$cans['fileid'];
  876. if(isset($cans['msgid']))$msgid=$cans['msgid'];
  877. $aors = m('im_groupuser')->getall("`gid`='$receid'",'uid');
  878. $asid = $asids = '';
  879. foreach($aors as $k=>$rs){
  880. $_uid = $rs['uid'];
  881. if($_uid != $sendid)$asid.=','.$_uid;
  882. $asids.=','.$_uid;
  883. }
  884. if($asids != '')$asids = substr($asids, 1);
  885. $arr = array(
  886. 'cont' => $cont,
  887. 'sendid' => $sendid,
  888. 'receid' => $receid,
  889. 'receuid' => $asids,
  890. 'type' => $type,
  891. 'optdt' => $optdt,
  892. 'zt' => '1',
  893. 'fileid' => $fileid,
  894. 'msgid' => $msgid
  895. );
  896. $bo = $this->insert($arr);
  897. $arr['id'] = $this->db->insert_id();
  898. $arr['nuid'] = $this->rock->request('nuid');
  899. $arr['gid'] = $receid;
  900. if($asid != ''){
  901. $asid = substr($asid, 1);
  902. $this->db->insert('[Q]im_messzt','`mid`,`uid`,`gid`','select '.$arr['id'].',`id`,'.$gid.' from `[Q]admin` where id in('.$asid.') and `status`=1', true);
  903. }
  904. $arr['receid'] = $asid;
  905. $farr = array();
  906. if($fileid>0){
  907. m('file')->addfile($fileid, 'im_mess', $arr['id']);
  908. $farr = m('file')->getone($fileid,'filesizecn,fileext,thumbpath,filename');
  909. if($farr)foreach($farr as $fk=>$fv)$arr[$fk] = $fv;
  910. }
  911. //推送到PC客户端上
  912. if($lx==0 && $asid != ''){
  913. $receids = m('admin')->getonline($asid);
  914. if($receids != ''){
  915. $pusharr = array(
  916. 'cont' => $cont,
  917. 'type' => 'group',
  918. 'gid' => $gid,
  919. 'gname' => $gname,
  920. 'optdt' => $optdt,
  921. 'gface' => arrvalue($grs,'face'),
  922. 'messid' => $arr['id'],
  923. 'fileid' => $fileid
  924. );
  925. if($farr)foreach($farr as $fk=>$fv)$pusharr[$fk] = $fv;
  926. $this->sendpush($arr['sendid'], $receids , $pusharr);
  927. }
  928. }
  929. $cont1 = $this->rock->jm->base64encode(''.$this->adminname.':'.$this->rock->jm->base64decode($cont).'');
  930. $this->addhistory('group', $gid, $arr['receuid'], $optdt, $cont1,$sendid,'','', $arr['id']);
  931. //推送的原生App上(使用异步推送哦)
  932. if($asid != ''){
  933. $tuicont['sendid'] = $arr['sendid'];
  934. $tuicont['sendname'] = $this->adminname;
  935. $tuicont['cont'] = $cont1;
  936. $tuicont['name'] = $gname;
  937. $tuicont['pushtype'] = 'chat'; //推送消息类型
  938. $tuicont['receid'] = $receid;
  939. $tuicont['fileid'] = $fileid;
  940. $tuicont['type'] = 'group';
  941. $tuicont['id'] = $arr['id'];
  942. $tuicont['optdt'] = $optdt;
  943. $tuicont['optdts'] = substr($optdt,11,5);
  944. $this->pushapp($asid, '['.$gname.']发来一条消息', $tuicont, $lx);
  945. }
  946. /*
  947. if($asid != ''){
  948. $last = date('Y-m-d H:i:s', time()-15);
  949. $where = "`uid` in($asid) and `online`=1 and `cfrom` in('appandroid','appios') and `moddt`<'$last'";
  950. $tos = m('logintoken')->rows($where);
  951. if($tos>0){//有打开应用
  952. $conts = substr($this->rock->jm->base64decode($cont),0,99);
  953. c('JPush')->send($asid,'['.$gname.']发来一条消息', ''.$this->adminname.':'.$conts, 1);
  954. }
  955. }*/
  956. $arr['gname'] = $gname;
  957. return $arr;
  958. }
  959. public function sendinfor($type, $sendid, $gid, $cans=array(), $lx=0)
  960. {
  961. $arr = array();
  962. if($type == 'user'){
  963. $arr = $this->senduser($sendid, $gid, $cans, $lx);
  964. }
  965. if($type == 'group'){
  966. $arr = $this->sendgroup($sendid, $gid, $cans, $lx);
  967. }
  968. return $arr;
  969. }
  970. /**
  971. * 获取用户的app上设置别名,也就是token拉
  972. */
  973. public function getalias($uid, $lx=0)
  974. {
  975. if($uid=='')return false;
  976. $where = "id in($uid) and ";
  977. if($uid=='all'){
  978. $where='';
  979. }else{
  980. if($this->contain($uid,'u') || $this->contain($uid,'d')){
  981. $uid = m('admin')->gjoin($uid);
  982. if($uid=='')return false;
  983. $where = "id in($uid) and ";
  984. }
  985. }
  986. $uwhere = "$where `status`=1";
  987. $rows = m('logintoken')->getrows("`uid` in(select id from `[Q]admin` where $uwhere) and `cfrom` in ('nppandroid','nppios') and `online`=1",'*','id desc');
  988. $uida = $pushuids = $alias2019 = $uid2019 = array();
  989. $uids = '0';
  990. $times = date('Y-m-d H:i:s', time()-5*60);//5分钟
  991. foreach($rows as $k=>$rs){
  992. $_uid = $rs['uid'];
  993. $_web = $rs['web'];
  994. $uida[] = $_uid;
  995. $uids .= ','.$_uid.'';
  996. $nestr = ''.$rs['token'].'|'.$_web.'|'.$_uid.'|';
  997. if(contain($_web,'getui')){
  998. $nestr.=''.$rs['pushtoken'].''; //个推
  999. }else if(contain($_web,'huawei') && !contain($rs['ip'],'.')){
  1000. $nestr.=''.$rs['ip'].'';
  1001. }else if(contain($_web,'xiaomi')){
  1002. $nestr.=''.$rs['pushtoken'].'';
  1003. }
  1004. $alias2019[] = $nestr;
  1005. if(!in_array($_uid, $uid2019))$uid2019[] = $_uid;
  1006. if($rs['ispush']=='1')$pushuids[] = $_uid;//可以手机推送的用户
  1007. }
  1008. return array('uids'=>$uids,'alias2019'=>$alias2019,'uid2019'=>$uid2019,'pushuids'=>$pushuids);
  1009. }
  1010. /**
  1011. * 推送到原生app上
  1012. */
  1013. public function pushapp($receid, $title, $conta, $lx)
  1014. {
  1015. $alias = $this->getalias($receid, $lx);
  1016. if(!$alias)return false;
  1017. //$alias = $garr['alias'];
  1018. //if(!$alias)return false;
  1019. $uids = $alias['uids'];
  1020. if($uids=='0')return;
  1021. $contjson = '';
  1022. foreach($conta as $k=>$v)$contjson.=',"'.$k.'":"'.$v.'"';
  1023. $contjson = '{'.substr($contjson,1).'}';
  1024. $pushcont = arrvalue($conta,'pushcont');
  1025. if(!$pushcont)$pushcont = arrvalue($conta,'cont'); //推送的内容已经是base64的
  1026. //最新webapp也用服务端推送
  1027. $uid2019 = $alias['uid2019'];
  1028. $alias2019 = $alias['alias2019'];
  1029. if($uid2019){
  1030. $reimtype = $this->option->getval('reimservertype');
  1031. $reimappwx= $this->option->getval('reimappwxsystem');
  1032. if($reimtype=='1' && $reimappwx=='1'){
  1033. $gbarr = $this->pushserver('sendapp', array(
  1034. 'receid' => join(',', $uid2019),
  1035. 'title' => $title,
  1036. 'content'=> $pushcont
  1037. ));
  1038. //服务端返回{"zshu":2,"yfuid":"1,8","wfuid":""}
  1039. if($gbarr && $gbarr['success'] && $bstr = arrvalue($gbarr, 'data')){
  1040. $data = json_decode($bstr, true);
  1041. $yfuid= explode(',', arrvalue($data, 'yfuid'));
  1042. if($yfuid){
  1043. $nealas = array();
  1044. foreach($alias2019 as $alis){
  1045. $bo = false;
  1046. foreach($yfuid as $yfid){if(contain($alis,'|'.$yfid.'|'))$bo=true;};
  1047. if(!$bo)$nealas[] = $alis;
  1048. }
  1049. $alias['alias2019'] = $nealas;
  1050. }
  1051. }
  1052. }
  1053. }
  1054. return c('JPush')->push($title, $pushcont, $contjson, $alias);
  1055. }
  1056. /**
  1057. * 推送到服务端运行
  1058. */
  1059. public function sendpush($sendid, $receid, $conarr=array())
  1060. {
  1061. $bsarr = array('msg'=>'notpushurl','code'=>2);
  1062. $bstt = json_encode($bsarr);
  1063. if($sendid==0)$sendid = 1;
  1064. $sers = $this->db->getone('[Q]admin',"`id`='$sendid'", "`name`,`face`");
  1065. if(!$sers)return $bstt;
  1066. $face = $sers['face'];
  1067. $carr['adminid'] = $sendid;
  1068. $carr['optdt'] = $this->rock->now;
  1069. $carr['sendname'] = $sers['name'];
  1070. $carr['face'] = $this->getface($face); //发送人头像
  1071. $carr['receid'] = $receid;
  1072. foreach($conarr as $k=>$v)$carr[$k]=$v;
  1073. return $this->pushserver('send', $carr);
  1074. }
  1075. /**
  1076. * 推送发送命令类型
  1077. */
  1078. public function sendcmd($receid, $conarr=array())
  1079. {
  1080. $conarr['type'] = 'cmd';
  1081. return $this->sendpush($this->adminid, $receid, $conarr);
  1082. }
  1083. /**
  1084. * 向服务端发送异步任务
  1085. * $runtime 运行的时间贞
  1086. */
  1087. public function asynurl($m, $a,$can=array(), $runtime=0)
  1088. {
  1089. $asyn = (int)getconfig('asynsend','0');
  1090. $runurl = m('base')->getasynurl($m, $a,$can);
  1091. $queuelogid= m('log')->addlogs('异步队列','', 3);
  1092. if($queuelogid)$runurl.= '&queuelogid='.$queuelogid.'';
  1093. //用官网VIP异步
  1094. if($asyn==2){
  1095. $barr = c('xinhuapi')->sendanay($m, $a,$can, $runtime);
  1096. if($barr['success'])return true;
  1097. }
  1098. $barr = $this->pushserver('runurl', array(
  1099. 'url' => $runurl,
  1100. 'runtime' => $runtime
  1101. ));
  1102. if($queuelogid){
  1103. m('log')->update(array(
  1104. 'url' => $runurl,
  1105. 'remark'=> '[asynurl]'.$runtime.'',
  1106. ),$queuelogid);
  1107. }
  1108. return $barr['success'];
  1109. }
  1110. /**
  1111. * 获取得到推送的端口号
  1112. */
  1113. public function getpushhostport($str)
  1114. {
  1115. $host = ''; $port = 0;
  1116. $stra = explode('//', $str);
  1117. if(isset($stra[1])){
  1118. $strb = explode(':', str_replace('/','', $stra[1]));
  1119. $host = $strb[0];
  1120. $port = (int)arrvalue($strb, 1, '0');
  1121. }
  1122. return array('host'=>$host,'port'=>$port);
  1123. }
  1124. /**
  1125. * 服务端推送,返回boolean看是否成功
  1126. */
  1127. public function pushserver($atype, $cans=array())
  1128. {
  1129. if(isempt($this->serverpushurl))return returnerror('没配置服务端');
  1130. $carr['from'] = $this->serverrecid;
  1131. $carr['adminid']= $this->adminid;
  1132. $carr['atype'] = $atype;
  1133. $carr['qtype'] = 'reim';
  1134. foreach($cans as $k=>$v)$carr[$k]=$v;
  1135. $reimtype = $this->option->getval('reimservertype');
  1136. if($reimtype=='1')return c('rockqueue')->pushdata($carr);
  1137. $str = json_encode($carr);
  1138. //echo 'abc ';return array('code'=>0);
  1139. $posts = $this->getpushhostport($this->serverpushurl);
  1140. $barr = c('socket')->udppush($str, $posts['host'], $posts['port']);
  1141. return $barr;
  1142. }
  1143. /**
  1144. * 判断异步地址是否可以使用
  1145. */
  1146. public function asynurlbo()
  1147. {
  1148. $url = $this->serverpushurl;
  1149. if(isempt($url))return false;
  1150. $ishttp = substr($url,0, 4)=='http';
  1151. if($ishttp){
  1152. $str = c('curl')->getcurl($url);
  1153. return contain($str, 'msg');
  1154. }else{
  1155. $spath = str_replace('\\','/', $url);
  1156. return is_writable($spath.'/Rock/push');
  1157. }
  1158. }
  1159. //创建群等
  1160. public function creategroup($name, $receid, $type=1, $explain='')
  1161. {
  1162. $arr['name'] = $name;
  1163. $arr['type'] = $type;
  1164. $arr['createid'] = $this->adminid;
  1165. $arr['createname'] = $this->adminname;
  1166. $arr['createdt'] = $this->rock->now;
  1167. $arr['explain'] = $explain;
  1168. $arr['valid'] = 1;
  1169. $gid = m('im_group')->insert($arr);
  1170. $this->db->insert('[Q]im_groupuser','gid,uid','select '.$gid.',id from [Q]admin where id in('.$receid.') and `status`=1', true);
  1171. $arr['id'] = $gid;
  1172. $arr['type'] = 'group';
  1173. return $arr;
  1174. }
  1175. /**
  1176. * 下载同步聊天记录到app本地
  1177. * $uid 对应用户,$maxid 从哪个最大的id,$minid从哪个最小Id
  1178. * 最多下载20天内的记录,每次下载30条
  1179. */
  1180. public function downrecord($uid, $maxid=0, $minid=999999999)
  1181. {
  1182. $whes = $this->rock->dbinstr('receuid', $uid);
  1183. $lastdt = date('Y-m-d 00:00:00', time()-20*24*3600);
  1184. $limit = 30;
  1185. $fields = 'optdt,zt,id,`type`,receid,cont,sendid,fileid';
  1186. $sql1 = "select $fields from `[Q]im_mess` where `id`> $maxid and $whes";
  1187. if($maxid==0){
  1188. $sql1.=' order by id desc';
  1189. }else{
  1190. $sql1.=' order by id asc';
  1191. }
  1192. $sql1.=' limit '.$limit.'';
  1193. $rows = $this->db->getall($sql1);
  1194. $nsaid = '0';
  1195. foreach($rows as $k=>$rs)$nsaid.=','.$rs['id'].'';
  1196. $olimie = $limit-$this->db->count;
  1197. if($olimie>0 && $minid>1){
  1198. $sql2 = "select $fields from `[Q]im_mess` where `id`< $minid and `optdt`>='$lastdt' and `id` not in($nsaid) and $whes order by id desc limit $olimie";
  1199. $rowss = $this->db->getall($sql2);
  1200. if($rowss)$rows = array_merge($rows, $rowss);
  1201. }
  1202. $suids = '0';
  1203. $dbs = m('im_messzt');
  1204. foreach($rows as $k=>$rs){
  1205. $suids.= ','.$rs['sendid'];
  1206. if($rs['type'] != 'user'){
  1207. $zt = 0;
  1208. if($dbs->rows("`mid`='".$rs['id']."' and `uid`='$uid'")==0)$zt=1;
  1209. $rows[$k]['zt'] = $zt;
  1210. }
  1211. if($rs['sendid']==$uid)$rows[$k]['zt'] = 1;
  1212. $id = (int)$rs['id'];
  1213. if($id>$maxid)$maxid = $id;
  1214. if($id<$minid)$minid = $id;
  1215. }
  1216. $rows = $this->ivaregarr($suids, $rows);
  1217. $rows = $this->replacefileid($rows);
  1218. $isdown = '0';
  1219. if(count($rows)==$limit)$isdown = '1'; //需要继续下载
  1220. $arr['rows'] = $rows;
  1221. $arr['maxid'] = $maxid;
  1222. $arr['minid'] = $minid;
  1223. $arr['isdown'] = $isdown;
  1224. return $arr;
  1225. }
  1226. /**
  1227. * 删除服务器上记录
  1228. */
  1229. public function clearrecord($type,$gid, $uid, $ids='',$day=0)
  1230. {
  1231. $whes = $this->rock->dbinstr('receuid', $uid);
  1232. $this->setallyd($type,$uid, $gid);
  1233. if(!isempt($type)){
  1234. if($type=='user'){
  1235. $where1 = "`type`='$type' and ((`receid`='$uid' and `sendid`='$gid') or (`receid`='$gid' and `sendid`='$uid')) and $whes";
  1236. }else{
  1237. $where1 = "`type`='$type' and `receid`='$gid' and $whes";
  1238. }
  1239. }else{
  1240. $where1 = $whes;
  1241. }
  1242. if($ids!='')$where1.=" and `id` in($ids)";
  1243. if($day>0){
  1244. $dts = date('Y-m-d H:i:s',time()-$day*24*3600);
  1245. $where1.=" and `optdt`< '$dts'";
  1246. }
  1247. $rows = $this->getall($where1, '`receuid`,`id`');
  1248. $xids = '0';
  1249. foreach($rows as $k=>$rs){
  1250. $sid = $rs['id'];
  1251. if($this->isempt($rs['receuid'])){
  1252. $xids.=','.$sid.'';
  1253. }else{
  1254. $ssid = '';
  1255. $uidsa = explode(',', $rs['receuid']);
  1256. foreach($uidsa as $suid){
  1257. if($suid != $uid){
  1258. $ssid.=','.$suid.'';
  1259. }
  1260. }
  1261. if($ssid==''){
  1262. $xids.=','.$sid.'';
  1263. }else{
  1264. $ssid = substr($ssid,1);
  1265. $this->update("`receuid`='$ssid'", $sid);
  1266. }
  1267. }
  1268. $this->hisobj->update("`cont`=''", "`type`='$type' and `uid`='$uid' and `messid`='$sid'");
  1269. }
  1270. if($xids!='0')$this->delete("`id` in($xids)");
  1271. if($ids=='' && $day==0)$this->delhistory($type,$gid, $uid);
  1272. }
  1273. /**
  1274. * 转发
  1275. */
  1276. public function forward($tuid, $type, $cont, $fid=0)
  1277. {
  1278. $uid = $this->adminid;
  1279. if($fid>0){
  1280. $frs = m('file')->getone($fid, '`filepath`,`filename`,`filesizecn`,`fileext`');
  1281. $msg = '文件不存在了';
  1282. if(!$frs)return $msg;
  1283. if(!file_exists($frs['filepath']))return $msg;
  1284. $cont = '';$jpgallext = '|jpg|png|gif|bmp|jpeg|';
  1285. if(contain($jpgallext,'|'.$frs['fileext'].'|')){
  1286. $cont = '[图片 '.$frs['filesizecn'].']';
  1287. }else{
  1288. $cont = '['.$frs['filename'].' '.$frs['filesizecn'].']';
  1289. }
  1290. $cont = $this->rock->jm->base64encode($cont);
  1291. }
  1292. $tuids = explode(',', $tuid);
  1293. foreach($tuids as $gid)$this->sendinfor($type, $uid, $gid, array(
  1294. 'optdt' => $this->rock->now,
  1295. 'cont' => $cont,
  1296. 'fileid'=> $fid
  1297. ));
  1298. return 'ok';
  1299. }
  1300. //会话管理的
  1301. public function createchat($name, $aid, $uids='', $na='', $optdt='', $iscjwx=false)
  1302. {
  1303. if($optdt=='')$optdt=$this->rock->now;
  1304. if($na=='')$na = $this->adminname;
  1305. if($uids=='')$uids = $aid;
  1306. $this->db->record('[Q]im_group', array(
  1307. 'type' => 1,
  1308. 'name' => $name,
  1309. 'createid' => $aid,
  1310. 'createname' => $na,
  1311. 'createdt' => $optdt,
  1312. 'valid' => '1'
  1313. ));
  1314. $gid = $this->db->insert_id();
  1315. $this->adduserchat($gid, $uids, false);
  1316. return $gid;
  1317. }
  1318. //邀请
  1319. public function adduserchat($gid, $uids, $isadd=false)
  1320. {
  1321. if(isempt($uids))return '';
  1322. $ids = '';
  1323. $uidss = explode(',', $uids);
  1324. $db = m('im_groupuser');
  1325. foreach($uidss as $aid){
  1326. if($db->rows("gid='$gid' and `uid`='$aid'")==0){
  1327. $db->insert(array('gid' => $gid,'uid' => $aid));
  1328. $ids .= ','.$aid.'';
  1329. }
  1330. }
  1331. if($ids!=''){
  1332. $ids = substr($ids,1);
  1333. $unaem = '';
  1334. $urows = m('admin')->getall('`id` in('.$ids.')');
  1335. foreach($urows as $k=>$rs)$unaem.=','.$rs['name'].'';
  1336. if($unaem!=''){
  1337. $this->addxitong($gid, ''.$this->adminname.'邀请“'.substr($unaem,1).'”加入本会话');
  1338. }
  1339. }
  1340. return $ids;
  1341. }
  1342. public function deluserchat($gid, $uids)
  1343. {
  1344. if(isempt($uids))return;
  1345. m('im_groupuser')->delete("`gid`='$gid' and `uid` in($uids)");
  1346. }
  1347. public function deletechat($gid)
  1348. {
  1349. m('im_group')->delete($gid);
  1350. m('im_groupuser')->delete("`gid`='$gid'");
  1351. m('im_messzt')->delete("`gid`='$gid'");
  1352. $this->delhistory('group',$gid, 0);
  1353. }
  1354. public function exitchat($gid, $aid)
  1355. {
  1356. $names = m('admin')->getmou('name', $aid);
  1357. $this->addxitong($gid, ''.$names.'退出本会话');
  1358. $dbs = m('im_groupuser');
  1359. $dbs->delete("`gid`='$gid' and `uid`='$aid'");
  1360. m('im_messzt')->delete("`gid`='$gid' and `uid`='$aid'");
  1361. if($dbs->rows('gid='.$gid.'')==0)m('im_group')->delete($gid);
  1362. $this->delhistory('group',$gid, $aid);
  1363. }
  1364. public function addxitong($gid, $cont, $fid=0)
  1365. {
  1366. $this->sendinfor('group', $this->adminid, $gid, array(
  1367. 'optdt' => $this->rock->now,
  1368. 'cont' => $this->rock->jm->base64encode($cont),
  1369. 'fileid'=> $fid
  1370. ));
  1371. }
  1372. //修改会话名称
  1373. public function editname($gid, $name)
  1374. {
  1375. m('im_group')->update("`name`='$name'",$gid);
  1376. $this->addxitong($gid, ''.$this->adminname.'将会话名称修改为“'.$name.'”');
  1377. }
  1378. //修改头像
  1379. public function editface($gid, $fileid)
  1380. {
  1381. $face= '';
  1382. if($fileid>0){
  1383. $frs = m('file')->getone($fileid);
  1384. if($frs)$face= $frs['thumbpath'];
  1385. }
  1386. m('im_group')->update("`face`='$face'",$gid);
  1387. }
  1388. //微信消息回调(弃用了)
  1389. public function getwxchat($arr)
  1390. {
  1391. $this->rock->debugs(json_encode($arr),'cccc');if(!isset($arr['MsgType']))return;
  1392. $MsgType = $arr['MsgType'];
  1393. $FromUserName = $arr['FromUserName'];
  1394. $user = $FromUserName;
  1395. $urs = m('admin')->getone("`user`='$FromUserName'",'id,name');
  1396. if(!$urs)return;
  1397. $sendid = $urs['id'];
  1398. $sendname = $urs['name'];
  1399. $this->adminid = $sendid;
  1400. $this->adminname= $sendname;
  1401. if($MsgType == 'event'){
  1402. $event = $arr['Event'];
  1403. if($event=='create_chat')m('weixin:chat')->addchat($sendid, $sendname,$arr);
  1404. if($event=='update_chat')m('weixin:chat')->updatechat($arr);
  1405. if($event=='quit_chat')m('weixin:chat')->quitchat($arr);
  1406. if($event=='subscribe')m('weixin:user')->subscribe($user,1);
  1407. if($event=='unsubscribe')m('weixin:user')->subscribe($user,4);
  1408. return;
  1409. }
  1410. if(!isset($arr['Type']))return;
  1411. $Type = $arr['Type'];
  1412. $gid = 0;
  1413. $optdt = date('Y-m-d H:i:s', $arr['CreateTime']);
  1414. $cont = '';
  1415. if($Type=='single' || $Type=='userid'){
  1416. $gid = (int)m('admin')->getmou('id', "`user`='".$arr['Id']."'");
  1417. $type= 'user';
  1418. }
  1419. if($Type=='group'){
  1420. $gid = m('weixin:chat')->getchatid($arr['Id'], $sendid, $sendname);
  1421. $type= 'group';
  1422. }
  1423. if($gid==0)return;
  1424. @$msgid = $arr['MsgId'];if(isempt($msgid))return;
  1425. if($this->rows("`msgid`='$msgid'")>0)return;
  1426. if($MsgType=='text'){
  1427. $cont = $arr['Content'];
  1428. }
  1429. if($MsgType=='location'){
  1430. $cont = '位置:'.$arr['Label'];
  1431. }
  1432. if($MsgType=='voice'){
  1433. $cont = '语音,请用微信收听';
  1434. if(isset($arr['MediaId']))$this->asynurl('asynrun','downwxmedia', array(
  1435. 'mediaid' => $arr['MediaId'],
  1436. 'msgid' => $msgid,
  1437. 'fileext' => 'amr',
  1438. 'adminid' => $sendid
  1439. ));
  1440. }
  1441. if($MsgType=='image'){
  1442. $cont = '[图片]';
  1443. $PicUrl = $this->rock->jm->encrypt($arr['PicUrl']);
  1444. $this->asynurl('asynrun','downwxpic', array(
  1445. 'picurl' => $PicUrl,
  1446. 'msgid' => $msgid,
  1447. 'adminid' => $sendid
  1448. ));
  1449. }
  1450. if($MsgType=='link'){
  1451. if(isempt($arr['Title']))$arr['Title']='链接';
  1452. $cont = '[A]'.$arr['Title'].'|'.$arr['Url'].'[/A]';
  1453. }
  1454. if($cont!='')$this->sendinfor($type,$sendid, $gid, array(
  1455. 'cont' => $this->rock->jm->base64encode($cont),
  1456. 'optdt' => $optdt,
  1457. 'msgid' => $msgid
  1458. ));
  1459. }
  1460. //下载微信上图片
  1461. public function downwximg($url, $msgid)
  1462. {
  1463. if($url=='' || $msgid=='')return;
  1464. $cont = c('curl')->getcurl($url);
  1465. $barr = c('down')->createimage($cont,'jpg','微信图片');
  1466. if($barr){
  1467. $fileid = $barr['id'];
  1468. $filesize = $barr['filesizecn'];
  1469. $mors = $this->getone("`msgid`='$msgid'",'id');
  1470. if($mors){
  1471. $id = $mors['id'];
  1472. $this->update(array('fileid' => $fileid), $id);
  1473. m('file')->addfile($fileid, 'im_mess', $id);
  1474. }
  1475. }
  1476. }
  1477. /**
  1478. * 定时未读的会话消息提醒推送到微信上
  1479. */
  1480. public function chatpushtowx($dt='')
  1481. {
  1482. if(getconfig('platdwnum'))return false;
  1483. if($dt=='')$dt = date('Y-m-d H:i:s', time()-5*60);
  1484. //$bowx = $this->installwx(0);
  1485. $bowxqy = $this->installwx(1);
  1486. if(!$bowxqy)return;
  1487. $rows = $this->db->getall("select * from `[Q]im_history` where `optdt`>='$dt' and `stotal`>0 and `type` in('user','group') order by `uid`,`optdt` asc");
  1488. $uarrs = array();
  1489. $gusrra = array();
  1490. foreach($rows as $k=>$rs){
  1491. $rson = false;
  1492. $key = $rs['type'].$rs['receid'];
  1493. $face = 'images/noface.png';
  1494. if($rs['type']=='group')$face = 'images/group.png';
  1495. if(!isset($gusrra[$key])){
  1496. if($rs['type']=='user'){
  1497. $rson = $this->db->getone('[Q]admin', $rs['receid'], 'name,face');
  1498. }else{
  1499. $rson = $this->db->getone('[Q]im_group', $rs['receid'], 'name,face');
  1500. }
  1501. }else{
  1502. $rson = $gusrra[$key];
  1503. }
  1504. if(!$rson)continue;
  1505. $gusrra[$key] = $rson;
  1506. $rs['name'] = $rson['name'];
  1507. $rs['face'] = $this->getface($rson['face'], URL.$face);
  1508. $uarrs[$rs['uid']][] = $rs;
  1509. }
  1510. $sendarr = array();
  1511. if($uarrs)foreach($uarrs as $uid=>$usend){
  1512. $cont = $tites = '';
  1513. $zshu = 0;
  1514. if($usend)foreach($usend as $k=>$rs){
  1515. $zshu++;
  1516. if($k>0)$cont.="\n";
  1517. $cont.=''.$rs['name'].':'.$this->rock->jm->base64decode($rs['cont']).' ('.substr($rs['optdt'],11,5).')';
  1518. }
  1519. if($zshu==0)continue;
  1520. if($zshu==1){
  1521. $title = '你有['.$rs['name'].']未读会话消息';
  1522. $url = ''.URL.'?m=chat&d=we&type='.$rs['type'].'&uid='.$rs['receid'].'';
  1523. }else{
  1524. $title = '你有'.$zshu.'个未读会话消息';
  1525. $url = ''.URL.'?d=we#list';
  1526. }
  1527. $wxarr = array(
  1528. 'title' => $title,
  1529. 'description' => $cont,
  1530. 'url' => $url,
  1531. 'uid' => $uid
  1532. );
  1533. //根据内容分组发送
  1534. $contkey = md5($cont);
  1535. $sendarr[$contkey][] = $wxarr;
  1536. }
  1537. $devagent = $this->optiondb->getval('weixinqy_devagent');
  1538. if(isempt($devagent))$devagent = '办公助手';
  1539. foreach($sendarr as $key=>$rowss){
  1540. $uids = '';
  1541. $wxarr= $rowss[0];
  1542. foreach($rowss as $k=>$rs){
  1543. $uids.=','.$rs['uid'].'';
  1544. }
  1545. //发送
  1546. if($uids!=''){
  1547. $uids = substr($uids, 1);
  1548. if($bowxqy){
  1549. $barr = m('weixinqy:index')->sendxiao($uids, 'REIM,REIM助手,'.$devagent.'', $wxarr);
  1550. m('log')->todolog('企业微信提醒', $barr);
  1551. }
  1552. }
  1553. }
  1554. }
  1555. /**
  1556. * 撤回消息功能
  1557. */
  1558. public function chehuimess($type, $gid, $id)
  1559. {
  1560. $chehui = (int)$this->optiondb->getval('reimchehuisystem',0);
  1561. if($chehui<=0)return '没有开启此功能';
  1562. $createid = m('im_group')->getmou('createid', $gid);
  1563. $rs = $this->getone('`id`='.$id.'');
  1564. if(!$rs)return '不存在';
  1565. if($createid != $this->adminid){
  1566. if($rs['sendid'] != $this->adminid)return '不是你发的';
  1567. $t3 = time()-strtotime($rs['optdt']);
  1568. if($t3>$chehui*60)return '已经超过'.$chehui.'分钟无法撤回';
  1569. }
  1570. $msg1= '<del style="color:gray">已撤回</del>';
  1571. $msg = $this->rock->jm->base64encode($msg1);
  1572. $msg2 = $this->rock->jm->base64encode($this->adminname.':');
  1573. $this->update("`cont`='$msg',`fileid`=0", $id);
  1574. $this->hisobj->update("`cont`='".$msg2.$msg."',`optdt`='{$this->rock->now}'", "`messid`='$id'");
  1575. $pusharr = array(
  1576. 'cont' => $msg,
  1577. 'type' => 'chehui',
  1578. 'messid' => $id,
  1579. );
  1580. $this->sendpush($this->adminid, $rs['receuid'], $pusharr);
  1581. $pusharr['atype'] = 'sendapp';
  1582. $this->sendpush($this->adminid, $rs['receuid'], $pusharr);
  1583. return array(
  1584. 'receid' => $rs['receuid'],
  1585. 'id' => $id,
  1586. 'msg' => $msg,
  1587. 'msg1' => $msg1,
  1588. );
  1589. }
  1590. }