erp/app/admin/logic/goods/GoodsLabelLogic.php
2024-04-27 11:41:34 +08:00

94 lines
1.9 KiB
PHP

<?php
namespace app\admin\logic\goods;
use app\common\model\goods\GoodsLabel;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 商品标签逻辑
* Class GoodsLabelLogic
* @package app\admin\logic\goods
*/
class GoodsLabelLogic extends BaseLogic
{
/**
* @notes 添加商品标签
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/04/27 09:23
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
GoodsLabel::create([
'name' => $params['name']
]);
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/04/27 09:23
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
GoodsLabel::where('id', $params['id'])->update([
'name' => $params['name']
]);
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/04/27 09:23
*/
public static function delete(array $params): bool
{
return GoodsLabel::destroy($params['id']);
}
/**
* @notes 获取商品标签详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/04/27 09:23
*/
public static function detail($params): array
{
return GoodsLabel::findOrEmpty($params['id'])->toArray();
}
}