diff --git a/app/controller/api/community/Community.php b/app/controller/api/community/Community.php index 3b472860..fa2e2d27 100644 --- a/app/controller/api/community/Community.php +++ b/app/controller/api/community/Community.php @@ -549,7 +549,7 @@ class Community extends BaseController } $status = $this->request->param('status'); if (!$status) { - app('json')->fail('请设置审核状态'); + return app('json')->fail('请设置审核状态'); } if ($status == 1) { Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->update(['status' => $status, 'mer_status' => 1]); @@ -629,4 +629,42 @@ class Community extends BaseController $res = $this->repository->create($data); return app('json')->success(['community_id' => $res]); } + + /** + * 审核委托商品 + * @return mixed + */ + public function checkEntrust($id) + { + $communityInfo = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->find(); + if (!$communityInfo) { + return app('json')->fail('委托商品不存在'); + } + $status = $this->request->param('status'); + if (!$status) { + return app('json')->fail('请设置审核状态'); + } + // 同意 + if ($status == 1) { + Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->update(['status' => $status, 'mer_status' => 1]); + } + // 拒绝 + if ($status == 2) { + Db::startTrans(); + try { + $list = Db::name('entrust')->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('entrust')->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, 'mer_status' => 2]); + Db::commit(); + } catch (\Exception $e) { + Db::rollback(); + return app('json')->fail('审核委托商品失败'); + } + } + return app('json')->success('审核操作成功'); + } } diff --git a/route/api.php b/route/api.php index dfd69872..c44ece06 100644 --- a/route/api.php +++ b/route/api.php @@ -376,6 +376,7 @@ Route::group('api/', function () { Route::post('resale/check/:id', 'Community/checkResale'); Route::post('/entrust', 'Community/entrust'); + Route::post('/entrust/check/:id', 'Community/checkEntrust'); })->prefix('api.community.');