General.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\LabelMessage;
  4. use app\common\model\PlatformSwitch;
  5. use app\common\model\User;
  6. use app\common\model\UserMessage;
  7. use app\common\model\UserSearch;
  8. use app\common\model\UserTag;
  9. use app\common\model\UserTrack;
  10. use think\Db;
  11. /**
  12. * @title 其他接口(需要登录状态)【多模块共用】
  13. * @controller General
  14. * @group base
  15. */
  16. class General extends Base
  17. {
  18. protected $need_login = [
  19. 'delSearchHistory',
  20. 'switchSet',
  21. 'batchDelSwitch',
  22. 'delTrack',
  23. 'label'
  24. ];
  25. public function initialize()
  26. {
  27. parent::initialize();
  28. parent::setUid();
  29. }
  30. /**
  31. * @title 用户搜索历史
  32. * @desc 用户搜索历史
  33. * @author qc
  34. * @method GET
  35. * @url /api/General/getSearchHistory
  36. * @header name:Authorization require:1 desc:Token
  37. * @param name:page type:int default:1 desc:页数
  38. * @param name:page_num type:int default:20 desc:每页数
  39. * @param name:type type:int default:-- desc:类型0=>"全部",1=>'视频',2=>'资料',3=>'图文',4=>'新闻',5=>'问答',6=>'商品',7=>'活动',8=>'招聘',9=>'供应商',10=>'供应商商品',11=>'需求'
  40. * @return name:title type:string default:-- desc:标题
  41. * @return name:type type:int default:-- desc:类型0全局,1视频,2图文,3资料,4新闻,5需求
  42. */
  43. public function getSearchHistory()
  44. {
  45. $title = input('title');
  46. $type= input('type',-1);
  47. $where= [];
  48. $where [] = ['user_id','=',$this->user_id];
  49. if($title)$where [] = ['title','like','%'.$title.'%'];
  50. if($type > -1)$where [] = ['type','=',$type];
  51. $list = UserSearch::where($where)
  52. ->limit($this->off_set,$this->page_num)
  53. ->order('create_at desc,id desc')
  54. ->select()->toArray();
  55. $this->success('ok',['list'=>$list]);
  56. }
  57. /**
  58. * @title 删除||清空搜索历史
  59. * @desc 删除||清空搜索历史
  60. * @author qc
  61. * @method POST
  62. * @url /api/General/delSearchHistory
  63. * @header name:Authorization require:1 desc:Token
  64. * @param name:id type:string default:0 desc:搜索记录id【不传值清空所有搜索记录】
  65. */
  66. public function delSearchHistory()
  67. {
  68. $id = input('post.id');
  69. $where= [];
  70. $where [] = ['user_id','=',$this->user_id];
  71. if($id)$where [] = ['id','in',$id];
  72. UserSearch::where($where)->delete();
  73. $this->success('删除成功');
  74. }
  75. /**
  76. * @title 以下接口为二期需求
  77. * @desc 以下接口为二期需求
  78. * @author qc
  79. * @url /api/General/secondPhase
  80. * @method
  81. * @return name:1 type:string default:-- desc:以下接口为二期需求
  82. */
  83. public function secondPhase(){}
  84. /**
  85. * @title 开关设置【详情页设置】
  86. * @desc 【追更开关】
  87. * @author qc
  88. * @method POST
  89. * @url /api/General/switchSet
  90. * @header name:Authorization require:1 desc:Token
  91. * @param name:id type:int require:1 default:-- desc:记录id【招聘订阅的是第三级分类id】
  92. * @param name:type type:int require:1 default:-- desc:类型【1=>'问答通知开关',2=>'视频追更',3=>'图文追更',4=>'资料追更',5=>'供应商订阅',6=>'招聘订阅',7=>'视频通知开关',8=>图文通知开关,9=>资料通知开关,10=>新闻通知,11=>供应商通知,12=>需求通知】
  93. * @return name:status type:int default:1 desc:1开启0关闭
  94. */
  95. public function switchSet()
  96. {
  97. $switch_status = PlatformSwitch::userSwitch($this->user_id,input('post.id',0),input('post.type',0));
  98. $switch_status ? $this->success('开启成功',['status'=>1]) : $this->success('关闭成功',['status'=>0]);
  99. }
  100. /**
  101. * @title 批量取消追更【所有模块共用】
  102. * @desc 批量取消追更
  103. * @author qc
  104. * @method POST
  105. * @url /api/General/batchDelSwitch
  106. * @header name:Authorization require:1 desc:Token
  107. * @param name:ids type:string require:1 default:-- desc:追更记录id(多个逗号隔开)
  108. */
  109. public function batchDelSwitch()
  110. {
  111. $ids = input('post.ids');
  112. PlatformSwitch::where('user_id',$this->user_id)->where('id','in',$ids)->delete();
  113. $this->success('取消成功');
  114. }
  115. /**
  116. * @title 批量删除学习历史(浏览记录)【所有模块共用】
  117. * @desc 批量删除学习历史
  118. * @author qc
  119. * @method POST
  120. * @url /api/General/delTrack
  121. * @header name:Authorization require:1 desc:Token
  122. * @param name:ids type:string require:1 default:-- desc:浏览记录id(多个逗号隔开)
  123. */
  124. public function delTrack()
  125. {
  126. UserTrack::delUserTrack($this->user_id,input('post.ids'));
  127. $this->success('删除成功');
  128. }
  129. /**
  130. * @title 用户绑定智能标签
  131. * @desc 用户绑定智能标签
  132. * @author qc
  133. * @url /api/General/label
  134. * @method POST
  135. * @param name:label type:varchar default:-- desc:标签--多个标签用,隔开
  136. */
  137. public function label($label = ''){
  138. $data = input();
  139. $uid = $this->user_id;
  140. // $label = explode(',',$data['label']);
  141. if(isset($data['label']) && $data['label'] != '' && $data['label'] != null){
  142. $label = $data['label'];
  143. }
  144. if($label != '' && $label != null){
  145. $label = explode(',',$label);
  146. foreach ($label as $k => $v){
  147. $find = Db::name('user_label')->where('user_id',$uid)->where('label',$v)->find();
  148. if($find){
  149. Db::name('user_label')->where('user_id',$uid)->where('label',$v)->setInc('num');
  150. }else{
  151. $arr = [
  152. 'user_id' => $uid,
  153. 'label' => $v,
  154. 'num' => 1,
  155. 'create_at' => date('Y-m-d H:i:s'),
  156. ];
  157. Db::name('user_label')->insert($arr);
  158. }
  159. }
  160. }
  161. // $this->success('操作成功');
  162. }
  163. /**
  164. * @title 获取信息列表-推送
  165. * @desc 获取信息列表-推送
  166. * @author qc
  167. * @url /api/General/getUserMessage
  168. * @method POST
  169. * @param name:page type:int default:-- desc:分页页数
  170. * @param name:limit type:int default:-- desc:每页查询数量
  171. * @return name:create_at type:datetime default:1 desc:创建时间
  172. * @return name:content type:string default:20 desc:消息内容
  173. * @return name:label_id type:string default:20 desc:0
  174. * @return name:jg_status type:string default:20 desc:推送状态0未推送1已推送
  175. * @return name:label type:string default:-- desc:标签
  176. * @return name:type type:string default:-- desc:1会员标签2搜索历史3模块详情4智能标签
  177. * @return name:module type:string default:-- desc:模块video=>视频,article=>图文,datum=>资料,goods=>商城商品,press=>新闻,supplier_goods=>供应商商品,demand=>需求,recruit=>招聘,forum=>问答,activity=>活动
  178. * @return name:first_id type:string default:-- desc:系列id
  179. * @return name:second_id type:string default:-- desc:详情id
  180. * @return name:title type:string default:-- desc:标题
  181. * @return name:is_regular type:string default:-- desc:是否定时
  182. * @return name:push_time type:string default:-- desc:定时时间
  183. * @return name:fs_time type:string default:-- desc:发送时间
  184. *
  185. */
  186. public function getUserMessage(){
  187. $uid = $this->user_id;
  188. $page = input('page');
  189. $limit = input('limit');
  190. if(!$page){
  191. $page = 1;
  192. }
  193. if(!$limit){
  194. $limit = 20;
  195. }
  196. $page_e = ($page * $limit);
  197. $page_k = (($page * $limit) - $limit);
  198. $lists = [];
  199. $list = LabelMessage::where('jg_status',1)->order('push_time desc,create_at desc')->select()->toArray();
  200. $lists = $list;
  201. $select = [];
  202. $sort = [];
  203. foreach ($lists as $k => $v){
  204. if($v['label']) {
  205. if($v['type'] == 3){
  206. $label_arr = explode(',',$v['label']);
  207. $where_str = '';
  208. $search_arr=[];
  209. $tag_arr = [];
  210. foreach ($label_arr as $t){
  211. $search_arr[] = " title like '".'%'.$t."%'" .' ';
  212. $tag_arr[] = $t;
  213. }
  214. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  215. $tags = UserTag::where('title','in',$tag_arr)->column('id');
  216. $user = User::where('label','<>',null)->where('id',$uid)->where('label','<>','||')->where('is_deleted',0)->field('id,label')->find();
  217. $label = explode('|',$user['label']);
  218. if (array_search($label, $tags) == false) {
  219. unset($lists[$k]);
  220. }else{
  221. $select[] = $v;
  222. if($v['is_regular'] == 0){
  223. $v['fs_time'] = $v['push_time'];
  224. $sort[] = $v['push_time'];
  225. }else{
  226. $v['fs_time'] = $v['create_at'];
  227. $sort[] = $v['create_at'];
  228. }
  229. }
  230. }else if($v['type'] == 4){
  231. $label = Db::name('user_label')->group('user_id')->where('label','in',$v['label'])->column('user_id');
  232. if(!$label){
  233. unset($lists[$k]);
  234. }else{
  235. $select[] = $v;
  236. if($v['is_regular'] == 0){
  237. $v['fs_time'] = $v['push_time'];
  238. $sort[] = $v['push_time'];
  239. }else{
  240. $v['fs_time'] = $v['create_at'];
  241. $sort[] = $v['create_at'];
  242. }
  243. }
  244. }
  245. }else{
  246. $select[] = $v;
  247. if($v['is_regular'] == 0){
  248. $v['fs_time'] = $v['push_time'];
  249. $sort[] = $v['push_time'];
  250. }else{
  251. $v['fs_time'] = $v['create_at'];
  252. $sort[] = $v['create_at'];
  253. }
  254. }
  255. }
  256. // $adds = array_values($select);
  257. // return $page_k.'-'.$page_e;
  258. $total_count = count($select);
  259. array_multisort($sort,SORT_DESC,$select);
  260. $adds = array_slice($select, $page_k, $page_e);
  261. $data = [
  262. 'list' => $adds,
  263. "total_count" => $total_count,
  264. "page_num"=> $limit
  265. ];
  266. return json(['code'=>1,'is_login'=>1,'msg'=>'ok','time'=>time(),'data'=>$data]);
  267. }
  268. }