quanwei
2025-10-31 f226d5fe6327e31bb471a96b7370cf94689c6608
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
<?php
 
namespace app\common\model\plus\business;
 
use think\facade\Cache;
use app\common\model\BaseModel;
 
/**
 * 名片设置模型
 */
class Setting extends BaseModel
{
    protected $name = 'business_card_setting';
    protected $pk = 'key';
    /**
     * 转义数组格式
     * @param $value
     * @return mixed
     */
    public function getValuesAttr($value)
    {
        return json_decode($value, true);
    }
 
    /**
     * 转义成json格式
     * @param $value
     * @return false|string
     */
    public function setValuesAttr($value)
    {
        return json_encode($value);
    }
    /**
     * 获取所有设置
     */
    public static function getAll()
    {
        $self = new static();
        $data = $self->where(['app_id' => self::$app_id])->select();
        $config = [];
        foreach ($data as $item) {
            $config[$item['key']] = $item;
        }
        return array_merge_multiple($self->defaultData(), $config);
    }
 
    /**
     * 获取设置项信息
     */
    public static function getItem($key, $app_id = null)
    {
        if (is_null($app_id)) {
            $app_id = static::$app_id;
        }
        return static::where(['key' => $key, 'app_id' => $app_id])->value('values', true);
    }
 
    /**
     * 获取设置项
     */
    public static function detail($key)
    {
        return (new static())->find(compact('key'));
    }
 
    /**
     * 默认配置
     */
    public function defaultData()
    {
        return [
            'basic' => [
                'key' => 'basic',
                'describe' => '基础设置',
                'values' => [
                    // 置顶金额
                    'top_amount' => '10',
                    // 置顶天数
                    'top_days' => '7',
                ]
            ],
            'background' => [
                'key' => 'background',
                'describe' => '页面背景图',
                'values' => [
                    // 数字资产图片1
                    'digital_asset_1' => '',
                    // 数字资产图片2
                    'digital_asset_2' => '',
                ]
            ]
        ];
    }
}