pwrelationmodel.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: sicilon_IT
  5. * Date: 2020/1/13
  6. * Time: 15:54
  7. */
  8. namespace app\index\model;
  9. use think\Model;
  10. class pwrelationmodel extends Model{
  11. protected $table='t_p2wrelation';
  12. public function getworkerlistbypid($pid){
  13. $where_arr['pid']=$pid;
  14. $where_arr['checkstatus']=1;
  15. $workerlist=$this->where($where_arr)->select();
  16. return $workerlist;
  17. }
  18. /*
  19. * 20200416
  20. * 修改:原有的不能发现在其它工地已记工的员工,导致重复记录
  21. * 修改为联表查询,相关员工的记工记录
  22. *todo 在人员再增加时,联表查询会有问题,此功能要取消,改为从上一级查询
  23. */
  24. public function getworkerunlist($pid,$checkdate,$shift){
  25. // $strsql="select a.*,b.wname,b.workclass,b.telno,b.wage, 5 as setscore,0 as mcheck from t_p2wrelation a left join t_workerinfo b on a.wid=b.id ";
  26. //
  27. // $strsql=$strsql." where a.pid = ".$pid." and a.checkstatus=1 and a.wid not in ";
  28. // if ($shift==1){
  29. // $strsql=$strsql."(select wid from t_daycheckinfo ";
  30. // $strsql=$strsql." where pid=".$pid." and checkdate='".$checkdate."' and score_1>0)";
  31. // }else{
  32. // $strsql=$strsql."(select wid from t_daycheckinfo ";
  33. // $strsql=$strsql." where pid=".$pid." and checkdate='".$checkdate."' and score_2>0)";
  34. // }
  35. $strsql="select a.*,b.wname,b.workclass,b.telno,b.wage, b.dayprice,5 as setscore,0 as mcheck from t_p2wrelation a left join t_workerinfo b on a.wid=b.id ";
  36. $strsql=$strsql." left join t_daycheckinfo c on a.wid=c.wid and c.checkdate='".$checkdate."'";
  37. $strsql=$strsql." where a.pid = ".$pid." and a.checkstatus=1 and a.startdate<='".$checkdate."' and ";
  38. if ($shift==1){
  39. $strsql=$strsql." (c.score_1 is null or c.score_1=0)";
  40. }else{
  41. $strsql=$strsql." (c.score_2 is null or c.score_2=0)";
  42. }
  43. $strsql=$strsql." order by workclass,wname";
  44. $workerlist=$this->query($strsql);
  45. return $workerlist;
  46. }
  47. /*
  48. * 20200603
  49. * 补考勤用新的,排除掉进入项目日期必须在考勤日期之前
  50. */
  51. public function selunwlistforupdate($pid,$checkdate,$shift){
  52. $strsql="select a.*,b.wname,b.workclass,b.telno,b.wage, b.dayprice,5 as setscore,0 as mcheck from t_p2wrelation a left join t_workerinfo b on a.wid=b.id ";
  53. $strsql=$strsql." left join t_daycheckinfo c on a.wid=c.wid and c.checkdate='".$checkdate."'";
  54. $strsql=$strsql." where a.pid = ".$pid." and a.checkstatus=1 and ";
  55. if ($shift==1){
  56. $strsql=$strsql." (c.score_1 is null or c.score_1=0)";
  57. }else{
  58. $strsql=$strsql." (c.score_2 is null or c.score_2=0)";
  59. }
  60. $strsql=$strsql." order by workclass,wname";
  61. $workerlist=$this->query($strsql);
  62. return $workerlist;
  63. }
  64. public function savenewrelation($relation){
  65. $id=$this->save($relation);
  66. return $id;
  67. }
  68. public function getpidbywid($wid){
  69. $where_arr['wid']=$wid;
  70. $where_arr['checkstatus']=1;
  71. $pwinfo=$this->where($where_arr)->find();
  72. return $pwinfo['pid'];
  73. }
  74. //取消某用户以前的历史关系,将checkstatus set=0
  75. private function cancelpwhistory($wid,$date){
  76. $where_arr['wid']=$wid;
  77. $where_arr['checkstatus']=1;
  78. $update_arr['checkstatus']=0;
  79. $update_arr['enddate']=$date;
  80. $this->where($where_arr)->update($update_arr);
  81. return 1;
  82. }
  83. public function addnewrelation($relation_arr){
  84. //先取消原有的关系
  85. $this->cancelpwhistory($relation_arr['wid'],$relation_arr['startdate']);
  86. $this->isUpdate(false)->save($relation_arr);
  87. return 1;
  88. }
  89. }