From 4409f59c7b235e1555e9436c25a93f3e7dc89ee3 Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Fri, 18 Aug 2023 09:54:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=90=8C=E6=84=8F=E6=8A=98=E6=89=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/community/Community.php | 40 +++++++++++++++++----- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/app/controller/api/community/Community.php b/app/controller/api/community/Community.php index 3454d40c..a1f1beba 100644 --- a/app/controller/api/community/Community.php +++ b/app/controller/api/community/Community.php @@ -513,24 +513,21 @@ class Community extends BaseController */ public function deleteResale($id) { - $communityInfo = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->find(); + $communityInfo = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->find(); if (!$communityInfo) { app('json')->fail('转售商品不存在'); } - // 启动事务 Db::startTrans(); - try { - Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->update(['is_del' => 1]); - Db::name('resale')->where('community_id', $id)->update(['is_del' => 1]); + try { $list = Db::name('resale')->where('community_id', $id)->where('is_del', 0)->where('status', 0)->select(); foreach($list as $prod) { Db::name('store_product')->where('product_id', $prod['product_id'])->inc('stock', $prod['number'])->update(); Db::name('store_product_attr_value')->where('product_id', $prod['product_id'])->where('unique', $prod['product_attr_unique'])->inc('stock', $prod['number'])->update(); } - // 提交事务 + Db::name('resale')->where('community_id', $id)->where('status', 0)->update(['is_del' => 1]); + Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->update(['is_del' => 1]); Db::commit(); } catch (\Exception $e) { - // 回滚事务 Db::rollback(); return app('json')->fail('删除转售商品失败'); } @@ -543,10 +540,37 @@ class Community extends BaseController */ public function checkResale($id) { - $communityInfo = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->find(); + $communityInfo = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->find(); if (!$communityInfo) { app('json')->fail('转售商品不存在'); } + $status = $this->request->param('status'); + if (!$status) { + app('json')->fail('请设置审核状态'); + } + if ($status == 1) { + $res = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->update(['status' => $status]); + if (!$res) { + return app('json')->fail('审核操作失败'); + } + } + if ($status == 2) { + Db::startTrans(); + try { + $list = Db::name('resale')->where('community_id', $id)->where('is_del', 0)->where('status', 0)->select(); + foreach($list as $prod) { + Db::name('store_product')->where('product_id', $prod['product_id'])->inc('stock', $prod['number'])->update(); + Db::name('store_product_attr_value')->where('product_id', $prod['product_id'])->where('unique', $prod['product_attr_unique'])->inc('stock', $prod['number'])->update(); + } + Db::name('resale')->where('community_id', $id)->where('status', 0)->update(['is_del' => 1]); + Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->update(['is_del' => 1, 'status' => $status]); + Db::commit(); + } catch (\Exception $e) { + Db::rollback(); + return app('json')->fail('审核转售商品折扣价失败'); + } + } + return app('json')->fail('审核操作成功'); } }