Jishuguifan.php 3.9 KB

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