Jianceproject.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 = [];
  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')->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'] = 1;
  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. Db::name($this->table)->where('id',$id)->update($data);
  59. $this->success();
  60. }
  61. public function del(){
  62. $ids = input('ids','');
  63. if (empty($ids)) {
  64. $this->error();
  65. }
  66. Db::name($this->table)->where('id',$ids)->where('company_id',$this->auth->company_id)->update(['deletetime'=>time()]);
  67. Db::name($this->table)->where('pid',$ids)->where('company_id',$this->auth->company_id)->update(['deletetime'=>time()]);
  68. $this->success();
  69. }
  70. }