| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\logic\setting\dict;
- use app\common\logic\BaseLogic;
- use app\common\model\dict\DictConfig;
- /**
- * 字典数据逻辑
- * Class DictConfigLogic
- * @package app\adminapi\logic\DictConfig
- */
- class DictConfigLogic extends BaseLogic
- {
- /**
- * @notes 添加编辑
- * @param array $params
- * @return DictConfig|\think\Model
- */
- public static function save(array $params)
- {
- try {
- $data = [
- 'name' => $params['name'],
- 'value' => $params['value'],
- 'content' => $params['content'] ? json_encode($params['content']) : null,
- 'status' => $params['status'],
- 'remark' => $params['remark'] ?? '',
- ];
- //校验字段类型是否重复
- $id = !empty($params['id'])? $params['id'] : 0;
- if (DictConfig::where(['value' => $params['value']])->where('id', '<>', $id)->value('id')) {
- throw new \think\Exception('字段类型已存在'.$params['id']);
- }
- if (!empty($params['id'])) {
- return DictConfig::where(['id' => $params['id']])->update($data);
- } else {
- return DictConfig::create($data);
- }
- } catch (\Exception $e) {
- self::setError($e->getMessage());
- return false;
- }
- }
- /**
- * @notes 删除字典数据
- * @param array $params
- * @return bool
- */
- public static function delete(array $params)
- {
- return DictConfig::destroy($params['id']);
- }
- /**
- * @notes 获取字典数据详情
- * @param $params
- * @return array
- */
- public static function detail($params): array
- {
- $detail = DictConfig::findOrEmpty($params['id'])->toArray();
- $detail['content'] = $detail['content'] ? json_decode($detail['content'], true) : [];
- return $detail;
- }
- }
|