diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 51911119..765b44cb 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -135,10 +135,8 @@ class Auth extends BaseController $user = $repository->mainUser($user); $pid = $this->request->param('spread', 0); $repository->bindSpread($user, intval($pid)); - $tokenInfo = $repository->createToken($user); $repository->loginAfter($user); - return app('json')->success($repository->returnToken($user, $tokenInfo)); } diff --git a/app/controller/api/community/Community.php b/app/controller/api/community/Community.php index 3b472860..154a7aa8 100644 --- a/app/controller/api/community/Community.php +++ b/app/controller/api/community/Community.php @@ -61,9 +61,6 @@ class Community extends BaseController public function lst() { $where = $this->request->params(['keyword','topic_id','is_hot','category_id','spu_id', 'is_type', 'resale_type']); - if (isset($where['category_id']) && $where['category_id'] == 0) { - $where['is_type'] = $this->repository::COMMUNIT_TYPE_FONT; - } if (!$where['category_id']) { unset($where['category_id']); } else if ($where['category_id'] == -1) { @@ -275,7 +272,7 @@ class Community extends BaseController public function checkParams() { - $data = $this->request->params(['image','topic_id','content','spu_id','order_id',['is_type',1],'video_link', 'resale_type', 'product_info']); + $data = $this->request->params(['image','topic_id','content','spu_id','order_id',['is_type',1],'video_link', 'resale_type', 'product_info', 'entrust_mer_id', 'entrust_day']); $config = systemConfig(["community_app_switch",'community_audit','community_video_audit']); $data['status'] = 0; $data['is_show'] = 0; @@ -549,7 +546,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]); @@ -624,9 +621,55 @@ class Community extends BaseController public function entrust() { $data = $this->checkParams(); + $merchantInfo = Db::name('merchant')->where('mer_id', $data['entrust_mer_id'] ?? 0)->where('type_id', Merchant::TypeSupplyChain)->fetchSql(false)->find(); + if (!$merchantInfo) { + return app('json')->fail('此商户不支持委托'); + } $this->checkUserAuth(); $data['uid'] = $this->request->uid(); $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('委托商品不存在'); + } + $entrustInfo = Db::name('entrust')->where('community_id', $id)->where('entrust_mer_id', $this->request->uid())->where('is_del', 0)->where('status', 0)->fetchSql(false)->find(); + if (!$entrustInfo) { + 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.');