配合前端对接微调接口
This commit is contained in:
		
							parent
							
								
									107fcbe698
								
							
						
					
					
						commit
						cc13121bb8
					
				@ -117,6 +117,19 @@ class Rule extends Backend
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                //这里需要针对name做唯一验证
 | 
					                //这里需要针对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 = \think\Loader::validate(ApiAuthRule::class);
 | 
				
			||||||
//                $ruleValidate->rule([
 | 
					//                $ruleValidate->rule([
 | 
				
			||||||
//                    'name' => 'require|unique:ApiAuthRule,name,' . $row->id,
 | 
					//                    'name' => 'require|unique:ApiAuthRule,name,' . $row->id,
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										76
									
								
								application/adminapi/controller/Group.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								application/adminapi/controller/Group.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,76 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace app\adminapi\controller;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use app\adminapi\model\AuthRule;
 | 
				
			||||||
 | 
					use app\common\controller\AdminApi;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use app\adminapi\model\AuthGroup;
 | 
				
			||||||
 | 
					use app\adminapi\model\AuthGroupAccess;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use fast\Tree;
 | 
				
			||||||
 | 
					use think\Db;
 | 
				
			||||||
 | 
					use think\Exception;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * api角色组
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @icon   fa fa-group
 | 
				
			||||||
 | 
					 * @remark 角色组可以有多个,角色有上下级层级关系,如果子角色有角色组和管理员的权限则可以派生属于自己组别下级的角色组或管理员
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class Group extends AdminApi
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    protected $model = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //无需要权限判断的方法
 | 
				
			||||||
 | 
					    protected $noNeedRight = ['roletree'];
 | 
				
			||||||
 | 
					    //当前登录管理员所有子组别
 | 
				
			||||||
 | 
					    protected $childrenGroupIds = [];
 | 
				
			||||||
 | 
					    //当前组别列表数据
 | 
				
			||||||
 | 
					    protected $grouplist = [];
 | 
				
			||||||
 | 
					    protected $groupdata = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 初始化操作
 | 
				
			||||||
 | 
					     * @access protected
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function _initialize()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -36,7 +36,7 @@ class Rule extends AdminApi
 | 
				
			|||||||
     * @ApiMethod (GET)
 | 
					     * @ApiMethod (GET)
 | 
				
			||||||
     * @ApiParams (name="is_tree", type="string", required=true, description="是否是树形结构")
 | 
					     * @ApiParams (name="is_tree", type="string", required=true, description="是否是树形结构")
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function rulelist()
 | 
					    public function index()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $admin_id = $this->auth->id;
 | 
					        $admin_id = $this->auth->id;
 | 
				
			||||||
        $is_tree = $this->request->get('is_tree');
 | 
					        $is_tree = $this->request->get('is_tree');
 | 
				
			||||||
@ -69,7 +69,12 @@ class Rule extends AdminApi
 | 
				
			|||||||
        $admin_id = $this->auth->id;
 | 
					        $admin_id = $this->auth->id;
 | 
				
			||||||
        $params = $this->request->post();
 | 
					        $params = $this->request->post();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try{
 | 
				
			||||||
            $menulist = $this->model->add($params,true);
 | 
					            $menulist = $this->model->add($params,true);
 | 
				
			||||||
 | 
					        } catch (\Exception $e) {
 | 
				
			||||||
 | 
					            $this->error($e->getMessage());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->success('查询成功', $menulist);
 | 
					        $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]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -3,6 +3,7 @@
 | 
				
			|||||||
namespace app\adminapi\model;
 | 
					namespace app\adminapi\model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use app\common\model\BaseModel;
 | 
					use app\common\model\BaseModel;
 | 
				
			||||||
 | 
					use fast\Tree;
 | 
				
			||||||
use think\Cache;
 | 
					use think\Cache;
 | 
				
			||||||
use think\Model;
 | 
					use think\Model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -173,9 +174,9 @@ class AuthRule extends BaseModel
 | 
				
			|||||||
            throw new \Exception(__('Parameter %s can not be empty', ''));
 | 
					            throw new \Exception(__('Parameter %s can not be empty', ''));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
 | 
					//        if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
 | 
				
			||||||
            $params[$this->dataLimitField] = $this->auth->id;
 | 
					//            $params[$this->dataLimitField] = $this->auth->id;
 | 
				
			||||||
        }
 | 
					//        }
 | 
				
			||||||
//判断逻辑
 | 
					//判断逻辑
 | 
				
			||||||
        if($trans){
 | 
					        if($trans){
 | 
				
			||||||
            self::beginTrans();
 | 
					            self::beginTrans();
 | 
				
			||||||
@ -189,7 +190,9 @@ class AuthRule extends BaseModel
 | 
				
			|||||||
                $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
 | 
					                $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
 | 
				
			||||||
                $this->validateFailException()->validate($validate);
 | 
					                $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);
 | 
					            $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;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -2,9 +2,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace app\common\model\school\activity\order;
 | 
					namespace app\common\model\school\activity\order;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use app\common\model\BaseModel;
 | 
				
			||||||
use think\Model;
 | 
					use think\Model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Detail extends Model
 | 
					class Detail extends BaseModel
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    // 表名
 | 
					    // 表名
 | 
				
			||||||
    protected $name = 'school_activity_order_detail';
 | 
					    protected $name = 'school_activity_order_detail';
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ use app\admin\model\Admin;
 | 
				
			|||||||
use app\admin\model\Manystore;
 | 
					use app\admin\model\Manystore;
 | 
				
			||||||
use app\common\model\BaseModel;
 | 
					use app\common\model\BaseModel;
 | 
				
			||||||
use app\common\model\school\activity\Activity;
 | 
					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\school\activity\Refund;
 | 
				
			||||||
use app\common\model\User;
 | 
					use app\common\model\User;
 | 
				
			||||||
use bw\Common;
 | 
					use bw\Common;
 | 
				
			||||||
@ -468,14 +469,24 @@ class Order extends BaseModel
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if(!$data) return $data;
 | 
					        if(!$data) return $data;
 | 
				
			||||||
        //加载订单详情
 | 
					        //加载订单详情
 | 
				
			||||||
        $data->detail;
 | 
					       $detail = $data->detail;
 | 
				
			||||||
        //订单用户
 | 
					        //订单用户
 | 
				
			||||||
//        $data->user;
 | 
					//        $data->user;
 | 
				
			||||||
        $data->user->visible(['id','nickname','mobile','avatar','realname']);
 | 
					        $data->user->visible(['id','nickname','mobile','avatar','realname']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $data["join_info"] =  Activity::getJoininfo($data["activity_id"],$detail["stock"]);
 | 
				
			||||||
        //规格信息
 | 
					        //规格信息
 | 
				
			||||||
        $data->ordercode;
 | 
					        $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;
 | 
					        return $data;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user