ATemplateHtml.php
3.1 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?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' => [
'template' => 'index',
'name'=>'首页'
],
'product' => [
'template' => 'product',
'name'=>'商品列表'
],
'product_info' => [
'template' => 'product_info',
'name'=>'商品详情'
],
'blogs' => [
'template' => 'blogs',
'name'=>'博客列表'
],
'blogs_info' => [
'template' => 'blogs_info',
'name'=>'博客详情'
],
'page' => [
'template' => 'page',
'name'=>'单页'
],
'news' => [
'template' => 'news',
'name'=>'新闻列表'
],
'news_info' => [
'template' => 'news_info',
'name'=>'新闻详情'
],
];
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->type = $data['type'];
$model->css = $data['css'];
$model->script = $data['script'];
$model->html = $data['html'];
$model->save();
return $model->id;
}
}