refactor(DemoLogic): 优化库存回滚功能
- 在 test3 函数中添加 $warehouse_id 参数,默认值为 1 - 修改查询条件,使用 $warehouse_id 替代硬编码的 1 - 修复更新语句中的 ID,使用 $find['id'] 替代 $v['id']
This commit is contained in:
parent
607b523fcd
commit
3b13ad4a2e
@ -98,13 +98,13 @@ class DemoLogic extends BaseLogic
|
|||||||
/**
|
/**
|
||||||
* 库存回滚
|
* 库存回滚
|
||||||
*/
|
*/
|
||||||
public static function test3($id)
|
public static function test3($id,$warehouse_id=1)
|
||||||
{
|
{
|
||||||
$arr=WarehouseProduct::where('oid', $id)->select();
|
$arr=WarehouseProduct::where('oid', $id)->select();
|
||||||
foreach ($arr as $k => $v) {
|
foreach ($arr as $k => $v) {
|
||||||
$find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id',1)->find();
|
$find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id',$warehouse_id)->find();
|
||||||
$nums = bcadd($find->nums, $v['nums'], 2);
|
$nums = bcadd($find->nums, $v['nums'], 2);
|
||||||
$res=WarehouseProductStorege::where('id', $v['id'])->update(['nums' => $nums]);
|
$res=WarehouseProductStorege::where('id', $find['id'])->update(['nums' => $nums]);
|
||||||
if($res){
|
if($res){
|
||||||
SqlChannelLog('WarehouseProductStorege', $v['id'], $v['nums'], 1, Request()->url(), 1);
|
SqlChannelLog('WarehouseProductStorege', $v['id'], $v['nums'], 1, Request()->url(), 1);
|
||||||
$v->save(['delete_time'=>time()]);
|
$v->save(['delete_time'=>time()]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user