hrcheckModel.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <?php
  2. //模块 hrcheck.考核评分
  3. class flow_hrcheckClassModel extends flowModel
  4. {
  5. //审核完成处理
  6. protected function flowcheckfinsh($zt){
  7. //最后得分计算,
  8. if($zt==1){
  9. $fenzp = floatval($this->rs['fenzp']);
  10. $fensj = floatval($this->rs['fensj']);
  11. $fenrs = floatval($this->rs['fenrs']);
  12. //默认分数=自己评分*50% + 上级评分*25% + 人事评分*25%
  13. $fen = $fenzp*0.5 + $fensj*0.25 + $fenrs*0.25;
  14. //3个平均分
  15. //$fen = ($fenzp+$fensj+$fenrs)/3;
  16. $this->update(array('fen' => $fen), $this->id);
  17. }
  18. }
  19. //需要评分就可以查看
  20. protected function flowisreadqx()
  21. {
  22. $boss = $this->getpfrows();
  23. if($boss)return true;
  24. return false;
  25. }
  26. private function getpfrows()
  27. {
  28. return m('hrcheckn')->getall('mid='.$this->id.' and `optid`='.$this->adminid.' and `optdt` is null','*', '`sort`');
  29. }
  30. public function flowrsreplace($rs, $lx=0)
  31. {
  32. if(isset($rs['abclex']))return $rs;
  33. $ztstr = '';
  34. if(isempt($rs['pfrens'])){
  35. $ztstr = '<font color=green>评分已完成</font>';
  36. }else{
  37. if($rs['uid']==$this->adminid){
  38. $ztstr = '待<font color=blue>'.$rs['pfrens'].'</font>评分';
  39. }else{
  40. $ztstr = '<font color=blue>待评分</font>';
  41. }
  42. }
  43. $rs['pfrenids'] = $ztstr;
  44. if($lx==1){
  45. $ckbo = $this->isreadqxs();//是否设置查看权限
  46. $ispf = $this->getpfrows();
  47. if(!$ispf){
  48. if($ckbo){ //设置可查看
  49. $rs['subdatastr'] = $this->getsubdatastr($this->id);
  50. $this->moders['isgbcy'] = 0;
  51. $this->moders['isgbjl'] = 0;
  52. }else{
  53. if($rs['uid']!=$this->adminid)$rs['fen'] = '-';
  54. }
  55. }else{
  56. $rs['fen'] = '-';
  57. }
  58. }
  59. if($rs['uid']!=$this->adminid && !contain($this->atype, 'all'))$rs['fen']='-';//自己只能看自己分
  60. return $rs;
  61. }
  62. public function getsubdatastr($id, $glx=0)
  63. {
  64. $srows = m('hrchecks')->getrows('`mid`='.$id.'','*','`sort`');
  65. $nrows = m('hrcheckn')->getrows('`mid`='.$id.'','*','`sort`');
  66. $pars = array();
  67. $fsarr = array();
  68. foreach($nrows as $k2=>$rs2){
  69. $pars[$rs2['pfid']] = $rs2['pfname'].'<br>'.$rs2['optname'].'(权重'.$rs2['weight'].'%)';
  70. $fsarr['s'.$rs2['sid'].'_'.$rs2['pfid'].''] = $rs2['defen'];
  71. }
  72. $fenshu = 0;
  73. $toarr = array();
  74. foreach($srows as $k1=>&$rs1){
  75. $rs1['xuhaos'] = $k1+1;
  76. foreach($pars as $k3=>$v3){
  77. $val = arrvalue($fsarr, 's'.$rs1['id'].'_'.$k3.'');
  78. if(!isset($toarr[$k3]))$toarr[$k3] = 0;
  79. $toarr[$k3]+=floatval($val);
  80. if($val==0)$val= '';
  81. $rs1['pfzd'.$k3.''] = $val; //得分
  82. }
  83. $fenshu+=floatval($rs1['fenshu']);
  84. }
  85. //统计的
  86. $tjarr = array();
  87. foreach($toarr as $k3=>$v1){
  88. if($v1==0)$v1='';
  89. $tjarr['pfzd'.$k3.''] = $v1;
  90. }
  91. $tjarr['itemname'] = '小计';
  92. $tjarr['fenshu'] = $fenshu;
  93. $srows[]= $tjarr;
  94. if($glx==1){
  95. return array(
  96. 'data'=>$srows,
  97. 'colums'=> $pars
  98. );
  99. }
  100. $herstr = 'xuhaos,,center@itemname,考核内容,left@fenshu,分值';
  101. foreach($pars as $k1=>$v1)$herstr.='@pfzd'.$k1.','.$v1.'';
  102. $pfrowsstr = c('html')->createrows($srows, $herstr,'#dddddd');
  103. return $pfrowsstr;
  104. }
  105. protected function flowinit()
  106. {
  107. $this->dtobj = c('date');
  108. }
  109. protected function flowbillwhere($uid, $lx)
  110. {
  111. $month = $this->rock->post('month');
  112. $where = '';
  113. if(!isempt($month)){
  114. $where="and a.`startdt` like '".$month."%'";
  115. }
  116. return array(
  117. 'table' => '`[Q]hrcheck` a left join `[Q]userinfo` b on a.uid=b.id',
  118. 'fields' => 'a.*,b.deptname',
  119. 'asqom' => 'a.',
  120. 'where' => $where,
  121. 'orlikefields' => 'b.deptname'
  122. );
  123. }
  124. //是否可评分
  125. protected function flowdatalog($arr)
  126. {
  127. $pfrows = $this->getpfrows();
  128. foreach($pfrows as $k=>&$rs){
  129. $rs['xuhaos'] = $k+1;
  130. $rs['defenstr'] = '<input type="number" min="0" max="'.$rs['fenshu'].'" class="inputs" onfocus="js.focusval=this.value" name="pingfen_'.$rs['id'].'" onblur="js.number(this)">';
  131. $rs['itemname'] = '<div style="max-width:200px">'.$rs['itemname'].'</div>';
  132. }
  133. $pfrowsstr = c('html')->createrows($pfrows, 'xuhaos,,center@itemname,考核内容,left@pfname,评分名称@fenshu,总分数@defenstr,评分分数','#dddddd');
  134. return array(
  135. 'pfrows' => $pfrows,
  136. 'pfrowsstr' => $pfrowsstr,
  137. );
  138. }
  139. public function hrkaohemrun()
  140. {
  141. $dt = $this->rock->date;
  142. $dbs = m('hrkaohes');
  143. $dbs1 = m('hrchecks');
  144. $dbn1 = m('hrcheckn');
  145. $dbn = m('hrkaohen');
  146. $rows = m('hrkaohem')->getall("`status`=1 and `startdt`<='$dt' and `enddt`>='$dt'");
  147. $keox = 0;
  148. foreach($rows as $k=>$rs){
  149. $bo = $this->xuyuns($rs);
  150. if(!$bo)continue;
  151. $keox++;
  152. $rowxm = $dbs->getall("`mid`='".$rs['id']."'",'*','`sort`');
  153. $rowpf = $dbn->getall("`mid`='".$rs['id']."'",'*','`sort`');
  154. $inarr = array(
  155. 'khid' => $rs['id'],
  156. 'title' => $rs['title'],
  157. 'startdt' => $this->rock->date,
  158. 'applydt' => $this->rock->date,
  159. 'optdt' => $this->rock->now,
  160. 'createdt' => $this->rock->now,
  161. 'optname' => $rs['optname'],
  162. 'optid' => $rs['optid'],
  163. 'isturn' => 1,
  164. 'month' => date('Y-m'),
  165. 'status' => 1,
  166. 'enddt' => ''
  167. );
  168. if($rs['pfsj']>0)$inarr['enddt'] = $this->dtobj->adddate($inarr['startdt'],'d', $rs['pfsj']);
  169. $recwe = $this->adminmodel->gjoin($rs['receid'],'', 'where');
  170. $uarr = $this->adminmodel->getall("`status`=1 and ($recwe)",'id,name');
  171. foreach($uarr as $uk=>$urs){
  172. $inarr['uid'] = $urs['id'];
  173. $inarr['applyname'] = $urs['name'];
  174. $pfren = $pfrenid = $pfrenids = $pfrens = '';
  175. $mid = 0;
  176. $where1 = "`uid`='".$urs['id']."' and `startdt`='".$inarr['startdt']."' and `khid`='".$rs['id']."'";
  177. if($mrs = $this->getone($where1)){
  178. $mid= (int)$mrs['id'];
  179. }else{
  180. $where1= '';
  181. }
  182. //保存的hrcheck表
  183. $bo = $this->record($inarr, $where1);
  184. if($mid==0)$mid = $this->db->insert_id();
  185. //在保存到hrchecks考核内容表
  186. $sids = '0';
  187. $sids1 = '0';
  188. foreach($rowxm as $k1=>$rs1){
  189. $where1 = "`mid`='$mid' and `itemname`='".$rs1['itemname']."'";
  190. $sid = (int)$dbs1->getmou('id',$where1);
  191. if($sid==0)$where1 = '';
  192. $fenshu = floatval($rs['maxfen']) * floatval($rs1['weight']) * 0.01;
  193. $dbs1->record(array(
  194. 'mid' => $mid,
  195. 'sort' => $k1,
  196. 'itemname' => $rs1['itemname'],
  197. 'weight' => $rs1['weight'],
  198. 'fenshu' => $fenshu
  199. ), $where1);
  200. if($sid==0)$sid = $this->db->insert_id();
  201. $sids.=','.$sid.'';
  202. //添加到hrcheckn考核内容表
  203. foreach($rowpf as $k2=>$rs2){
  204. $pfarr = $this->getpftype($urs, $rs2);
  205. $where2= "`mid`='$mid' and `pfid`='".$rs2['id']."' and `sid`='$sid'";
  206. $sid1 = 0;
  207. $srs = $dbn1->getone($where2);
  208. if($srs){
  209. $sid1 = (int)$srs['id'];
  210. }
  211. if($sid1==0)$where2 = '';
  212. $dbn1->record(array(
  213. 'mid' => $mid,
  214. 'sort' => $k2,
  215. 'itemname' => $rs1['itemname'],
  216. 'weight' => $rs2['pfweight'],
  217. 'pfid' => $rs2['id'],
  218. 'pfname' => $rs2['pfname'],
  219. 'sid' => $sid,
  220. 'fenshu' => $fenshu,
  221. 'optid' => $pfarr[0],
  222. 'optname' => $pfarr[1],
  223. ),$where2);
  224. if($sid1==0)$sid1 = $this->db->insert_id();
  225. $sids1.=','.$sid1.'';
  226. if(!isempt($pfarr[0]) && !contain(','.$pfrenid.',',','.$pfarr[0].',')){
  227. $pfren .= ','.$pfarr[1];
  228. $pfrenid .= ','.$pfarr[0];
  229. }
  230. //未评分人
  231. $ispf = false;
  232. if($srs && !isempt($srs['optdt']))$ispf=true;
  233. if(!$ispf && !isempt($pfarr[0]) && !contain(','.$pfrenids.',',','.$pfarr[0].',')){
  234. $pfrenids .= ','.$pfarr[0];
  235. $pfrens .= ','.$pfarr[1];
  236. }
  237. }
  238. }
  239. $dbs1->delete("`mid`='$mid' and `id` not in($sids)");
  240. $dbn1->delete("`mid`='$mid' and `id` not in($sids1)");
  241. if($pfrenid!=''){
  242. $pfrenid = substr($pfrenid,1);
  243. $pfren = substr($pfren,1);
  244. }
  245. if($pfrenids!=''){
  246. $pfrenids = substr($pfrenids, 1);
  247. $pfrens = substr($pfrens, 1);
  248. }
  249. $this->update(array(
  250. 'pfrenid' => $pfrenid,
  251. 'pfren' => $pfren,
  252. 'pfrenids' => $pfrenids,
  253. 'pfrens' => $pfrens,
  254. ), $mid);
  255. //发给对应人通知
  256. $this->loaddata($mid, false);
  257. $this->numtodosend('pftodo','评分');
  258. }
  259. }
  260. return $keox;
  261. }
  262. private function xuyuns($rs){
  263. $pinlv = $rs['pinlv'];
  264. $sctime = $rs['sctime'];
  265. if(isempt($sctime))return false;
  266. if($pinlv=='d')return true; //每天
  267. if($pinlv=='m'){
  268. if(date('d')==date('d', strtotime($sctime)))return true;
  269. }
  270. //每季度
  271. if($pinlv=='j'){
  272. $m = (int)date('m');
  273. $jdr = array(1,4,7,10);
  274. if(in_array($m, $jdr)){
  275. if(date('d')==date('d', strtotime($sctime)))return true;
  276. }
  277. }
  278. //每年
  279. if($pinlv=='y'){
  280. if(date('m-d')==date('m-d', strtotime($sctime)))return true;
  281. }
  282. return false;
  283. }
  284. //获取评分人
  285. private function getpftype($urs, $rs2){
  286. $pftype = $rs2['pftype'];
  287. $sid = '';
  288. $sna = '';
  289. if(!isempt($rs2['pfren'])){
  290. $sid = $rs2['pfrenid'];
  291. $sna = $rs2['pfren'];
  292. }
  293. if($pftype=='my'){
  294. $sid = $urs['id'];
  295. $sna = $urs['name'];
  296. }
  297. //上级
  298. if($pftype=='super' && $sid==''){
  299. $sua = $this->adminmodel->getsuperman($urs['id']);
  300. if($sua){
  301. $sid = $sua[0];
  302. $sna = $sua[1];
  303. }
  304. }
  305. return array($sid, $sna);
  306. }
  307. public function defen($mid)
  308. {
  309. $rows = m('hrcheckn')->getall('`mid`='.$mid.'');
  310. $fshu = 0;
  311. $pfren = $pfrenid = $pfrenids = $pfrens = '';
  312. foreach($rows as $k=>$rs){
  313. $fshu += floatval($rs['defen']) * floatval($rs['weight']) * 0.01;
  314. if(!isempt($rs['optid']) && !contain(','.$pfrenid.',',','.$rs['optid'].',')){
  315. $pfren .= ','.$rs['optname'];
  316. $pfrenid .= ','.$rs['optid'];
  317. }
  318. if(isempt($rs['optdt']) && !isempt($rs['optid']) && !contain(','.$pfrenids.',',','.$rs['optid'].',')){
  319. $pfrenids .= ','.$rs['optid'];
  320. $pfrens .= ','.$rs['optname'];
  321. }
  322. }
  323. if($pfrenid!=''){
  324. $pfrenid = substr($pfrenid,1);
  325. $pfren = substr($pfren,1);
  326. }
  327. if($pfrenids!=''){
  328. $pfrenids = substr($pfrenids, 1);
  329. $pfrens = substr($pfrens, 1);
  330. }
  331. $this->update(array(
  332. 'pfrenid' => $pfrenid,
  333. 'pfren' => $pfren,
  334. 'pfrenids' => $pfrenids,
  335. 'pfrens' => $pfrens,
  336. 'fen' => $fshu,
  337. ), $mid);
  338. }
  339. /**
  340. * 提交评分
  341. */
  342. public function pingfen()
  343. {
  344. $str = $this->rock->post('str');
  345. $star= c('array')->strtoarray($str);
  346. $dbn = m('hrcheckn');
  347. foreach($star as $kv2){
  348. $sid = $kv2[0];
  349. $defen = $kv2[1];
  350. $uarr = array(
  351. 'defen' => $defen,
  352. 'optdt' => $this->rock->now
  353. );
  354. $dbn->update($uarr, $sid);
  355. }
  356. $this->defen($this->id);
  357. $sm = $this->rock->post('sm');
  358. $this->addlog(array(
  359. 'name' => '评分',
  360. 'explain' => $sm
  361. ));
  362. //$this->numtodosend('pftz','评分', $sm);
  363. return 'ok';
  364. }
  365. }
粤ICP备19079148号