Jishuguifan.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. ->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 = ['&nbsp;&nbsp;&nbsp;&nbsp;','&nbsp;&nbsp;&nbsp;&nbsp;','&nbsp;&nbsp;&nbsp;&nbsp;'];
  41. $tree->icon = [' ',' ',' '];
  42. $tree->nbsp = ' ';
  43. $treedata = $tree->getTreeList($tree->getTreeArray($tid), 'name');
  44. $rs = [
  45. 'tree' => $treedata,
  46. 'is_collect' => $this->is_collect($tid,$this->auth->id),
  47. 'collect_id' => $tid
  48. ];
  49. $this->success(1, $rs);
  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. if($info['tid'] == 0){
  71. $info['tid'] = $info['id'];
  72. }
  73. $rs = [
  74. 'info' => $info,
  75. 'is_collect' => $this->is_collect($info['tid'],$this->auth->id),
  76. 'collect_id' => $info['tid'],
  77. 'up_id' => $up_id,
  78. 'down_id' => $down_id,
  79. ];
  80. $this->success(1, $rs);
  81. }
  82. //下载功能
  83. public function download(){
  84. $where = [
  85. 'worker_id' => $this->auth->id,
  86. 'table_id' => input('id',0),
  87. ];
  88. $check = Db::name('worker_download')->where($where)->find();
  89. if($check){
  90. Db::name('worker_download')->where($where)->update(['updatetime'=>time()]);
  91. $this->success();
  92. }else{
  93. $where['updatetime'] = time();
  94. Db::name('worker_download')->insertGetId($where);
  95. $this->success();
  96. }
  97. }
  98. //收藏,取消收藏
  99. public function collect(){
  100. $where = [
  101. 'worker_id' => $this->auth->id,
  102. 'table' => 'jishuguifan',
  103. 'table_id' => input('id',0),
  104. ];
  105. $check = Db::name('worker_collect')->where($where)->find();
  106. if($check){
  107. Db::name('worker_collect')->where($where)->delete();
  108. $this->success('已取消收藏');
  109. }else{
  110. Db::name('worker_collect')->insertGetId($where);
  111. $this->success('收藏成功');
  112. }
  113. }
  114. //动态是否收藏
  115. private function is_collect($id,$uid){
  116. $where = [
  117. 'worker_id' => $uid,
  118. 'table' => 'jishuguifan',
  119. 'table_id' => $id,
  120. ];
  121. $check = Db::name('worker_collect')->where($where)->find();
  122. if($check){
  123. return 1;
  124. }else{
  125. return 0;
  126. }
  127. }
  128. }