gworkermodel.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. *
  44. *
  45. * @param [type] $start
  46. * @param [type] $rlen
  47. * @param [type] $cid
  48. * @return void
  49. * @author wj
  50. * @date 2025-02-17
  51. */
  52. public function getnotinprojectuserlist($start, $rlen) {
  53. $strsql = "select a.*,c.pname,c.is_worker ";
  54. $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";
  55. $strsql = $strsql . " where a.isactive=1 and a.cprojectid=3";
  56. $strsql = $strsql . " order by a.dayprice,create_date desc";
  57. $strsql = $strsql . " limit " . $start . "," . $rlen;
  58. $workerlist = $this->query($strsql);
  59. return $workerlist;
  60. }
  61. /*
  62. * steelxu
  63. * 20200212
  64. * 获取指定项目员工
  65. */
  66. public function getprjworker($start, $rlen, $pid) {
  67. $strsql = "select * ";
  68. $strsql = $strsql . "from t_workerinfo ";
  69. $strsql = $strsql . " where cprojectid=" . $pid;
  70. $strsql = $strsql . " order by wname";
  71. $strsql = $strsql . " limit " . $start . "," . $rlen;
  72. $workerlist = $this->query($strsql);
  73. return $workerlist;
  74. }
  75. /*
  76. * 20200303
  77. * 预检查是否有索引字段重复
  78. */
  79. private function precheckindex($info) {
  80. $where_arr['telno'] = $info['telno'];
  81. $rec = $this->where($where_arr)->find();
  82. if ($rec) {
  83. return false;
  84. } else {
  85. return true;
  86. }
  87. }
  88. /*
  89. * 20200303
  90. * edit
  91. * 有索引表,增加预检 *
  92. */
  93. public function saveworkerinfo($worker) {
  94. //预检
  95. $ishave = $this->precheckindex($worker);
  96. Log::info($ishave);
  97. if (!$ishave) {
  98. return -1;
  99. }
  100. Log::info($worker);
  101. $sid = $this->allowField(true)->isUpdate(false)->setAttr('id', null)->save($worker);
  102. if ($sid == 1) {
  103. return $this->id;
  104. } else {
  105. return $sid;
  106. }
  107. }
  108. /*
  109. * 20200204
  110. * steelxu
  111. * 更新工人的cprojectid,
  112. * 实现工人指量设置,换项目的功能
  113. * */
  114. public function updateprj($pid, $wid) {
  115. $where_arr['id'] = $wid;
  116. $update_arr['cprojectid'] = $pid;
  117. $res = $this->where($where_arr)->update($update_arr);
  118. return $res;
  119. }
  120. /*
  121. * steelxu
  122. * 20200211
  123. * 根据工人ID获取信息
  124. */
  125. public function getinfobyid($wid) {
  126. $where_arr['id'] = $wid;
  127. $rec = $this->where($where_arr)->find();
  128. return $rec;
  129. }
  130. /*
  131. * 20200325
  132. * 获取所有工人的id和身份证
  133. */
  134. public function selshengfengzhenglist() {
  135. $strsql = "select id,shengfengid ";
  136. $strsql = $strsql . " from t_workerinfo";
  137. $wlist = $this->query($strsql);
  138. return $wlist;
  139. }
  140. /*
  141. * 2030215
  142. * 只返回公司的员工id和身份证
  143. */
  144. public function selcompanyshengfengzhenglist($cid) {
  145. $strsql = "select a.id,a.shengfengid ";
  146. $strsql = $strsql . " from t_workerinfo a left join t_pinfo b on a.cprojectid=b.id";
  147. $strsql = $strsql . " where b.companyid=" . $cid;
  148. $wlist = $this->query($strsql);
  149. return $wlist;
  150. }
  151. /*
  152. * 20200417
  153. * 根据电话获取用户信息
  154. *
  155. */
  156. public function seluinfobytel($tel) {
  157. $where_arr['telno'] = $tel;
  158. $rec = $this->where($where_arr)->find();
  159. return $rec;
  160. }
  161. /*
  162. * 20200515
  163. * 根据身份证获取数据
  164. */
  165. public function selinfobysfz($sfzid) {
  166. $where_arr['shengfengid'] = $sfzid;
  167. $rec = $this->where($where_arr)->find();
  168. return $rec;
  169. }
  170. /*
  171. * 20210311
  172. * 根据姓名获取数据
  173. */
  174. public function selinfobyname($name) {
  175. $strsql = "select * from t_workerinfo where wname like '%" . $name . "%' order by id,cprojectid";
  176. $rlist = $this->query($strsql);
  177. $rlist = collection($rlist)->toArray();
  178. return $rlist;
  179. }
  180. /*
  181. * 20210416
  182. * 获取生日是今天的员工
  183. */
  184. public function selworklistbybirthday($birthday) {
  185. if ($birthday != '0301') {
  186. $strsql = "select * from t_workerinfo where SUBSTR(shengfengid FROM 11 FOR 4)='" . $birthday . "'";
  187. } else {
  188. $strsql = "select * from t_workerinfo where SUBSTR(shengfengid FROM 11 FOR 4)='" . $birthday . "' or SUBSTR(shengfengid FROM 11 FOR 4)='0209'";
  189. }
  190. $rlist = $this->query($strsql);
  191. $rlist = collection($rlist)->toArray();
  192. return $rlist;
  193. }
  194. /*
  195. * 20210416
  196. * 更新工人年龄
  197. */
  198. public function updwagebyid($id, $wage) {
  199. $where_arr['id'] = $id;
  200. $upd_arr['wage'] = $wage;
  201. $this->where($where_arr)->update($upd_arr);
  202. }
  203. /*
  204. * 20210427
  205. * 更新工人信息(电话、工种)
  206. */
  207. public function updinfobyid($id, $arr) {
  208. $where_arr['id'] = $id;
  209. $count = $this->where($where_arr)->update($arr);
  210. return $count;
  211. }
  212. /*
  213. * 20210725
  214. * 获取每个工地的人数统计
  215. */
  216. public function selwcountbyprj() {
  217. $strsql = 'select cprojectid, count(*) as pwcount ';
  218. $strsql = $strsql . ' from t_workerinfo ';
  219. $strsql = $strsql . " where cprojectid>3";
  220. $strsql = $strsql . " group by cprojectid";
  221. $rlist = $this->query($strsql);
  222. $rlist = collection($rlist)->toArray();
  223. return $rlist;
  224. }
  225. /*
  226. * 20210807
  227. * 获取所有cprojectid>3的用户
  228. */
  229. public function selinfolistwithprjid() {
  230. $strsql = 'select * from t_workerinfo where cprojectid>3';
  231. $rlist = $this->query($strsql);
  232. $rlist = collection($rlist)->toArray();
  233. return $rlist;
  234. }
  235. }