159 lines
4.4 KiB
PHP
159 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic\goods;
|
|
|
|
|
|
use app\common\model\goods\Goods;
|
|
use app\common\logic\BaseLogic;
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
* 商品列表逻辑
|
|
* Class GoodsLogic
|
|
* @package app\admin\logic\goods
|
|
*/
|
|
class GoodsLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加商品列表
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2024/04/23 11:28
|
|
*/
|
|
public static function add(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
Goods::create([
|
|
'name' => $params['name'],
|
|
'py' => $params['py'],
|
|
'number' => $params['number'],
|
|
'spec' => $params['spec'],
|
|
'class' => $params['class'],
|
|
'brand' => $params['brand'],
|
|
'unit' => $params['unit'],
|
|
'buy' => $params['buy'],
|
|
'sell' => $params['sell'],
|
|
'retail' => $params['retail'],
|
|
'integral' => $params['integral'],
|
|
'code' => $params['code'],
|
|
'warehouse' => $params['warehouse'],
|
|
'location' => $params['location'],
|
|
'stocktip' => $params['stocktip'],
|
|
'retail_name' => $params['retail_name'],
|
|
'imgs' => $params['imgs'],
|
|
'details' => $params['details'] ? implode(',', $params['details']) : '',
|
|
'data' => $params['data'],
|
|
'more' => $params['more'],
|
|
'sort' => $params['sort']
|
|
]);
|
|
|
|
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 11:28
|
|
*/
|
|
public static function edit(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
Goods::where('id', $params['id'])->update([
|
|
'name' => $params['name'],
|
|
'py' => $params['py'],
|
|
'number' => $params['number'],
|
|
'spec' => $params['spec'],
|
|
'class' => $params['class'],
|
|
'brand' => $params['brand'],
|
|
'unit' => $params['unit'],
|
|
'buy' => $params['buy'],
|
|
'sell' => $params['sell'],
|
|
'retail' => $params['retail'],
|
|
'integral' => $params['integral'],
|
|
'code' => $params['code'],
|
|
'warehouse' => $params['warehouse'],
|
|
'location' => $params['location'],
|
|
'stocktip' => $params['stocktip'],
|
|
'retail_name' => $params['retail_name'],
|
|
'imgs' => $params['imgs'],
|
|
'details' => $params['details'] ? implode(',', $params['details']) : '',
|
|
'data' => $params['data'],
|
|
'more' => $params['more'],
|
|
'sort' => $params['sort']
|
|
]);
|
|
|
|
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 11:28
|
|
*/
|
|
public static function delete(array $params): bool
|
|
{
|
|
return Goods::destroy($params['id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取商品列表详情
|
|
* @param $params
|
|
* @return array
|
|
* @author likeadmin
|
|
* @date 2024/04/23 11:28
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
return Goods::findOrEmpty($params['id'])->toArray();
|
|
}
|
|
/**
|
|
* @notes 设置标签
|
|
* @param $params
|
|
* @return bool
|
|
* @date 2024/04/23 11:28
|
|
*/
|
|
public static function setLabel($params)
|
|
{
|
|
try {
|
|
$value = $params['sys_labels'];
|
|
if (!empty($value)) {
|
|
if (!is_array($value)){
|
|
$value= ',' . $value . ',';
|
|
}else{
|
|
$value = ',' . implode(',', $value) . ',';
|
|
}
|
|
}
|
|
Goods::where('id', $params['id'])->update(['sys_labels' => $value]);
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
}
|