hrcheckModel.php 11 KB

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