Jiance.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. $this->success(1,$top);
  71. }
  72. //提交
  73. public function submit(){
  74. $id = input('id',0);
  75. Db::name('jiance')->where('id',$id)->where('company_id',$this->auth->company_id)->update(['status'=>1]);
  76. $this->success();
  77. }
  78. //记录列表
  79. public function job_list(){
  80. $jiance_id = input('jiance_id',0);
  81. $project_id = input('project_id',0);
  82. $jiance = Db::name('jiance')->where('id',$jiance_id)->value('status');
  83. $list = Db::name('jiance_joblog')->alias('joblog')
  84. ->field('joblog.*,project.title as project_title')
  85. ->join('jiance_project project','joblog.project_id = project.id','LEFT')
  86. ->where('joblog.jiance_id',$jiance_id)
  87. ->where('joblog.project_id',$project_id)
  88. ->order('joblog.id desc')
  89. ->select();
  90. $rs = [
  91. 'jiance_status' => $jiance,
  92. 'list' => $list,
  93. ];
  94. $this->success(1,$rs);
  95. }
  96. //新增记录
  97. public function job_add(){
  98. $data = [
  99. 'jiance_id' => input('jiance_id',0),
  100. 'project_id' => input('project_id',0),
  101. 'worker_id' => $this->auth->id,
  102. 'weizhi' => input('weizhi',''),
  103. 'number' => input('number',1),
  104. 'hege_status' => input('hege_status',1),
  105. 'result' => input('result',''),
  106. 'images' => input('images',''),
  107. 'createtime' => time(),
  108. ];
  109. Db::name('jiance_joblog')->insertGetId($data);
  110. //检测位置历史
  111. $this->weizhi_history($data['weizhi']);
  112. $this->success();
  113. }
  114. //编辑详情
  115. public function job_info(){
  116. $id = input('id',0);
  117. $info = Db::name('jiance_joblog')->where('id',$id)->find();
  118. $this->success(1,$info);
  119. }
  120. //编辑记录
  121. public function job_edit(){
  122. $id = input('id',0);
  123. $data = [
  124. 'weizhi' => input('weizhi',''),
  125. 'number' => input('number',1),
  126. 'hege_status' => input('hege_status',1),
  127. 'result' => input('result',''),
  128. 'images' => input('images',''),
  129. ];
  130. Db::name('jiance_joblog')->where('id',$id)->update($data);
  131. //检测位置历史
  132. $this->weizhi_history($data['weizhi']);
  133. $this->success();
  134. }
  135. //检测搜索历史,新增一个
  136. private function weizhi_history($weizhi){
  137. if(empty($weizhi)){ return true;}
  138. //查重
  139. $check = Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->where('weizhi',$weizhi)->find();
  140. if($check){ return true;}
  141. //新增
  142. $data = [
  143. 'worker_id' => $this->auth->id,
  144. 'weizhi' => $weizhi,
  145. ];
  146. Db::name('worker_weizhi_history')->insertGetId($data);
  147. //只留20个
  148. $count = Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->count();
  149. if($count > 20){
  150. Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->order('id asc')->limit($count - 20)->delete();
  151. }
  152. }
  153. //删除记录
  154. public function job_del(){
  155. $id = input('id',0);
  156. Db::name('jiance_joblog')->where('id',$id)->delete();
  157. $this->success();
  158. }
  159. //检测位置历史记录
  160. public function history_list(){
  161. $lists = Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->order('id desc')->column('weizhi');
  162. $this->success(1,$lists);
  163. }
  164. }