Jishuguifan.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\api\controller\worker;
  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')
  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. /*$result = [];
  43. foreach ($treedata as $k => $v) {
  44. $result[$v['id']] = $v;
  45. }*/
  46. $this->success(1, $treedata);
  47. }
  48. //详情
  49. public function info(){
  50. $id = input('id',0);
  51. $info = Db::name('jishuguifan')
  52. ->where('id',$id)
  53. ->find();
  54. //收藏
  55. $info['is_collect'] = $this->is_collect($info['id'],$this->auth->id);
  56. //上一篇
  57. $up_id = 0;
  58. $up = Db::name('jishuguifan')->where('pid',$info['pid'])->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('pid',$info['pid'])->where('ismenu',0)->where('id','>',$info['id'])->order('id asc')->value('id');
  65. if($down){
  66. $down_id = $down;
  67. }
  68. $rs = [
  69. 'info' => $info,
  70. 'up_id' => $up_id,
  71. 'down_id' => $down_id,
  72. ];
  73. $this->success(1, $rs);
  74. }
  75. //下载功能
  76. public function download(){
  77. $where = [
  78. 'worker_id' => $this->auth->id,
  79. 'table_id' => input('id',0),
  80. ];
  81. $check = Db::name('worker_download')->where($where)->find();
  82. if($check){
  83. Db::name('worker_download')->where($where)->update(['updatetime'=>time()]);
  84. $this->success();
  85. }else{
  86. $where['updatetime'] = time();
  87. Db::name('worker_download')->insertGetId($where);
  88. $this->success();
  89. }
  90. }
  91. //收藏,取消收藏
  92. public function collect(){
  93. $where = [
  94. 'worker_id' => $this->auth->id,
  95. 'table' => 'jishuguifan',
  96. 'table_id' => input('id',0),
  97. ];
  98. $check = Db::name('worker_collect')->where($where)->find();
  99. if($check){
  100. Db::name('worker_collect')->where($where)->delete();
  101. $this->success('已取消收藏');
  102. }else{
  103. Db::name('worker_collect')->insertGetId($where);
  104. $this->success('收藏成功');
  105. }
  106. }
  107. //动态是否收藏
  108. private function is_collect($id,$uid){
  109. $where = [
  110. 'worker_id' => $uid,
  111. 'table' => 'jishuguifan',
  112. 'table_id' => $id,
  113. ];
  114. $check = Db::name('worker_collect')->where($where)->find();
  115. if($check){
  116. return 1;
  117. }else{
  118. return 0;
  119. }
  120. }
  121. }