152 lines
4.0 KiB
PHP
152 lines
4.0 KiB
PHP
<?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\item;
|
||
|
||
use app\common\enum\YesNoEnum;
|
||
use app\common\model\item\ItemCate;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 项目分类逻辑
|
||
* Class ItemCateLogic
|
||
* @package app\adminapi\logic\item
|
||
*/
|
||
class ItemCateLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加项目分类
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/01/16 13:23
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ItemCate::create([
|
||
'name' => $params['name'],
|
||
'sort' => $params['sort'],
|
||
'is_show' => $params['is_show'],
|
||
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
|
||
]);
|
||
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑项目分类
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/01/16 13:23
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ItemCate::where('id', $params['id'])->update([
|
||
'name' => $params['name'],
|
||
'sort' => $params['sort'],
|
||
'is_show' => $params['is_show'],
|
||
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
|
||
]);
|
||
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除项目分类
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/01/16 13:23
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return ItemCate::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取项目分类详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/01/16 13:23
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$itemCate = ItemCate::findOrEmpty($params['id'])->toArray();
|
||
|
||
$langs = json_decode($articleCate['langs'], true);
|
||
if(empty($langs)){
|
||
$langs = [];
|
||
}
|
||
$itemCate['langs'] = $langs;
|
||
return $itemCate;
|
||
}
|
||
|
||
/**
|
||
* @notes 更改项目分类状态
|
||
* @param array $params
|
||
* @return bool
|
||
* @author heshihu
|
||
* @date 2022/2/21 18:04
|
||
*/
|
||
public static function updateStatus(array $params)
|
||
{
|
||
ItemCate::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 ItemCate::where(['is_show' => YesNoEnum::YES])
|
||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||
->select()
|
||
->toArray();
|
||
}
|
||
} |