first commit
This commit is contained in:
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2020/4/15
|
||||
* Time: 16:58
|
||||
*/
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\facade\Log;
|
||||
use think\Model;
|
||||
use app\api\model\UserCollect;
|
||||
|
||||
class SchoolChoice extends Model
|
||||
{
|
||||
/*
|
||||
* 院校查询
|
||||
* */
|
||||
public static function getSchoolByCondition($array,$page = 1,$limit =10 ,$user_id,$vipType){
|
||||
if($array['userPro'] == 1){
|
||||
$table = 'rec_js';
|
||||
$tableMajor = 'rec_js_major';
|
||||
}else{
|
||||
$table = $array['subType'] == 1 ? 'rec_wen':'rec_li';
|
||||
$tableMajor = $array['subType'] == 1 ? 'rec_wen_major':'rec_li_major';
|
||||
}
|
||||
$where = [];
|
||||
//方便统计总数定义推荐类型
|
||||
$whereType = [];
|
||||
//推薦類型默認0
|
||||
$type = 0;
|
||||
$year = config('setsub.year');
|
||||
//默认排序条件
|
||||
$sort = 'recommendType desc';
|
||||
//搜索条件
|
||||
unset($array['is_login']);
|
||||
unset($array['page']);
|
||||
unset($array['type']);
|
||||
foreach ($array as $key => $value) {
|
||||
if (!empty($value)) {
|
||||
switch ($key) {
|
||||
case 'userPro':
|
||||
$where[] = ['yzy_province', '=', $value];
|
||||
break;
|
||||
case 'subType':
|
||||
$where[] = ['wenli', '=', $value];
|
||||
break;
|
||||
case 'score':
|
||||
$where[] = [$key, '=', $value];
|
||||
break;
|
||||
case 'reType':
|
||||
//未购买权限limit-1
|
||||
if(($value == 1 || $value ==2) && ($limit == 2 || $limit ==5)){
|
||||
$limit = $limit - 1;
|
||||
}
|
||||
$type = $value;
|
||||
$whereType[] = ['recommendType', '=', $value];
|
||||
break;
|
||||
case 'province':
|
||||
$where[] = ['sch_province', 'in', ($value)];
|
||||
break;
|
||||
case 'chooseLevel':
|
||||
$where[] = ['mykemu', '=', $value];
|
||||
break;
|
||||
case 'batch':
|
||||
$where[] = ['batch', 'in', ($value)];
|
||||
break;
|
||||
case 'schoolType':
|
||||
$where[] = ['sch_cate_id', 'in', ($value)];
|
||||
break;
|
||||
case 'is_985':
|
||||
$where[] = ['is_985', '=', $value];
|
||||
break;
|
||||
case 'is_211':
|
||||
$where[] = ['is_211', '=', $value];
|
||||
break;
|
||||
case 'is_yldx':
|
||||
$where[] = ['is_yldx', '=', $value];
|
||||
break;
|
||||
case 'is_ylxk':
|
||||
$where[] = ['is_ylxk', '=', $value];
|
||||
break;
|
||||
case 'is_public':
|
||||
$where[] = ['is_public', '=', $value];
|
||||
break;
|
||||
case 'sort':
|
||||
$sort = config('setsub.sort')[$value];
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//计算总数
|
||||
if($vipType == 1){
|
||||
$count = Db::table($table)
|
||||
->where($where)
|
||||
->where($whereType)
|
||||
->count();
|
||||
}else{
|
||||
$count = $limit;
|
||||
}
|
||||
|
||||
|
||||
//查询院校总数,可保底,稳妥,冲
|
||||
$resNum = self::getSchoolNum($where,$limit,$vipType,$table,$type);
|
||||
//查询数据
|
||||
$result = Db::table($table)->alias('a')
|
||||
->field('alias,probability,rankOfCn,sch_province_title,sch_cate_title,is_985,is_syl,is_211,tags,sch_province,sch_id,id,enterNum,batch,batch_title,recommendType,majorNum')
|
||||
->where($where)
|
||||
->where($whereType)
|
||||
->page($page, $limit)
|
||||
->order($sort)
|
||||
->select();
|
||||
|
||||
empty($result) ? $msg = '暂无数据!' : $msg = '查询成功!';
|
||||
|
||||
//查询用户收藏的院校
|
||||
$resCollect = [];
|
||||
if($user_id){
|
||||
$resCollect = UserCollect::getUserCollect($user_id,1);
|
||||
}
|
||||
|
||||
//查询位次和院校排名
|
||||
foreach ($result as $key =>$val){
|
||||
$result[$key]['logo'] = '';
|
||||
|
||||
$result[$key]['tags'] = $val['sch_province_title']." ".$val['sch_cate_title'];
|
||||
//判断211,985,双一流是否是1
|
||||
if($val['is_985'])
|
||||
$result[$key]['tags'] = $result[$key]['tags']." "."985";
|
||||
if($val['is_211'])
|
||||
$result[$key]['tags'] = $result[$key]['tags']." "."211";
|
||||
if($val['is_syl'])
|
||||
$result[$key]['tags'] = $result[$key]['tags']." "."双一流";
|
||||
$resSeat = Db::table('yzy_sch_score')->field('lowSort as lowestRank,minScore')
|
||||
->where([
|
||||
['province','=',$array['userPro']],
|
||||
['wenli','=',$array['subType']],
|
||||
['batch','=',$val['batch']],
|
||||
['sch_id','=',$val['sch_id']],
|
||||
['year','=',$year]
|
||||
])->find();
|
||||
|
||||
$result[$key]['lowestRank'] = $resSeat['lowestRank'];
|
||||
$result[$key]['minScore'] = $resSeat['minScore'];
|
||||
|
||||
|
||||
//收藏赋值
|
||||
$result[$key]['is_collect'] = 0;
|
||||
if(is_array($resCollect)){
|
||||
if(in_array($val['id'],$resCollect)){
|
||||
$result[$key]['is_collect'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//分页数据
|
||||
$info = [
|
||||
'limit' => $limit,
|
||||
'page_current' => $page,
|
||||
'page_sum' => ceil($count / $limit),
|
||||
];
|
||||
//组合返回
|
||||
$list = [
|
||||
'msg' => $msg,
|
||||
'count' => $count,
|
||||
'info' => $info,
|
||||
'res' => $result,
|
||||
'countSchool' => $resNum
|
||||
];
|
||||
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
//获取院校总数和保底,稳妥、推荐
|
||||
public static function getSchoolNum($where,$limit,$vipType,$table,$type){
|
||||
$arrNomalCount = array();
|
||||
$arrNomalCount[1] = 0;
|
||||
$arrNomalCount[2] = 0;
|
||||
$arrNomalCount[3] = 0;
|
||||
$arrLimitCount = array();
|
||||
$result = array();
|
||||
$cacheTime = empty($vipType)?3600:false;
|
||||
//总数
|
||||
$arrNomalCount[0] = Db::table($table)
|
||||
->where($where)->cache($cacheTime)
|
||||
->count();
|
||||
if($vipType == 0){
|
||||
//保底数量
|
||||
$arrNomalCount[3] = Db::table($table)
|
||||
->where($where)->where('recommendType','=',3)->cache($cacheTime)
|
||||
->count();
|
||||
//稳妥数量
|
||||
$arrNomalCount[2] = Db::table($table)
|
||||
->where($where)->where('recommendType','=',2)->cache($cacheTime)
|
||||
->count();
|
||||
//冲刺数量
|
||||
$arrNomalCount[1] = Db::table($table)
|
||||
->where($where)->where('recommendType','=',1)->cache($cacheTime)
|
||||
->count();
|
||||
|
||||
//未购买权限的底部数据
|
||||
$arrLimitCount['3'] = $arrNomalCount[3] - $limit;
|
||||
$arrLimitCount['3']= $arrLimitCount['3']>0? $arrLimitCount['3']:0;
|
||||
$arrLimitCount['2'] = $arrNomalCount[2] - $limit;
|
||||
$arrLimitCount['2']= $arrLimitCount['2']>0? $arrLimitCount['2']:0;
|
||||
$arrLimitCount['1'] = $arrNomalCount[1] - $limit;
|
||||
$arrLimitCount['1']= $arrLimitCount['1']>0? $arrLimitCount['1']:0;
|
||||
|
||||
}else{
|
||||
if($type){
|
||||
$arrNomalCount[$type] = Db::table($table)
|
||||
->where($where)->where('recommendType','=',$type)
|
||||
->count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$result['topNumCount'] = $arrNomalCount;
|
||||
$result['bottomNumCount'] = $arrLimitCount;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 获取院校数量
|
||||
* */
|
||||
|
||||
public static function getSchoolCount($array){
|
||||
if($array['userPro'] == 1){
|
||||
$table = 'rec_js';
|
||||
}else{
|
||||
$table = $array['subType'] == 1 ? 'rec_wen':'rec_li';
|
||||
}
|
||||
$where = [];
|
||||
unset($array['is_login']);
|
||||
unset($array['type']);
|
||||
unset($array['page']);
|
||||
//搜索条件
|
||||
foreach ($array as $key => $value) {
|
||||
if (!empty($value)) {
|
||||
switch ($key) {
|
||||
case 'userPro':
|
||||
$where[] = ['yzy_province', '=', $value];
|
||||
break;
|
||||
case 'subType':
|
||||
$where[] = ['wenli', '=', $value];
|
||||
break;
|
||||
case 'score':
|
||||
$where[] = [$key, '=', $value];
|
||||
break;
|
||||
case 'province':
|
||||
$where[] = ['sch_province', 'in', ($value)];
|
||||
break;
|
||||
case 'chooseLevel':
|
||||
$where[] = ['mykemu', '=', $value];
|
||||
break;
|
||||
case 'batch':
|
||||
$where[] = ['batch', 'in', ($value)];
|
||||
break;
|
||||
case 'reType':
|
||||
$where[] = ['recommendType', '=', $value];
|
||||
break;
|
||||
case 'schoolType':
|
||||
$where[] = ['sch_cate_id', 'in', ($value)];
|
||||
break;
|
||||
case 'is_985':
|
||||
$where[] = ['is_985', '=', $value];
|
||||
break;
|
||||
case 'is_211':
|
||||
$where[] = ['is_211', '=', $value];
|
||||
break;
|
||||
case 'is_yldx':
|
||||
$where[] = ['is_yldx', '=', $value];
|
||||
break;
|
||||
case 'is_ylxk':
|
||||
$where[] = ['is_ylxk', '=', $value];
|
||||
break;
|
||||
case 'is_public':
|
||||
$where[] = ['is_public', '=', $value];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//计算总数
|
||||
$count = Db::table($table)
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
return $count;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user