Jishuguifan.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace app\api\controller\worker;
  3. use app\common\controller\Apiw;
  4. use think\Db;
  5. use fast\Tree;
  6. /**
  7. * 技术规范
  8. */
  9. class Jishuguifan extends Apiw
  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 = ['&nbsp;&nbsp;&nbsp;&nbsp;','&nbsp;&nbsp;&nbsp;&nbsp;','&nbsp;&nbsp;&nbsp;&nbsp;'];
  42. $tree->icon = [' ',' ',' '];
  43. $tree->nbsp = ' ';
  44. $treedata = $tree->getTreeList($tree->getTreeArray($tid), 'name');
  45. $rs = [
  46. 'tree' => $treedata,
  47. 'is_collect' => $this->is_collect($tid,$this->auth->id),
  48. 'collect_id' => $tid
  49. ];
  50. $this->success(1, $rs);
  51. }
  52. //详情
  53. public function info(){
  54. $id = input('id',0);
  55. $info = Db::name('jishuguifan')
  56. ->where('id',$id)
  57. ->find();
  58. $info = info_domain_image($info,['file','image']);
  59. //上一篇
  60. $up_id = 0;
  61. $up = Db::name('jishuguifan')->where('tid',$info['tid'])->where('ismenu',0)->where('id','<',$info['id'])->order('id desc')->value('id');
  62. if($up){
  63. $up_id = $up;
  64. }
  65. //下一篇
  66. $down_id = 0;
  67. $down = Db::name('jishuguifan')->where('tid',$info['tid'])->where('ismenu',0)->where('id','>',$info['id'])->order('id asc')->value('id');
  68. if($down){
  69. $down_id = $down;
  70. }
  71. if($info['tid'] == 0){
  72. $info['tid'] = $info['id'];
  73. }
  74. $rs = [
  75. 'info' => $info,
  76. 'is_collect' => $this->is_collect($info['tid'],$this->auth->id),
  77. 'collect_id' => $info['tid'],
  78. 'up_id' => $up_id,
  79. 'down_id' => $down_id,
  80. ];
  81. $this->success(1, $rs);
  82. }
  83. //下载功能
  84. public function download(){
  85. $where = [
  86. 'worker_id' => $this->auth->id,
  87. 'table_id' => input('id',0),
  88. ];
  89. $check = Db::name('worker_download')->where($where)->find();
  90. if($check){
  91. Db::name('worker_download')->where($where)->update(['updatetime'=>time()]);
  92. $this->success();
  93. }else{
  94. $where['updatetime'] = time();
  95. Db::name('worker_download')->insertGetId($where);
  96. $this->success();
  97. }
  98. }
  99. //收藏,取消收藏
  100. public function collect(){
  101. $where = [
  102. 'worker_id' => $this->auth->id,
  103. 'table' => 'jishuguifan',
  104. 'table_id' => input('id',0),
  105. ];
  106. $check = Db::name('worker_collect')->where($where)->find();
  107. if($check){
  108. Db::name('worker_collect')->where($where)->delete();
  109. $this->success('已取消收藏');
  110. }else{
  111. Db::name('worker_collect')->insertGetId($where);
  112. $this->success('收藏成功');
  113. }
  114. }
  115. //动态是否收藏
  116. private function is_collect($id,$uid){
  117. $where = [
  118. 'worker_id' => $uid,
  119. 'table' => 'jishuguifan',
  120. 'table_id' => $id,
  121. ];
  122. $check = Db::name('worker_collect')->where($where)->find();
  123. if($check){
  124. return 1;
  125. }else{
  126. return 0;
  127. }
  128. }
  129. }