first commit

This commit is contained in:
Your Name
2026-01-19 14:19:22 +08:00
commit fe2d9c1868
4777 changed files with 665503 additions and 0 deletions

View File

@@ -0,0 +1,129 @@
<?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();
}
}