Files
zzp-server/app/adminapi/logic/setting/LanguageLogic.php
2026-01-19 14:19:22 +08:00

157 lines
4.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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;
use app\common\enum\YesNoEnum;
use app\common\model\setting\Language;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 语言包逻辑
* Class LanguageLogic
* @package app\adminapi\logic\setting
*/
class LanguageLogic extends BaseLogic
{
/**
* @notes 添加语言包
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/30 13:59
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Language::create([
'name' => $params['name'],
'name_loc' => $params['name_loc'],
'symbol' => $params['symbol'],
'trans_symbol' => $params['trans_symbol'],
'logo' => $params['logo'],
'precision' => $params['precision'],
'time_format' => $params['time_format'],
'is_show' => $params['is_show'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑语言包
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/30 13:59
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Language::where('id', $params['id'])->update([
'name' => $params['name'],
'name_loc' => $params['name_loc'],
'symbol' => $params['symbol'],
'trans_symbol' => $params['trans_symbol'],
'logo' => $params['logo'],
'precision' => $params['precision'],
'time_format' => $params['time_format'],
'is_show' => $params['is_show'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除语言包
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/30 13:59
*/
public static function delete(array $params): bool
{
return Language::destroy($params['id']);
}
/**
* @notes 获取语言包详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/11/30 13:59
*/
public static function detail($params): array
{
return Language::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 更改状态
* @param array $params
* @return bool
* @author heshihu
* @date 2022/2/22 10:18
*/
public static function updateStatus(array $params)
{
Language::update([
'id' => $params['id'],
'is_show' => $params['is_show']
]);
return true;
}
/**
* @notes 语言包数据
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/10/13 10:53
*/
public static function getAllData()
{
return Language::where(['is_show' => YesNoEnum::YES])
->order(['sort' => 'desc', 'id' => 'desc'])
->select()
->toArray();
}
}