ProjectAssociation.php
2.0 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
<?php
namespace App\Models\ProjectAssociation;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class ProjectAssociation extends Model
{
protected $table = 'gl_project_association';
/**
* 保存|修改数据
* @param array $data
* @return bool
*/
public function saveData(array $data): bool
{
# V6项目ID
$project_id = (int)$data['project_id'] ?? 0;
$isRes = self::query()->where('project_id', $project_id)->first();
if (!$isRes) {
$isRes = new self();
$isRes->project_id = $project_id;
}
# AICC朋友ID
$isRes->friend_id = $data['friend_id'] ?? 0;
# AICC朋友昵称
$isRes->nickname = $data['nickname'] ?? 0;
# AICC用户ID
$isRes->user_id = $data['user_id'] ?? 0;
# AICC用户姓名
$isRes->user_name = $data['user_name'] ?? '';
# AICC朋友头像
$isRes->image = $data['image'] ?? '';
return $isRes->save();
}
/**
* 检查项目是否存在
* @param $project_id
* @return Builder|Model|object|null
*/
public function check($project_id)
{
return self::query()->where('project_id', $project_id)->first();
}
/**
* @param int $page
* @param int $perPage
* @return array
*/
public function allData(int $page = 1, int $perPage = 15)
{
$status = 1; # 1 - 正常, 0 - 禁用
$lists = self::query()->where('status', $status)
->where('project_id', '!=', 0)
->where('friend_id', '!=', 0)
->where('user_id', '!=', 0)
->paginate($perPage, ['project_id', 'friend_id', 'user_id'], 'page', $page);
$items = $lists->Items();
$totalPage = $lists->lastPage();
$total = $lists->total();
$currentPage = $lists->currentPage();
return compact('total', 'items', 'totalPage', 'currentPage');
}
}