feat(admin): 添加库存回滚功能

- 在 IndexController 中添加 demo3 方法,用于触发库存回滚
- 在 DemoLogic 中实现 test3 方法,执行库存回滚逻辑
- 使用 WarehouseProduct 和 WarehouseProductStorege 模型处理库存数据
- 库存回滚成功后更新数据库并记录日志
This commit is contained in:
mkm 2025-01-22 10:22:08 +08:00
parent d0a583a9bd
commit 607b523fcd
2 changed files with 25 additions and 0 deletions

View File

@ -30,4 +30,10 @@ class IndexController extends BaseAdminController
$res=DemoLogic::test();
return $this->success('成功');
}
public function demo3()
{
$id=$this->request->get('id');
$res=DemoLogic::test3($id);
return $this->success('成功');
}
}

View File

@ -6,6 +6,8 @@ use app\common\logic\BaseLogic;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_group_price\StoreProductGroupPrice;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use think\facade\Db;
class DemoLogic extends BaseLogic
@ -92,4 +94,21 @@ class DemoLogic extends BaseLogic
SqlChannelLog('StoreBranchProduct', $find['id'], $v['cart_num'], -1, Request()->url(), 1);
}
}
/**
* 库存回滚
*/
public static function test3($id)
{
$arr=WarehouseProduct::where('oid', $id)->select();
foreach ($arr as $k => $v) {
$find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id',1)->find();
$nums = bcadd($find->nums, $v['nums'], 2);
$res=WarehouseProductStorege::where('id', $v['id'])->update(['nums' => $nums]);
if($res){
SqlChannelLog('WarehouseProductStorege', $v['id'], $v['nums'], 1, Request()->url(), 1);
$v->save(['delete_time'=>time()]);
}
}
}
}