dailyModel.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. class flow_dailyClassModel extends flowModel
  3. {
  4. public function initModel()
  5. {
  6. $this->typearr = explode(',','日报,周报,月报,年报');
  7. $this->logobj = m('log');
  8. }
  9. protected function flowchangedata()
  10. {
  11. $this->rs['typess'] = $this->typearr[$this->rs['type']];
  12. }
  13. public function flowrsreplace($rs, $lx=0)
  14. {
  15. if($rs['mark']=='0')$rs['mark'] = '';
  16. $cfrom = $this->rock->get('cfrom');
  17. if($lx==2){
  18. if($cfrom!='mweb'){
  19. if(isset($rs['optdt']))$rs['optdt'] = str_replace(' ','<br>', $rs['optdt']);
  20. if(isset($rs['adddt']))$rs['adddt'] = str_replace(' ','<br>', $rs['adddt']);
  21. }
  22. $zt = $this->logobj->isread('daily', $rs['id'], $this->adminid);
  23. if($zt>0)$rs['ishui'] = 1;
  24. $dt = $rs['dt'];
  25. if($rs['type']!=0 && !isempt($rs['enddt']) && $cfrom!='mweb'){
  26. $dt.='<br><font color="#aaaaaa">'.$rs['enddt'].'</font>';
  27. }
  28. $rs['dt'] = $dt;
  29. }
  30. $this->replacepbr($rs, 'content');
  31. $rs['type'] = $this->typearr[$rs['type']];
  32. return $rs;
  33. }
  34. //提交保存完日报通知上级
  35. protected function flowsubmit($na, $sm)
  36. {
  37. $uparr = m('admin')->getsuperman($this->uid);
  38. $recid = arrvalue($uparr, 0);
  39. if(!$recid || $recid==0)return;
  40. $typea = $this->typearr[$this->rs['type']];
  41. $title = ''.$this->rs['optname'].'的'.$typea.'';
  42. $cont = c('html')->substrstr($this->rs['content'],0, 100);
  43. $this->push($recid, '', "".$typea."日期:{dt}\n".$cont, $title);
  44. }
  45. protected function flowaddlog($a)
  46. {
  47. if($a['name'] == '日报评分'){
  48. $fenshu = (int)$this->rock->post('fenshu','0');
  49. $this->push($this->rs['uid'], '', ''.$this->adminname.'评分你[{dt}]的{typess},分数('.$fenshu.')',''.$this->modename.'评分');
  50. $this->update(array(
  51. 'mark' => $fenshu
  52. ), $this->id);
  53. }
  54. if($a['name'] == '点评'){
  55. $this->nexttodo($this->uid, 'pinglun', $a['explain'], '点评');
  56. }
  57. }
  58. protected function flowdatalog($arr)
  59. {
  60. $ispingfen = 0;
  61. $barr = m('admin')->getsuperman($this->uid); //获取我的上级主管
  62. if($barr){
  63. $hes = $barr[0];
  64. if(contain(','.$hes.',',','.$this->adminid.','))$ispingfen = 1; //是否可以评分
  65. }
  66. $arr['ispingfen'] = $ispingfen;
  67. $arr['mark'] = $this->rs['mark'];
  68. return $arr;
  69. }
  70. protected function flowgetoptmenu($opt)
  71. {
  72. //if($this->uid==$this->adminid)return false;
  73. $to = m('log')->isread($this->mtable, $this->id);
  74. return $to<=0;
  75. }
  76. protected function flowoptmenu($ors, $crs)
  77. {
  78. $table = $this->mtable;
  79. $mid = $this->id;
  80. $uid = $this->adminid;
  81. $lx = $ors['num'];
  82. $log = m('log');
  83. if($lx=='yd'){
  84. $log->addread($table, $mid, $uid);
  85. }
  86. if($lx=='allyd'){
  87. $ydid = $log->getread($table, $uid);
  88. $where = m('view')->viewwhere($this->modeid, $uid);
  89. $where = "((1=1 $where) or (`uid`='$uid') )";
  90. $where = "`id` not in($ydid) and $where";
  91. $rows = m($table)->getrows($where,'id');
  92. foreach($rows as $k=>$rs)$log->addread($table, $rs['id'], $uid);
  93. }
  94. }
  95. protected function flowprintrows($rows)
  96. {
  97. foreach($rows as $k=>$rs){
  98. $rows[$k]['plan_style'] = 'text-align:left';
  99. $rows[$k]['content'] = str_replace("\n",'<br>', $rs['content']);
  100. $rows[$k]['plan'] = str_replace("\n",'<br>', $rs['plan']);
  101. $rows[$k]['type'] = $this->typearr[$rs['type']];
  102. }
  103. return $rows;
  104. }
  105. //条件过滤已从流程模块条件下设置
  106. protected function flowbillwhere($uid, $lx)
  107. {
  108. $type = $this->rock->post('type');
  109. $key = $this->rock->post('key');
  110. $dt = $this->rock->post('dt');
  111. $where = '';
  112. $keywhere = '';
  113. if(!isempt($type))$where.=" and a.`type`='$type'";
  114. if(!isempt($dt))$where.=" and a.`dt` like '$dt%'";
  115. if(!isempt($key))$keywhere=m('admin')->getkeywhere($key, 'b.', "or a.`content` like '%$key%'");
  116. return array(
  117. 'table' => '`[Q]daily` a left join `[Q]admin` b on a.`uid`=b.`id`',
  118. 'fields'=> 'a.*,b.`name`,b.`deptname`',
  119. 'where' => $where,
  120. 'keywhere' => $keywhere,
  121. 'asqom' => 'a.', //主表别名
  122. 'order' => 'a.`optdt` desc'
  123. );
  124. }
  125. /**
  126. * 日报分析
  127. */
  128. public function dailyanay($uid=0, $month='')
  129. {
  130. $dto = c('date');
  131. if($month=='')$month = $this->rock->date;
  132. $mon = substr($month,0, 7);
  133. $start = $mon.'-01';
  134. $enddt = $dto->getenddt($mon);
  135. $jg = $dto->getmaxdt($start);
  136. $dtarr = $dailydt = $leavedt = $zhoubdt = array();
  137. for($i=1; $i<=$jg; $i++){
  138. $oi = ''.$i.'';
  139. if($i<10)$oi= '0'.$i.'';
  140. $dt = $mon.'-'.$oi.'';
  141. if($dt>=$this->rock->date)break;
  142. $dtarr[] = array($dt, strtotime($dt));
  143. }
  144. $kql = m('kaoqin');
  145. $dbfx = m('dailyfx');
  146. $where = m('admin')->monthuwheres($start, $enddt);
  147. if($uid!=0)$where="and `id`='$uid'";
  148. $urows = m('userinfo')->getall("1=1 $where", 'id,name,workdate,quitdt,isdaily');
  149. //日报
  150. $dailya = $this->getall("`type`=0 and `dt` like '$mon%' group by `uid`,`dt`",'`uid`,`dt`');
  151. foreach($dailya as $k=>$rs){
  152. $dailydt['a'.$rs['uid'].'_'.$rs['dt'].''] = 1;
  153. }
  154. //周报
  155. $dailya = $this->getall("`type`=1 and `adddt` like '$mon%'",'`uid`,`adddt`');
  156. foreach($dailya as $k=>$rs){
  157. $zhoubdt['a'.$rs['uid'].'_'.substr($rs['adddt'],0,10).''] = 1;
  158. }
  159. //读取是不是全天请假(这种情况无法统计,全天请假写了2个上午和下午的请假条,下次改进)
  160. $qjarr = $this->db->getall("select `stime`,`etime`,`uid` from `[Q]kqinfo` where `status`=1 and `kind`='请假' and `etime`>='$start' and `stime`<='$enddt' ");
  161. if($qjarr){
  162. foreach($qjarr as $k=>$rs){
  163. $qjarr[$k]['stimes'] = strtotime($rs['stime']);
  164. $qjarr[$k]['etimes'] = strtotime($rs['etime']);
  165. }
  166. foreach($dtarr as $d1=>$dtss){
  167. $dt = $dtss[0];
  168. foreach($qjarr as $k=>$rs){
  169. $uid = $rs['uid'];
  170. $sbdt = $kql->getsbstr($uid, $dt);
  171. if($rs['stimes']<=$sbdt['stimes'] && $rs['etimes']>=$sbdt['etimes']){
  172. $leavedt['a'.$uid.'_'.$dt.''] = 1; //全天请假
  173. }
  174. }
  175. }
  176. }
  177. foreach($urows as $k=>$urs){
  178. $totaly = 0;//应写
  179. $totalx = 0;//已写次数
  180. $totalw = 0;//未写次数
  181. $dtjoin = '';
  182. $uid = $urs['id'];
  183. $dtarra = array();
  184. $ruzd = 0;$lzzt = 9999999999999;
  185. if(!isempt($urs['workdate']))$ruzd = strtotime($urs['workdate']);
  186. if(!isempt($urs['quitdt']))$lzzt = strtotime($urs['quitdt']);
  187. $uarr = array(
  188. 'uid' => $uid,
  189. 'month' => $mon,
  190. 'optdt' => $this->rock->now
  191. );
  192. foreach($dtarr as $d1=>$dtss){
  193. $dt = $dtss[0];
  194. $d = $d1+1;
  195. $zt = 0; //0未写,1已写,2请假,3休息日,4没入职或已离职,5不需要写日报,时间还没到,6写周报了
  196. //入职离职判断
  197. if($dtss[1]<$ruzd || $dtss[1]>$lzzt){
  198. $uarr['day'.$d.''] = 4;
  199. continue;
  200. }
  201. $keys = 'a'.$uid.'_'.$dt.'';
  202. $xbo = true;
  203. $iswork = $kql->isworkdt($uid, $dt);
  204. if($iswork==0){
  205. $zt = 3;
  206. if(isset($dailydt[$keys])){
  207. $zt = 1;
  208. }
  209. }else{
  210. if(isset($leavedt[$keys])){
  211. $zt = 2;
  212. }else{
  213. $totaly++;
  214. }
  215. if(isset($dailydt[$keys])){
  216. $zt = 1;
  217. }
  218. if($zt==0 && isset($zhoubdt[$keys])){
  219. $zt = 6;//写周报了
  220. }
  221. if($zt==0){
  222. if($urs['isdaily']==0){
  223. $zt = 5;
  224. }else{
  225. $totalw++;//没写没请假
  226. }
  227. }
  228. }
  229. $uarr['day'.$d.''] = $zt;
  230. }
  231. $totalx = $totaly - $totalw;
  232. $uarr['totaly'] = $totaly;
  233. $uarr['totalx'] = $totalx;
  234. $uarr['totalw'] = $totalw;
  235. $where = "`uid`='$uid' and `month`='$mon'";
  236. if($dbfx->rows($where)==0)$where = '';
  237. $dbfx->record($uarr, $where);
  238. }
  239. }
  240. /**
  241. * 未写日报通知
  242. * return 未写人员如:貂蝉(人事部),大乔(开发部)
  243. */
  244. public function dailytodo($dt='')
  245. {
  246. if($dt=='')$dt = $this->rock->date;
  247. $dta = explode('-', $dt);
  248. $month = substr($dt, 0,7);
  249. $d = (int)$dta[2];
  250. $rows= $this->db->getall("select a.`id`,a.`name`,a.`deptname`,b.`day".$d."` from `[Q]admin` a left join `[Q]dailyfx` b on a.`id`=b.`uid` and b.`month`='$month' where a.`status`=1 and b.`day".$d."`=0");
  251. $w = c('date')->cnweek($dt);
  252. $cont= '你昨天['.$dt.',周'.$w.']的'.$this->modename.'未写,请及时补充填写。';
  253. $receid = '';
  254. foreach($rows as $k=>$rs){
  255. $receid.=','.$rs['id'].'';
  256. }
  257. $this->flowweixinarr = array(
  258. 'url' => $this->getwxurl()
  259. );
  260. if($receid!='')$this->push(substr($receid, 1),'', $cont, ''.$this->modename.'未写提醒');
  261. }
  262. }
粤ICP备19079148号