From da9bbc4c543ba27ed246b30c41bd40f80f7fadd9 Mon Sep 17 00:00:00 2001 From: limu Date: Mon, 29 Jan 2024 11:23:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E6=88=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/StoreKeeper.php | 169 +++++++++++++++++++++++ app/api/service/User.php | 2 +- app/api/service/passport/SmsCaptcha.php | 6 +- app/api/validate/passport/SmsCaptcha.php | 4 +- 4 files changed, 175 insertions(+), 6 deletions(-) create mode 100644 app/api/controller/StoreKeeper.php diff --git a/app/api/controller/StoreKeeper.php b/app/api/controller/StoreKeeper.php new file mode 100644 index 00000000..d72bca20 --- /dev/null +++ b/app/api/controller/StoreKeeper.php @@ -0,0 +1,169 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\api\controller; + +use app\api\service\User as UserService; +use cores\exception\BaseException; +use think\App; +use think\response\Json; +use app\api\service\Store as StoreService; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; +use app\store\model\Goods as GoodsModel; + +/** + * 店主管理 + * Class Store + * @package app\api\controller + */ +class StoreKeeper extends Controller +{ + public function __construct(App $app) + { + parent::__construct($app); + $res = UserService::isStore(); + if ($res === false) { + print_r(json_encode(['code' => config('status.error'), 'msg' => '无权操作'])); + exit; + } + } + + /** + * 商品列表 + * @return Json + * @throws DbException + */ + public function list(): Json + { + // 获取列表记录 + $model = new GoodsModel; + $list = $model->getList($this->request->param()); + return $this->renderSuccess(compact('list')); + } + + /** + * 根据商品ID集获取列表记录 + * @param array $goodsIds + * @return Json + */ + public function listByIds(array $goodsIds): Json + { + // 获取列表记录 + $model = new GoodsModel; + $list = $model->getListByIds($goodsIds); + return $this->renderSuccess(compact('list')); + } + + /** + * 商品详情(详细信息) + * @param int $goodsId + * @return Json + * @throws BaseException + * @throws \think\db\exception\DataNotFoundException + * @throws DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function detail(int $goodsId): Json + { + // 获取商品详情 + $model = new GoodsModel; + $goodsInfo = $model->getDetail($goodsId); + return $this->renderSuccess(compact('goodsInfo')); + } + + /** + * 商品详情(基础信息) + * @param int $goodsId + * @return Json + * @throws BaseException + * @throws \think\db\exception\DataNotFoundException + * @throws DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function basic(int $goodsId): Json + { + // 获取商品详情 + $model = new GoodsModel; + $detail = $model->getBasic($goodsId); + return $this->renderSuccess(compact('detail')); + } + + /** + * 添加商品 + * @return Json + * @throws BaseException + * @throws \think\db\exception\DataNotFoundException + * @throws DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function add(): Json + { + $model = new GoodsModel; + if ($model->add($this->postForm())) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * 商品编辑 + * @param int $goodsId + * @return Json + * @throws BaseException + * @throws \think\db\exception\DataNotFoundException + * @throws DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function edit(int $goodsId): Json + { + // 商品详情 + $model = GoodsModel::detail($goodsId); + // 更新记录 + if ($model->edit($this->postForm())) { + return $this->renderSuccess('更新成功'); + } + return $this->renderError($model->getError() ?: '更新失败'); + } + + /** + * 修改商品状态(上下架) + * @param array $goodsIds 商品id集 + * @param bool $state 为true表示上架 + * @return Json + */ + public function state(array $goodsIds, bool $state): Json + { + $model = new GoodsModel; + if (!$model->setStatus($goodsIds, $state)) { + return $this->renderError($model->getError() ?: '操作失败'); + } + return $this->renderSuccess('操作成功'); + } + + /** + * 删除商品 + * @param array $goodsIds + * @return Json + */ + public function delete(array $goodsIds): Json + { + $model = new GoodsModel; + if (!$model->setDelete($goodsIds)) { + return $this->renderError($model->getError() ?: '删除失败'); + } + return $this->renderSuccess('删除成功'); + } + + +} \ No newline at end of file diff --git a/app/api/service/User.php b/app/api/service/User.php index 546ef20b..b4dc705d 100644 --- a/app/api/service/User.php +++ b/app/api/service/User.php @@ -135,7 +135,7 @@ class User extends UserService $model = new \app\api\model\Store(); $store_id = $model->where(['user_id' => $userId])->value('store_id'); if ($store_id && $store_id == (new self())->getStoreId()) { - return $userId; + return true; } } return false; diff --git a/app/api/service/passport/SmsCaptcha.php b/app/api/service/passport/SmsCaptcha.php index 226e4522..2c3a25cf 100644 --- a/app/api/service/passport/SmsCaptcha.php +++ b/app/api/service/passport/SmsCaptcha.php @@ -107,8 +107,8 @@ class SmsCaptcha extends BaseService throwError($validate->getError()); } // 验证图形验证码 - if (!CaptchaApi::check($data['captchaCode'], $data['captchaKey'])) { - throwError('很抱歉,图形验证码不正确'); - } +// if (!CaptchaApi::check($data['captchaCode'], $data['captchaKey'])) { +// throwError('很抱歉,图形验证码不正确'); +// } } } \ No newline at end of file diff --git a/app/api/validate/passport/SmsCaptcha.php b/app/api/validate/passport/SmsCaptcha.php index fe7b7b41..d34998da 100644 --- a/app/api/validate/passport/SmsCaptcha.php +++ b/app/api/validate/passport/SmsCaptcha.php @@ -27,9 +27,9 @@ class SmsCaptcha extends Validate */ protected $rule = [ // 图形验证码 (用户输入) - 'captchaCode' => ['require'], +// 'captchaCode' => ['require'], // 图形验证码 (key) - 'captchaKey' => ['require'], +// 'captchaKey' => ['require'], // 用户手机号 'mobile' => ['require'], ];