General.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\PlatformSwitch;
  4. use app\common\model\UserSearch;
  5. /**
  6. * @title 其他接口
  7. * @controller General
  8. * @group base
  9. */
  10. class General extends Base
  11. {
  12. public function initialize()
  13. {
  14. parent::initialize();
  15. parent::checkLogin();
  16. }
  17. /**
  18. * @title 用户搜索历史
  19. * @desc 用户搜索历史
  20. * @author qc
  21. * @method GET
  22. * @url /api/General/getSearchHistory
  23. * @header name:Authorization require:1 desc:Token
  24. * @param name:page type:int default:0 desc:页数
  25. * @param name:page_num type:int default:20 desc:每页数
  26. * @param name:type type:int default:-- desc:类型0=>"全部",1=>'视频',2=>'图文',3=>'资料',4=>'新闻',5=>'需求',6=>'问答',7=>'商品',8=>'招聘',9=>'供应商',10=>'供应商产品',
  27. * @return name:title type:string default:-- desc:标题
  28. * @return name:type type:int default:-- desc:类型0全局,1视频,2图文,3资料,4新闻,5需求
  29. */
  30. public function getSearchHistory()
  31. {
  32. $title = input('title');
  33. $type= input('type',-1);
  34. $where= [];
  35. $where [] = ['user_id','=',$this->user_id];
  36. if($title)$where [] = ['title','like','%'.$title.'%'];
  37. if($type > -1)$where [] = ['type','=',$type];
  38. $list = UserSearch::where($where)
  39. ->limit($this->off_set,$this->page_num)
  40. ->order('create_at desc,id desc')
  41. ->select()->toArray();
  42. $this->success('ok',['list'=>$list]);
  43. }
  44. /**
  45. * @title 删除||清空搜索历史
  46. * @desc 删除||清空搜索历史
  47. * @author qc
  48. * @method POST
  49. * @url /api/General/delSearchHistory
  50. * @header name:Authorization require:1 desc:Token
  51. * @param name:id type:int default:0 desc:搜索记录id【不传值清空所有搜索记录】
  52. */
  53. public function delSearchHistory()
  54. {
  55. $id = input('post.id');
  56. $where= [];
  57. $where [] = ['user_id','=',$this->user_id];
  58. if($id)$where [] = ['id','=',$id];
  59. UserSearch::where($where)->delete();
  60. $this->success('删除成功');
  61. }
  62. /**
  63. * @title 以下接口为二期需求
  64. * @desc 以下接口为二期需求
  65. * @author qc
  66. * @url /api/General/secondPhase
  67. * @method
  68. * @return name:1 type:string default:-- desc:以下接口为二期需求
  69. */
  70. public function secondPhase(){}
  71. /**
  72. * @title 开关设置
  73. * @desc 【追更开关】
  74. * @author qc
  75. * @method POST
  76. * @url /api/General/switchSet
  77. * @header name:Authorization require:1 desc:Token
  78. * @param name:id type:int require:1 default:-- desc:记录id
  79. * @param name:type type:int require:1 default:-- desc:类型【1=>'问答通知开关',2=>'视频追更',3=>'图文追更',4=>'资料追更',5=>'供应商追更',6=>'招聘追更'】
  80. */
  81. public function switchSet()
  82. {
  83. $switch_status = PlatformSwitch::userSwitch($this->user_id,input('post.id',0),input('post.type',0));
  84. $switch_status ? $this->success('开启成功',['status'=>1]) : $this->success('关闭成功',['status'=>0]);
  85. }
  86. }