daycheckinfo.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: sicilon_IT
  5. * Date: 2020/2/3
  6. * Time: 1:45
  7. */
  8. namespace app\index\model;
  9. use think\Model;
  10. class daycheckinfo extends Model{
  11. protected $table='t_daycheckinfo';
  12. // 是否存在相庆的记录
  13. /*
  14. * 20200416
  15. * 修改
  16. * 因为更换工地当天,存在误操作
  17. * 因在源头解决,所以此修改取消
  18. */
  19. public function getinfobywid($pid,$checkdate,$wid){
  20. $where_arr['wid']=$wid;
  21. //$where_arr['pid']=$pid;//20200416,取消此条件,同一个,同一天只能有一个记录,这样可能导致工地记录不准确,
  22. $where_arr['checkdate']=$checkdate;
  23. $rec=$this->where($where_arr)->find();
  24. return $rec;
  25. }
  26. //新增
  27. public function addnewcheck($checkinfo){
  28. //判断是否存在
  29. $pid=$checkinfo['pid'];
  30. $checkdate=$checkinfo['checkdate'];
  31. $wid=$checkinfo['wid'];
  32. $rec=$this->getinfobywid($pid,$checkdate,$wid);
  33. if (empty($rec)){
  34. $this->isUpdate(false)->setAttr('id',null)->save($checkinfo);
  35. $rid=$this->id;
  36. }else{
  37. $rid=$rec['id'];
  38. $this->updatebycheck($checkinfo,$rid);
  39. }
  40. $this->addtwoshift($rid);
  41. return $rid;
  42. }
  43. public function updatebycheck($checkinfo,$id){
  44. $where_arr['id']=$id;
  45. $rid=$this->where($where_arr)->update($checkinfo);
  46. return $rid;
  47. }
  48. private function addtwoshift($id){
  49. $stradd='update t_daycheckinfo ';
  50. $stradd=$stradd." set dayscore=if(isnull(score_1),0,score_1)+if(isnull(score_2),0,score_2)";
  51. $stradd=$stradd." where id=".$id;
  52. $this->execute($stradd);
  53. }
  54. public function getusercheckinfobywid($wid){
  55. $where_arr['wid']=$wid;
  56. $list=$this->where($where_arr)->order('checkdate')->select();
  57. return $list;
  58. }
  59. /*
  60. * 20200216
  61. * steelxu
  62. * 按月,按人查询的端口
  63. */
  64. public function getusercheckinfobywidwithmonth($wid,$strmonth){
  65. $strsql="select *";
  66. $strsql=$strsql." from t_daycheckinfo";
  67. $strsql=$strsql." where wid=".$wid." and checkdate like '".$strmonth."%'";
  68. $strsql=$strsql." order by checkdate";
  69. $list=$this->query($strsql);
  70. return $list;
  71. }
  72. public function getchecklistbyheadwithdate($headid,$checkdate){
  73. $strsql="select *";
  74. $strsql=$strsql." from t_daycheckinfo";
  75. $strsql=$strsql." where checkdate='".$checkdate."' and ((headid_1=".$headid.") or (headid_2=".$headid."))";
  76. $rlist=$this->query($strsql);
  77. return $rlist;
  78. }
  79. /*
  80. * 20200206
  81. * steelxu
  82. * 汇总统计记工数据
  83. * param $formatmoth 是格式化的月份,格式化工作在上一级完成
  84. * 20200401
  85. * 修改,测试项目记录的不导出
  86. */
  87. public function countcheckbymonth($formatmonth,$start,$len){
  88. $strsql= "select wid,wname,count(dayscore) as daycount,sum(dayscore) as monthsum ";
  89. $strsql=$strsql." from t_daycheckinfo ";
  90. $strsql=$strsql." where checkdate like '".$formatmonth."%' and pid>3 and dayscore>0" ;//
  91. $strsql=$strsql." group by wid";
  92. if ($len>0){
  93. //导出到execl时,传入 $len参数为0,不加此行,导出所有数据
  94. $strsql=$strsql." limit ".$start.",".$len;
  95. }
  96. $rlist=$this->query($strsql);
  97. return $rlist;
  98. }
  99. /*
  100. * 20200421
  101. * 在原方法上,增加返回的推荐奖励数据的一个方法
  102. * 从架构上而言,这是一种临时的省事的做法,
  103. * 再有新的奖励,就必须创建一个奖励类来处理业务逻辑,再合并到输出中
  104. */
  105. public function countcheckwithawardbymonth($formatmonth,$start,$len){
  106. $strsql= "select a.wid,a.wname,count(a.dayscore) as daycount,sum(a.dayscore) as monthsum,b.sumaward";
  107. $strsql=$strsql." from t_daycheckinfo a left join t_recuitaward b on a.wid=b.recuituser and b.summonth='".$formatmonth."'";
  108. $strsql=$strsql." where checkdate like '".$formatmonth."%' and pid>3 and dayscore>0" ;//
  109. $strsql=$strsql." group by wid";
  110. if ($len>0){
  111. //导出到execl时,传入 $len参数为0,不加此行,导出所有数据
  112. $strsql=$strsql." limit ".$start.",".$len;
  113. }
  114. $rlist=$this->query($strsql);
  115. return $rlist;
  116. }
  117. /*
  118. * 20230215
  119. * 在原有的方式上,加上一个公司id来处理
  120. */
  121. public function countcompanycheckwithawardbymonth($formatmonth,$start,$len,$cid){
  122. $strsql= "select a.wid,a.wname,count(a.dayscore) as daycount,sum(a.dayscore) as monthsum,b.sumaward";
  123. $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";
  124. $strsql=$strsql." where checkdate like '".$formatmonth."%' and c.companyid=".$cid." and dayscore>0" ;//
  125. $strsql=$strsql." group by wid";
  126. if ($len>0){
  127. //导出到execl时,传入 $len参数为0,不加此行,导出所有数据
  128. $strsql=$strsql." limit ".$start.",".$len;
  129. }
  130. $rlist=$this->query($strsql);
  131. return $rlist;
  132. }
  133. /*
  134. * 20200208
  135. * steelxu
  136. * 获取某员工某月的记工记录
  137. */
  138. public function getcheckinfobywidwithmonth($wid,$strmonth){
  139. $strsql= "select * ";
  140. $strsql=$strsql." from t_daycheckinfo ";
  141. $strsql=$strsql." where wid=".$wid." and checkdate like '".$strmonth."%' and pid>3";//
  142. $strsql=$strsql." order by checkdate ";
  143. $rlist=$this->query($strsql);
  144. return $rlist;
  145. }
  146. /*
  147. * 20200208
  148. * steelxu
  149. * 取消某员工某班次的记录
  150. * 本函数未更新操作记录
  151. */
  152. public function revokecheckshift($checkdate,$wid,$shift,$id){
  153. $strsql="update t_daycheckinfo";
  154. $strsql=$strsql." set score_".$shift."=0,headid_".$shift."=0,gid_".$shift."=0";
  155. $strsql=$strsql." where checkdate='".$checkdate."' and wid=".$wid;
  156. $res=$this->execute($strsql);
  157. $this->addtwoshift($id);
  158. return $res;
  159. }
  160. /*
  161. * 20200208 获取某公司某班组长记工的记录
  162. * steelxu
  163. * 解决班组长可以撤销操作记录的功能
  164. */
  165. public function getlistbyheadwithshift($checkdate,$shift,$headid,$gid){
  166. $strsql="select id,wid,wname,checkdate,score_".$shift." as score";
  167. $strsql=$strsql." from t_daycheckinfo";
  168. $strsql=$strsql." where checkdate='".$checkdate."' and headid_".$shift."=".$headid." and gid_".$shift."=".$gid;
  169. $rlist=$this->query($strsql);
  170. return $rlist;
  171. }
  172. /*
  173. * 20200215
  174. * steelxu
  175. * 按月给工人汇总工分
  176. */
  177. public function totalcheckbymonthwithwid($wid){
  178. $strsql="select wid,wname,left(checkdate,7) as strmonth,count(*) as daycount,sum(dayscore) as monthsum";
  179. $strsql=$strsql." from t_daycheckinfo";
  180. $strsql=$strsql." where wid=".$wid;
  181. $strsql=$strsql." group by left(checkdate,7)";
  182. $strsql=$strsql." order by left(checkdate,7) desc";
  183. $rlist=$this->query($strsql);
  184. return $rlist;
  185. }
  186. /*
  187. * 20200307
  188. * 做一个查加班的记录
  189. * 此记录是单独记录,但不是
  190. *
  191. */
  192. public function selscorewithprjbyscore($start,$len){
  193. $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 ";
  194. $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";
  195. $strsql=$strsql." where score_1>5 or score_2>5 ";
  196. $strsql=$strsql." order by a.pid,a.wid";
  197. $strsql=$strsql." limit $start,$len";
  198. $rlist=$this->query($strsql);
  199. return $rlist;
  200. }
  201. /*
  202. * 20230215
  203. * 修改查加班的记录的功能 ,只能查自己公司的
  204. */
  205. public function selscorewithprjbyscorecid($start,$len,$cid){
  206. $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 ";
  207. $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";
  208. $strsql=$strsql." where (a.score_1>5 or a.score_2>5) and d.companyid=".$cid;
  209. $strsql=$strsql." order by a.pid,a.wid";
  210. $strsql=$strsql." limit $start,$len";
  211. $rlist=$this->query($strsql);
  212. return $rlist;
  213. }
  214. /*
  215. * 20200308 完成按班组统计的数据
  216. */
  217. public function selsuminfobygid($gid,$strmonth){
  218. // $datenow=date('Y-m-d');
  219. $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";
  220. $strsql=$strsql." from t_daycheckinfo";
  221. $strsql=$strsql." where checkdate like '$strmonth%'";
  222. $strsql=$strsql." group by checkdate";
  223. // echo $strsql;
  224. // echo '<br>';
  225. $rlist=$this->query($strsql);
  226. return $rlist;
  227. }
  228. /*
  229. * 20200312
  230. * 按项目,起始日期,统计出勤记录
  231. *
  232. */
  233. public function selcinfowithdate($startday,$endday,$pid){
  234. $strsql="select checkdate,pid,count(*) as workernumber ";
  235. $strsql=$strsql." from t_daycheckinfo";
  236. $strsql=$strsql." where checkdate>='".$startday."' and checkdate<='".$endday."' and pid=".$pid;
  237. $strsql=$strsql." group by checkdate";
  238. $r_list=$this->query($strsql);
  239. return $r_list;
  240. }
  241. /*
  242. * 20200315
  243. * 实现按班组按人的统计
  244. */
  245. public function selworksumbygidwithdate($gid,$strmonth){
  246. // $datenow=date('Y-m-d');
  247. $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";
  248. $strsql=$strsql." from t_daycheckinfo";
  249. $strsql=$strsql." where checkdate like '$strmonth%'";
  250. $strsql=$strsql." group by checkdate,wid";
  251. $strsql=$strsql." having d_score_1>0 or d_score_2>0";
  252. // echo $strsql;
  253. // echo '<br>';
  254. $rlist=$this->query($strsql);
  255. return $rlist;
  256. }
  257. /*
  258. * 20200419
  259. * 获取某员工某一时间段的工作记录
  260. *
  261. */
  262. public function selcountbyidwithdate($id,$bdate,$edate){
  263. $strsql="select wid,checkdate, sum(dayscore) as sumds";
  264. $strsql=$strsql." from t_daycheckinfo";
  265. $strsql=$strsql." where wid=$id and checkdate>='".$bdate."' and checkdate<='".$edate."'";
  266. $strsql=$strsql." group by checkdate";
  267. $strsql=$strsql." having sumds>=10";
  268. $rlist=$this->query($strsql);
  269. if($rlist){
  270. $rlist=collection($rlist)->toArray();
  271. return count($rlist);
  272. }else{
  273. return 0;
  274. }
  275. }
  276. /*
  277. * 20200729
  278. * 根据GID获取已取班次已经记工的人数
  279. */
  280. public function selcountbygid($gid,$checkdate,$shift){
  281. $strsql="select count(id) as checkcount";
  282. $strsql=$strsql." from t_daycheckinfo";
  283. $strsql=$strsql." where gid_$shift=$gid and checkdate='".$checkdate."' and score_$shift>0";
  284. $count=$this->query($strsql);
  285. $count=collection($count)->toArray();
  286. return $count;
  287. }
  288. /*
  289. * 20210807
  290. */
  291. public function selscorebyidwithdays($id,$bdate){
  292. $strsql="select wid,checkdate, sum(dayscore) as sumds";
  293. $strsql=$strsql." from t_daycheckinfo";
  294. $strsql=$strsql." where wid=$id and checkdate>='".$bdate."'";
  295. $rlist=$this->query($strsql);
  296. if($rlist){
  297. $rlist=collection($rlist)->toArray();
  298. return count($rlist);
  299. }else{
  300. return 0;
  301. }
  302. }
  303. /*
  304. * 20230215
  305. */
  306. public function selinfobyid($id){
  307. $where['id']=$id;
  308. $rec=$this->where($where)->find();
  309. return $rec;
  310. }
  311. }