Jishuguifan.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace app\company\controller;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. use fast\Tree;
  6. /**
  7. * 技术规范
  8. */
  9. class Jishuguifan extends Apic
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = ['info'];
  13. protected $table = 'jishuguifan';
  14. public function index(){
  15. $list = Db::name($this->table)->field('id,pid,name,createtime')->where('company_id',$this->auth->company_id)->order('id asc')->select();
  16. /*$tree = Tree::instance()->init($list);
  17. $tree->icon = ['','',''];
  18. $tree->nbsp = '';
  19. $tree = $tree->getTreeList($tree->getTreeArray(0),'name');
  20. $this->success(1,$tree);*/
  21. $this->success(1,$list);
  22. }
  23. public function add(){
  24. $pid = input('pid',0);
  25. //找到最顶级id
  26. $tid = 0;
  27. if($pid != 0){
  28. $tid = Db::name($this->table)->where('id',$pid)->value('tid');//父级的tid
  29. if($tid == 0){ //父级就是顶级时
  30. $tid = $pid; //顶级=父级
  31. }
  32. }
  33. $data = [
  34. 'company_id' => $this->auth->company_id,
  35. 'pid' => $pid,
  36. 'tid' => $tid,
  37. 'name' => input('name',''),
  38. 'content' => input('content','','htmlspecialchars_decode'),
  39. 'ismenu' => input('ismenu',1),
  40. 'file' => input('file',''),
  41. 'createtime' => time(),
  42. 'updatetime' => time(),
  43. ];
  44. Db::name($this->table)->insertGetId($data);
  45. $this->success();
  46. }
  47. public function info(){
  48. $id = input('id',0);
  49. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  50. $info = info_domain_image($info,['file']);
  51. $this->success(1,$info);
  52. }
  53. public function edit(){
  54. $id = input('id',0);
  55. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  56. if(empty($info)){
  57. $this->error('没找到该信息,请刷新重试');
  58. }
  59. $pid = input('pid',0);
  60. //找到最顶级id
  61. $tid = 0;
  62. if($pid != 0){
  63. $tid = Db::name($this->table)->where('id',$pid)->value('tid');//父级的tid
  64. if($tid == 0){ //父级就是顶级时
  65. $tid = $pid; //顶级=父级
  66. }
  67. }
  68. $data = [
  69. 'pid' => $pid,
  70. 'tid' => $tid,
  71. 'name' => input('name',''),
  72. 'content' => input('content','','htmlspecialchars_decode'),
  73. 'ismenu' => input('ismenu',1),
  74. 'file' => input('file',''),
  75. 'updatetime' => time(),
  76. ];
  77. Db::name($this->table)->where('id',$id)->update($data);
  78. $this->success();
  79. }
  80. public function del(){
  81. $ids = input('ids','');
  82. $ids = explode(',',$ids);
  83. if (empty($ids)) {
  84. $this->error();
  85. }
  86. Db::name($this->table)->where('id','IN',$ids)->where('company_id',$this->auth->company_id)->delete();
  87. $this->success();
  88. }
  89. }