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,26 +66,22 @@ class StoreProductLogic extends BaseLogic
"unique" => setUnique($res['id'], '', 0), "unique" => setUnique($res['id'], '', 0),
'sales' => 0, 'sales' => 0,
]); ]);
StoreCategory::where('id', $params['cate_id'])->inc('three')->update();
Db::commit(); Db::commit();
if ($params['is_store_all'] == 1) { if ($params['is_store_all'] == 1) {
$store_arr = SystemStore::where('is_show', 1)->column('id'); $store_arr = SystemStore::where('is_show', 1)->column('id');
foreach($store_arr as $store_id){ foreach ($store_arr as $store_id) {
Redis::send('store-storage', ['product_arr' => ['id'=>$res['id'],'stock'=>0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]); Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]);
} }
// Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $store_arr]); // Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $store_arr]);
} else { } else {
if (is_array($params['store_arr']) && count($params['store_arr']) > 0) { if (is_array($params['store_arr']) && count($params['store_arr']) > 0) {
foreach($params['store_arr'] as $key =>$store_id){ foreach ($params['store_arr'] as $key => $store_id) {
Redis::send('store-storage', ['product_arr' => ['id'=>$res['id'],'stock'=>0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]); Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]);
} }
// Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]); // Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]);
} }
} }
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
@ -185,30 +181,27 @@ class StoreProductLogic extends BaseLogic
*/ */
public static function updateGoodsclass($cate_id, $type = 0) public static function updateGoodsclass($cate_id, $type = 0)
{ {
$pid = StoreCategory::where('id', $cate_id)->value('pid'); $one = StoreCategory::where('id', $cate_id)->find();
if ($pid) { if ($one) {
//查二级分类 //查二级分类
$StoreCategory = StoreCategory::where('id', $pid)->find(); $two = StoreCategory::where('id', $one['pid'])->find();
if ($StoreCategory) { if ($two) {
$StoreCategory = StoreCategory::where('id', $StoreCategory['id'])->find(); if ($two['pid'] != 0) {
self::cate_update($cate_id,0,3); self::cate_update($cate_id,$two['id'],0,3);
self::cate_update($pid,0,2); self::cate_update($two['id'],$two['pid'],0,2);
self::cate_update($StoreCategory['id'],0,1); self::cate_update($two['pid'],0,0,1);
} else { }
self::cate_update($cate_id,0,2);
self::cate_update($pid,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){ $find = Db::name('store_product_cate')->where(['store_id' => 1, 'cate_id' => $cate_id, 'leve' => $leve])->find();
Db::name('store_product_cate')->where('id',$find['id'])->inc('count',1)->update(); if ($find) {
}else{ Db::name('store_product_cate')->where('id', $find['id'])->inc('count', 1)->update();
Db::name('store_product_cate')->insert(['store_id' => 1, 'cate_id' => $cate_id,'count'=>1,'leve'=>$leve,'create_time'=>time(),'update_time'=>time()]); } else {
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,10 +270,11 @@ class StoreProductLogic extends BaseLogic
/** /**
* 增加库存 * 增加库存
*/ */
public static function stock($data){ public static function stock($data)
{
Db::startTrans(); Db::startTrans();
try { try {
$find=StoreBranchProduct::where(['id' => $data['id']])->find(); $find = StoreBranchProduct::where(['id' => $data['id']])->find();
SystemStoreStorage::create([ SystemStoreStorage::create([
'product_id' => $find['product_id'], 'product_id' => $find['product_id'],
'store_id' => $find['store_id'], 'store_id' => $find['store_id'],
@ -294,6 +288,5 @@ class StoreProductLogic extends BaseLogic
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
} }
} }
} }

View File

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