feat: 修改了库存管理逻辑和分类接口

This commit is contained in:
mkm 2024-06-11 17:09:02 +08:00
parent e913dcb2ca
commit 2d189279cf
2 changed files with 24 additions and 31 deletions

View File

@ -66,8 +66,6 @@ class StoreProductLogic extends BaseLogic
"unique" => setUnique($res['id'], '', 0),
'sales' => 0,
]);
StoreCategory::where('id', $params['cate_id'])->inc('three')->update();
Db::commit();
if ($params['is_store_all'] == 1) {
@ -84,8 +82,6 @@ class StoreProductLogic extends BaseLogic
// Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]);
}
}
return true;
} catch (\Exception $e) {
Db::rollback();
@ -185,30 +181,27 @@ class StoreProductLogic extends BaseLogic
*/
public static function updateGoodsclass($cate_id, $type = 0)
{
$pid = StoreCategory::where('id', $cate_id)->value('pid');
if ($pid) {
$one = StoreCategory::where('id', $cate_id)->find();
if ($one) {
//查二级分类
$StoreCategory = StoreCategory::where('id', $pid)->find();
if ($StoreCategory) {
$StoreCategory = StoreCategory::where('id', $StoreCategory['id'])->find();
self::cate_update($cate_id,0,3);
self::cate_update($pid,0,2);
self::cate_update($StoreCategory['id'],0,1);
} else {
self::cate_update($cate_id,0,2);
self::cate_update($pid,0,1);
$two = StoreCategory::where('id', $one['pid'])->find();
if ($two) {
if ($two['pid'] != 0) {
self::cate_update($cate_id,$two['id'],0,3);
self::cate_update($two['id'],$two['pid'],0,2);
self::cate_update($two['pid'],0,0,1);
}
}
} else {
self::cate_update($cate_id,0,1);
}
}
public static function cate_update($cate_id=0,$product_id=0,$leve=1){
public static function cate_update($cate_id = 0,$pid=0, $product_id = 0, $leve = 1)
{
$find = Db::name('store_product_cate')->where(['store_id' => 1, 'cate_id' => $cate_id, 'leve' => $leve])->find();
if ($find) {
Db::name('store_product_cate')->where('id', $find['id'])->inc('count', 1)->update();
} else {
Db::name('store_product_cate')->insert(['store_id' => 1, 'cate_id' => $cate_id,'count'=>1,'leve'=>$leve,'create_time'=>time(),'update_time'=>time()]);
Db::name('store_product_cate')->insert(['pid'=>$pid,'store_id' => 1, 'cate_id' => $cate_id, 'count' => 1, 'leve' => $leve, 'create_time' => time(), 'update_time' => time()]);
}
}
/**
@ -277,7 +270,8 @@ class StoreProductLogic extends BaseLogic
/**
* 增加库存
*/
public static function stock($data){
public static function stock($data)
{
Db::startTrans();
try {
$find = StoreBranchProduct::where(['id' => $data['id']])->find();
@ -294,6 +288,5 @@ class StoreProductLogic extends BaseLogic
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -27,7 +27,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array
{
return [
'=' => [ 'name', 'data', 'store_id', 'sort'],
'=' => ['name', 'data', 'store_id', 'sort', 'pid'],
];
}