Jiance.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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',0);
  17. if(!empty($status)){
  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. $lists = Db::name('jiance_project')->field('id,pid,title,type,info')
  36. ->where('company_id',$this->auth->company_id)
  37. ->where('deletetime',NULL)
  38. ->where('id','IN',$info['project_ids'])
  39. ->order('weigh asc')->select();
  40. }
  41. //提交
  42. public function submit(){
  43. }
  44. //记录列表
  45. public function job_list(){
  46. $jiance_id = input('jiance_id',0);
  47. $project_id = input('project_id',0);
  48. $jiance = Db::name('jiance')->field('id,bianhao,status,project_ids')->where('id',$jiance_id)->find();
  49. $list = Db::name('jiance_joblog')->alias('joblog')
  50. ->field('joblog.*,project.title as project_title')
  51. ->join('jiance_project project','joblog.project_id = project.id','LEFT')
  52. ->where('joblog.jiance_id',$jiance_id)
  53. ->where('joblog.project_id',$project_id)
  54. ->select();
  55. $rs = [
  56. '',
  57. '',
  58. ];
  59. $this->success(1,$list);
  60. }
  61. //新增记录
  62. public function job_add(){
  63. $data = [
  64. 'jiance_id' => input('jiance_id',0),
  65. 'project_id' => input('project_id',0),
  66. 'worker_id' => $this->auth->id,
  67. 'weizhi' => input('weizhi',''),
  68. 'number' => input('number',1),
  69. 'hege_status' => input('hege_status',1),
  70. 'result' => input('result',''),
  71. 'images' => input('images',''),
  72. 'createtime' => time(),
  73. ];
  74. Db::name('jiance_joblog')->insertGetId($data);
  75. //检测位置历史
  76. $this->weizhi_history($data['weizhi']);
  77. $this->success();
  78. }
  79. //编辑详情
  80. public function job_info(){
  81. $id = input('id',0);
  82. $info = Db::name('jiance_joblog')->where('id',$id)->find();
  83. $this->success(1,$info);
  84. }
  85. //编辑记录
  86. public function job_edit(){
  87. $id = input('id',0);
  88. $data = [
  89. 'weizhi' => input('weizhi',''),
  90. 'number' => input('number',1),
  91. 'hege_status' => input('hege_status',1),
  92. 'result' => input('result',''),
  93. 'images' => input('images',''),
  94. ];
  95. Db::name('jiance_joblog')->where('id',$id)->update($data);
  96. //检测位置历史
  97. $this->weizhi_history($data['weizhi']);
  98. $this->success();
  99. }
  100. //检测搜索历史,新增一个
  101. private function weizhi_history($weizhi){
  102. if(empty($weizhi)){ return true;}
  103. //查重
  104. $check = Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->where('weizhi',$weizhi)->find();
  105. if($check){ return true;}
  106. //新增
  107. $data = [
  108. 'worker_id' => $this->auth->id,
  109. 'weizhi' => $weizhi,
  110. ];
  111. Db::name('worker_weizhi_history')->insertGetId($data);
  112. //只留20个
  113. $count = Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->count();
  114. if($count > 10){
  115. Db::name('worker_weizhi_history')->where('worker_id',$this->auth->id)->order('id asc')->limit($count - 10)->delete();
  116. }
  117. }
  118. //删除记录
  119. public function job_del(){
  120. $id = input('id',0);
  121. Db::name('jiance_joblog')->where('id',$id)->delete();
  122. $this->success();
  123. }
  124. //检测位置历史记录
  125. public function history_list(){
  126. }
  127. }