123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- <?php
- namespace app\api\controller;
- use app\common\model\LabelMessage;
- use app\common\model\PlatformSwitch;
- use app\common\model\User;
- use app\common\model\UserMessage;
- use app\common\model\UserSearch;
- use app\common\model\UserTag;
- use app\common\model\UserTrack;
- use think\Db;
- /**
- * @title 其他接口(需要登录状态)【多模块共用】
- * @controller General
- * @group base
- */
- class General extends Base
- {
- protected $need_login = [
- 'delSearchHistory',
- 'switchSet',
- 'batchDelSwitch',
- 'delTrack',
- 'label'
- ];
- public function initialize()
- {
- parent::initialize();
- parent::setUid();
- }
- /**
- * @title 用户搜索历史
- * @desc 用户搜索历史
- * @author qc
- * @method GET
- * @url /api/General/getSearchHistory
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @param name:type type:int default:-- desc:类型0=>"全部",1=>'视频',2=>'资料',3=>'图文',4=>'新闻',5=>'问答',6=>'商品',7=>'活动',8=>'招聘',9=>'供应商',10=>'供应商商品',11=>'需求'
- * @return name:title type:string default:-- desc:标题
- * @return name:type type:int default:-- desc:类型0全局,1视频,2图文,3资料,4新闻,5需求
- */
- public function getSearchHistory()
- {
- $title = input('title');
- $type= input('type',-1);
- $where= [];
- $where [] = ['user_id','=',$this->user_id];
- if($title)$where [] = ['title','like','%'.$title.'%'];
- if($type > -1)$where [] = ['type','=',$type];
- $list = UserSearch::where($where)
- ->limit($this->off_set,$this->page_num)
- ->order('create_at desc,id desc')
- ->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 删除||清空搜索历史
- * @desc 删除||清空搜索历史
- * @author qc
- * @method POST
- * @url /api/General/delSearchHistory
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:string default:0 desc:搜索记录id【不传值清空所有搜索记录】
- */
- public function delSearchHistory()
- {
- $id = input('post.id');
- $where= [];
- $where [] = ['user_id','=',$this->user_id];
- if($id)$where [] = ['id','in',$id];
- UserSearch::where($where)->delete();
- $this->success('删除成功');
- }
- /**
- * @title 以下接口为二期需求
- * @desc 以下接口为二期需求
- * @author qc
- * @url /api/General/secondPhase
- * @method
- * @return name:1 type:string default:-- desc:以下接口为二期需求
- */
- public function secondPhase(){}
- /**
- * @title 开关设置【详情页设置】
- * @desc 【追更开关】
- * @author qc
- * @method POST
- * @url /api/General/switchSet
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int require:1 default:-- desc:记录id【招聘订阅的是第三级分类id】
- * @param name:type type:int require:1 default:-- desc:类型【1=>'问答通知开关',2=>'视频追更',3=>'图文追更',4=>'资料追更',5=>'供应商订阅',6=>'招聘订阅',7=>'视频通知开关',8=>图文通知开关,9=>资料通知开关,10=>新闻通知,11=>供应商通知,12=>需求通知】
- * @return name:status type:int default:1 desc:1开启0关闭
- */
- public function switchSet()
- {
- $switch_status = PlatformSwitch::userSwitch($this->user_id,input('post.id',0),input('post.type',0));
- $switch_status ? $this->success('开启成功',['status'=>1]) : $this->success('关闭成功',['status'=>0]);
- }
- /**
- * @title 批量取消追更【所有模块共用】
- * @desc 批量取消追更
- * @author qc
- * @method POST
- * @url /api/General/batchDelSwitch
- * @header name:Authorization require:1 desc:Token
- * @param name:ids type:string require:1 default:-- desc:追更记录id(多个逗号隔开)
- */
- public function batchDelSwitch()
- {
- $ids = input('post.ids');
- PlatformSwitch::where('user_id',$this->user_id)->where('id','in',$ids)->delete();
- $this->success('取消成功');
- }
- /**
- * @title 批量删除学习历史(浏览记录)【所有模块共用】
- * @desc 批量删除学习历史
- * @author qc
- * @method POST
- * @url /api/General/delTrack
- * @header name:Authorization require:1 desc:Token
- * @param name:ids type:string require:1 default:-- desc:浏览记录id(多个逗号隔开)
- */
- public function delTrack()
- {
- UserTrack::delUserTrack($this->user_id,input('post.ids'));
- $this->success('删除成功');
- }
- /**
- * @title 用户绑定智能标签
- * @desc 用户绑定智能标签
- * @author qc
- * @url /api/General/label
- * @method POST
- * @param name:label type:varchar default:-- desc:标签--多个标签用,隔开
- */
- public function label($label = ''){
- $data = input();
- $uid = $this->user_id;
- // $label = explode(',',$data['label']);
- if(isset($data['label']) && $data['label'] != '' && $data['label'] != null){
- $label = $data['label'];
- }
- if($label != '' && $label != null){
- $label = explode(',',$label);
- foreach ($label as $k => $v){
- $find = Db::name('user_label')->where('user_id',$uid)->where('label',$v)->find();
- if($find){
- Db::name('user_label')->where('user_id',$uid)->where('label',$v)->setInc('num');
- }else{
- $arr = [
- 'user_id' => $uid,
- 'label' => $v,
- 'num' => 1,
- 'create_at' => date('Y-m-d H:i:s'),
- ];
- Db::name('user_label')->insert($arr);
- }
- }
- }
- // $this->success('操作成功');
- }
- /**
- * @title 获取信息列表-推送
- * @desc 获取信息列表-推送
- * @author qc
- * @url /api/General/getUserMessage
- * @method POST
- * @param name:page type:int default:-- desc:分页页数
- * @param name:limit type:int default:-- desc:每页查询数量
- * @return name:create_at type:datetime default:1 desc:创建时间
- * @return name:content type:string default:20 desc:消息内容
- * @return name:label_id type:string default:20 desc:0
- * @return name:jg_status type:string default:20 desc:推送状态0未推送1已推送
- * @return name:label type:string default:-- desc:标签
- * @return name:type type:string default:-- desc:1会员标签2搜索历史3模块详情4智能标签
- * @return name:module type:string default:-- desc:模块video=>视频,article=>图文,datum=>资料,goods=>商城商品,press=>新闻,supplier_goods=>供应商商品,demand=>需求,recruit=>招聘,forum=>问答,activity=>活动
- * @return name:first_id type:string default:-- desc:系列id
- * @return name:second_id type:string default:-- desc:详情id
- * @return name:title type:string default:-- desc:标题
- * @return name:is_regular type:string default:-- desc:是否定时
- * @return name:push_time type:string default:-- desc:定时时间
- * @return name:fs_time type:string default:-- desc:发送时间
- *
- */
- public function getUserMessage(){
- $uid = $this->user_id;
- $page = input('page');
- $limit = input('limit');
- if(!$page){
- $page = 1;
- }
- if(!$limit){
- $limit = 20;
- }
- $page_e = ($page * $limit);
- $page_k = (($page * $limit) - $limit);
- $lists = [];
- $list = LabelMessage::where('jg_status',1)->order('push_time desc,create_at desc')->select()->toArray();
- $lists = $list;
- $select = [];
- $sort = [];
- foreach ($lists as $k => $v){
- if($v['label']) {
- if($v['type'] == 3){
- $label_arr = explode(',',$v['label']);
- $where_str = '';
- $search_arr=[];
- $tag_arr = [];
- foreach ($label_arr as $t){
- $search_arr[] = " title like '".'%'.$t."%'" .' ';
- $tag_arr[] = $t;
- }
- if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
- $tags = UserTag::where('title','in',$tag_arr)->column('id');
- $user = User::where('label','<>',null)->where('id',$uid)->where('label','<>','||')->where('is_deleted',0)->field('id,label')->find();
- $label = explode('|',$user['label']);
- if (array_search($label, $tags) == false) {
- unset($lists[$k]);
- }else{
- $select[] = $v;
- if($v['is_regular'] == 0){
- $v['fs_time'] = $v['push_time'];
- $sort[] = $v['push_time'];
- }else{
- $v['fs_time'] = $v['create_at'];
- $sort[] = $v['create_at'];
- }
- }
- }else if($v['type'] == 4){
- $label = Db::name('user_label')->group('user_id')->where('label','in',$v['label'])->column('user_id');
- if(!$label){
- unset($lists[$k]);
- }else{
- $select[] = $v;
- if($v['is_regular'] == 0){
- $v['fs_time'] = $v['push_time'];
- $sort[] = $v['push_time'];
- }else{
- $v['fs_time'] = $v['create_at'];
- $sort[] = $v['create_at'];
- }
- }
- }
- }else{
- $select[] = $v;
- if($v['is_regular'] == 0){
- $v['fs_time'] = $v['push_time'];
- $sort[] = $v['push_time'];
- }else{
- $v['fs_time'] = $v['create_at'];
- $sort[] = $v['create_at'];
- }
- }
- }
- // $adds = array_values($select);
- // return $page_k.'-'.$page_e;
- $total_count = count($select);
- array_multisort($sort,SORT_DESC,$select);
- $adds = array_slice($select, $page_k, $page_e);
- $data = [
- 'list' => $adds,
- "total_count" => $total_count,
- "page_num"=> $limit
- ];
- return json(['code'=>1,'is_login'=>1,'msg'=>'ok','time'=>time(),'data'=>$data]);
- }
- }
|