1
0

reimModel.php 51 KB

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