quanwei
13 hours ago 408c463c5b66bba2aa1c81d8dca23e04c1608e24
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
<?php
 
namespace app\supplier\model\settings;
 
use think\facade\Cache;
use app\common\model\settings\Setting as SettingModel;
use app\common\enum\settings\SettingEnum;
 
class Setting extends SettingModel
{
    /**
     * 更新系统设置
     */
    public function edit($key, $values,$shop_supplier_id=0)
    {
        // 处理 key,如果包含 nav_ 则只保留 nav 部分
        $processedKey = strpos($key, 'nav_') !== false ? 'nav' : $key;
        $model = self::detail($key,$shop_supplier_id) ?: $this;
        // 删除系统设置缓存
        Cache::delete('setting_' . self::$app_id. '_'.$shop_supplier_id);
        return $model->save([
                'key' => $key,
                'describe' => SettingEnum::data()[$processedKey]['describe'],
                'values' => $values,
                'app_id' => self::$app_id,
                'shop_supplier_id' => $shop_supplier_id
            ]) !== false;
    }
 
    /**
     * 验证商城设置
     */
    private function validStore($values)
    {
        if (!isset($values['delivery_type']) || empty($values['delivery_type'])) {
            $this->error = '配送方式至少选择一个';
            return false;
        }
        return true;
    }
 
    /**
     * 验证小票打印机设置
     */
    private function validPrinter($values)
    {
        if ($values['is_open'] == false) {
            return true;
        }
        if (!$values['printer_id']) {
            $this->error = '请选择订单打印机';
            return false;
        }
        if (empty($values['order_status'])) {
            $this->error = '请选择订单打印方式';
            return false;
        }
        return true;
    }
 
}