Jiance.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. namespace app\api\controller\worker;
  3. use app\common\controller\Apiw;
  4. use think\Db;
  5. /**
  6. * 检测下发
  7. */
  8. class Jiance extends Apiw
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = [];
  12. protected $table = 'jiance';
  13. //首页列表
  14. public function index(){
  15. $map = [];
  16. $status = input('status','all');
  17. if($status != 'all'){
  18. $map['jiance.status'] = $status;
  19. }
  20. $list = Db::name('jiance')
  21. ->field('jiance.id,jiance.bianhao,jiance.status,jiance_number,uc.projectname')
  22. ->join('user_company uc','jiance.uc_id = uc.id','LEFT')
  23. ->where('jiance.worker_id',$this->auth->id)
  24. ->where('jiance.deletetime',NULL)
  25. ->where($map)
  26. ->autopage()
  27. ->select();
  28. $this->success(1,$list);
  29. }
  30. //详情页
  31. public function info(){
  32. $id = input('id',0);
  33. $info = Db::name('jiance')->field('id,bianhao,status,project_ids')->where('id',$id)->find();
  34. //所有项目
  35. $project = Db::name('jiance_project')->field('id,pid,title,type,info,weigh')
  36. ->where('company_id',$this->auth->company_id)
  37. ->where('deletetime',NULL)
  38. ->where('id','IN',$info['project_ids'])
  39. ->order('pid asc,type asc,weigh asc,id asc')->select();
  40. //所有记录
  41. $joblog = Db::name('jiance_joblog')->field('project_id,count(id) as jilunum')->where('jiance_id',$id)->group('project_id')->select();
  42. $joblog = array_column($joblog,'jilunum','project_id');
  43. //循环处理
  44. $top = [];
  45. foreach($project as $key => $val){
  46. //组合记录数
  47. $project[$key]['jilunum'] = isset($joblog[$val['id']]) ? $joblog[$val['id']] : 0;
  48. //拿出来一级
  49. if($val['pid'] == 0){
  50. $top[] = $val;
  51. unset($project[$key]);
  52. }
  53. }
  54. // dump($top);
  55. // dump($project);
  56. //数据结构排序,二级结构,不需要tree
  57. foreach($top as $tk => $tv){
  58. foreach($project as $key => $val){
  59. if($val['pid'] == $tv['id']){
  60. if($val['type'] == 1){
  61. $tv['child_type1'][] = $val;
  62. }else{
  63. $tv['child_type2'][] = $val;
  64. }
  65. }
  66. }
  67. $top[$tk] = $tv;
  68. }
  69. // dump($top);
  70. //
  71. unset($info['project_ids']);
  72. $result = [
  73. 'jiance' => $info,
  74. 'project' => $top,
  75. ];
  76. $this->success(1,$result);
  77. }
  78. //提交
  79. public function submit(){
  80. $id = input('id',0);
  81. Db::name('jiance')->where('id',$id)->where('company_id',$this->auth->company_id)->update(['status'=>1]);
  82. $this->success();
  83. }
  84. //记录列表
  85. public function job_list(){
  86. $jiance_id = input('jiance_id',0);
  87. $project_id = input('project_id',0);
  88. $jiance = Db::name('jiance')->where('id',$jiance_id)->value('status');
  89. $list = Db::name('jiance_joblog')->alias('joblog')
  90. ->field('joblog.*,project.title as project_title')
  91. ->join('jiance_project project','joblog.project_id = project.id','LEFT')
  92. ->where('joblog.jiance_id',$jiance_id)
  93. ->where('joblog.project_id',$project_id)
  94. ->select();
  95. $rs = [
  96. 'jiance_status' => $jiance,
  97. 'list' => $list,
  98. ];
  99. $this->success(1,$rs);
  100. }
  101. //新增记录
  102. public function job_add(){
  103. $data = [
  104. 'jiance_id' => input('jiance_id',0),
  105. 'project_id' => input('project_id',0),
  106. 'worker_id' => $this->auth->id,
  107. 'weizhi' => input('weizhi',''),
  108. 'number' => input('number',1),
  109. 'hege_status' => input('hege_status',1),
  110. 'result' => input('result',''),
  111. 'images' => input('images',''),
  112. 'createtime' => time(),
  113. ];
  114. Db::name('jiance_joblog')->insertGetId($data);
  115. //检测位置历史
  116. $this->weizhi_history($data['weizhi']);
  117. $this->success();
  118. }
  119. //编辑详情
  120. public function job_info(){
  121. $id = input('id',0);
  122. $info = Db::name('jiance_joblog')->where('id',$id)->find();
  123. $this->success(1,$info);
  124. }
  125. //编辑记录
  126. public function job_edit(){
  127. $id = input('id',0);
  128. $data = [
  129. 'weizhi' => input('weizhi',''),
  130. 'number' => input('number',1),
  131. 'hege_status' => input('hege_status',1),
  132. 'result' => input('result',''),
  133. 'images' => input('images',''),
  134. ];
  135. Db::name('jiance_joblog')->where('id',$id)->update($data);
  136. //检测位置历史
  137. $this->weizhi_history($data['weizhi']);
  138. $this->success();
  139. }
  140. //检测搜索历史,新增一个
  141. private function weizhi_history($weizhi){
  142. if(empty($weizhi)){ return true;}
  143. //查重
  144. $check = Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->where('weizhi',$weizhi)->find();
  145. if($check){ return true;}
  146. //新增
  147. $data = [
  148. 'worker_id' => $this->auth->id,
  149. 'weizhi' => $weizhi,
  150. ];
  151. Db::name('worker_weizhi_history')->insertGetId($data);
  152. //只留20个
  153. $count = Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->count();
  154. if($count > 10){
  155. Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->order('id asc')->limit($count - 10)->delete();
  156. }
  157. }
  158. //删除记录
  159. public function job_del(){
  160. $id = input('id',0);
  161. Db::name('jiance_joblog')->where('id',$id)->delete();
  162. $this->success();
  163. }
  164. //检测位置历史记录
  165. public function history_list(){
  166. $lists = Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->order('id desc')->column('weizhi');
  167. $this->success(1,$lists);
  168. }
  169. }