ManystoreConfig.php
3.7 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
141
<?php
namespace app\common\model;
use think\Cache;
use think\Model;
class ManystoreConfig extends Model
{
// 表名
protected $name = 'manystore_config';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
];
public function manystore_config(){
if(empty(SCHOOL_ID)){
return [];
}
$seller_value_model = new ManystoreValue();
$config = Cache::get('manystore_config:'.SCHOOL_ID);
if(!$config){
$config_value_data_array = [];
$config_value_data = collection($seller_value_model->where(array('school_id' => SCHOOL_ID))->select())->toArray();
foreach ($config_value_data as $value) {
$config_value_data_array[$value['config_id']] = $value;
}
$config = [];
foreach ($this->select() as $k => $v) {
$value = $v->toArray();
$data_value = isset($config_value_data_array[$value['id']]['value']) ? $config_value_data_array[$value['id']]['value'] : $value['default'];
if (in_array($value['type'], ['selects', 'checkbox', 'images', 'files'])) {
$value['value'] = explode(',', $data_value);
} else if ($value['type'] == 'array') {
$value['value'] = (array)json_decode($data_value, TRUE);
} else {
$value['value'] = $data_value;
}
$config[$value['name']] = $value['value'];
}
Cache::set('manystore_config:'.SCHOOL_ID,$config);
}
return !empty($config) ? $config : [];
}
public static function getArrayData($data)
{
$fieldarr = $valuearr = [];
$field = isset($data['field']) ? $data['field'] : [];
$value = isset($data['value']) ? $data['value'] : [];
foreach ($field as $m => $n) {
if ($n != '') {
$fieldarr[] = $field[$m];
$valuearr[] = $value[$m];
}
}
return $fieldarr ? array_combine($fieldarr, $valuearr) : [];
}
/**
* 将字符串解析成键值数组
* @param string $text
* @return array
*/
public static function decode($text, $split = "\r\n")
{
$content = explode($split, $text);
$arr = [];
foreach ($content as $k => $v) {
if (stripos($v, "|") !== false) {
$item = explode('|', $v);
$arr[$item[0]] = $item[1];
}
}
return $arr;
}
/**
* 将键值数组转换为字符串
* @param array $array
* @return string
*/
public static function encode($array, $split = "\r\n")
{
$content = '';
if ($array && is_array($array)) {
$arr = [];
foreach ($array as $k => $v) {
$arr[] = "{$k}|{$v}";
}
$content = implode($split, $arr);
}
return $content;
}
/**
* 本地上传配置信息
* @return array
*/
public static function upload()
{
$uploadcfg = config('upload');
$upload = [
'cdnurl' => $uploadcfg['cdnurl'],
'uploadurl' => $uploadcfg['uploadurl'],
'bucket' => 'local',
'maxsize' => $uploadcfg['maxsize'],
'mimetype' => $uploadcfg['mimetype'],
'multipart' => [],
'multiple' => $uploadcfg['multiple'],
];
return $upload;
}
}