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), "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) {
@ -84,8 +82,6 @@ class StoreProductLogic extends BaseLogic
// 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(); $find = Db::name('store_product_cate')->where(['store_id' => 1, 'cate_id' => $cate_id, 'leve' => $leve])->find();
if ($find) { if ($find) {
Db::name('store_product_cate')->where('id', $find['id'])->inc('count', 1)->update(); Db::name('store_product_cate')->where('id', $find['id'])->inc('count', 1)->update();
} else { } 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(); Db::startTrans();
try { try {
$find = StoreBranchProduct::where(['id' => $data['id']])->find(); $find = StoreBranchProduct::where(['id' => $data['id']])->find();
@ -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'],
]; ];
} }