Jishuguifan.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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,image,createtime')
  23. ->where('company_id',$this->auth->company_id)
  24. ->where('pid',0)
  25. ->order('id' , 'asc')
  26. ->autopage()
  27. ->select();
  28. $list = list_domain_image($list,['image']);
  29. $this->success(1, $list);
  30. }
  31. //二级
  32. public function lists(){
  33. $tid = input('id',0);
  34. $list = Db::name('jishuguifan')->field('id,pid,name,image,ismenu,createtime')
  35. ->where('company_id',$this->auth->company_id)
  36. ->where('tid',$tid)
  37. ->select();
  38. $list = list_domain_image($list,['image']);
  39. $tree = Tree::instance();
  40. $tree->init($list, 'pid');
  41. $tree->icon = ['','',''];
  42. // $tree->icon = ['','',''];
  43. $tree->nbsp = 'nbsp';
  44. $treedata = $tree->getTreeList($tree->getTreeArray($tid), 'name');
  45. /*$result = [];
  46. foreach ($treedata as $k => $v) {
  47. $result[$v['id']] = $v;
  48. }*/
  49. $this->success(1, $treedata);
  50. }
  51. //详情
  52. public function info(){
  53. $id = input('id',0);
  54. $info = Db::name('jishuguifan')
  55. ->where('id',$id)
  56. ->find();
  57. $info = info_domain_image($info,['file','image']);
  58. //上一篇
  59. $up_id = 0;
  60. $up = Db::name('jishuguifan')->where('tid',$info['tid'])->where('ismenu',0)->where('id','<',$info['id'])->order('id desc')->value('id');
  61. if($up){
  62. $up_id = $up;
  63. }
  64. //下一篇
  65. $down_id = 0;
  66. $down = Db::name('jishuguifan')->where('tid',$info['tid'])->where('ismenu',0)->where('id','>',$info['id'])->order('id asc')->value('id');
  67. if($down){
  68. $down_id = $down;
  69. }
  70. $rs = [
  71. 'info' => $info,
  72. 'up_id' => $up_id,
  73. 'down_id' => $down_id,
  74. ];
  75. $this->success(1, $rs);
  76. }
  77. }