From 48e51a87b7902b6c726c72c3aca8e9657ccd9768 Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Tue, 8 Oct 2024 14:15:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=91=E5=AE=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/LocalStore.php | 16 ++++++++++++++-- app/api/logic/LocalStoreLogic.php | 32 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/api/controller/LocalStore.php b/app/api/controller/LocalStore.php index f3e3cd18..55165c25 100755 --- a/app/api/controller/LocalStore.php +++ b/app/api/controller/LocalStore.php @@ -398,12 +398,24 @@ class LocalStore extends Api // 绑定用户 public function bindUser() { - + try { + $post = $this->request->post(); + LocalStoreLogic::bindUser($post); + return JsonServer::success('添加成功'); + } catch (\Exception $e) { + return JsonServer::error($e->getMessage()); + } } //解绑用户 public function unbindUser() { - + try { + $post = $this->request->post(); + LocalStoreLogic::unbindUser($post); + return JsonServer::success('解绑成功'); + } catch (\Exception $e) { + return JsonServer::error($e->getMessage()); + } } } \ No newline at end of file diff --git a/app/api/logic/LocalStoreLogic.php b/app/api/logic/LocalStoreLogic.php index ce3b1f41..594729c2 100644 --- a/app/api/logic/LocalStoreLogic.php +++ b/app/api/logic/LocalStoreLogic.php @@ -5,6 +5,7 @@ namespace app\api\logic; use app\common\basics\Logic; use app\common\model\LocalStore; use app\common\model\localstore\LocalGoodsStore; +use app\common\model\localstore\LocalStoreBind; use app\common\model\LocalStoreOrder; use app\common\model\LocalStorePostStation; use app\common\model\user\User; @@ -491,4 +492,35 @@ class LocalStoreLogic extends Logic return false; } + + public static function bindUser($post) + { + if ($post['user']['id'] <=0 ) { + throw new \Exception('缺少用户ID'); + } + + if (empty($post['user']['rule'])) { + throw new \Exception('请为用户分配权限'); + } + + $data = array(); + foreach ($post['user']['rule'] as $k => &$v) { + $data[$k]['lstore_id'] = $post['lstore_id']; + $data[$k]['bind_user_id'] = $post['user']['id']; + $data[$k]['rule_id'] = $v; + $data[$k]['bind_time'] = time(); + } + + $model = new LocalStoreBind(); + $result = $model->insertAll($data); + if ($result) { + return true; + } + + throw new \Exception('添加失败'); + } + + public static function unbindUser($post) + { + } } \ No newline at end of file