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