Usercenter.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 Usercenter extends Apiw
  10. {
  11. protected $noNeedLogin = ['collect_list','download_list'];
  12. protected $noNeedRight = ['*'];
  13. public function collect_list(){
  14. $table = input('type','jishuguifan');
  15. //验证表名
  16. $table_name = [
  17. 'jishuguifan',
  18. 'news',
  19. 'caozuoguifan',
  20. ];
  21. if(!in_array($table,$table_name)){
  22. $this->error();
  23. }
  24. //拿收藏的ids
  25. $where = [
  26. 'worker_id' => $this->auth->id,
  27. 'table' => $table,
  28. ];
  29. $table_ids = Db::name('worker_collect')->where($where)->group('table_id')->column('table_id');
  30. if(!empty($table_ids)){
  31. $ids_str = implode(',',$table_ids);
  32. //字段
  33. $table_field = [
  34. 'jishuguifan' => 'id,name,ismenu',
  35. 'news' => 'id,title,image,createtime',
  36. 'caozuoguifan' => 'id,title,image,createtime',
  37. ];
  38. $list = Db::name($table)->field($table_field[$table])
  39. ->where('id','IN',$table_ids)
  40. ->orderRaw('field(id,'.$ids_str.')')
  41. ->autopage()
  42. ->select();
  43. $list = list_domain_image($list,['image']);
  44. }else{
  45. $list = [];
  46. }
  47. $this->success(1, $list);
  48. }
  49. //下载功能
  50. public function download_list(){
  51. $list = Db::name('worker_download')->alias('down')
  52. ->join('jishuguifan j','down.table_id = j.id','LEFT')
  53. ->field('j.id,j.name,j.ismenu,down.updatetime')
  54. ->where('down.worker_id',$this->auth->id)
  55. ->autopage()
  56. ->group('down.table_id')
  57. ->select();
  58. $this->success(1,$list);
  59. }
  60. }