102 lines
2.2 KiB
PHP
102 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic\goods;
|
|
|
|
|
|
use app\common\model\goods\Unit;
|
|
use app\common\logic\BaseLogic;
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
* 计量单位逻辑
|
|
* Class UnitLogic
|
|
* @package app\admin\logic\goods
|
|
*/
|
|
class UnitLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加计量单位
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2024/04/23 10:42
|
|
*/
|
|
public static function add(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
Unit::create([
|
|
'name' => $params['name'],
|
|
'py' => $params['py'],
|
|
'number' => $params['number'],
|
|
'data' => $params['data'],
|
|
'more' => $params['more']
|
|
]);
|
|
|
|
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/23 10:42
|
|
*/
|
|
public static function edit(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
Unit::where('id', $params['id'])->update([
|
|
'name' => $params['name'],
|
|
'py' => $params['py'],
|
|
'number' => $params['number'],
|
|
'data' => $params['data'],
|
|
'more' => $params['more']
|
|
]);
|
|
|
|
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/23 10:42
|
|
*/
|
|
public static function delete(array $params): bool
|
|
{
|
|
return Unit::destroy($params['id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取计量单位详情
|
|
* @param $params
|
|
* @return array
|
|
* @author likeadmin
|
|
* @date 2024/04/23 10:42
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
return Unit::findOrEmpty($params['id'])->toArray();
|
|
}
|
|
} |