This commit is contained in:
lewis 2025-01-22 16:08:21 +08:00
commit 6cb055d9fb
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,$warehouse_id=1)
{
$arr=WarehouseProduct::where('oid', $id)->select();
foreach ($arr as $k => $v) {
$find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id',$warehouse_id)->find();
$nums = bcadd($find->nums, $v['nums'], 2);
$res=WarehouseProductStorege::where('id', $find['id'])->update(['nums' => $nums]);
if($res){
SqlChannelLog('WarehouseProductStorege', $v['id'], $v['nums'], 1, Request()->url(), 1);
$v->save(['delete_time'=>time()]);
}
}
}
}