diff --git a/app/admin/controller/IndexController.php b/app/admin/controller/IndexController.php index 8adcaad5..be3c3f21 100644 --- a/app/admin/controller/IndexController.php +++ b/app/admin/controller/IndexController.php @@ -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('成功'); + } } \ No newline at end of file diff --git a/app/api/logic/DemoLogic.php b/app/api/logic/DemoLogic.php index 91572955..80835356 100644 --- a/app/api/logic/DemoLogic.php +++ b/app/api/logic/DemoLogic.php @@ -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()]); + } + } + } }