Project.php
1.8 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
<?php
namespace App\Models;
use Illuminate\Support\Facades\DB;
class Project extends Base
{
//设置关联表名
protected $table = 'gl_project';
//自动维护create_at创建时间 updated_at修改时间
public $timestamps = true;
protected $dateFormat = 'Y-m-d';
const DATABASE_NAME_FIX = 'globalso_project_';
/**
* @name:获取当前对象不分页列表
*/
public function page_lists(){
$lists = DB::table($this->table)->select(['*'])->where($this->map)->orderBy($this->order)->get();
return $lists;
}
/**
* 通过ID获取项目信息
* @param $id
* @return self
*/
public static function getProjectById($id)
{
return self::where(['id' => $id])->first();
}
/**
* 项目部署服务器信息
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function serverConfig()
{
return self::hasOne(ServerConfig::class, 'id', 'serve_id');
}
/**
* 项目部署mysql数据库信息
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function mysqlConfig()
{
return self::hasOne(ServerConfig::class, 'id', 'mysql_id');
}
/**
* 项目使用Redis服务器信息, 如果没有即使用默认配置
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function redisConfig()
{
return self::hasOne(ServerConfig::class, 'id', 'redis_id');
}
/**
* 获取项目对应数据库名称
* 初始化数据库、数据表迭代等功能使用
* TODO 如果前缀变更,请使用该方法进行处理
* @return string
*/
public function databaseName()
{
return self::DATABASE_NAME_FIX . $this->id;
}
}