Merge pull request 'feat(WarehouseOrderLogic): 修复订单管理逻辑错误,优化库存更新方式,提高了代码的可读性和稳定性,并更新了相关API接口。' (#148) from dev into main

Reviewed-on: #148
This commit is contained in:
mkm 2024-08-21 20:16:08 +08:00
commit 6cf2f7287b
2 changed files with 9 additions and 2 deletions

View File

@ -148,6 +148,7 @@ class WarehouseOrderLogic extends BaseLogic
self::setError('该订单下还有商品没有删除,请先删除商品');
return false;
}
WarehouseOrder::destroy($params['id']);
$find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
if ($find) {
WarehouseOrder::where('id', $params['id'])->update([
@ -155,7 +156,6 @@ class WarehouseOrderLogic extends BaseLogic
'total_price' => $find['total_price']
]);
}
WarehouseOrder::destroy($params['id']);
return true;
}

View File

@ -9,6 +9,7 @@ use app\common\model\purchase_product_offer\PurchaseProductOffer;
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 support\Log;
use think\facade\Db;
@ -167,7 +168,13 @@ class WarehouseProductLogic extends BaseLogic
StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update();
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update();
}
$find = WarehouseProduct::where('oid', $res['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
if ($find) {
WarehouseOrder::where('id', $res['oid'])->update([
'nums' => $find['nums'],
'total_price' => $find['total_price']
]);
}
return true;
}
return false;