554 lines
24 KiB
PHP
554 lines
24 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic\warehouse_product;
|
|
|
|
use app\admin\logic\delivery_service\DeliveryServiceLogic;
|
|
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
|
|
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
|
use app\common\model\PurchaseFunds;
|
|
use app\common\model\warehouse_product\WarehouseProduct;
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
|
use app\common\model\store_product\StoreProduct;
|
|
use app\common\model\system_store_storage\SystemStoreStorage;
|
|
use app\common\model\warehouse_order\WarehouseOrder;
|
|
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
|
use think\db\exception\DataNotFoundException;
|
|
use think\db\exception\DbException;
|
|
use think\db\exception\ModelNotFoundException;
|
|
use think\facade\Db;
|
|
use support\exception\BusinessException;
|
|
|
|
|
|
/**
|
|
* 商品仓储信息逻辑
|
|
* Class WarehouseProductLogic
|
|
* @package app\admin\logic\warehouse_product
|
|
*/
|
|
class WarehouseProductLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加商品仓储信息
|
|
* @param array $params
|
|
* @author admin
|
|
* @date 2024/07/31 16:55
|
|
*/
|
|
public static function add(array $params, $type = 1,$admin_id=0)
|
|
{
|
|
// Db::startTrans();
|
|
try {
|
|
$after_nums = 0;
|
|
if (!in_array($params['order_type'],[6,9])) {
|
|
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
|
if ($storege) {
|
|
$after_nums = $storege['nums'] + $params['nums'];
|
|
if ($type == 1) {
|
|
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
|
|
if (!$storeProduct) {
|
|
throw new BusinessException('商品不存在');
|
|
}
|
|
if ($storeProduct['purchase'] <= 0) {
|
|
$total_price = 0;
|
|
} else {
|
|
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
|
}
|
|
WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storege['id']]);
|
|
SqlChannelLog('WarehouseProductStorege', $storege['id'], $after_nums, 1, Request()->url(),$admin_id);
|
|
|
|
}
|
|
} else {
|
|
$after_nums = $params['nums'];
|
|
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty();
|
|
if (!$storeProduct) {
|
|
throw new BusinessException('商品不存在');
|
|
}
|
|
if ($storeProduct['purchase'] <= 0) {
|
|
$total_price = 0;
|
|
} else {
|
|
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
|
}
|
|
$data = [
|
|
'warehouse_id' => $params['warehouse_id'],
|
|
'product_id' => $params['product_id'],
|
|
'nums' => $params['nums'],
|
|
'total_price' => $total_price
|
|
];
|
|
if ($params['financial_pm'] == 0) {
|
|
$data['nums'] = -$params['nums'];
|
|
}
|
|
$storege = WarehouseProductStorege::create($data);
|
|
SqlChannelLog('WarehouseProductStorege', $storege['id'], -$params['nums'], 1, Request()->url(),$admin_id);
|
|
|
|
}
|
|
}
|
|
$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 = [
|
|
'warehouse_id' => $params['warehouse_id'],
|
|
'supplier_id' => $params['supplier_id'] ?? 0,
|
|
'oid' => $params['oid'] ?? 0,
|
|
'store_id' => $params['store_id'] ?? 0,
|
|
'product_id' => $params['product_id'],
|
|
'financial_pm' => $params['financial_pm'],
|
|
'batch' => $batch_count + 1,
|
|
'nums' => $params['nums'],
|
|
'before_nums' => 0,
|
|
'after_nums' => 0,
|
|
'price' => $params['price'] ?? '',
|
|
'purchase' => $params['purchase'] ?? '',
|
|
// 'cost' => $params['cost'] ?? '',
|
|
'total_price' => $params['total_price'] ?? '',
|
|
'admin_id' => $params['admin_id'],
|
|
'code' => $params['code'] ?? '',
|
|
'status' => 1,
|
|
'pay_type' => $params['pay_type'] ?? 0,
|
|
'mark' => $params['mark'] ?? '',
|
|
];
|
|
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
|
$data['manufacture'] = strtotime($params['manufacture']);
|
|
}
|
|
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
|
$data['expiration_date'] = strtotime($params['expiration_date']);
|
|
}
|
|
$res = WarehouseProduct::create($data);
|
|
SqlChannelLog('WarehouseProduct', $res['id'], $params['nums'], $params['financial_pm'] == 1 ? 1 : -1, Request()->url(),$admin_id);
|
|
|
|
if (!empty($params['purchase_funds_id'])) {
|
|
PurchaseFunds::where('id', $params['purchase_funds_id'])->dec('current_amount', $params['total_price'])->save();
|
|
}
|
|
|
|
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
|
$productSourceLinkInfoLogic->purchaseProductOffer = $params;
|
|
$productSourceLinkInfoLogic->setInfo([
|
|
'types' => ProductSourceLinkInfo::TypeIn,
|
|
'buyer_id' => $params['buyer_id'],
|
|
'warehouse_id' => $params['warehouse_id'],
|
|
'link_id' => $res['id'],
|
|
]);
|
|
$productSourceLinkInfoLogic->putInStorage();
|
|
|
|
DeliveryServiceLogic::subPurchaseFunds($params['buyer_id'], $params['total_price']);
|
|
return $res;
|
|
} catch (\Throwable $e) {
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 设置出库商品
|
|
*/
|
|
public static function setOutbound(array $params, $type = 1,$admin_id=0)
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
$after_nums = 0;
|
|
if ($params['order_type'] != 6) {
|
|
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
|
if ($storege) {
|
|
$after_nums = bcsub($storege['nums'], $params['nums']);
|
|
$total_price = bcmul($after_nums, $params['purchase'], 2);
|
|
WarehouseProductStorege::update(['nums' => bcsub($storege['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storege['id']]);
|
|
SqlChannelLog('WarehouseProductStorege', $storege['id'], bcsub($storege['nums'], $params['nums']), -1, Request()->url(),$admin_id);
|
|
} else {
|
|
$data = [
|
|
'warehouse_id' => $params['warehouse_id'],
|
|
'product_id' => $params['product_id'],
|
|
'nums' => -$params['nums'],
|
|
'total_price' => 0
|
|
];
|
|
$storege = WarehouseProductStorege::create($data);
|
|
SqlChannelLog('WarehouseProductStorege', $storege->id, -$params['nums'], -1, Request()->url(),$admin_id);
|
|
}
|
|
} else {
|
|
$storege['nums'] = 0;
|
|
}
|
|
|
|
$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 = [
|
|
'warehouse_id' => $params['warehouse_id'],
|
|
'supplier_id' => $params['supplier_id'] ?? 0,
|
|
'oid' => $params['oid'] ?? 0,
|
|
'store_id' => $params['store_id'] ?? 0,
|
|
'product_id' => $params['product_id'],
|
|
'financial_pm' => $params['financial_pm'],
|
|
'batch' => $batch_count + 1,
|
|
'nums' => $params['nums'],
|
|
'before_nums' => $storege['nums'],
|
|
'after_nums' => $after_nums,
|
|
'price' => $params['price'] ?? 0,
|
|
'purchase' => $params['purchase'] ?? 0,
|
|
'vip_price' => $params['vip_price'] ?? 0,
|
|
'cost' => $params['cost'] ?? 0,
|
|
'total_price' => $params['total_price'] ?? 0,
|
|
'admin_id' => $params['admin_id'],
|
|
'code' => $params['code'] ?? '',
|
|
'unit' => $params['unit'] ?? 0,
|
|
'status' => 0,
|
|
'mark' => $params['mark'] ?? '',
|
|
'order_type' => $params['order_type'] ?? '',
|
|
];
|
|
$res = WarehouseProduct::create($data);
|
|
SqlChannelLog('WarehouseProduct', $res->id, $params['nums'], $params['financial_pm'] == 1 ? 1 : -1, Request()->url(),$admin_id);
|
|
|
|
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
|
$productSourceLinkInfoLogic->warehouseProduct = $data;
|
|
$productSourceLinkInfoLogic->setInfo([
|
|
'warehouse_id' => $params['warehouse_id'],
|
|
'store_id' => $data['store_id'],
|
|
'link_id' => $res['id'],
|
|
]);
|
|
$productSourceLinkInfoLogic->outbound();
|
|
|
|
Db::commit();
|
|
return $res;
|
|
} catch (\Throwable $e) {
|
|
Db::rollback();
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @notes 编辑商品仓储信息
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/07/31 16:55
|
|
*/
|
|
public static function edit(array $params,$admin_id=0)
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
$find = WarehouseOrder::where('id', $params['oid'])->find();
|
|
if ($find) {
|
|
$res = WarehouseProduct::where('id', $params['id'])->withTrashed()->find();
|
|
$updateNums = bcsub($params['nums'], $res['nums'],2);
|
|
if ($updateNums != 0) {
|
|
if ($res['status'] == 1) {
|
|
throw new BusinessException('门店已确认入库,不能修改数量');
|
|
}
|
|
$storageNum = $res['financial_pm'] == 0 ? -$updateNums : $updateNums;
|
|
$productNum = $updateNums;
|
|
self::updateWarehouseProduct($res, $storageNum, $productNum);
|
|
|
|
self::updateProductSourceLink($res, $params, $updateNums);
|
|
}
|
|
$datas = [
|
|
'total_price' => $params['total_price'],
|
|
];
|
|
if ($find['financial_pm'] == 1) {
|
|
$datas['supplier_id'] = $params['supplier_id'];
|
|
$datas['pay_type'] = $params['pay_type'];
|
|
$datas['purchase'] = $params['purchase'];
|
|
} else {
|
|
$datas['price'] = $params['price'];
|
|
}
|
|
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
|
$datas['manufacture'] = strtotime($params['manufacture']);
|
|
}
|
|
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
|
$datas['expiration_date'] = strtotime($params['expiration_date']);
|
|
}
|
|
$res->save($datas);
|
|
self::updateWarehouseOrder($res['oid']);
|
|
}
|
|
Db::commit();
|
|
return $res;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @notes 删除商品仓储信息
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2024/07/31 16:55
|
|
*/
|
|
public static function delete(array $params,$admin_id=0): bool
|
|
{
|
|
$res = WarehouseProduct::where('id', $params['id'])->find();
|
|
if ($res) {
|
|
Db::startTrans();
|
|
try {
|
|
$storageNum = $res['financial_pm'] == 1 ? -$res['nums'] : $res['nums'];
|
|
$productNum = -$res['nums'];
|
|
self::updateWarehouseProduct($res, $storageNum, $productNum);
|
|
$res->delete();
|
|
self::updateWarehouseOrder($res['oid']);
|
|
$types = $res['financial_pm'] == 1 ? ProductSourceLinkInfo::TypeIn : ProductSourceLinkInfo::TypeOut;
|
|
|
|
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
|
$productSourceLinkInfoLogic->deleteByLinkId($res['id'], $types);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Throwable $th) {
|
|
Db::rollback();
|
|
throw new BusinessException($th->getMessage());
|
|
}
|
|
}
|
|
throw new BusinessException('没有查到出入库信息');
|
|
}
|
|
|
|
/**
|
|
* * @notes 结算
|
|
* @param $id
|
|
* @return void
|
|
*/
|
|
public static function settlement($id)
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
$find = WarehouseProduct::where(['id' => $id, 'financial_pm' => 1, 'is_pay' => 0])->find();
|
|
if ($find) {
|
|
$find->is_pay = 1;
|
|
$find->save();
|
|
} else {
|
|
throw new BusinessException('没有查到出入库信息');
|
|
}
|
|
Db::commit();
|
|
} catch (\Throwable $th) {
|
|
Db::rollback();
|
|
throw new BusinessException($th->getMessage());
|
|
}
|
|
}
|
|
/**
|
|
* * @notes 仓库重置出入库数量
|
|
* @param $id
|
|
* @return void
|
|
*/
|
|
public static function settNums($params,$admin_id=0)
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
$warehouseProduct = WarehouseProduct::where('id', $params['id'])->find();
|
|
if ($warehouseProduct) {
|
|
$updateNums = bcsub($params['nums'], $warehouseProduct['nums'],2);
|
|
if ($updateNums != 0) {
|
|
$storageNum = $warehouseProduct['financial_pm'] == 0 ? -$updateNums : $updateNums;
|
|
$productNum = $updateNums;
|
|
self::updateWarehouseProduct($warehouseProduct, $storageNum, $productNum);
|
|
|
|
self::updateProductSourceLink($warehouseProduct, $params, $updateNums);
|
|
}
|
|
if($warehouseProduct['financial_pm']==1){
|
|
$datas = [
|
|
'nums' => $params['nums'],
|
|
'total_price' => bcmul($params['nums'], $warehouseProduct['purchase'], 2),
|
|
];
|
|
}else{
|
|
$datas = [
|
|
'nums' => $params['nums'],
|
|
'total_price' => bcmul($params['nums'], $warehouseProduct['price'], 2),
|
|
];
|
|
}
|
|
|
|
$warehouseProduct->save($datas);
|
|
self::updateWarehouseOrder($warehouseProduct['oid']);
|
|
}
|
|
Db::commit();
|
|
} catch (\Throwable $th) {
|
|
Db::rollback();
|
|
throw new BusinessException($th->getMessage());
|
|
}
|
|
}
|
|
/**
|
|
* @notes 获取商品仓储信息详情
|
|
* @param $params
|
|
* @return array
|
|
* @author admin
|
|
* @date 2024/07/31 16:55
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
$data = WarehouseProduct::findOrEmpty($params['id'])->toArray();
|
|
if ($data) {
|
|
$data['manufacture'] = date('Y-m-d', $data['manufacture']);
|
|
$data['expiration_date'] = date('Y-m-d', $data['expiration_date']);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* @deprecated 已废弃
|
|
*/
|
|
private static function decProductIncStorege($warehouseProduct,$nums,$admin_id=0)
|
|
{
|
|
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
|
->where('product_id', $warehouseProduct['product_id'])->find();
|
|
$warehouseProductStorage->nums = bcadd($warehouseProductStorage->nums,$nums,2);
|
|
$warehouseProductStorage->save();
|
|
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['id'], $nums, 1, Request()->url(),$admin_id);
|
|
|
|
$update = [
|
|
'nums' => bcsub($warehouseProduct['nums'], $nums, 2),
|
|
'total_price' => bcsub($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
|
|
];
|
|
WarehouseProduct::where('id',$warehouseProduct['id'])->update($update);
|
|
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, -1, Request()->url(),$admin_id);
|
|
|
|
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
|
if ($find) {
|
|
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
|
|
'nums' => $find['nums'],
|
|
'total_price' => $find['total_price']
|
|
]);
|
|
}
|
|
|
|
self::updateStoreStorage($warehouseProduct['oid'], $nums, 'dec');
|
|
}
|
|
|
|
/**
|
|
* @deprecated 已废弃
|
|
*/
|
|
//增加
|
|
private static function incProductDecStorege($warehouseProduct, $nums,$admin_id=0)
|
|
{
|
|
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
|
->where('product_id', $warehouseProduct['product_id'])->find();
|
|
$warehouseProductStorage->nums = bcsub($warehouseProductStorage->nums,$nums,2);
|
|
$warehouseProductStorage->save();
|
|
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['id'], $nums, -1, Request()->url(),$admin_id);
|
|
|
|
$update = [
|
|
'nums' => bcadd($warehouseProduct['nums'], $nums, 2),
|
|
'total_price' => bcadd($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
|
|
];
|
|
WarehouseProduct::where('id',$warehouseProduct['id'])->update($update);
|
|
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, 1, Request()->url(),$admin_id);
|
|
|
|
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
|
if ($find) {
|
|
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
|
|
'nums' => $find['nums'],
|
|
'total_price' => $find['total_price']
|
|
]);
|
|
}
|
|
|
|
self::updateStoreStorage($warehouseProduct['oid'], $nums);
|
|
}
|
|
|
|
/**
|
|
* @deprecated 已废弃
|
|
*/
|
|
private static function updateStoreStorage($outboundId, $nums, $type = 'inc')
|
|
{
|
|
$storeStorage = SystemStoreStorage::where('outbound_id', $outboundId)->find();
|
|
if (empty($storeStorage)) {
|
|
return;
|
|
}
|
|
$storeStorage->nums = $type == 'inc' ? $storeStorage->nums + $nums : $storeStorage->nums - $nums;
|
|
$storeStorage->save();
|
|
if ($storeStorage->status == 0) {
|
|
return;
|
|
}
|
|
// 门店入库单已确认,增加/减少 门店库存
|
|
$storeBranchProduct = StoreBranchProduct::where('store_id', $storeStorage->store_id)
|
|
->where('product_id', $storeStorage->product_id)->find();
|
|
if (!empty($storeBranchProduct)) {
|
|
$storeBranchProduct->stock = $type == 'inc' ? $storeBranchProduct->stock + $nums : $storeBranchProduct->stock - $nums;
|
|
$storeBranchProduct->save();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 增加商品数量
|
|
* @param $warehouseProduct
|
|
* @param $storageNum
|
|
* @param $productNum
|
|
* @return void
|
|
* @throws DataNotFoundException
|
|
* @throws DbException
|
|
* @throws ModelNotFoundException
|
|
*/
|
|
public static function updateWarehouseProduct($warehouseProduct, $storageNum, $productNum)
|
|
{
|
|
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
|
|
->where('product_id', $warehouseProduct['product_id'])->find();
|
|
$warehouseProductStorage->nums = bcadd($warehouseProductStorage->nums, $storageNum, 2);
|
|
$warehouseProductStorage->save();
|
|
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['id'], $storageNum, $storageNum > 0 ? 1 : -1, Request()->url());
|
|
|
|
$update = [
|
|
'nums' => bcadd($warehouseProduct['nums'], $productNum, 2),
|
|
'total_price' => bcadd($warehouseProduct['total_price'], bcmul($productNum, $warehouseProduct['price'], 2), 2),
|
|
];
|
|
WarehouseProduct::where('id',$warehouseProduct['id'])->update($update);
|
|
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $productNum, $productNum > 0 ? 1 : -1, Request()->url());
|
|
|
|
self::updateStoreStorage2($warehouseProduct, $productNum);
|
|
}
|
|
|
|
/**
|
|
* 更新订单数量和总价
|
|
* @param $oid
|
|
* @return void
|
|
* @throws DataNotFoundException
|
|
* @throws DbException
|
|
* @throws ModelNotFoundException
|
|
*/
|
|
public static function updateWarehouseOrder($oid)
|
|
{
|
|
$find = WarehouseProduct::where('oid', $oid)->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
|
if ($find) {
|
|
WarehouseOrder::where('id', $oid)->update([
|
|
'nums' => $find['nums'],
|
|
'total_price' => $find['total_price']
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改门店商品库存
|
|
* @param $warehouseProduct
|
|
* @param $nums
|
|
* @return void
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public static function updateStoreStorage2($warehouseProduct, $nums)
|
|
{
|
|
if ($warehouseProduct['financial_pm'] == 0 && $warehouseProduct['status'] == 1) {
|
|
// 出库单已确认,增加门店库存
|
|
$storeBranchProduct = StoreBranchProduct::where('store_id', $warehouseProduct->store_id)
|
|
->where('product_id', $warehouseProduct->product_id)->find();
|
|
if (!empty($storeBranchProduct)) {
|
|
$storeBranchProduct->stock = $storeBranchProduct->stock + $nums;
|
|
$storeBranchProduct->save();
|
|
}
|
|
} elseif ($warehouseProduct['store_id'] == 1 && $warehouseProduct['financial_pm'] == 1 && $warehouseProduct['status'] == 1) {
|
|
// 入库单已确认,减少门店库存
|
|
$storeBranchProduct = StoreBranchProduct::where('store_id', $warehouseProduct->store_id)
|
|
->where('product_id', $warehouseProduct->product_id)->find();
|
|
if (!empty($storeBranchProduct)) {
|
|
$storeBranchProduct->stock = $storeBranchProduct->stock - $nums;
|
|
$storeBranchProduct->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function updateProductSourceLink($warehouseProduct, $params, $updateNums)
|
|
{
|
|
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
|
$productSourceLinkInfoLogic->setInfo([
|
|
'link_id' => $warehouseProduct['id'],
|
|
'product_id' => $warehouseProduct['product_id'],
|
|
'nums' => $params['nums'],
|
|
'add_nums' => $updateNums,
|
|
]);
|
|
if ($warehouseProduct['financial_pm'] == 1) {
|
|
$productSourceLinkInfoLogic->updateInStorageNum();
|
|
} else {
|
|
$productSourceLinkInfoLogic->setInfo([
|
|
'add_nums' => bcsub($params['nums'], $warehouseProduct['nums'],2),
|
|
]);
|
|
$productSourceLinkInfoLogic->updateOutboundNum();
|
|
}
|
|
}
|
|
|
|
}
|