作者 开飞机的舒克

修改用户编辑功能

... ... @@ -4,6 +4,11 @@ namespace app\admin\controller\user;
use app\common\controller\Backend;
use app\common\library\Auth;
use think\Db;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 会员管理
... ... @@ -82,7 +87,43 @@ class User extends Backend
$this->error(__('No Results were found'));
}
$this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
return parent::edit($ids);
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
if ($params['is_teach'] == 1){
$params['teach_phone'] = $params['mobile'];
}else{
$params['teach_phone'] = null;
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
/**
... ...
... ... @@ -40,12 +40,6 @@
</div>
</div>
<div class="form-group">
<label for="c-mobile" class="control-label col-xs-12 col-sm-2">{:__('Teach_phone')}:</label>
<div class="col-xs-12 col-sm-4">
<input id="c-teach_phone" data-rule="" class="form-control" name="row[teach_phone]" type="text" value="{$row.teach_phone|htmlentities}">
</div>
</div>
<div class="form-group">
<label for="content" class="control-label col-xs-12 col-sm-2">{:__('Is_teach')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_radios('row[is_teach]', ['0'=>__('Is_teach 0'), '1'=>__('Is_teach 1')], $row['is_teach'])}
... ...