129 lines
3.5 KiB
PHP
129 lines
3.5 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\goods;
|
||
|
||
use app\common\enum\YesNoEnum;
|
||
use app\common\model\goods\GoodsCate;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 商品分类逻辑
|
||
* Class GoodsCateLogic
|
||
* @package app\adminapi\logic\goods
|
||
*/
|
||
class GoodsCateLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加商品分类
|
||
* @param array $params
|
||
* @return bool
|
||
* @author BD
|
||
* @date 2024/03/11 01:58
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
GoodsCate::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 BD
|
||
* @date 2024/03/11 01:58
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
GoodsCate::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 BD
|
||
* @date 2024/03/11 01:58
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return GoodsCate::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取商品分类详情
|
||
* @param $params
|
||
* @return array
|
||
* @author BD
|
||
* @date 2024/03/11 01:58
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
return GoodsCate::findOrEmpty($params['id'])->toArray();
|
||
}
|
||
|
||
/**
|
||
* @notes 商品分类数据
|
||
* @return array
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @author BD
|
||
* @date 2024/03/11 01:58
|
||
*/
|
||
public static function getAllData()
|
||
{
|
||
return GoodsCate::where(['is_show' => YesNoEnum::YES])
|
||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||
->select()
|
||
->toArray();
|
||
}
|
||
} |