diff --git a/application/admin/controller/manystore/Apirule.php b/application/admin/controller/manystore/Apirule.php new file mode 100644 index 0000000..9b58e7c --- /dev/null +++ b/application/admin/controller/manystore/Apirule.php @@ -0,0 +1,149 @@ +model = new ManystoreApiAuthRule(); + // 必须将结果集转换为数组 + $ruleList = collection($this->model->order('weigh', 'desc')->order('id', 'asc')->select())->toArray(); + foreach ($ruleList as $k => &$v) { + $v['title'] = __($v['title']); + $v['remark'] = __($v['remark']); + } + unset($v); + Tree::instance()->init($ruleList); + $this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); + $ruledata = [0 => __('None')]; + foreach ($this->rulelist as $k => &$v) { + if (!$v['ismenu']) { + continue; + } + $ruledata[$v['id']] = $v['title']; + } + unset($v); + $this->view->assign('ruledata', $ruledata); + } + + /** + * 查看 + */ + public function index() + { + if ($this->request->isAjax()) { + $list = $this->rulelist; + $total = count($this->rulelist); + + $result = array("total" => $total, "rows" => $list); + + return json($result); + } + return $this->view->fetch(); + } + + /** + * 添加 + */ + public function add() + { + if ($this->request->isPost()) { + $this->token(); + $params = $this->request->post("row/a", [], 'strip_tags'); + if ($params) { + if (!$params['ismenu'] && !$params['pid']) { + $this->error(__('The non-menu rule must have parent')); + } + $result = $this->model->validate()->save($params); + if ($result === false) { + $this->error($this->model->getError()); + } + Cache::rm('__menu__'); + $this->success(); + } + $this->error(); + } + return $this->view->fetch(); + } + + /** + * 编辑 + */ + public function edit($ids = null) + { + $row = $this->model->get(['id' => $ids]); + if (!$row) { + $this->error(__('No Results were found')); + } + if ($this->request->isPost()) { + $this->token(); + $params = $this->request->post("row/a", [], 'strip_tags'); + if ($params) { + if (!$params['ismenu'] && !$params['pid']) { + $this->error(__('The non-menu rule must have parent')); + } + if ($params['pid'] != $row['pid']) { + $childrenIds = Tree::instance()->init(collection(ManystoreApiAuthRule::select())->toArray())->getChildrenIds($row['id']); + if (in_array($params['pid'], $childrenIds)) { + $this->error(__('Can not change the parent to child')); + } + } + //这里需要针对name做唯一验证 + $ruleValidate = \think\Loader::validate('ManystoreApiAuthRule'); + $ruleValidate->rule([ + 'name' => 'require|format|unique:ManystoreApiAuthRule,name,' . $row->id, + ]); + $result = $row->validate()->save($params); + if ($result === false) { + $this->error($row->getError()); + } + Cache::rm('__manystore_menu__'); + $this->success(); + } + $this->error(); + } + $this->view->assign("row", $row); + return $this->view->fetch(); + } + + /** + * 删除 + */ + public function del($ids = "") + { + if ($ids) { + $delIds = []; + foreach (explode(',', $ids) as $k => $v) { + $delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, true)); + } + $delIds = array_unique($delIds); + $count = $this->model->where('id', 'in', $delIds)->delete(); + if ($count) { + Cache::rm('__manystore_menu__'); + $this->success(); + } + } + $this->error(); + } +} diff --git a/application/admin/controller/manystore/Index.php b/application/admin/controller/manystore/Index.php index 13f49ab..850fa78 100644 --- a/application/admin/controller/manystore/Index.php +++ b/application/admin/controller/manystore/Index.php @@ -15,6 +15,8 @@ use app\common\model\school\classes\Order; use app\common\model\school\classes\order\OrderDetail; use app\common\model\school\classes\order\ServiceOrder; use app\manystore\model\Manystore; +use app\manystore\model\ManystoreApiAuthGroup; +use app\manystore\model\ManystoreApiAuthGroupAccess; use app\manystore\model\ManystoreLog; use app\manystore\model\ManystoreShop; use app\manystore\model\ManystoreAuthGroup; @@ -71,6 +73,7 @@ class Index extends Backend $this->view->assign("statusList", $this->shopModel->getStatusList()); $this->view->assign("typeList", $this->shopModel->getTypeList()); $this->view->assign("shop_backend_url", config("site.shop_backend_url")); + $this->view->assign("shop_api_backend_url", config("site.shop_api_backend_url")); $this->getCity(); $this->getAuthMsg(); @@ -124,6 +127,53 @@ class Index extends Backend + /** + * 免登录进入机构api版本后台 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function freeapi($ids = ''){ + $param = $this->request->param(); + if($this->request->isPost()){ + + $this->error("API版本后台正在开发中,敬请期待!"); +// try{ + if(isset($param['ids']))$ids = $param['ids']; +// //机构登录 +// //如果存在登录,先退出登录 +// $auth = \app\manystore\library\Auth::instance(); +// if($auth->isLogin()){ +// $auth->logout(); +// Hook::listen("manystore_logout_after", $this->request); +// } +// //执行登录 +// ManystoreLog::setTitle(__('Login')); +// $result = $auth->freelogin($ids, 0); +// if ($result === true) { +// Hook::listen("admin_login_after", $this->request); +// $this->success(__('Login successful'), null, [ 'id' => $auth->id, 'avatar' => $auth->avatar]); +// } else { +// $msg = $auth->getError(); +// $msg = $msg ? $msg : __('Username or password is incorrect'); +// $this->error($msg, null, ['token' => $this->request->token()]); +// } +// + + +// }catch (\Exception $e){ +// $this->error($e->getMessage()); +// } + + } + $row = $this->model->get($ids); + $this->view->assign('vo', $row); + return $this->view->fetch(); + } + + /** * 查看 @@ -485,6 +535,11 @@ class Index extends Backend if(!$group_id){ throw new \Exception('添加失败'); } + $manystoreApiAuthGroupModel = new ManystoreApiAuthGroup(); + $api_group_id = $manystoreApiAuthGroupModel->insertGetId($group); + if(!$api_group_id){ + throw new \Exception('添加失败'); + } $manystoreAuthGroupAccessModel = new ManystoreAuthGroupAccess(); $group_access = []; @@ -493,6 +548,14 @@ class Index extends Backend $manystoreAuthGroupAccessModel->insert($group_access); + $manystoreApiAuthGroupAccessModel = new ManystoreApiAuthGroupAccess(); + $group_access = []; + $group_access['uid'] = $this->model->id; + $group_access['group_id'] = $api_group_id; + + $manystoreApiAuthGroupAccessModel->insert($group_access); + + //调用事件 $data = ['shop' => $this->shopModel]; @@ -642,6 +705,10 @@ class Index extends Backend \app\common\model\school\classes\Verification::where(array('shop_id'=>$row['shop_id']))->delete(); Order::where(array('shop_id'=>$row['shop_id']))->delete(); OrderDetail::where(array('shop_id'=>$row['shop_id']))->delete(); + + \app\admin\model\school\classes\activity\order\Order::where(array('shop_id'=>$row['shop_id']))->delete(); + \app\admin\model\school\classes\activity\order\OrderDetail::where(array('shop_id'=>$row['shop_id']))->delete(); + \app\admin\model\school\classes\hour\Order::where(array('shop_id'=>$row['shop_id']))->delete(); ServiceOrder::where(array('shop_id'=>$row['shop_id']))->delete(); $classesLibs = \app\common\model\school\classes\ClassesLib::where(array('shop_id'=>$row['shop_id']))->select(); diff --git a/application/admin/lang/zh-cn/manystore/apirule.php b/application/admin/lang/zh-cn/manystore/apirule.php new file mode 100644 index 0000000..1c533fd --- /dev/null +++ b/application/admin/lang/zh-cn/manystore/apirule.php @@ -0,0 +1,20 @@ + '显示全部', + 'Condition' => '规则条件', + 'Remark' => '备注', + 'Icon' => '图标', + 'Alert' => '警告', + 'Name' => '规则', + 'Controller/Action' => '控制器名/方法名', + 'Ismenu' => '菜单', + 'Search icon' => '搜索图标', + 'Toggle menu visible' => '点击切换菜单显示', + 'Toggle sub menu' => '点击切换子菜单', + 'Menu tips' => '父级菜单无需匹配控制器和方法,子级菜单请使用控制器名', + 'Node tips' => '控制器/方法名,如果有目录请使用 目录名/控制器名/方法名', + 'The non-menu rule must have parent' => '非菜单规则节点必须有父级', + 'Can not change the parent to child' => '父组别不能是它的子组别', + 'Name only supports letters, numbers, underscore and slash' => 'URL规则只能是小写字母、数字、下划线和/组成', +]; diff --git a/application/admin/validate/ManystoreApiAuthRule.php b/application/admin/validate/ManystoreApiAuthRule.php new file mode 100644 index 0000000..33cb831 --- /dev/null +++ b/application/admin/validate/ManystoreApiAuthRule.php @@ -0,0 +1,52 @@ + '[a-z0-9_\/]+']; + + /** + * 验证规则 + */ + protected $rule = [ + 'name' => 'require|format|unique:ManystoreApiAuthRule', + 'title' => 'require', + ]; + + /** + * 提示消息 + */ + protected $message = [ + 'name.format' => 'URL规则只能是小写字母、数字、下划线和/组成' + ]; + + /** + * 字段描述 + */ + protected $field = [ + ]; + + /** + * 验证场景 + */ + protected $scene = [ + ]; + + public function __construct(array $rules = [], $message = [], $field = []) + { + $this->field = [ + 'name' => __('Name'), + 'title' => __('Title'), + ]; + $this->message['name.format'] = __('Name only supports letters, numbers, underscore and slash'); + parent::__construct($rules, $message, $field); + } + +} diff --git a/application/admin/validate/manystore/Apirule.php b/application/admin/validate/manystore/Apirule.php new file mode 100644 index 0000000..2ea7dff --- /dev/null +++ b/application/admin/validate/manystore/Apirule.php @@ -0,0 +1,52 @@ + '[a-z0-9_\/]+']; + + /** + * 验证规则 + */ + protected $rule = [ + 'name' => 'require|format|unique:Apirule', + 'title' => 'require', + ]; + + /** + * 提示消息 + */ + protected $message = [ + 'name.format' => 'URL规则只能是小写字母、数字、下划线和/组成' + ]; + + /** + * 字段描述 + */ + protected $field = [ + ]; + + /** + * 验证场景 + */ + protected $scene = [ + ]; + + public function __construct(array $rules = [], $message = [], $field = []) + { + $this->field = [ + 'name' => __('Name'), + 'title' => __('Title'), + ]; + $this->message['name.format'] = __('Name only supports letters, numbers, underscore and slash'); + parent::__construct($rules, $message, $field); + } + +} diff --git a/application/admin/view/manystore/apirule/add.html b/application/admin/view/manystore/apirule/add.html new file mode 100644 index 0000000..4a9d737 --- /dev/null +++ b/application/admin/view/manystore/apirule/add.html @@ -0,0 +1,68 @@ +
+{include file="auth/rule/tpl" /} \ No newline at end of file diff --git a/application/admin/view/manystore/apirule/edit.html b/application/admin/view/manystore/apirule/edit.html new file mode 100644 index 0000000..ba12a20 --- /dev/null +++ b/application/admin/view/manystore/apirule/edit.html @@ -0,0 +1,68 @@ + +{include file="auth/rule/tpl" /} \ No newline at end of file diff --git a/application/admin/view/manystore/apirule/index.html b/application/admin/view/manystore/apirule/index.html new file mode 100644 index 0000000..7b418b4 --- /dev/null +++ b/application/admin/view/manystore/apirule/index.html @@ -0,0 +1,35 @@ + +卸载将会删除所有插件文件且不可找回!!! 插件如果有创建数据库表请手动删除!!!
如有重要数据请备份后再操作!', + 'Upgrade tips' => '确认升级[%s]?如果之前购买插件时未登录,此次升级可能出现购买后才可以下载的提示!!!
升级后可能出现部分冗余数据记录,请根据需要移除即可!!!
{:__('Title')} | +{:__('Content')} | +
---|---|
{:__($key)} | +{$vo|htmlentities} | +
{$manystore.nickname|htmlentities} {$auth_type_text}
+ {:__('Online')} +