1
0

remindModel.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <?php
  2. //单据提醒设置
  3. class flow_remindClassModel extends flowModel
  4. {
  5. public function flowrsreplace($rs, $lx=0)
  6. {
  7. if($rs['status']==0)$rs['ishui']=1;
  8. if($lx==1){
  9. $barrs = $this->getstatusarr();
  10. $zts = $barrs[$rs['status']];
  11. $rs['status'] = '<font color="'.$zts[1].'">'.$zts[0].'</font>';
  12. }
  13. return $rs;
  14. }
  15. public function getstatusarr()
  16. {
  17. $barr[1] = array('启用','green');
  18. $barr[0] = array('停用','#888888');
  19. return $barr;
  20. }
  21. //多个连表查询
  22. public function flowbillwhere($uid, $lx)
  23. {
  24. return array(
  25. 'table' => '`[Q]'.$this->mtable.'` a left join `[Q]flow_set` b on a.modenum=b.`num`',
  26. 'fields' => 'a.id,a.ratecont,a.startdt,a.enddt,a.status,a.explain,a.recename,a.optname,a.optdt,b.name as modename',
  27. 'orlikefields' => 'b.name,a.ratecont',
  28. 'asqom' => 'a.'
  29. );
  30. }
  31. //获取进入需要提醒内容
  32. public function getreminddt($dt='',$modenum='')
  33. {
  34. if($dt=='')$dt = $this->rock->date;
  35. $dt = substr($dt, 0, 10);
  36. $now = $this->rock->now;
  37. $rows = $this->getall("`status`=1 and `startdt`<='$now' and (`enddt` is null or `enddt`>='$now')");
  38. $dtobj = c('date');
  39. $w = date('w', strtotime($dt));
  40. if($w==0)$w = 7;
  41. $nw = 'w'.$w.'';
  42. $nrows = array();
  43. $timestr= '';
  44. foreach($rows as $k=>$rs){
  45. $ratea = explode(',', $rs['rate']);
  46. $rateb = explode(',', $rs['rateval']);
  47. $len = count($ratea);
  48. for($i=0; $i<$len; $i++){
  49. $timea = $this->getssdt($dt, $nw, $ratea[$i], arrvalue($rateb, $i), $rs['uid'], $rs['startdt']);
  50. if($timea)foreach($timea as $time){
  51. if(!contain($timestr, '['.$time.']')){
  52. $rs['runtime'] = $time;
  53. $rs['runtimes'] = date('Y-m-d H:i:s',$time);
  54. $rs['rates'] = $ratea[$i]; //频率类型
  55. $nrows[] = $rs;
  56. $timestr.='['.$time.']';
  57. }
  58. }
  59. }
  60. }
  61. return $nrows;
  62. }
  63. //判断时间是否可使用
  64. private function getssdt($dt, $nw, $rate, $valstr, $uid, $startdts)
  65. {
  66. $timea = array();
  67. $vala = explode('|', $valstr);
  68. $val = $vala[0];
  69. $val2 = arrvalue($vala, 1);
  70. //仅一次
  71. if($rate=='o' && contain($val, $dt)){
  72. $timea[] = strtotime($val);
  73. }
  74. //星期和天
  75. if($nw==$rate || $rate=='d'){
  76. $time = ''.$dt.' '.$val.'';
  77. $timea[] = strtotime($time);
  78. }
  79. //每小时
  80. if($rate=='h'){
  81. $ksis = substr($startdts, 11);
  82. if(isempt($val2))$val2 = '23:59:59';
  83. $stime = strtotime(''.$dt.' '.$ksis.'');
  84. $etime = strtotime(''.$dt.' '.$val2.'');
  85. for($i=0;$i<=23;$i++){
  86. $time = strtotime(''.$dt.' '.$i.':'.$val.'');
  87. if($stime<=$time && $etime>=$time)$timea[] = $time;
  88. }
  89. }
  90. //每月
  91. if($rate=='m'){
  92. $time = ''.substr($dt,0, 8).''.$val.'';
  93. if(contain($time, $dt))$timea[] = strtotime($time);
  94. }
  95. //每年
  96. if($rate=='y'){
  97. $time = ''.substr($dt,0, 5).''.$val.'';
  98. if(contain($time, $dt))$timea[] = strtotime($time);
  99. }
  100. //工作日,休息日
  101. if($rate=='g' || $rate=='x'){
  102. $time = ''.$dt.' '.$val.'';
  103. $timea[] = strtotime($time);
  104. }
  105. return $timea;
  106. }
  107. //时间段读取
  108. public function getremindtodo($startdt='', $enddt='')
  109. {
  110. if($startdt=='')$startdt = $this->rock->now;
  111. $stime= strtotime($startdt)-10;
  112. if($enddt=='')$enddt = date('Y-m-d H:i:s', $stime + 310); //默认是5分钟内提醒
  113. $dt = substr($startdt, 0, 10);
  114. $rows = $this->getreminddt($startdt);
  115. $etime= strtotime($enddt);
  116. $sarr = $modearr = array();
  117. $modenums = '';
  118. $kqd = m('kaoqin');
  119. foreach($rows as $k=>$rs){
  120. $rate = $rs['rates']; //频率类型
  121. $bo = true;
  122. if($rs['runtime']>=$stime && $rs['runtime']<=$etime){
  123. //工作日休息日判断
  124. if($rate=='g' || $rate=='x'){
  125. $isw = $kqd->isworkdt($rs['uid'], $dt);
  126. if($isw==1 && $rate=='x')$bo = false;
  127. if($isw==0 && $rate=='g')$bo = false;
  128. }
  129. if($bo){
  130. $modenums.=",'".$rs['modenum']."'";
  131. $sarr[] = $rs;
  132. }
  133. }
  134. }
  135. //$this->flowtodosettx(8);
  136. if($modenums=='')return false;
  137. $modenums = substr($modenums, 1);
  138. $modrs = m('flow_set')->getall("`num` in ($modenums) and `status`=1");
  139. foreach($modrs as $k=>$rs)$modearr[$rs['num']] = $rs;
  140. $flowtodoid = ''; //单据通知设置ID
  141. $subscribid = array(); //订阅的
  142. foreach($sarr as $k=>$rs){
  143. $mid = $rs['mid'];
  144. if($rs['modenum']=='flowtodo'){
  145. $flowtodoid.=','.$mid.'';
  146. continue;
  147. }
  148. $mrs = arrvalue($modearr, $rs['modenum']);
  149. if(!$mrs)continue;
  150. $cont = $rs['explain'];
  151. $GLOBALS['adminid'] = $rs['uid'];
  152. $receid = $rs['uid'];
  153. $recename = $rs['optname'];
  154. if(!isempt($rs['receid'])){
  155. $receid = 'u'.$receid.','.$rs['receid'].'';
  156. $recename .= ','.$rs['recename'].'';
  157. }
  158. //订阅的
  159. if($rs['modenum']=='subscribe'){
  160. $subscribid[] = array(
  161. 'id' => $mid,
  162. 'uid' => $rs['uid'],
  163. 'receid'=> $receid,
  164. 'recename'=> $recename,
  165. );
  166. continue;
  167. }
  168. $this->pushs($receid, $cont, $mrs['name'], array(
  169. 'id' => $mid,
  170. 'modenum' => $rs['modenum'],
  171. 'modename' => $mrs['name'],
  172. 'moders' => $mrs
  173. ));
  174. }
  175. //单据通知提醒需要另外提醒
  176. if($flowtodoid !='')$this->flowtodosettx(substr($flowtodoid, 1));
  177. //订阅的处理(建议用异步的)
  178. if($subscribid){
  179. if(getconfig('asynsend')){
  180. $reim = m('reim');
  181. foreach($subscribid as $subo){
  182. $GLOBALS['adminid'] = $subo['uid'];
  183. $reim->asynurl('asynrun','subscribe', array(
  184. 'recename' => $this->rock->jm->base64encode($subo['recename']),
  185. 'receid' => $subo['receid'],
  186. 'id' => $subo['id'],
  187. 'uid' => $subo['uid']
  188. ));
  189. }
  190. }else{
  191. //没有异步直接调用
  192. $subflow = m('flow')->initflow('subscribeinfo');
  193. foreach($subscribid as $subo){
  194. $GLOBALS['adminid'] = $subo['uid'];
  195. $subflow->subscribe($subo['id'],$subo['uid'],$subo['receid'],$subo['recename']);
  196. }
  197. }
  198. }
  199. return $sarr;
  200. }
  201. //单据通知设置的,必须有触发条件和选择计划任务
  202. private function flowtodosettx($tids)
  203. {
  204. $rows = $this->db->getall('select a.*,b.num as modenum from `[Q]flow_todo` a left join `[Q]flow_set` b on a.`setid`=b.`id` where a.`id` in('.$tids.') and b.`status`=1 and a.`status`=1 and a.`botask`=1 and a.whereid>0');
  205. //print_r($rows);
  206. //有设置了提醒
  207. foreach($rows as $rk=>$rs){
  208. $modenum = $rs['modenum'];
  209. $flow = m('flow')->initflow($modenum);
  210. $flowrows = $flow->gettodorows($rs['whereid']);
  211. $zongcount = count($flowrows);
  212. $tostr = '';//提醒的内容
  213. $todofields = array();
  214. if(!isempt($rs['todofields']))$todofields = explode(',', $rs['todofields']);
  215. $title = $rs['name'];
  216. $sanda = array();
  217. foreach($flowrows as $k1=>$rs1){
  218. if($k1>0)$tostr .= "\n";
  219. $tostrs = $this->rock->reparr($rs['summary'], $rs1);
  220. $tostr .= $tostrs;
  221. $receid = $rs['receid']; //接收人
  222. //提交人
  223. if($rs['toturn']=='1' && isset($rs1['optid']))$receid = $this->strappend($receid,$rs1['optid']);
  224. //参与人
  225. if($rs['tocourse']=='1'){
  226. $cyrenId = $this->billmodel->getmou('allcheckid', "`table`='".$flow->mtable."' and `mid`='".$rs1['id']."'");
  227. $receid = $this->strappend($receid, $cyrenId);
  228. }
  229. foreach($todofields as $tfid){
  230. $tfss = arrvalue($rs1, $tfid);
  231. if(!isempt($tfss))$receid = $this->strappend($receid, $tfss);
  232. }
  233. if(!isempt($receid)){
  234. $receid = $this->adminmodel->gjoins($receid);
  235. if($zongcount<20){
  236. $flow->id = $rs1['id'];
  237. $flow->push($receid, '', $tostrs, $title);
  238. }else{
  239. $receida= explode(',', $receid);
  240. foreach($receida as $ruid){
  241. if(!isset($sanda[$ruid]))$sanda[$ruid] = array();
  242. if(!in_array($tostrs,$sanda[$ruid]))$sanda[$ruid][] = $tostrs;
  243. }
  244. }
  245. }
  246. }
  247. //相同内容转化
  248. if($sanda){
  249. $sendarr = array();
  250. foreach($sanda as $uid=>$narr){
  251. $enstr = '';
  252. foreach($narr as $k=>$v){
  253. if($k>0)$enstr.='<br>';
  254. $enstr.=''.$v.'';
  255. }
  256. if($enstr!=''){
  257. $sendarr[md5($enstr)][] = array(
  258. 'uid' => $uid,
  259. 'cont'=> $enstr
  260. );
  261. }
  262. }
  263. //发送
  264. foreach($sendarr as $key=>$rowss){
  265. $uids = '';
  266. $cont = $rowss[0]['cont'];
  267. foreach($rowss as $k=>$rsc){
  268. $uids.=','.$rsc['uid'].'';
  269. }
  270. //发送
  271. if($uids!=''){
  272. $uids = substr($uids, 1);
  273. $flow->flowweixinarr = array(
  274. 'url' => $flow->getweurl()
  275. );
  276. $flow->push($uids, '', $cont, $title);
  277. }
  278. }
  279. }
  280. }
  281. }
  282. }
粤ICP备19079148号