General.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\PlatformSwitch;
  4. use app\common\model\UserSearch;
  5. use app\common\model\UserTrack;
  6. /**
  7. * @title 其他接口(需要登录状态)【多模块共用】
  8. * @controller General
  9. * @group base
  10. */
  11. class General extends Base
  12. {
  13. protected $need_login = [
  14. 'delSearchHistory',
  15. 'switchSet',
  16. 'batchDelSwitch',
  17. 'delTrack',
  18. ];
  19. public function initialize()
  20. {
  21. parent::initialize();
  22. parent::setUid();
  23. }
  24. /**
  25. * @title 用户搜索历史
  26. * @desc 用户搜索历史
  27. * @author qc
  28. * @method GET
  29. * @url /api/General/getSearchHistory
  30. * @header name:Authorization require:1 desc:Token
  31. * @param name:page type:int default:1 desc:页数
  32. * @param name:page_num type:int default:20 desc:每页数
  33. * @param name:type type:int default:-- desc:类型0=>"全部",1=>'视频',2=>'资料',3=>'图文',4=>'新闻',5=>'问答',6=>'商品',7=>'活动',8=>'招聘',9=>'供应商',10=>'供应商商品',11=>'需求'
  34. * @return name:title type:string default:-- desc:标题
  35. * @return name:type type:int default:-- desc:类型0全局,1视频,2图文,3资料,4新闻,5需求
  36. */
  37. public function getSearchHistory()
  38. {
  39. $title = input('title');
  40. $type= input('type',-1);
  41. $where= [];
  42. $where [] = ['user_id','=',$this->user_id];
  43. if($title)$where [] = ['title','like','%'.$title.'%'];
  44. if($type > -1)$where [] = ['type','=',$type];
  45. $list = UserSearch::where($where)
  46. ->limit($this->off_set,$this->page_num)
  47. ->order('create_at desc,id desc')
  48. ->select()->toArray();
  49. $this->success('ok',['list'=>$list]);
  50. }
  51. /**
  52. * @title 删除||清空搜索历史
  53. * @desc 删除||清空搜索历史
  54. * @author qc
  55. * @method POST
  56. * @url /api/General/delSearchHistory
  57. * @header name:Authorization require:1 desc:Token
  58. * @param name:id type:string default:0 desc:搜索记录id【不传值清空所有搜索记录】
  59. */
  60. public function delSearchHistory()
  61. {
  62. $id = input('post.id');
  63. $where= [];
  64. $where [] = ['user_id','=',$this->user_id];
  65. if($id)$where [] = ['id','in',$id];
  66. UserSearch::where($where)->delete();
  67. $this->success('删除成功');
  68. }
  69. /**
  70. * @title 以下接口为二期需求
  71. * @desc 以下接口为二期需求
  72. * @author qc
  73. * @url /api/General/secondPhase
  74. * @method
  75. * @return name:1 type:string default:-- desc:以下接口为二期需求
  76. */
  77. public function secondPhase(){}
  78. /**
  79. * @title 开关设置【详情页设置】
  80. * @desc 【追更开关】
  81. * @author qc
  82. * @method POST
  83. * @url /api/General/switchSet
  84. * @header name:Authorization require:1 desc:Token
  85. * @param name:id type:int require:1 default:-- desc:记录id【招聘订阅的是第三级分类id】
  86. * @param name:type type:int require:1 default:-- desc:类型【1=>'问答通知开关',2=>'视频追更',3=>'图文追更',4=>'资料追更',5=>'供应商订阅',6=>'招聘订阅',7=>'视频通知开关',8=>图文通知开关,9=>资料通知开关,10=>新闻通知,11=>供应商通知,12=>需求通知】
  87. * @return name:status type:int default:1 desc:1开启0关闭
  88. */
  89. public function switchSet()
  90. {
  91. $switch_status = PlatformSwitch::userSwitch($this->user_id,input('post.id',0),input('post.type',0));
  92. $switch_status ? $this->success('开启成功',['status'=>1]) : $this->success('关闭成功',['status'=>0]);
  93. }
  94. /**
  95. * @title 批量取消追更【所有模块共用】
  96. * @desc 批量取消追更
  97. * @author qc
  98. * @method POST
  99. * @url /api/General/batchDelSwitch
  100. * @header name:Authorization require:1 desc:Token
  101. * @param name:ids type:string require:1 default:-- desc:追更记录id(多个逗号隔开)
  102. */
  103. public function batchDelSwitch()
  104. {
  105. $ids = input('post.ids');
  106. PlatformSwitch::where('user_id',$this->user_id)->where('id','in',$ids)->delete();
  107. $this->success('取消成功');
  108. }
  109. /**
  110. * @title 批量删除学习历史(浏览记录)【所有模块共用】
  111. * @desc 批量删除学习历史
  112. * @author qc
  113. * @method POST
  114. * @url /api/General/delTrack
  115. * @header name:Authorization require:1 desc:Token
  116. * @param name:ids type:string require:1 default:-- desc:浏览记录id(多个逗号隔开)
  117. */
  118. public function delTrack()
  119. {
  120. UserTrack::delUserTrack($this->user_id,input('post.ids'));
  121. $this->success('删除成功');
  122. }
  123. }