ATemplateHtml.php
2.5 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
<?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 ATemplateHtml extends \App\Models\Base{
protected $table = 'gl_aside_template_html';
protected $hidden = ['deleted_at'];
use SoftDeletes;
public static $sourceMap = [
// 数据表/数据类型 =》 模板类型/模板名称
'index' => 'index',
'product' => 'product',
'product_info' => 'product_info',
'blogs' => 'blogs',
'blogs_info' => 'blogs_info',
'page' => 'page',
];
public static $typeMap = [
'index' => '首页',
'product' => '商品列表',
'product_info' => '商品详情',
'blogs' => '博客',
'blogs_info' => '博客详情',
'page' => '单页',
'news' => '新闻列表',
'news_info' => '新闻详情',
];
/**
* 模板中的数据
* @param $template_id
* @return mixed
* @author:dc
* @time 2023/5/10 10:30
*/
public static function _all($template_id){
return static::where(['template_id'=>$template_id])->get();
}
/**
* 是否存在type
* @param int $template_id
* @param $type
* @return mixed
* @author:dc
* @time 2023/5/10 16:03
*/
public static function _typeExist(int $template_id,$type){
return static::where(['template_id'=>$template_id,'type'=>$type])->limit(1)->count();
}
public static function _bAll($template_id){
return static::where(['template_id'=>$template_id,'status'=>1])->get();
}
public static function _find($id){
return static::where('id',$id)->first();
}
/**
* @param array $data
* @param int $id
* @return mixed
* @author:dc
* @time 2023/5/11 10:20
*/
public static function _save(int $template_id, array $data,int $id = 0){
if($id){
$model = static::where('id',$id)->first();
}
if(empty($model)) $model = new static();
$model->template_id = $template_id;
$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;
}
}