feat: 修改仓库库存计算逻辑,优化商品库存检查,删除冗余库存检查代码,更改库存查询字段。
This commit is contained in:
parent
d443e8e151
commit
c9f7d1a996
@ -74,13 +74,13 @@ class WarehouseOrderController extends BaseAdminController
|
||||
$delivery_time = $this->request->post('delivery_time');
|
||||
$mark = $this->request->post('mark');
|
||||
$count = count($store_arr);
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
$stock = bcmul($arr['stock'], $count);
|
||||
$nums = WarehouseProductStorege::where('warehouse_id', $warehouse_id)->where('product_id', $arr['id'])->value('nums');
|
||||
if ($nums < $stock) {
|
||||
return $this->fail('商品库存不足');
|
||||
}
|
||||
}
|
||||
// foreach ($product_arr as $key => $arr) {
|
||||
// $stock = bcmul($arr['stock'], $count);
|
||||
// $nums = WarehouseProductStorege::where('warehouse_id', $warehouse_id)->where('product_id', $arr['id'])->value('nums');
|
||||
// if ($nums < $stock) {
|
||||
// return $this->fail('商品库存不足');
|
||||
// }
|
||||
// }
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($count == 1) {
|
||||
@ -124,7 +124,6 @@ class WarehouseOrderController extends BaseAdminController
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
d($e);
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
|
||||
|
@ -32,7 +32,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['oid','product_id'],
|
||||
'=' => ['oid','product_id','is_pay'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI
|
||||
public function lists(): array
|
||||
{
|
||||
return StoreOrderCartInfo::where($this->searchWhere)
|
||||
->field('cart_info,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength)
|
||||
->field('oid,cart_info,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength)
|
||||
->select()->each(function ($item) {
|
||||
$find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find();
|
||||
if($find){
|
||||
|
@ -60,7 +60,7 @@ class WarehouseLogic extends BaseLogic
|
||||
$topData[] = [
|
||||
'title' => '总仓库库存',
|
||||
'desc' => '平台统计仓库库存',
|
||||
'total_money' => WarehouseProductStorege::sum('stock'),
|
||||
'total_money' => WarehouseProductStorege::sum('nums'),
|
||||
'cash_title' => 0,
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
@ -68,7 +68,7 @@ class WarehouseLogic extends BaseLogic
|
||||
$topData[] = [
|
||||
'title' => '海吉星仓库库存',
|
||||
'desc' => '平台统计海吉星仓库库存',
|
||||
'total_money' => WarehouseProductStorege::where('warehouse_id',1)->sum('stock'),
|
||||
'total_money' => WarehouseProductStorege::where('warehouse_id',1)->sum('nums'),
|
||||
'cash_title' => 0,
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
@ -76,7 +76,7 @@ class WarehouseLogic extends BaseLogic
|
||||
$topData[] = [
|
||||
'title' => '泸县集采集配库存',
|
||||
'desc' => '平台统计泸县集采集配库存',
|
||||
'total_money' => WarehouseProductStorege::where('warehouse_id',2)->sum('stock'),
|
||||
'total_money' => WarehouseProductStorege::where('warehouse_id',2)->sum('nums'),
|
||||
'cash_title' => 0,
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
@ -105,17 +105,19 @@ class WarehouseLogic extends BaseLogic
|
||||
|
||||
public static function warehouse_list()
|
||||
{
|
||||
$list = StoreProduct::where('is_show', 1)->select()->each(function ($item) {
|
||||
$item->sales = StoreOrderCartInfo::where('product_id', $item['id'])->sum('cart_num');
|
||||
$store_stock = StoreBranchProduct::where('product_id', $item['id'])->sum('stock');
|
||||
$warehouse_stock = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
|
||||
$item->store_stock=$store_stock;
|
||||
$item->warehouse_stock=$warehouse_stock;
|
||||
$item->total_stock=$store_stock+$warehouse_stock;
|
||||
$item->total_purchase=WarehouseProduct::where('product_id', $item['id'])->sum('total_price');
|
||||
$item->total_completed_amount=WarehouseProduct::where('product_id', $item['id'])->where('is_pay',1)->sum('total_price');
|
||||
$item->total_outstanding_amount=WarehouseProduct::where('product_id', $item['id'])->where('is_pay',0)->sum('total_price');
|
||||
|
||||
$list = StoreProduct::where('is_show', 1)
|
||||
->field('id,store_name,image')
|
||||
->select()->each(function ($item) {
|
||||
// $item->sales = StoreOrderCartInfo::where('product_id', $item['id'])->where('is_pay',1)->sum('cart_num');
|
||||
// $store_stock = StoreBranchProduct::where('product_id', $item['id'])->sum('stock');
|
||||
// $warehouse_stock = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
|
||||
// $item->store_stock=$store_stock;
|
||||
// $item->warehouse_stock=$warehouse_stock;
|
||||
// $item->total_stock=$store_stock+$warehouse_stock;
|
||||
// $item->total_purchase=WarehouseProduct::where('product_id', $item['id'])->sum('total_price');
|
||||
// $item->total_completed_amount=WarehouseProduct::where('product_id', $item['id'])->where('is_pay',1)->sum('total_price');
|
||||
// $item->total_outstanding_amount=WarehouseProduct::where('product_id', $item['id'])->where('is_pay',0)->sum('total_price');
|
||||
// sum(branch_product.stock) as store_stock,sum(w_p.total_price) as total_purchase,
|
||||
})->toArray();
|
||||
return $list;
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ class WarehouseProductLogic extends BaseLogic
|
||||
if ($storege) {
|
||||
if ($params['financial_pm'] == 0) {
|
||||
$after_nums = $storege['nums'] - $params['nums'];
|
||||
if ($after_nums < 0) {
|
||||
throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
|
||||
}
|
||||
// if ($after_nums < 0) {
|
||||
// throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
|
||||
// }
|
||||
WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update();
|
||||
//门店加库存
|
||||
$storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id',$params['store_id'])->find();
|
||||
|
@ -5,6 +5,7 @@ namespace app\common\model\store_product;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user