meetModel.php 9.9 KB

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