123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace app\api\controller\worker;
- use app\common\controller\Apiw;
- use think\Db;
- use fast\Tree;
- /**
- * 技术规范
- */
- class Jishuguifan extends Apiw
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- //所有一级
- public function index()
- {
- $keyword = input('keyword','');
- $where_search = [];
- if(!empty($keyword)){
- $where_search['name'] = ['LIKE','%'.$keyword.'%'];
- }
- //
- $list = Db::name('jishuguifan')->field('id,name,ismenu,image,createtime')
- ->where('company_id',$this->auth->company_id)
- ->where('pid',0)
- ->order('id' , 'asc')
- ->autopage()
- ->select();
- $list = list_domain_image($list,['image']);
- $this->success(1, $list);
- }
- //二级
- public function lists(){
- $tid = input('id',0);
- $list = Db::name('jishuguifan')->field('id,pid,name,image,ismenu,createtime')
- ->where('company_id',$this->auth->company_id)
- ->where('tid',$tid)
- ->select();
- $list = list_domain_image($list,['image']);
- $tree = Tree::instance();
- $tree->init($list, 'pid');
- // $tree->icon = [' ',' ',' '];
- $tree->icon = [' ',' ',' '];
- $tree->nbsp = ' ';
- $treedata = $tree->getTreeList($tree->getTreeArray($tid), 'name');
- $rs = [
- 'tree' => $treedata,
- 'is_collect' => $this->is_collect($tid,$this->auth->id),
- 'collect_id' => $tid
- ];
- $this->success(1, $rs);
- }
- //详情
- public function info(){
- $id = input('id',0);
- $info = Db::name('jishuguifan')
- ->where('id',$id)
- ->find();
- $info = info_domain_image($info,['file','image']);
- //上一篇
- $up_id = 0;
- $up = Db::name('jishuguifan')->where('tid',$info['tid'])->where('ismenu',0)->where('id','<',$info['id'])->order('id desc')->value('id');
- if($up){
- $up_id = $up;
- }
- //下一篇
- $down_id = 0;
- $down = Db::name('jishuguifan')->where('tid',$info['tid'])->where('ismenu',0)->where('id','>',$info['id'])->order('id asc')->value('id');
- if($down){
- $down_id = $down;
- }
- if($info['tid'] == 0){
- $info['tid'] = $info['id'];
- }
- $rs = [
- 'info' => $info,
- 'is_collect' => $this->is_collect($info['tid'],$this->auth->id),
- 'collect_id' => $info['tid'],
- 'up_id' => $up_id,
- 'down_id' => $down_id,
- ];
- $this->success(1, $rs);
- }
- //下载功能
- public function download(){
- $where = [
- 'worker_id' => $this->auth->id,
- 'table_id' => input('id',0),
- ];
- $check = Db::name('worker_download')->where($where)->find();
- if($check){
- Db::name('worker_download')->where($where)->update(['updatetime'=>time()]);
- $this->success();
- }else{
- $where['updatetime'] = time();
- Db::name('worker_download')->insertGetId($where);
- $this->success();
- }
- }
- //收藏,取消收藏
- public function collect(){
- $where = [
- 'worker_id' => $this->auth->id,
- 'table' => 'jishuguifan',
- 'table_id' => input('id',0),
- ];
- $check = Db::name('worker_collect')->where($where)->find();
- if($check){
- Db::name('worker_collect')->where($where)->delete();
- $this->success('已取消收藏');
- }else{
- Db::name('worker_collect')->insertGetId($where);
- $this->success('收藏成功');
- }
- }
- //动态是否收藏
- private function is_collect($id,$uid){
- $where = [
- 'worker_id' => $uid,
- 'table' => 'jishuguifan',
- 'table_id' => $id,
- ];
- $check = Db::name('worker_collect')->where($where)->find();
- if($check){
- return 1;
- }else{
- return 0;
- }
- }
- }
|