reimModel.php 51 KB

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