ATemplate.php
2.3 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace App\Models\Template;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 由 A端增删改
* 模板
* @author:dc
* @time 2023/5/9 13:56
* Class ATemplate
* @package App\Models\Template
*/
class ATemplate extends \App\Models\Base{
protected $table = 'gl_aside_template';
protected $hidden = ['deleted_at'];
use SoftDeletes;
/**
* 显示
*/
const STATUS_ACTIVE = 1;
/**
* 隐藏
*/
const STATUS_DISABLED = 0;
/**
* b 端调用
* @param int $limit
* @return mixed
* @author:dc
* @time 2023/5/9 14:14
*/
public static function _bAll(int $limit = 20)
{
return static::where(function ($query){
$query->where('status',static::STATUS_ACTIVE);
})
->select(['id','name','url','thumb','created_at','updated_at'])
->orderBy('sort')
->paginate($limit);
}
/**
* @param $id
* @return array
* @author:dc
* @time 2023/5/9 15:16
*/
public static function _bFind($id)
{
$data = static::where('id',$id)->first();
if(!$data || $data->status === static::STATUS_DISABLED){
return [];
}
return $data;
}
/**
* 获取默认模板
* @return mixed
* @author:dc
* @time 2023/5/9 15:09
*/
public static function _default()
{
return static::where(['status'=>static::STATUS_ACTIVE,'is_default'=>1])->first();
}
/**
* 查询
* @param $id
* @return mixed
* @author:dc
* @time 2023/5/10 10:15
*/
public static function _find($id)
{
return static::where('id',$id)->first();
}
// /**
// * @param array $data
// * @param int $id
// * @author:dc
// * @time 2023/5/11 10:08
// */
// public static function _save(array $data,int $id=0){
// if($id){
// $model = static::where('id',$id)->first();
// }
// if(empty($model)) $model = new static();
//
// $model->name = $data['name'];
// $model->status = $data['status'];
// $model->is_default = $data['is_default'];
// $model->sort = $data['sort'];
// $model->thumb = $data['thumb'];
// $model->url = $data['url'];
//
// $model->save();
//
// return $model->id;
// }
}