123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace bibidd\Controller;
- use Bibidd\Controller\CommonBaseController;
- /**
- * 视频标题查询
- */
- class VideoSeacherController extends CommonBaseController
- {
- /**
- * 通过关键字查询
- * @return void
- */
- public function search_by_key_word()
- {
- $this->addHeaders(); //添加头部请求
- $user_info = $this->checkUserIsExist($_POST['uid']); //检查用户
- $uid = $user_info['id'];
- $key_word= $_POST['keyWord'];
- $page = $_POST['page'];
- $one_size = $_POST['pageSize']; //每頁30行記錄
- $page_one = ($page - 1) * $one_size;
- if(empty($key_word) || mb_strlen($key_word)>40)
- {
- $this->returnDataAndSendMsg("搜索关键字不能为空或长度不能超过40个字符");
- die();
- }
- $key_word = trim($key_word); //去除两边空格
- $video_list = M('video_list_test')->where("MATCH(china_title) AGAINST ('+\"$key_word\"' IN BOOLEAN MODE) AND uploader != '吃瓜'")->LIMIT($page_one, $one_size)->select();
- foreach ($video_list as $key=>$value)
- {
- $v_id = $value['id'];
- $value['isUnlock']=false; //是否解锁
- $value['payType']= $this->uploader_map_to_pay_type($value['uploader']); //付费方式
- $video_list[$key] = $value;
- $jiesuo_chigua = M("chigua_vieo_jiesuo")->field("id")->where("user_id = '$uid' AND video_list_test_id='$v_id'")->find();
- if(!empty($jiesuo_chigua))
- {
- $value['isUnlock']=true; //是否解锁
- $video_list[$key] = $value;
- continue;
- }
- $jiesuo_other = M("free_riben_jiesuo")->field("id")->where("uid='$uid' AND v_id='$v_id'")->find();
- if(!empty($jiesuo_other))
- {
- $value['isUnlock']=true; //是否解锁
- $video_list[$key] = $value;
- continue;
- }
- }
- $data['code'] = '200';
- $data['message'] = 'ok';
- $data['all_num'] = M('video_list_test')->where("MATCH(china_title) AGAINST ('+\"$key_word\"' IN BOOLEAN MODE) AND uploader != '吃瓜'")->count();
- $data['data'] = $video_list;
- echo json_encode($data);
- if(!empty($video_list))
- {
- //记录查询次数,统计最新关键字
- $serch_count_info = M("search_count")->where("key_word='$key_word'")->find();
- if(!empty($serch_count_info))
- {
- //更新查询次数
- $serch_count_info['search_count']+=1;
- $serch_count_info['last_update_time']=date('Y-m-d H:i:s');
- $serch_count_info['pian_count']=$data['all_num'];
- M("search_count")->save($serch_count_info);
- $this->count_for_days($serch_count_info);
- die();
- }
- $serch_count_info['search_count']=1;
- $serch_count_info['last_update_time']=date('Y-m-d H:i:s');
- $serch_count_info['key_word']=$key_word;
- $serch_count_info['pian_count']=$data['all_num'];
- M("search_count")->add($serch_count_info);
- $this->count_for_days($serch_count_info);
- }
- }//end fn
- /**
- * 统计每日流水
- * @return void
- */
- private function count_for_days($serch_count_info)
- {
- $serach_id = $serch_count_info['id'];
- $counrent_date = date('Y-m-d 00:00:00');
- $days_info = M("search_count_sub")->where("search_count_id='$serach_id' AND search_date='$counrent_date'")->find();
- if(!empty($days_info))
- {
- //更新
- $id = $days_info['id'];
- $sub_info = $days_info;
- $sub_info['search_count']+=1;
- $sub_info['pian_count']= $serch_count_info['pian_count'];
- M("search_count_sub")->where("id='$id'")->save($sub_info);
- die();
- }
- $sub_info['search_count_id'] = $serach_id;
- $sub_info['search_date'] = $counrent_date;
- $sub_info['search_count'] = 1;
- $sub_info['pian_count']= $serch_count_info['pian_count'];
- M("search_count_sub")->add($sub_info);
- }
- /**
- * 查询热门10条关键字
- * @return void
- */
- public function query_key_word_top_10()
- {
- $this->addHeaders(); //添加头部请求
- $top_10_data = M("search_count")->order("search_count DESC")->LIMIT(10)->select();
- $data['code'] = '200';
- $data['message'] = 'ok';
- $data['data'] = $top_10_data;
- echo json_encode($data);
- }
- }
|