Decorate.php
4.2 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
<?php
namespace addons\shopro\model;
use addons\shopro\model\DecorateContent;
use think\Model;
use addons\shopro\exception\Exception;
/**
* 模板装修
*/
class Decorate extends Model
{
// 表名,不含前缀
protected $name = 'shopro_decorate';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
protected $hidden = ['createtime', 'updatetime', 'deletetime'];
// 追加属性
protected $append = [
];
//获取当前平台模板装修数据
public static function getCurrentPlatformDecorate($platform = '', $id = 0)
{
$where = ['deletetime' => null];
if ($id !== 0) {
$where['id'] = $id;
}
if ($platform == 'preview') {
$decorate = self::where($where)->order('id asc')->find();
}else{
$where['status'] = 'normal';
$where['type'] = 'shop';
$decorate = self::where('find_in_set(:platform,platform)', ['platform' => $platform])->where($where)->order('id asc')->find();
}
if (!$decorate) {
throw new Exception('未找到模板');
}
$template = self::getDecorateContent($decorate);
return $template;
}
public static function getCustomDecorate($id)
{
$decorateContent = DecorateContent::all(['decorate_id' => $id]);
foreach ($decorateContent as &$v) {
$v['content'] = self::getDecorateContentByType($v);
}
return $decorateContent;
}
public static function asyncDecorateScreenShot($params)
{
$decorate = self::get($params['shop_id']);
if ($decorate) {
$decorate->image = $params['image'];
$decorate->save();
}
}
public static function getDecorateContent($decorate)
{
$template['home'] = []; //首页
$template['user'] = []; //个人中心
$template['tabbar'] = []; //底部菜单
$template['popup'] = []; //弹出提醒
$template['float-button'] = []; //悬浮按钮
$decorateContent = DecorateContent::all(['decorate_id' => $decorate->id]);
foreach ($decorateContent as $k => $v) {
$v['content'] = self::getDecorateContentByType($v);
$template[$v->category][] = $v;
}
return $template;
}
public static function getDecorateContentByType($templateValue)
{
$content = json_decode($templateValue->content, true);
switch ($templateValue['type']) {
case 'search':
case 'coupons':
case 'live':
case 'seckill':
case 'groupon':
case 'wallet-card':
case 'order-card':
case 'rich-text':
case 'nav-bg':
break;
case 'banner':
case 'menu':
case 'adv':
case 'grid-list':
case 'popup':
case 'nav-list':
foreach ($content['list'] as &$l) {
$l['image'] = cdnurl($l['image'], true);
}
break;
case 'user':
case 'title-block':
case 'goods-list':
case 'goods-group':
// halt($content['image']);
$content['image'] = cdnurl($content['image'], true);
break;
case 'tabbar':
if ($content['style'] < 3) {
foreach ($content['list'] as &$l) {
$l['image'] = cdnurl($l['image'], true);
$l['activeImage'] = cdnurl($l['activeImage'], true);
}
}
break;
case 'float-button':
$content['image'] = cdnurl($content['image'], true);
foreach ($content['list'] as &$l) {
if ($l['style'] == 1) {
$l['image'] = cdnurl($l['image'], true);
}
$l['btnimage'] = cdnurl($l['btnimage'], true);
}
}
return $content;
}
}