Jishuguifan.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use fast\Tree;
  6. /**
  7. * 技术规范
  8. */
  9. class Jishuguifan extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. //所有一级
  14. public function index()
  15. {
  16. $keyword = input('keyword','');
  17. $where_search = [];
  18. if(!empty($keyword)){
  19. $where_search['name'] = ['LIKE','%'.$keyword.'%'];
  20. }
  21. //
  22. $list = Db::name('jishuguifan')->field('id,name,ismenu')
  23. ->where('company_id',$this->auth->company_id)
  24. ->where('pid',0)
  25. ->order('id' , 'asc')
  26. ->select();
  27. $this->success(1, $list);
  28. }
  29. //二级
  30. public function lists(){
  31. $tid = input('id',0);
  32. $list = Db::name('jishuguifan')->field('id,pid,name,ismenu')
  33. ->where('company_id',$this->auth->company_id)
  34. ->where('tid',$tid)
  35. ->select();
  36. $tree = Tree::instance();
  37. $tree->init($list, 'pid');
  38. $tree->icon = ['','',''];
  39. // $tree->icon = ['','',''];
  40. $tree->nbsp = 'nbsp';
  41. $treedata = $tree->getTreeList($tree->getTreeArray($tid), 'name');
  42. /*$result = [];
  43. foreach ($treedata as $k => $v) {
  44. $result[$v['id']] = $v;
  45. }*/
  46. $this->success(1, $treedata);
  47. }
  48. //详情
  49. public function info(){
  50. $id = input('id',0);
  51. $info = Db::name('jishuguifan')
  52. ->where('id',$id)
  53. ->find();
  54. $info = info_domain_image($info,['file']);
  55. //上一篇
  56. $up_id = 0;
  57. $up = Db::name('jishuguifan')->where('tid',$info['tid'])->where('ismenu',0)->where('id','<',$info['id'])->order('id desc')->value('id');
  58. if($up){
  59. $up_id = $up;
  60. }
  61. //下一篇
  62. $down_id = 0;
  63. $down = Db::name('jishuguifan')->where('tid',$info['tid'])->where('ismenu',0)->where('id','>',$info['id'])->order('id asc')->value('id');
  64. if($down){
  65. $down_id = $down;
  66. }
  67. $rs = [
  68. 'info' => $info,
  69. 'up_id' => $up_id,
  70. 'down_id' => $down_id,
  71. ];
  72. $this->success(1, $rs);
  73. }
  74. }