123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <?php
- /**
- * Created by PhpStorm.
- * User: sicilon_IT
- * Date: 2020/2/3
- * Time: 1:45
- */
- namespace app\index\model;
- use think\Model;
- class daycheckinfo extends Model{
- protected $table='t_daycheckinfo';
- // 是否存在相庆的记录
- /*
- * 20200416
- * 修改
- * 因为更换工地当天,存在误操作
- * 因在源头解决,所以此修改取消
- */
- public function getinfobywid($pid,$checkdate,$wid){
- $where_arr['wid']=$wid;
- //$where_arr['pid']=$pid;//20200416,取消此条件,同一个,同一天只能有一个记录,这样可能导致工地记录不准确,
- $where_arr['checkdate']=$checkdate;
- $rec=$this->where($where_arr)->find();
- return $rec;
- }
- //新增
- public function addnewcheck($checkinfo){
- //判断是否存在
- $pid=$checkinfo['pid'];
- $checkdate=$checkinfo['checkdate'];
- $wid=$checkinfo['wid'];
- $rec=$this->getinfobywid($pid,$checkdate,$wid);
- if (empty($rec)){
- $this->isUpdate(false)->setAttr('id',null)->save($checkinfo);
- $rid=$this->id;
- }else{
- $rid=$rec['id'];
- $this->updatebycheck($checkinfo,$rid);
- }
- $this->addtwoshift($rid);
- return $rid;
- }
- public function updatebycheck($checkinfo,$id){
- $where_arr['id']=$id;
- $rid=$this->where($where_arr)->update($checkinfo);
- return $rid;
- }
- private function addtwoshift($id){
- $stradd='update t_daycheckinfo ';
- $stradd=$stradd." set dayscore=if(isnull(score_1),0,score_1)+if(isnull(score_2),0,score_2)";
- $stradd=$stradd." where id=".$id;
- $this->execute($stradd);
- }
- public function getusercheckinfobywid($wid){
- $where_arr['wid']=$wid;
- $list=$this->where($where_arr)->order('checkdate')->select();
- return $list;
- }
- /*
- * 20200216
- * steelxu
- * 按月,按人查询的端口
- */
- public function getusercheckinfobywidwithmonth($wid,$strmonth){
- $strsql="select *";
- $strsql=$strsql." from t_daycheckinfo";
- $strsql=$strsql." where wid=".$wid." and checkdate like '".$strmonth."%'";
- $strsql=$strsql." order by checkdate";
- $list=$this->query($strsql);
- return $list;
- }
- public function getchecklistbyheadwithdate($headid,$checkdate){
- $strsql="select *";
- $strsql=$strsql." from t_daycheckinfo";
- $strsql=$strsql." where checkdate='".$checkdate."' and ((headid_1=".$headid.") or (headid_2=".$headid."))";
- $rlist=$this->query($strsql);
- return $rlist;
- }
- /*
- * 20200206
- * steelxu
- * 汇总统计记工数据
- * param $formatmoth 是格式化的月份,格式化工作在上一级完成
- * 20200401
- * 修改,测试项目记录的不导出
- */
- public function countcheckbymonth($formatmonth,$start,$len){
- $strsql= "select wid,wname,count(dayscore) as daycount,sum(dayscore) as monthsum ";
- $strsql=$strsql." from t_daycheckinfo ";
- $strsql=$strsql." where checkdate like '".$formatmonth."%' and pid>3 and dayscore>0" ;//
- $strsql=$strsql." group by wid";
- if ($len>0){
- //导出到execl时,传入 $len参数为0,不加此行,导出所有数据
- $strsql=$strsql." limit ".$start.",".$len;
- }
- $rlist=$this->query($strsql);
- return $rlist;
- }
- /*
- * 20200421
- * 在原方法上,增加返回的推荐奖励数据的一个方法
- * 从架构上而言,这是一种临时的省事的做法,
- * 再有新的奖励,就必须创建一个奖励类来处理业务逻辑,再合并到输出中
- */
- public function countcheckwithawardbymonth($formatmonth,$start,$len){
- $strsql= "select a.wid,a.wname,count(a.dayscore) as daycount,sum(a.dayscore) as monthsum,b.sumaward";
- $strsql=$strsql." from t_daycheckinfo a left join t_recuitaward b on a.wid=b.recuituser and b.summonth='".$formatmonth."'";
- $strsql=$strsql." where checkdate like '".$formatmonth."%' and pid>3 and dayscore>0" ;//
- $strsql=$strsql." group by wid";
- if ($len>0){
- //导出到execl时,传入 $len参数为0,不加此行,导出所有数据
- $strsql=$strsql." limit ".$start.",".$len;
- }
- $rlist=$this->query($strsql);
- return $rlist;
- }
- /*
- * 20230215
- * 在原有的方式上,加上一个公司id来处理
- */
- public function countcompanycheckwithawardbymonth($formatmonth,$start,$len,$cid){
- $strsql= "select a.wid,a.wname,count(a.dayscore) as daycount,sum(a.dayscore) as monthsum,b.sumaward";
- $strsql=$strsql." from t_daycheckinfo a left join t_recuitaward b on a.wid=b.recuituser and b.summonth='".$formatmonth."' left join t_pinfo c on a.pid=c.id";
- $strsql=$strsql." where checkdate like '".$formatmonth."%' and c.companyid=".$cid." and dayscore>0" ;//
- $strsql=$strsql." group by wid";
- if ($len>0){
- //导出到execl时,传入 $len参数为0,不加此行,导出所有数据
- $strsql=$strsql." limit ".$start.",".$len;
- }
- $rlist=$this->query($strsql);
- return $rlist;
- }
- /*
- * 20200208
- * steelxu
- * 获取某员工某月的记工记录
- */
- public function getcheckinfobywidwithmonth($wid,$strmonth){
- $strsql= "select * ";
- $strsql=$strsql." from t_daycheckinfo ";
- $strsql=$strsql." where wid=".$wid." and checkdate like '".$strmonth."%' and pid>3";//
- $strsql=$strsql." order by checkdate ";
- $rlist=$this->query($strsql);
- return $rlist;
- }
- /*
- * 20200208
- * steelxu
- * 取消某员工某班次的记录
- * 本函数未更新操作记录
- */
- public function revokecheckshift($checkdate,$wid,$shift,$id){
- $strsql="update t_daycheckinfo";
- $strsql=$strsql." set score_".$shift."=0,headid_".$shift."=0,gid_".$shift."=0";
- $strsql=$strsql." where checkdate='".$checkdate."' and wid=".$wid;
- $res=$this->execute($strsql);
- $this->addtwoshift($id);
- return $res;
- }
- /*
- * 20200208 获取某公司某班组长记工的记录
- * steelxu
- * 解决班组长可以撤销操作记录的功能
- */
- public function getlistbyheadwithshift($checkdate,$shift,$headid,$gid){
- $strsql="select id,wid,wname,checkdate,score_".$shift." as score";
- $strsql=$strsql." from t_daycheckinfo";
- $strsql=$strsql." where checkdate='".$checkdate."' and headid_".$shift."=".$headid." and gid_".$shift."=".$gid;
- $rlist=$this->query($strsql);
- return $rlist;
- }
- /*
- * 20200215
- * steelxu
- * 按月给工人汇总工分
- */
- public function totalcheckbymonthwithwid($wid){
- $strsql="select wid,wname,left(checkdate,7) as strmonth,count(*) as daycount,sum(dayscore) as monthsum";
- $strsql=$strsql." from t_daycheckinfo";
- $strsql=$strsql." where wid=".$wid;
- $strsql=$strsql." group by left(checkdate,7)";
- $strsql=$strsql." order by left(checkdate,7) desc";
- $rlist=$this->query($strsql);
- return $rlist;
- }
- /*
- * 20200307
- * 做一个查加班的记录
- * 此记录是单独记录,但不是
- *
- */
- public function selscorewithprjbyscore($start,$len){
- $strsql="select a.wid,a.wname,a.checkdate,a.score_1,b.wname as mname_1,a.score_2,c.wname as mname_2,d.pname as prjname ";
- $strsql=$strsql." from t_daycheckinfo a INNER JOIN t_workerinfo b on a.headid_1=b.id INNER JOIN t_workerinfo c on a.headid_2=c.id INNER JOIN t_pinfo d on a.pid=d.id";
- $strsql=$strsql." where score_1>5 or score_2>5 ";
- $strsql=$strsql." order by a.pid,a.wid";
- $strsql=$strsql." limit $start,$len";
- $rlist=$this->query($strsql);
- return $rlist;
- }
- /*
- * 20230215
- * 修改查加班的记录的功能 ,只能查自己公司的
- */
- public function selscorewithprjbyscorecid($start,$len,$cid){
- $strsql="select a.wid,a.wname,a.checkdate,a.score_1,b.wname as mname_1,a.score_2,c.wname as mname_2,d.pname as prjname ";
- $strsql=$strsql." from t_daycheckinfo a INNER JOIN t_workerinfo b on a.headid_1=b.id INNER JOIN t_workerinfo c on a.headid_2=c.id INNER JOIN t_pinfo d on a.pid=d.id";
- $strsql=$strsql." where (a.score_1>5 or a.score_2>5) and d.companyid=".$cid;
- $strsql=$strsql." order by a.pid,a.wid";
- $strsql=$strsql." limit $start,$len";
- $rlist=$this->query($strsql);
- return $rlist;
- }
- /*
- * 20200308 完成按班组统计的数据
- */
- public function selsuminfobygid($gid,$strmonth){
- // $datenow=date('Y-m-d');
- $strsql="select checkdate,sum(case when gid_1=$gid then score_1 else 0 end) as d_score_1,sum(case when gid_2=$gid then score_2 else 0 end) as d_score_2";
- $strsql=$strsql." from t_daycheckinfo";
- $strsql=$strsql." where checkdate like '$strmonth%'";
- $strsql=$strsql." group by checkdate";
- // echo $strsql;
- // echo '<br>';
- $rlist=$this->query($strsql);
- return $rlist;
- }
- /*
- * 20200312
- * 按项目,起始日期,统计出勤记录
- *
- */
- public function selcinfowithdate($startday,$endday,$pid){
- $strsql="select checkdate,pid,count(*) as workernumber ";
- $strsql=$strsql." from t_daycheckinfo";
- $strsql=$strsql." where checkdate>='".$startday."' and checkdate<='".$endday."' and pid=".$pid;
- $strsql=$strsql." group by checkdate";
- $r_list=$this->query($strsql);
- return $r_list;
- }
- /*
- * 20200315
- * 实现按班组按人的统计
- */
- public function selworksumbygidwithdate($gid,$strmonth){
- // $datenow=date('Y-m-d');
- $strsql="select checkdate,wid,wname,sum(case when gid_1=$gid then score_1 else 0 end) as d_score_1,sum(case when gid_2=$gid then score_2 else 0 end) as d_score_2";
- $strsql=$strsql." from t_daycheckinfo";
- $strsql=$strsql." where checkdate like '$strmonth%'";
- $strsql=$strsql." group by checkdate,wid";
- $strsql=$strsql." having d_score_1>0 or d_score_2>0";
- // echo $strsql;
- // echo '<br>';
- $rlist=$this->query($strsql);
- return $rlist;
- }
- /*
- * 20200419
- * 获取某员工某一时间段的工作记录
- *
- */
- public function selcountbyidwithdate($id,$bdate,$edate){
- $strsql="select wid,checkdate, sum(dayscore) as sumds";
- $strsql=$strsql." from t_daycheckinfo";
- $strsql=$strsql." where wid=$id and checkdate>='".$bdate."' and checkdate<='".$edate."'";
- $strsql=$strsql." group by checkdate";
- $strsql=$strsql." having sumds>=10";
- $rlist=$this->query($strsql);
- if($rlist){
- $rlist=collection($rlist)->toArray();
- return count($rlist);
- }else{
- return 0;
- }
- }
- /*
- * 20200729
- * 根据GID获取已取班次已经记工的人数
- */
- public function selcountbygid($gid,$checkdate,$shift){
- $strsql="select count(id) as checkcount";
- $strsql=$strsql." from t_daycheckinfo";
- $strsql=$strsql." where gid_$shift=$gid and checkdate='".$checkdate."' and score_$shift>0";
- $count=$this->query($strsql);
- $count=collection($count)->toArray();
- return $count;
- }
- /*
- * 20210807
- */
- public function selscorebyidwithdays($id,$bdate){
- $strsql="select wid,checkdate, sum(dayscore) as sumds";
- $strsql=$strsql." from t_daycheckinfo";
- $strsql=$strsql." where wid=$id and checkdate>='".$bdate."'";
- $rlist=$this->query($strsql);
- if($rlist){
- $rlist=collection($rlist)->toArray();
- return count($rlist);
- }else{
- return 0;
- }
- }
- /*
- * 20230215
- */
- public function selinfobyid($id){
- $where['id']=$id;
- $rec=$this->where($where)->find();
- return $rec;
- }
- }
|