Jishuguifan.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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,image,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. $list = list_domain_image($list,['image']);
  22. $this->success(1,$list);
  23. }
  24. public function add(){
  25. $pid = input('pid',0);
  26. //找到最顶级id
  27. $tid = 0;
  28. if($pid != 0){
  29. $tid = Db::name($this->table)->where('id',$pid)->value('tid');//父级的tid
  30. if($tid == 0){ //父级就是顶级时
  31. $tid = $pid; //顶级=父级
  32. }
  33. }
  34. $data = [
  35. 'company_id' => $this->auth->company_id,
  36. 'pid' => $pid,
  37. 'tid' => $tid,
  38. 'name' => input('name',''),
  39. 'image' => input('image',''),
  40. 'content' => input('content','','htmlspecialchars_decode'),
  41. 'ismenu' => input('ismenu',1),
  42. 'file' => input('file',''),
  43. 'createtime' => time(),
  44. 'updatetime' => time(),
  45. ];
  46. Db::name($this->table)->insertGetId($data);
  47. $this->success();
  48. }
  49. public function info(){
  50. $id = input('id',0);
  51. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  52. $info = info_domain_image($info,['file','image']);
  53. $this->success(1,$info);
  54. }
  55. public function edit(){
  56. $id = input('id',0);
  57. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->find();
  58. if(empty($info)){
  59. $this->error('没找到该信息,请刷新重试');
  60. }
  61. $pid = input('pid',0);
  62. //找到最顶级id
  63. $tid = 0;
  64. if($pid != 0){
  65. $tid = Db::name($this->table)->where('id',$pid)->value('tid');//父级的tid
  66. if($tid == 0){ //父级就是顶级时
  67. $tid = $pid; //顶级=父级
  68. }
  69. }
  70. $data = [
  71. 'pid' => $pid,
  72. 'tid' => $tid,
  73. 'name' => input('name',''),
  74. 'image' => input('image',''),
  75. 'content' => input('content','','htmlspecialchars_decode'),
  76. 'ismenu' => input('ismenu',1),
  77. 'file' => input('file',''),
  78. 'updatetime' => time(),
  79. ];
  80. Db::name($this->table)->where('id',$id)->update($data);
  81. $this->success();
  82. }
  83. public function del(){
  84. $ids = input('ids','');
  85. $ids = explode(',',$ids);
  86. if (empty($ids)) {
  87. $this->error();
  88. }
  89. Db::name($this->table)->where('id','IN',$ids)->where('company_id',$this->auth->company_id)->delete();
  90. $this->success();
  91. }
  92. }