first commit
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2020/4/21
|
||||
* Time: 19:37
|
||||
*/
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\lib\exception\ParamException;
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class CollectMajor extends Model
|
||||
{
|
||||
protected $table = 'user_collect_major';
|
||||
|
||||
/*
|
||||
* 收藏专业
|
||||
* @param userID int 用户id
|
||||
* @param data 收藏内容
|
||||
* @return | bool
|
||||
* */
|
||||
public static function addUserCollectMajor($userID, $data)
|
||||
{
|
||||
|
||||
$data['user_id'] = $userID;
|
||||
$data['add_time'] = time();
|
||||
$result = self::insertGetId($data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*
|
||||
* 检查是否已收藏过该专业
|
||||
* */
|
||||
public static function checkMyCollectMajor($sch_id,$userPro,$majorCode,$subType,$score,$userID)
|
||||
{
|
||||
$result = self::where([['user_id', '=', $userID],['sch_id', '=', $sch_id],['is_collect', '=', 1],['userPro','=',$userPro],['majorCode','=',$majorCode],['subType','=',$subType],['score','=',$score]])->count();
|
||||
if($result){
|
||||
throw new ParamException([
|
||||
'code' => 401,
|
||||
'msg' => '已收藏过该专业',
|
||||
'errorCode' => 10001
|
||||
]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据用户id查询用户收藏的全部专业学校id
|
||||
* */
|
||||
public static function getUserCollectMajor($userID,$userPro,$subType,$score)
|
||||
{
|
||||
$result = self::field('majorCode,sch_id,code')->where([['user_id', '=', $userID], ['is_collect', '=', 1],['userPro','=',$userPro],['subType','=',$subType],['score','=',$score]])->select()->toArray();
|
||||
if ($result) {
|
||||
foreach($result as $key => $val){
|
||||
$result[$key]['majorCode'] = $val['sch_id']."_".$val['majorCode']."_".$val['code'];
|
||||
}
|
||||
$result = array_column($result, 'majorCode');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 移除收藏的专业
|
||||
* */
|
||||
public static function delMyCollectMajor($id, $userID)
|
||||
{
|
||||
$result = self::where([['id', '=', $id], ['user_id', '=', $userID]])->update(['is_collect' => 2]);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 查询我收藏的专业
|
||||
* */
|
||||
public static function getMyCollectMajor($data,$userID,$page = 1, $limit = 10)
|
||||
{
|
||||
$where [] = empty($data['score'])?
|
||||
[['user_id','=',$userID],['userPro','=',$data['userPro']],['is_collect','=',1]]:[['user_id','=',$userID],['userPro','=',$data['userPro']],['is_collect','=',1],['score','=',$data['score']]];
|
||||
//统计收藏专业数量
|
||||
$count = self::where($where)->count();
|
||||
//查询专业数据
|
||||
$result = self::where($where)
|
||||
->page($page, $limit)->select();
|
||||
empty($result) ? $msg = '暂无数据!' : $msg = '查询成功!';
|
||||
|
||||
//分页数据
|
||||
$info = [
|
||||
'limit' => $limit,
|
||||
'page_current' => $page,
|
||||
'page_sum' => ceil($count / $limit),
|
||||
];
|
||||
//组合返回
|
||||
$list = [
|
||||
'msg' => $msg,
|
||||
'count' => $count,
|
||||
'info' => $info,
|
||||
'res' => $result,
|
||||
];
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user