meetModel.php 9.8 KB

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