<?php
|
|
namespace app\operations\model\plus\business;
|
|
use think\facade\Cache;
|
use app\common\model\plus\business\Setting as SettingModel;
|
|
/**
|
* 名片设置模型
|
*/
|
class Setting extends SettingModel
|
{
|
/**
|
* 设置项描述
|
* @var array
|
*/
|
private $describe = [
|
'basic' => '基础设置',
|
'background' => '页面背景图',
|
];
|
|
/**
|
* 更新系统设置
|
*/
|
public function edit($data)
|
{
|
$this->startTrans();
|
try {
|
foreach ($data as $key => $values){
|
$this->saveValues($key, $values);
|
}
|
$this->commit();
|
// 删除系统设置缓存
|
Cache::delete('business_setting_' . self::$app_id);
|
return true;
|
} catch (\Exception $e) {
|
$this->error = $e->getMessage();
|
$this->rollback();
|
return false;
|
}
|
}
|
|
/**
|
* 保存设置项
|
*/
|
private function saveValues($key, $values)
|
{
|
$where['key'] = $key;
|
$where['app_id'] = self::$app_id;
|
$data = [
|
'key' => $key,
|
'describe' => $this->describe[$key],
|
'values' => $values,
|
'app_id' => self::$app_id,
|
];
|
// 判断是否存在记录,存在则更新,否则新增
|
$info = self::detail($key);
|
if (empty($info)) {
|
(new self)->save($data);
|
} else {
|
self::update($data, $where);
|
}
|
}
|
}
|