Student.php
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace app\api\model;
use think\Model;
class Student extends Model
{
protected $name = 'student';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 添加一条学生的数据
public function addOne($data)
{
return $this->insert($data);
}
// 获取高中同校的本校学长总数
public function countByUniversityIdAndSchoolId($universityId, $schoolId)
{
return $this->where(['university_id' => ['=', $universityId], 'show_switch' => ['=', 1], 'school_id' => ['=', $schoolId]])->useSoftDelete($this->deleteTime)->count();
}
// 获取高中同城/省的本校学长总数
public function countByUniversityIdAndSchoolIds($universityId, $schoolIds)
{
return $this->where(['university_id' => ['=', $universityId], 'show_switch' => ['=', 1], 'school_id' => ['in', $schoolIds]])->useSoftDelete($this->deleteTime)->count();
}
// 根据用户ID获取一个可以展示的学生的数据
public function infoByUserIdCanShow($userId)
{
return $this
->where(['user_id' => ['=', $userId]])
->useSoftDelete($this->deleteTime)
->find();
}
// 获取高中同城/省的本校学长
public function listByUniversityIdAndSchoolIds($where, $page, $size)
{
return $this
->where($where)
->useSoftDelete($this->deleteTime)
->order($this->createTime, 'desc')
->page($page, $size)
->select();
}
// 修改一个学生的数据
public function updateOne($id, $data)
{
return $this->where(['user_id' => ['=', $id]])->update($data);
}
// 修改一群学生的数据
public function updateByIds($userIds, $data)
{
return $this->where(['user_id' => ['in', $userIds]])->update($data);
}
// 根据条件查询
public function listByWhere($where)
{
return $this->where($where)->select();
}
public function infoByUserId($userId)
{
return $this->where(['user_id' => ['=', $userId]])->find();
}
}