Jishuguifan.php 2.3 KB

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