gworkermodel.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: sicilon_IT
  5. * Date: 2020/1/12
  6. * Time: 21:59
  7. */
  8. namespace app\index\model;
  9. use think\Model;
  10. use think\Log;
  11. class gworkermodel extends Model{
  12. protected $table='t_workerinfo';
  13. public function getidbytel($tel){
  14. $recordlist=$this->where('telno',$tel)->find();
  15. if ($recordlist){
  16. return $recordlist['id'];
  17. }else{
  18. return 0;
  19. }
  20. }
  21. //获取所有工人信息,并带项目名称
  22. public function getallworker($start,$rlen){
  23. $strsql="select a.*,c.pname,c.is_worker ";
  24. $strsql=$strsql."from t_workerinfo a left join t_p2wrelation b on a.id=b.wid and b.checkstatus=1 left join t_pinfo c on b.pid=c.id";
  25. $strsql=$strsql." limit ".$start.",".$rlen;
  26. $workerlist=$this->query($strsql);
  27. return $workerlist;
  28. }
  29. /*
  30. * 20230214
  31. * 获取一个企业的项目的所有工人
  32. */
  33. public function getallworkerbycid($start,$rlen,$cid){
  34. $strsql="select a.*,c.pname,c.is_worker ";
  35. $strsql=$strsql."from t_workerinfo a left join t_p2wrelation b on a.id=b.wid and b.checkstatus=1 left join t_pinfo c on b.pid=c.id";
  36. $strsql=$strsql." where c.companyid=".$cid;
  37. $strsql=$strsql." order by a.dayprice,create_date desc";
  38. $strsql=$strsql." limit ".$start.",".$rlen;
  39. $workerlist=$this->query($strsql);
  40. return $workerlist;
  41. }
  42. /*
  43. * steelxu
  44. * 20200212
  45. * 获取指定项目员工
  46. */
  47. public function getprjworker($start,$rlen,$pid){
  48. $strsql="select * ";
  49. $strsql=$strsql."from t_workerinfo ";
  50. $strsql=$strsql." where cprojectid=".$pid;
  51. $strsql=$strsql." order by wname";
  52. $strsql=$strsql." limit ".$start.",".$rlen;
  53. $workerlist=$this->query($strsql);
  54. return $workerlist;
  55. }
  56. /*
  57. * 20200303
  58. * 预检查是否有索引字段重复
  59. */
  60. private function precheckindex($info){
  61. $where_arr['telno']=$info['telno'];
  62. $rec=$this->where($where_arr)->find();
  63. if ($rec){
  64. return false;
  65. }else{
  66. return true;
  67. }
  68. }
  69. /*
  70. * 20200303
  71. * edit
  72. * 有索引表,增加预检 *
  73. */
  74. public function saveworkerinfo($worker){
  75. //预检
  76. $ishave=$this->precheckindex($worker);
  77. Log::info($ishave);
  78. if (!$ishave){
  79. return -1;
  80. }
  81. Log::info($worker);
  82. $sid=$this->allowField(true)->isUpdate(false)->setAttr('id',null)->save($worker);
  83. if ($sid==1){
  84. return $this->id;
  85. }else{
  86. return $sid;
  87. }
  88. }
  89. /*
  90. * 20200204
  91. * steelxu
  92. * 更新工人的cprojectid,
  93. * 实现工人指量设置,换项目的功能
  94. * */
  95. public function updateprj($pid,$wid){
  96. $where_arr['id']=$wid;
  97. $update_arr['cprojectid']=$pid;
  98. $res=$this->where($where_arr)->update($update_arr);
  99. return $res;
  100. }
  101. /*
  102. * steelxu
  103. * 20200211
  104. * 根据工人ID获取信息
  105. */
  106. public function getinfobyid($wid){
  107. $where_arr['id']=$wid;
  108. $rec=$this->where($where_arr)->find();
  109. return $rec;
  110. }
  111. /*
  112. * 20200325
  113. * 获取所有工人的id和身份证
  114. */
  115. public function selshengfengzhenglist(){
  116. $strsql="select id,shengfengid ";
  117. $strsql=$strsql." from t_workerinfo";
  118. $wlist=$this->query($strsql);
  119. return $wlist;
  120. }
  121. /*
  122. * 2030215
  123. * 只返回公司的员工id和身份证
  124. */
  125. public function selcompanyshengfengzhenglist($cid){
  126. $strsql="select a.id,a.shengfengid ";
  127. $strsql=$strsql." from t_workerinfo a left join t_pinfo b on a.cprojectid=b.id";
  128. $strsql=$strsql." where b.companyid=".$cid;
  129. $wlist=$this->query($strsql);
  130. return $wlist;
  131. }
  132. /*
  133. * 20200417
  134. * 根据电话获取用户信息
  135. *
  136. */
  137. public function seluinfobytel($tel){
  138. $where_arr['telno']=$tel;
  139. $rec=$this->where($where_arr)->find();
  140. return $rec;
  141. }
  142. /*
  143. * 20200515
  144. * 根据身份证获取数据
  145. */
  146. public function selinfobysfz($sfzid){
  147. $where_arr['shengfengid']=$sfzid;
  148. $rec=$this->where($where_arr)->find();
  149. return $rec;
  150. }
  151. /*
  152. * 20210311
  153. * 根据姓名获取数据
  154. */
  155. public function selinfobyname($name){
  156. $strsql="select * from t_workerinfo where wname like '%".$name."%' order by id,cprojectid";
  157. $rlist=$this->query($strsql);
  158. $rlist=collection($rlist)->toArray();
  159. return $rlist;
  160. }
  161. /*
  162. * 20210416
  163. * 获取生日是今天的员工
  164. */
  165. public function selworklistbybirthday($birthday){
  166. if($birthday!='0301') {
  167. $strsql="select * from t_workerinfo where SUBSTR(shengfengid FROM 11 FOR 4)='".$birthday."'";
  168. }else{
  169. $strsql="select * from t_workerinfo where SUBSTR(shengfengid FROM 11 FOR 4)='".$birthday."' or SUBSTR(shengfengid FROM 11 FOR 4)='0209'";
  170. }
  171. $rlist=$this->query($strsql);
  172. $rlist=collection($rlist)->toArray();
  173. return $rlist;
  174. }
  175. /*
  176. * 20210416
  177. * 更新工人年龄
  178. */
  179. public function updwagebyid($id,$wage){
  180. $where_arr['id']=$id;
  181. $upd_arr['wage']=$wage;
  182. $this->where($where_arr)->update($upd_arr);
  183. }
  184. /*
  185. * 20210427
  186. * 更新工人信息(电话、工种)
  187. */
  188. public function updinfobyid($id,$arr){
  189. $where_arr['id']=$id;
  190. $count=$this->where($where_arr)->update($arr);
  191. return $count;
  192. }
  193. /*
  194. * 20210725
  195. * 获取每个工地的人数统计
  196. */
  197. public function selwcountbyprj(){
  198. $strsql='select cprojectid, count(*) as pwcount ';
  199. $strsql=$strsql.' from t_workerinfo ';
  200. $strsql=$strsql." where cprojectid>3";
  201. $strsql=$strsql." group by cprojectid";
  202. $rlist=$this->query($strsql);
  203. $rlist=collection($rlist)->toArray();
  204. return $rlist;
  205. }
  206. /*
  207. * 20210807
  208. * 获取所有cprojectid>3的用户
  209. */
  210. public function selinfolistwithprjid(){
  211. $strsql='select * from t_workerinfo where cprojectid>3';
  212. $rlist=$this->query($strsql);
  213. $rlist=collection($rlist)->toArray();
  214. return $rlist;
  215. }
  216. }