From cc13121bb85efe981cb3642d001c02b64b983407 Mon Sep 17 00:00:00 2001 From: 15090180611 <215509543@qq.com> Date: Fri, 18 Apr 2025 17:22:09 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E5=90=88=E5=89=8D=E7=AB=AF=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=E5=BE=AE=E8=B0=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/auth/api/Rule.php | 13 ++ application/adminapi/controller/Group.php | 76 ++++++++ application/adminapi/controller/Rule.php | 101 ++++++++++- application/adminapi/model/AuthRule.php | 166 +++++++++++++++++- .../model/school/activity/order/Detail.php | 3 +- .../model/school/activity/order/Order.php | 13 +- 6 files changed, 364 insertions(+), 8 deletions(-) create mode 100644 application/adminapi/controller/Group.php diff --git a/application/admin/controller/auth/api/Rule.php b/application/admin/controller/auth/api/Rule.php index f0c8cb6..45455e5 100644 --- a/application/admin/controller/auth/api/Rule.php +++ b/application/admin/controller/auth/api/Rule.php @@ -117,6 +117,19 @@ class Rule extends Backend } } //这里需要针对name做唯一验证 + + $name =$this->model->where("id","<>", $ids)->where("name", $params['name'])->find(); + if ($name) { + $this->error(__('The name already exist')); + } + if ($params['rule_name'] && $params['rule_name'] != $row['rule_name']) { + $rule_name = $this->model->where("id","<>", $ids)->where("rule_name", $params['rule_name'])->find(); + if ($rule_name) { + $this->error(__('The rule_name already exist')); + } + } + + // $ruleValidate = \think\Loader::validate(ApiAuthRule::class); // $ruleValidate->rule([ // 'name' => 'require|unique:ApiAuthRule,name,' . $row->id, diff --git a/application/adminapi/controller/Group.php b/application/adminapi/controller/Group.php new file mode 100644 index 0000000..482b64e --- /dev/null +++ b/application/adminapi/controller/Group.php @@ -0,0 +1,76 @@ +model = new AuthGroup; + parent::_initialize(); + + $this->childrenGroupIds = $this->auth->getChildrenGroupIds(true); + + $groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray(); + + Tree::instance()->init($groupList); + $groupList = []; + if ($this->auth->isSuperAdmin()) { + $groupList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0)); + } else { + $groups = $this->auth->getGroups(); + $groupIds = []; + foreach ($groups as $m => $n) { + if (in_array($n['id'], $groupIds) || in_array($n['pid'], $groupIds)) { + continue; + } + $groupList = array_merge($groupList, Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['pid']))); + foreach ($groupList as $index => $item) { + $groupIds[] = $item['id']; + } + } + } + $groupName = []; + foreach ($groupList as $k => $v) { + $groupName[$v['id']] = $v['name']; + } + + $this->grouplist = $groupList; + $this->groupdata = $groupName; + + + } + +} \ No newline at end of file diff --git a/application/adminapi/controller/Rule.php b/application/adminapi/controller/Rule.php index 628663f..530c817 100644 --- a/application/adminapi/controller/Rule.php +++ b/application/adminapi/controller/Rule.php @@ -36,7 +36,7 @@ class Rule extends AdminApi * @ApiMethod (GET) * @ApiParams (name="is_tree", type="string", required=true, description="是否是树形结构") */ - public function rulelist() + public function index() { $admin_id = $this->auth->id; $is_tree = $this->request->get('is_tree'); @@ -69,7 +69,12 @@ class Rule extends AdminApi $admin_id = $this->auth->id; $params = $this->request->post(); - $menulist = $this->model->add($params,true); + try{ + $menulist = $this->model->add($params,true); + } catch (\Exception $e) { + $this->error($e->getMessage()); + } + $this->success('查询成功', $menulist); } @@ -77,4 +82,96 @@ class Rule extends AdminApi + /** + * 编辑权限节点(接口或菜单) + * + * @ApiMethod (POST) + * @ApiParams (name="pid", type="int", required=true, description="父ID") + * @ApiParams (name="ismenu", type="int", required=true, description="是否为菜单 0接口 1菜单") + * @ApiParams (name="name", type="string", required=true, description="节点URL(节点URL和外链选填其一)") + * @ApiParams (name="url", type="string", required=true, description="外链(节点URL和外链选填其一)") + * @ApiParams (name="rule_name", type="string", required=true, description="权限标识(菜单才需要)") + * @ApiParams (name="title", type="string", required=true, description="节点中文名") + * @ApiParams (name="icon", type="string", required=true, description="图标(菜单才需要)") + * @ApiParams (name="weigh", type="int", required=true, description="权重") + * @ApiParams (name="menutype", type="string", required=true, description="菜单类型:'addtabs','blank','dialog','ajax'") + * @ApiParams (name="extend", type="string", required=true, description="额外扩展属性(比如加类名做特特殊回调逻辑)") + * @ApiParams (name="status", type="string", required=true, description="状态(normal=正常,hidden=隐藏)") + * + */ + public function edit($id=null) + { + $admin_id = $this->auth->id; + $params = $this->request->post(); + + try{ + $menulist = $this->model->edit($id,$params,true); + } catch (\Exception $e) { + $this->error($e->getMessage()); + } + + + + + $this->success('查询成功', $menulist); + } + + + + + /** + * 查看详情 + * + * @ApiMethod (GET) + * @ApiParams (name="id", type="string", required=true, description="规则详情ID") + */ + public function detail() + { + $admin_id = $this->auth->id; + $id = $this->request->get('id/d'); + + try{ + $menulist = $this->model->detail($id,$show_field=[],$except_field=[]); + } catch (\Exception $e) { + $this->error($e->getMessage()); + } + + + + $this->success('查询成功', $menulist); + } + + + + /** + * 删除规则 + * + * @ApiMethod (GET) + * @ApiParams (name="ids", type="string", required=true, description="规则详情ID,多值逗号分割") + */ + public function del() + { + $admin_id = $this->auth->id; + $ids = $this->request->get('ids/s'); + + + try{ + $menulist = $this->model->del($ids,true); + } catch (\Exception $e) { + $this->error($e->getMessage()); + } + + + + $this->success('执行成功', ["count"=>$menulist]); + } + + + + + + + + + } \ No newline at end of file diff --git a/application/adminapi/model/AuthRule.php b/application/adminapi/model/AuthRule.php index 091c3c0..07f47c6 100644 --- a/application/adminapi/model/AuthRule.php +++ b/application/adminapi/model/AuthRule.php @@ -3,6 +3,7 @@ namespace app\adminapi\model; use app\common\model\BaseModel; +use fast\Tree; use think\Cache; use think\Model; @@ -173,9 +174,9 @@ class AuthRule extends BaseModel throw new \Exception(__('Parameter %s can not be empty', '')); } - if ($this->dataLimit && $this->dataLimitFieldAutoFill) { - $params[$this->dataLimitField] = $this->auth->id; - } +// if ($this->dataLimit && $this->dataLimitFieldAutoFill) { +// $params[$this->dataLimitField] = $this->auth->id; +// } //判断逻辑 if($trans){ self::beginTrans(); @@ -189,7 +190,9 @@ class AuthRule extends BaseModel $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->validateFailException()->validate($validate); } - + if (!$params['ismenu'] && !$params['pid']) { + throw new \Exception(__('The non-menu rule must have parent')); + } $result = $this->allowField(true)->save($params); @@ -207,4 +210,159 @@ class AuthRule extends BaseModel } + + + + /** 通用编辑(后台api版本) + * @param $params + * @param $trans + * @return $this + * @throws \Exception + */ + public function edit($id,$params,$trans=false){ + + $row = $this->get($id); + if (!$row) { + throw new \Exception(__('No Results were found')); + } + +// $adminIds = $this->getDataLimitAdminIds(); +// if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { +// throw new \Exception(__('You have no permission')); +// } + + + if (!$params['ismenu'] && !$params['pid']) { + throw new \Exception(__('The non-menu rule must have parent')); + } + if ($params['pid'] == $row['id']) { + throw new \Exception(__('Can not change the parent to self')); + } + if ($params['pid'] != $row['pid']) { + $childrenIds = Tree::instance()->init(collection(\app\admin\model\api\AuthRule::select())->toArray())->getChildrenIds($row['id']); + if (in_array($params['pid'], $childrenIds)) { + throw new \Exception(__('Can not change the parent to child')); + } + } + +//这里需要针对name做唯一验证 + $name = self::where("id","<>", $id)->where("name", $params['name'])->find(); + if ($name) { + throw new \Exception(__('The name already exist')); + } + if ($params['rule_name'] && $params['rule_name'] != $row['rule_name']) { + $rule_name = self::where("id","<>", $id)->where("rule_name", $params['rule_name'])->find(); + if ($rule_name) { + throw new \Exception(__('The rule_name already exist')); + } + } + if (empty($params)) { + throw new \Exception(__('Parameter %s can not be empty', '')); + } +//判断逻辑 + if($trans){ + self::beginTrans(); + } + $res = true; + try{ + + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; + $row->validateFailException()->validate($validate); + } + $result = $row->allowField(true)->save($params); + + if($trans){ + self::commitTrans(); + } + }catch (\Exception $e){ + if($trans){ + self::rollbackTrans(); + } + throw new \Exception($e->getMessage().$e->getFile().$e->getLine()); + } + return $row; + } + + + + + /** 通用详情(后台api版本) + * @param $params + * @param $trans + * @return $this + * @throws \Exception + */ + public function detail($id,$show_field=[],$except_field=[]){ + $row = $this->get($id); + if (!$row) { + throw new \Exception(__('No Results were found')); + } + if($show_field){ + $row->visible($show_field); + } + if($except_field){ + $row->hidden($except_field); + } + return $row; + } + + + + + /** 通用删除(后台api版本) + * @param $params + * @param $trans + * @return $this + * @throws \Exception + */ + public function del($ids = null,$trans=false){ + if (empty($ids)) { + throw new \Exception(__('Parameter %s can not be empty', 'ids')); + } +//判断逻辑 + +// $pk = $this->getPk(); +// $adminIds = $this->getDataLimitAdminIds(); +// if (is_array($adminIds)) { +// $this->where($this->dataLimitField, 'in', $adminIds); +// } + if($trans){ + self::beginTrans(); + } + $res = true; + try{ + + $delIds = []; + foreach (explode(',', $ids) as $k => $v) { + $delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, true)); + } + $delIds = array_unique($delIds); + $count = $this->where('id', 'in', $delIds)->delete(); + if ($count) { + Cache::rm('__menu__'); + } + + + +// foreach ($list as $item) { +// $count += $item->delete(); +// } + + if($trans){ + self::commitTrans(); + } + }catch (\Exception $e){ + if($trans){ + self::rollbackTrans(); + } + throw new \Exception($e->getMessage().$e->getFile().$e->getLine()); + } + return $count; + } + + + } diff --git a/application/common/model/school/activity/order/Detail.php b/application/common/model/school/activity/order/Detail.php index a385f2c..35cd21a 100644 --- a/application/common/model/school/activity/order/Detail.php +++ b/application/common/model/school/activity/order/Detail.php @@ -2,9 +2,10 @@ namespace app\common\model\school\activity\order; +use app\common\model\BaseModel; use think\Model; -class Detail extends Model +class Detail extends BaseModel { // 表名 protected $name = 'school_activity_order_detail'; diff --git a/application/common/model/school/activity/order/Order.php b/application/common/model/school/activity/order/Order.php index e71e605..2e8cb63 100644 --- a/application/common/model/school/activity/order/Order.php +++ b/application/common/model/school/activity/order/Order.php @@ -7,6 +7,7 @@ use app\admin\model\Admin; use app\admin\model\Manystore; use app\common\model\BaseModel; use app\common\model\school\activity\Activity; +use app\common\model\school\activity\Cate; use app\common\model\school\activity\Refund; use app\common\model\User; use bw\Common; @@ -468,14 +469,24 @@ class Order extends BaseModel if(!$data) return $data; //加载订单详情 - $data->detail; + $detail = $data->detail; //订单用户 // $data->user; $data->user->visible(['id','nickname','mobile','avatar','realname']); + $data["join_info"] = Activity::getJoininfo($data["activity_id"],$detail["stock"]); //规格信息 $data->ordercode; + $cate_list = Cate::where("status",'1')->column("name","id"); + $classes_cate_ids = $detail['cate_ids']; + $classes_cate = []; + foreach (explode(",", $classes_cate_ids) as $classes_cate_id){ + if(isset($cate_list[$classes_cate_id]))$classes_cate[] = $cate_list[$classes_cate_id]; + } + $data['classes_cate'] = $classes_cate; + + return $data;