feat: 修改了商品仓储信息确认操作
This commit is contained in:
parent
7438141702
commit
ead2595094
@ -6,7 +6,9 @@ namespace app\admin\controller\store_product;
|
|||||||
use app\admin\controller\BaseAdminController;
|
use app\admin\controller\BaseAdminController;
|
||||||
use app\admin\lists\store_product\StoreProductLists;
|
use app\admin\lists\store_product\StoreProductLists;
|
||||||
use app\admin\logic\store_product\StoreProductLogic;
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
|
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||||
use app\admin\validate\store_product\StoreProductValidate;
|
use app\admin\validate\store_product\StoreProductValidate;
|
||||||
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||||
use Webman\RedisQueue\Redis;
|
use Webman\RedisQueue\Redis;
|
||||||
@ -113,16 +115,41 @@ class StoreProductController extends BaseAdminController
|
|||||||
if ($count == 1) {
|
if ($count == 1) {
|
||||||
$store_id = $store_arr[0];
|
$store_id = $store_arr[0];
|
||||||
foreach ($product_arr as $key => $arr) {
|
foreach ($product_arr as $key => $arr) {
|
||||||
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
// $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
$data=[
|
||||||
|
'warehouse_id'=>$warehouse_id,
|
||||||
|
'product_id' => $arr['id'],
|
||||||
|
'store_id' => $store_id,
|
||||||
|
'financial_pm' => 0,
|
||||||
|
'batch' => 1,
|
||||||
|
'nums' => $arr['stock'],
|
||||||
|
'status' =>1,
|
||||||
|
'admin_id' =>$this->adminId,
|
||||||
|
];
|
||||||
|
WarehouseProductLogic::add($data);
|
||||||
|
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock',$arr['stock'])->update();
|
||||||
|
|
||||||
|
// StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||||
|
|
||||||
// Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);
|
// Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach ($product_arr as $key => $arr) {
|
foreach ($product_arr as $key => $arr) {
|
||||||
foreach ($store_arr as $k => $store_id) {
|
foreach ($store_arr as $k => $store_id) {
|
||||||
$find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
$data=[
|
||||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
'warehouse_id'=>$warehouse_id,
|
||||||
|
'product_id' => $arr['id'],
|
||||||
|
'store_id' => $store_id,
|
||||||
|
'financial_pm' => 0,
|
||||||
|
'batch' => 1,
|
||||||
|
'nums' => $arr['stock'],
|
||||||
|
'status' =>1,
|
||||||
|
'admin_id' =>$this->adminId,
|
||||||
|
];
|
||||||
|
WarehouseProductLogic::add($data);
|
||||||
|
StoreBranchProduct::where('product_id', $arr['id'])->where('store_id', $store_id)->inc('stock',$arr['stock'])->update();
|
||||||
|
// $find = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||||
|
// StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $find, $warehouse_id);
|
||||||
// Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);
|
// Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id, 'stock_type' => $stock_type, 'admin_id' => $this->adminId, 'warehouse_id' => $warehouse_id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ class WarehouseProductController extends BaseAdminController
|
|||||||
{
|
{
|
||||||
$params = (new WarehouseProductValidate())->post()->goCheck('add');
|
$params = (new WarehouseProductValidate())->post()->goCheck('add');
|
||||||
$params['admin_id']=$this->adminId;
|
$params['admin_id']=$this->adminId;
|
||||||
|
$params['store_id']=0;
|
||||||
$result = WarehouseProductLogic::add($params);
|
$result = WarehouseProductLogic::add($params);
|
||||||
if (WarehouseProductLogic::hasError()) {
|
if (WarehouseProductLogic::hasError()) {
|
||||||
return $this->fail(WarehouseProductLogic::getError());
|
return $this->fail(WarehouseProductLogic::getError());
|
||||||
@ -103,12 +104,12 @@ class WarehouseProductController extends BaseAdminController
|
|||||||
* 确认操作
|
* 确认操作
|
||||||
*/
|
*/
|
||||||
public function enter(){
|
public function enter(){
|
||||||
$id=$this->request->post('id');
|
// $id=$this->request->post('id');
|
||||||
$result = WarehouseProductLogic::enter($id);
|
// $result = WarehouseProductLogic::enter($id);
|
||||||
if (true === $result) {
|
// if (true === $result) {
|
||||||
return $this->success('编辑成功', [], 1, 1);
|
// return $this->success('编辑成功', [], 1, 1);
|
||||||
}
|
// }
|
||||||
return $this->fail(WarehouseProductLogic::getError());
|
// return $this->fail(WarehouseProductLogic::getError());
|
||||||
return $this->success($result);
|
return $this->success('');
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -46,7 +46,7 @@ class StoreProductLogic extends BaseLogic
|
|||||||
'bar_code' => $params['bar_code'] ?? '',
|
'bar_code' => $params['bar_code'] ?? '',
|
||||||
'cate_id' => $params['cate_id'],
|
'cate_id' => $params['cate_id'],
|
||||||
'unit' => $params['unit'],
|
'unit' => $params['unit'],
|
||||||
'stock' => $params['stock'],
|
'stock' => 0,
|
||||||
'price' => $params['price'],
|
'price' => $params['price'],
|
||||||
'vip_price' => $params['vip_price'],
|
'vip_price' => $params['vip_price'],
|
||||||
'cost' => $params['cost'],
|
'cost' => $params['cost'],
|
||||||
@ -73,7 +73,7 @@ class StoreProductLogic extends BaseLogic
|
|||||||
"cost" => $params['cost'],
|
"cost" => $params['cost'],
|
||||||
"purchase" => $params['purchase'],
|
"purchase" => $params['purchase'],
|
||||||
"unit" => $params["unit"],
|
"unit" => $params["unit"],
|
||||||
"stock" => $params['stock'],
|
"stock" => 0,
|
||||||
"product_id" => $res['id'],
|
"product_id" => $res['id'],
|
||||||
"unique" => setUnique($res['id'], '', 0),
|
"unique" => setUnique($res['id'], '', 0),
|
||||||
'sales' => 0,
|
'sales' => 0,
|
||||||
@ -446,9 +446,9 @@ class StoreProductLogic extends BaseLogic
|
|||||||
'bar_code' => $attr_value['bar_code']
|
'bar_code' => $attr_value['bar_code']
|
||||||
];
|
];
|
||||||
StoreBranchProductAttrValue::create($arr);
|
StoreBranchProductAttrValue::create($arr);
|
||||||
if ($product_arr['stock'] > 0) {
|
// if ($product_arr['stock'] > 0) {
|
||||||
self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id);
|
// self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id);
|
||||||
}
|
// }
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -460,9 +460,9 @@ class StoreProductLogic extends BaseLogic
|
|||||||
//更新门店库存
|
//更新门店库存
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
if ($product_arr['stock'] > 0) {
|
// if ($product_arr['stock'] > 0) {
|
||||||
self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id);
|
// self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id);
|
||||||
}
|
// }
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -497,9 +497,9 @@ class StoreProductLogic extends BaseLogic
|
|||||||
'stock' => 0,
|
'stock' => 0,
|
||||||
];
|
];
|
||||||
StoreBranchProductExchange::create($product);
|
StoreBranchProductExchange::create($product);
|
||||||
if ($product_arr['stock'] > 0) {
|
// if ($product_arr['stock'] > 0) {
|
||||||
self::storage($find, $store_id, $admin_id, $product_arr,$warehouse_id);
|
// self::storage($find, $store_id, $admin_id, $product_arr,$warehouse_id);
|
||||||
}
|
// }
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -510,9 +510,9 @@ class StoreProductLogic extends BaseLogic
|
|||||||
} else {
|
} else {
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
if ($product_arr['stock'] > 0) {
|
// if ($product_arr['stock'] > 0) {
|
||||||
self::storage($find, $store_id, $admin_id, $product_arr,2,$warehouse_id);
|
// self::storage($find, $store_id, $admin_id, $product_arr,2,$warehouse_id);
|
||||||
}
|
// }
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -11,6 +11,7 @@ use app\common\model\system_store_storage\SystemStoreStorage;
|
|||||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
use support\exception\BusinessException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,20 +34,46 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
// Db::startTrans();
|
// Db::startTrans();
|
||||||
// try {
|
// try {
|
||||||
|
$before_nums=0;
|
||||||
|
$after_nums=0;
|
||||||
|
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||||
|
if($storege){
|
||||||
|
if ($params['financial_pm'] == 0) {
|
||||||
|
$after_nums=$storege['nums']-$params['nums'];
|
||||||
|
if($after_nums<0){
|
||||||
|
throw new BusinessException('库存不足');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update();
|
||||||
|
} else {
|
||||||
|
$after_nums=$storege['nums']+$params['nums'];
|
||||||
|
WarehouseProductStorege::where('id', $storege['id'])->inc('nums', $params['nums'])->update();
|
||||||
|
}
|
||||||
|
$before_nums=$storege['nums'];
|
||||||
|
}else{
|
||||||
|
WarehouseProductStorege::create([
|
||||||
|
'warehouse_id' => $params['warehouse_id'],
|
||||||
|
'product_id' => $params['product_id'],
|
||||||
|
'nums' => $params['nums'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();
|
||||||
$data = [
|
$data = [
|
||||||
'warehouse_id' => $params['warehouse_id'],
|
'warehouse_id' => $params['warehouse_id'],
|
||||||
'store_id' => $params['store_id'] ?? 0,
|
'store_id' => $params['store_id'] ?? 0,
|
||||||
'product_id' => $params['product_id'],
|
'product_id' => $params['product_id'],
|
||||||
'financial_pm' => $params['financial_pm'],
|
'financial_pm' => $params['financial_pm'],
|
||||||
'batch' => 0,
|
'batch' => $batch_count+1,
|
||||||
'nums' => $params['nums'],
|
'nums' => $params['nums'],
|
||||||
|
'before_nums' => $before_nums,
|
||||||
|
'after_nums' => $after_nums,
|
||||||
'price' => $params['price'] ?? '',
|
'price' => $params['price'] ?? '',
|
||||||
'purchase' => $params['purchase'] ?? '',
|
'purchase' => $params['purchase'] ?? '',
|
||||||
'cost' => $params['cost'] ?? '',
|
'cost' => $params['cost'] ?? '',
|
||||||
'total_price' => $params['total_price'] ?? '',
|
'total_price' => $params['total_price'] ?? '',
|
||||||
'admin_id' => $params['admin_id'],
|
'admin_id' => $params['admin_id'],
|
||||||
'code' => $params['code'] ?? '',
|
'code' => $params['code'] ?? '',
|
||||||
'status' => $params['status'] ?? 0,
|
'status' => 1,
|
||||||
'mark' => $params['mark'] ?? '',
|
'mark' => $params['mark'] ?? '',
|
||||||
];
|
];
|
||||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||||
@ -56,7 +83,8 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
$data['expiration_date'] = strtotime($params['expiration_date']);
|
$data['expiration_date'] = strtotime($params['expiration_date']);
|
||||||
}
|
}
|
||||||
$res = WarehouseProduct::create($data);
|
$res = WarehouseProduct::create($data);
|
||||||
self::enter($res['id'], $params['financial_pm']);
|
|
||||||
|
// self::enter($res['id'], $params['financial_pm']);
|
||||||
// Db::commit();
|
// Db::commit();
|
||||||
return $res;
|
return $res;
|
||||||
// } catch (\Exception $e) {
|
// } catch (\Exception $e) {
|
||||||
@ -108,38 +136,6 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 确认商品仓储信息
|
|
||||||
* @param array $params
|
|
||||||
* @author admin
|
|
||||||
* @date 2024/07/31 16:55
|
|
||||||
*/
|
|
||||||
public static function enter($id, $financial_pm = 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
$find = WarehouseProduct::where('id', $id)->find();
|
|
||||||
$find->status = 1;
|
|
||||||
$find->batch = WarehouseProduct::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id'], 'financial_pm' => $financial_pm, 'store_id' => $find['store_id']])->count();
|
|
||||||
$find->save();
|
|
||||||
|
|
||||||
$storege = WarehouseProductStorege::where('warehouse_id', $find['warehouse_id'])->where('product_id', $find['product_id'])->find();
|
|
||||||
|
|
||||||
if ($storege) {
|
|
||||||
if ($financial_pm == 0) {
|
|
||||||
WarehouseProductStorege::where('id',$storege['id'])->dec('nums', $find['nums'])->update();
|
|
||||||
} else {
|
|
||||||
WarehouseProductStorege::where('id',$storege['id'])->inc('nums', $find['nums'])->update();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
WarehouseProductStorege::create([
|
|
||||||
'warehouse_id' => $find['warehouse_id'],
|
|
||||||
'product_id' => $find['product_id'],
|
|
||||||
'nums' => $find['nums'],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 删除商品仓储信息
|
* @notes 删除商品仓储信息
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
Loading…
x
Reference in New Issue
Block a user