feat: 修改了库存管理逻辑以支持仓库库存查询和更新

This commit is contained in:
mkm 2024-08-03 11:22:35 +08:00
parent 89775fdccb
commit d9fca4bf15
4 changed files with 28 additions and 18 deletions

View File

@ -314,7 +314,7 @@ class TradeStatisticLogic extends BaseLogic
$depositWehre['financial_type'] = 11;
$orderDepositMoney = $this->getFinanceFlow($depositWehre, "sum");
$lastOrderDepositMoney = $this->getFinanceFlow($dateWhere, "sum", "", $isNum);
$OrderDepositCurve = $this->getFinanceFlow($where, "group", "create_time");
$OrderDepositCurve = $this->getFinanceFlow($depositWehre, "group", "create_time");
$OrderDepositChain = countRate($orderDepositMoney, $lastOrderDepositMoney);
$topData[8] = [
@ -483,17 +483,17 @@ class TradeStatisticLogic extends BaseLogic
$orderGroup = "create_time";
$OrderMoney = $this->getOrderTotalMoney($where, $selectType, $orderGroup);
//用户充值收入
$rechargeGroup = "create_time";
$RechargeMoneyHome = $this->getRechargeTotalMoney($where, $selectType, $rechargeGroup);
$RechargeMoneyAdmin = $this->getBillYeTotalMoney($where, $selectType, $rechargeGroup);
$RechargeMoney = $this->totalArrData([$RechargeMoneyHome, $RechargeMoneyAdmin]);
// $rechargeGroup = "create_time";
// $RechargeMoneyHome = $this->getRechargeTotalMoney($where, $selectType, $rechargeGroup);
// $RechargeMoneyAdmin = $this->getBillYeTotalMoney($where, $selectType, $rechargeGroup);
// $RechargeMoney = $this->totalArrData([$RechargeMoneyHome, $RechargeMoneyAdmin]);
//购买会员收入
$memberGroup = "create_time";
$MemberMoney = $this->getMemberTotalMoney($where, $selectType, $memberGroup);
// $memberGroup = "create_time";
// $MemberMoney = $this->getMemberTotalMoney($where, $selectType, $memberGroup);
//线下收款收入
$offlineGroup = "create_time";
$OfflineMoney = $this->getOfflineTotalMoney($where, $selectType, $offlineGroup);
return $this->totalArrData([$OrderMoney, $RechargeMoney, $MemberMoney, $OfflineMoney]);
return $this->totalArrData([$OrderMoney, $OfflineMoney]);
}

View File

@ -8,6 +8,8 @@ use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue
use app\common\model\system_store_storage\SystemStoreStorage;
use app\common\logic\BaseLogic;
use app\common\model\store_product\StoreProduct;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use think\facade\Db;
@ -59,11 +61,12 @@ class SystemStoreStorageLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
$stock=StoreProduct::where('id', $params['product_id'])->value('stock');
$nums=SystemStoreStorage::where('id', $params['id'])->value('nums');
$stock=bcadd($stock,$nums);
if($stock<$params['nums']){
self::setError('库存不足,主库为:'.$stock);
$find=SystemStoreStorage::where('id', $params['id'])->find();
//查看仓库库存
$productStorege=WarehouseProductStorege::where('product_id', $params['product_id'],['warehouse_id'=>$find['warehouse_id']])->find();
if($productStorege && $productStorege['nums']<$params['nums']){
self::setError('库存不足,仓库库存为:'.$productStorege['nums']);
return false;
}
Db::startTrans();
@ -71,8 +74,12 @@ class SystemStoreStorageLogic extends BaseLogic
SystemStoreStorage::where('id', $params['id'])->update([
'nums' => $params['nums'],
'admin_id' => $params['admin_id'],
'status' => 0,
'mark' => '',
]);
StoreProduct::where('id', $params['product_id'])->update(['stock'=>bcsub($stock,$params['nums'])]);
StoreProduct::where('id', $params['product_id'])->inc('stock',bcsub($find['nums'] ,$params['nums'],2))->update();
WarehouseProductStorege::where('id',$productStorege['id'])->inc('stock',bcsub($find['nums'] ,$params['nums'],2))->update();
WarehouseProduct::where('id',$find['outbound_id'])->update(['nums',$params['nums']]);
Db::commit();
return true;
} catch (\Exception $e) {

View File

@ -90,10 +90,10 @@ class WarehouseProductLogic extends BaseLogic
if(isset($params['expiration_date']) &&$params['expiration_date']!=''){
$data['expiration_date']=strtotime($params['expiration_date']);
}
WarehouseProduct::where('id', $params['id'])->update($data);
$res=WarehouseProduct::where('id', $params['id'])->update($data);
Db::commit();
return true;
return $res;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());

View File

@ -169,6 +169,7 @@ class StoreStorageSend implements Consumer
'nums' => $product_arr['stock'],
'admin_id' => $admin_id,
'type' => $stock_type,
'warehouse_id'=>$warehouse_id,
];
$data=[
'warehouse_id'=>$warehouse_id,
@ -187,11 +188,13 @@ class StoreStorageSend implements Consumer
$storage['mark'] = '库存不足,分库存为:' .$warehouse['nums'];
$data['mark'] = '库存不足,分库存为:' .$warehouse['nums'].' 总仓库存为:'.$find['stock'];
}
$res=WarehouseProductLogic::add($data);
$storage['outbound_id']=$res['id']??0;
SystemStoreStorage::create($storage);
WarehouseProductLogic::add($data);
} else {
$res=WarehouseProductLogic::add($data);
$storage['outbound_id']=$res['id']??0;
SystemStoreStorage::create($storage);
WarehouseProductLogic::add($data);
}
}