Jianceproject.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\company\controller;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. /**
  6. * 检测下发
  7. */
  8. class Jianceproject extends Apic
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['info'];
  12. protected $table = 'jiance_project';
  13. //检测项目,父+子,一次给出
  14. public function index(){
  15. $lists = Db::name('jiance_project')->field('id,pid as parentId,title,createtime')
  16. ->where('company_id',$this->auth->company_id)
  17. ->where('deletetime',NULL)->order('weigh asc,id asc')->select();
  18. $this->success(1,$lists);
  19. }
  20. public function add(){
  21. $data = [
  22. 'company_id' => $this->auth->company_id,
  23. 'pid' => input('pid',0),
  24. 'title' => input('title',''),
  25. 'type' => input('type',1),
  26. 'info' => input('info',''),
  27. 'weigh' => input('weigh',0),
  28. 'createtime' => time(),
  29. ];
  30. if($data['pid'] == 0){
  31. $data['info'] = '';
  32. $data['type'] = 0;
  33. }
  34. $id = Db::name($this->table)->insertGetId($data);
  35. if($data['weigh'] == 0){
  36. Db::name($this->table)->where('id',$id)->update(['weigh'=>$id]);
  37. }
  38. $this->success();
  39. }
  40. public function info(){
  41. $id = input('id',0);
  42. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->where('deletetime',NULL)->find();
  43. $this->success(1,$info);
  44. }
  45. public function edit(){
  46. $id = input('id',0);
  47. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->where('deletetime',NULL)->find();
  48. if(empty($info)){
  49. $this->error('没找到该信息,请刷新重试');
  50. }
  51. //
  52. $data = [
  53. 'title' => input('title',''),
  54. 'type' => input('type',1),
  55. 'info' => input('info',''),
  56. 'weigh' => input('weigh',$id),
  57. ];
  58. if($info['pid'] == 0){
  59. $data['info'] = '';
  60. $data['type'] = 0;
  61. }
  62. Db::name($this->table)->where('id',$id)->update($data);
  63. $this->success();
  64. }
  65. public function del(){
  66. $ids = input('ids','');
  67. if (empty($ids)) {
  68. $this->error();
  69. }
  70. Db::name($this->table)->where('id',$ids)->where('company_id',$this->auth->company_id)->update(['deletetime'=>time()]);
  71. Db::name($this->table)->where('pid',$ids)->where('company_id',$this->auth->company_id)->update(['deletetime'=>time()]);
  72. $this->success();
  73. }
  74. }