meetModel.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?php
  2. class flow_meetClassModel extends flowModel
  3. {
  4. public function initModel()
  5. {
  6. $this->hyarra = array('正常','会议中','结束','取消');
  7. $this->hyarrb = array('green','blue','#ff6600','#888888');
  8. $this->dbobj = c('date');
  9. $this->reatearr = array(
  10. 'd' => '每天',
  11. 'w1' => '每周一',
  12. 'w2' => '每周二',
  13. 'w3' => '每周三',
  14. 'w4' => '每周四',
  15. 'w5' => '每周五',
  16. 'w6' => '每周六',
  17. 'w7' => '每周日',
  18. 'm' => '每月',
  19. 'y' => '每年',
  20. );
  21. }
  22. public function getratestore()
  23. {
  24. $arr = array();
  25. foreach($this->reatearr as $k=>$v)$arr[] = array(
  26. 'value' => $k,
  27. 'name' => $v
  28. );
  29. return $arr;
  30. }
  31. public function flowrsreplace($rs, $lx=0)
  32. {
  33. if(arrvalue($rs, 'type')=='1'){
  34. $ztrs = '<font color=green>启用</font>';
  35. if($rs['status']=='0'){
  36. $ztrs = '<font color=#888888>停用</font>';
  37. $rs['ishui']=1;
  38. }
  39. if(!isempt($rs['rate']))$ztrs.=','.arrvalue($this->reatearr,$rs['rate']).''; //转未汉字
  40. $rs['state'] = $ztrs;
  41. return $rs;//说明是固定会议
  42. }
  43. $rs['week'] = $this->dbobj->cnweek($rs['startdt']);
  44. $zt = $rs['state'];
  45. $nzt = $zt;
  46. $time = time();
  47. $stime = strtotime($rs['startdt']);
  48. $etime = strtotime($rs['enddt']);
  49. if($zt < 2){
  50. if($etime<$time){
  51. $nzt = 2;
  52. }else if($stime>$time){
  53. $nzt = 0;
  54. }else{
  55. $nzt = 1;
  56. }
  57. }
  58. if($zt != $nzt){
  59. $this->update('state='.$nzt.'', $rs['id']);
  60. $zt = $nzt;
  61. }
  62. $rs['ishui'] = ($zt>=2) ? 1 : 0;
  63. if($lx==1){
  64. $content = '';
  65. $inpurl = $this->getinputurl('meetjy',0,'def_mid='.$this->id.'');
  66. $rows = $this->getrows('`mid`='.$this->id.' and `type`=2','id,content,optname,optdt,optid','id');
  67. //是否可以加会议纪要
  68. $dtss = c('date')->adddate($this->rock->date,'d',-10).' 00:00:00';
  69. $addbo = $rs['startdt']>$dtss && $zt>0;
  70. $fobj = m('file');
  71. foreach($rows as $k=>$rs1){
  72. $content.= '<div style="border-bottom:1px #cccccc solid;padding:5px">['.$rs1['optname'].']纪要';
  73. $inpurl1 = $this->getinputurl('meetjy',$rs1['id']);
  74. if($addbo && $rs1['optid']==$this->adminid)$content.= '&nbsp;<a href="'.$inpurl1.'" class="blue">[编辑]</a>';
  75. $content.= ':<br>'.$rs1['content'].'';
  76. $fstr = $fobj->getstr('meet', $rs1['id'], 2);
  77. if($fstr!='')$content.= '<br>'.$fstr.'';
  78. $content.= '</div>';
  79. }
  80. if($addbo){
  81. $content.='&nbsp;<a href="'.$inpurl.'" class="blue">+新增纪要</a>';
  82. }
  83. $rs['content']= $content;
  84. $rs['content_style'] = 'padding:0px';
  85. }
  86. $rs['state'] = $this->getstatezt($zt);
  87. $rs['nzt'] = $zt;
  88. if(isset($rs['issms'])){
  89. $issms = '否';
  90. if($rs['issms']==1)$issms = '是';
  91. $rs['issms'] = $issms;
  92. }
  93. //打印时
  94. if($lx==3){
  95. if(substr($rs['startdt'],0,10)==$this->rock->date)$rs['startdt'] = substr($rs['startdt'],11);
  96. if(substr($rs['enddt'],0,10)==$this->rock->date)$rs['enddt'] = substr($rs['enddt'],11);
  97. $rs['ermurl'] = $this->rock->jm->base64encode(getconfig('outurl',URL).'task.php?a=x&num=meet&mid='.$rs['id'].'&showtype=qd');
  98. }
  99. return $rs;
  100. }
  101. //签到菜单判断
  102. protected function flowgetoptmenu($num)
  103. {
  104. if($num=='qdnoup'){
  105. if($this->rock->get('showtype')!='qd')return false;
  106. }
  107. }
  108. public function getstatezt($zt)
  109. {
  110. return '<font color="'.$this->hyarrb[$zt].'">'.$this->hyarra[$zt].'</font>';
  111. }
  112. protected function flowsubmit($na, $sm)
  113. {
  114. if($this->rs['status']==1){
  115. $this->tisongtodo();
  116. }
  117. //固定会议
  118. if($this->rs['type']=='1'){
  119. $this->createmeet($this->id);
  120. }
  121. }
  122. //审核完成后发通知
  123. protected function flowcheckfinsh($zt)
  124. {
  125. if($zt==1)$this->tisongtodo();
  126. }
  127. private function tisongtodo()
  128. {
  129. if($this->rs['type']!='0')return;//这个是普通会议才需要通知。
  130. if($this->rs['startdt'] < $this->rock->now)return;//已过期了
  131. //发给参会人
  132. //$cont = '{optname}发起会议“{title}”在{hyname},时间{startdt}至{enddt}';
  133. //$this->push($this->rs['joinid'], '会议', $cont);
  134. $cont = "您好,您有一个新的会议计划。\n\n会议主题:{title}\n会议时间:{startdt}至{enddt}\n会议地点:{hyname}";
  135. $zcren= arrvalue($this->rs,'zcren');
  136. if(!isempt($zcren)){
  137. $cont.="\n会议主持人:{zcren}";
  138. }else{
  139. $cont.="\n发起人:{optname}";
  140. }
  141. $this->pushs($this->rs['joinid'], $cont, '会议通知');
  142. $tplnum = m('option')->getval('meetsmstpl', 'meetapply');
  143. $this->sendsms($this->rs, $tplnum, array(
  144. 'optname' => $this->adminname,
  145. 'title' => $this->rs['title'],
  146. 'hyname' => $this->rs['hyname'],
  147. 'startdt' => $this->rs['startdt'],
  148. 'enddt' => $this->rs['enddt'],
  149. ));
  150. }
  151. protected function flowaddlog($a)
  152. {
  153. $actname = $a['name'];
  154. if($actname == '取消会议'){
  155. $this->push($this->rs['joinid'], '会议', ''.$this->adminname.'取消会议“{title}”,时间{startdt}至{enddt},请悉知。');
  156. $this->update('`state`=3', $this->id);
  157. $tplnum = m('option')->getval('meetsmstplqx', 'meetcancel');
  158. $this->sendsms($this->rs, $tplnum, array(
  159. 'optname' => $this->adminname,
  160. 'title' => $this->rs['title'],
  161. 'hyname' => $this->rs['hyname'],
  162. 'startdt' => $this->rs['startdt'],
  163. 'enddt' => $this->rs['enddt'],
  164. ));
  165. }
  166. if($actname == '结束会议'){
  167. $this->update('`state`=2', $this->id);
  168. }
  169. }
  170. //发短信提醒
  171. public function sendsms($rs, $tplnum, $params)
  172. {
  173. $receid = $rs['joinid'];
  174. $issms = arrvalue($rs,'issms');
  175. if(isempt($receid) || $issms!='1')return;
  176. $jyid = $rs['jyid'];
  177. if(!isempt($jyid))$receid.=','.$jyid.''; //发个纪要人
  178. $zcrenid= arrvalue($rs, 'zcrenid');
  179. if(!isempt($zcrenid))$receid.=','.$zcrenid.''; //发个主持人
  180. $qiannum= ''; //签名编号,可以为空
  181. $barr = c('xinhuapi')->sendsms($receid, $qiannum, $tplnum, $params);
  182. return $barr;
  183. }
  184. protected function flowbillwhere($uid, $lx)
  185. {
  186. $dt = $this->rock->post('dt');
  187. $where = '';
  188. //固定会议
  189. if($lx=='allgd'){
  190. $where = 'and `type`=1';
  191. }else{
  192. $where = 'and `type`=0';
  193. }
  194. if($dt!='')$where.=" and startdt like '$dt%'";
  195. //$fields = 'id,startdt,enddt,optname,state,title,hyname,joinname,`explain`,jyname';
  196. return array(
  197. //'fields' => $fields,
  198. 'where' => $where,
  199. 'order' => 'startdt desc'
  200. );
  201. }
  202. //每天运行计划任务将固定会议生成普通会议通知对应人
  203. public function createmeet($id=0, $nowdt='', $gbrr=false)
  204. {
  205. $owhe = '';
  206. if($id>0)$owhe='`id`='.$id.' and ';
  207. $narr = $this->getall(''.$owhe.'`type`=1 and `status`=1');
  208. $dtobj = c('date');
  209. $jlarr = array();
  210. foreach($narr as $k=>$rs){
  211. $gdt = $dtobj->daterate($rs['rate'], $rs['startdt'], $nowdt);
  212. if(!$gdt)continue;
  213. $startdt = ''.$gdt.' '.substr($rs['startdt'],11).'';
  214. $enddt = ''.$gdt.' '.substr($rs['enddt'],11).'';
  215. $ars = $rs;
  216. $ars['mid'] = $rs['id'];
  217. $ars['type'] = '0';
  218. $ars['startdt'] = $startdt;
  219. $ars['enddt'] = $enddt;
  220. $ars['state'] = 0;
  221. $ars['rate'] = '';
  222. unset($ars['id']);
  223. $this->adminmodel->setcompanyid($rs['comid']);
  224. $GLOBALS['adminid'] = $ars['optid'];
  225. $where = "`mid`=".$rs['id']." and `startdt` like '".$gdt."%'";
  226. $ors = $this->getone($where);
  227. $uwerew = '';
  228. $iid = 0;
  229. if($ors){
  230. $iid = $ors['id'];
  231. $uwerew = "`id`='$iid'";
  232. }
  233. $jlarr[] = $ars;
  234. if($gbrr)continue; //不写入数据库里
  235. $this->record($ars, $uwerew);
  236. if($iid==0){
  237. $iid = $this->db->insert_id();
  238. $this->loaddata($iid, false);
  239. $this->tisongtodo();//通知
  240. }
  241. }
  242. return $jlarr;
  243. }
  244. public function meettodo()
  245. {
  246. $rows = $this->getall("`state` in(0,1) and `type`=0 and `startdt` like '".$this->rock->date."%' and `status`=1");
  247. $time = time();
  248. foreach($rows as $k=>$rs){
  249. $this->adminmodel->setcompanyid($rs['comid']); //设置对应单位id
  250. $zt = $rs['state'];
  251. $dts = explode(' ', $rs['startdt']);
  252. $sttime = strtotime($rs['startdt']);
  253. $ettime = strtotime($rs['enddt']);
  254. $GLOBALS['adminid'] = $rs['optid'];
  255. $nzt = -1;
  256. if($ettime <= $time){
  257. $nzt = 2;
  258. }else{
  259. if($time >= $sttime && $time< $ettime){
  260. if($zt==0)$nzt = 1;
  261. }else{
  262. $jg = $sttime - $time;
  263. if($jg <= 600 && $zt==0){ //提前10分钟就提醒
  264. $ssj = floor($jg/60);
  265. $tzuid = $this->adminmodel->gjoin($rs['joinid']);
  266. //$cont = '会议“'.$rs['title'].'”将在'.$ssj.'分钟后的'.$dts[1].'开始请做好准备,在会议室“'.$rs['hyname'].'”';
  267. $this->loaddata($rs['id'], false);
  268. $this->meettodos($rs, '您好,会议即将在'.$ssj.'分钟后的'.$dts[1].'开始,请准时参加。');//快到时间通知
  269. //短信通知
  270. if($ssj<6)$this->sendsms($rs, 'meettodo', array(
  271. 'fenz' => ''.$ssj.'',
  272. 'title' => $rs['title'],
  273. 'time' => $dts[1],
  274. 'hyname' => $rs['hyname']
  275. ));
  276. }
  277. }
  278. }
  279. if($nzt != -1)$this->update("`state`='$nzt'", $rs['id']);
  280. }
  281. }
  282. private function meettodos($rs, $kss)
  283. {
  284. $receid = $rs['joinid'];
  285. if(isempt($receid))return;
  286. $cont = "".$kss."\n\n会议主题:{title}\n会议时间:{startdt}至{enddt}\n会议地点:{hyname}";
  287. $zcren= arrvalue($rs,'zcren');
  288. if(!isempt($zcren)){
  289. $cont.="\n会议主持人:{zcren}";
  290. }else{
  291. $cont.="\n发起人:{optname}";
  292. }
  293. $jyid = $rs['jyid'];
  294. if(!isempt($jyid))$receid.=','.$jyid.''; //发个纪要人
  295. $zcrenid= arrvalue($rs, 'zcrenid');
  296. if(!isempt($zcrenid))$receid.=','.$zcrenid.''; //发个主持人
  297. $this->pushs($receid, $cont, '会议提醒');
  298. }
  299. }
粤ICP备19079148号