dailyModel.php 8.4 KB

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