model = model('InviteRecord'); $this->view->assign("payTypeList", $this->model->getPayTypeList()); $this->view->assign("statusList", $this->model->getStatusList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法 * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('pkey_name')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $total = $this->model->alias('r') ->join('admin_extend e','e.admin_id=r.invite_id and e.create_by='.$this->auth->id) ->where($where) ->count(); $list = $this->model->alias('r') ->join('admin a','r.invite_id = a.id') ->join('admin_extend e','e.admin_id=r.invite_id and e.create_by='.$this->auth->id) ->field('r.*,a.nickname as anickname') ->where($where) ->order('r.status asc,r.id desc') ->limit($offset, $limit) ->select(); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 编辑 */ public function edit($ids = NULL) { $row = $this->model->get($ids); $this->assign('id',$ids); $extend = model('admin_extend')->where('admin_id',$this->auth->id)->find(); $this->assign('extend',$extend); if (!$row) $this->error(__('No Results were found')); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } if ($this->request->isPost()) { $params = $this->request->post("row/a"); $extends = $this->request->post("extend/a"); $id = $this->request->post("activity_id"); if ($params) { try { $this->model=model('admin'); $params['salt'] = Random::alnum(); $params['password'] = md5(md5($params['password']) . $params['salt']); $params['avatar'] = asset('/img/avatar.png'); //设置新管理员默认头像。 $result = $this->model->validate('Admin.add')->insertGetId($params); if ($result) { $dataset = []; $dataset[] = ['uid' => $result, 'group_id' => 4]; model('AuthGroupAccess')->saveAll($dataset); //分组表 model('invite_record')->update(['admin_id'=>$result,'status'=>'1'],['id'=>$id]); $extends['create_by'] = $this->auth->id; $extends['admin_id'] = $result; $extends['createtime'] = time(); $extends['updatetime'] = time(); if($extends['pay_method'] == 1){ $extends['pay_method'] = 3; }elseif($extends['pay_method'] == 2){ $extends['pay_method'] = 4; }else{ $extends['pay_method'] = 2; } model('admin_extend')->insert($extends); $this->success(); } else { $this->error($row->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } $this->view->assign("row", $row); return $this->view->fetch(); } }