作者 开飞机的舒克

修改用户编辑功能

@@ -4,6 +4,11 @@ namespace app\admin\controller\user; @@ -4,6 +4,11 @@ namespace app\admin\controller\user;
4 4
5 use app\common\controller\Backend; 5 use app\common\controller\Backend;
6 use app\common\library\Auth; 6 use app\common\library\Auth;
  7 +use think\Db;
  8 +use think\Exception;
  9 +use think\exception\DbException;
  10 +use think\exception\PDOException;
  11 +use think\exception\ValidateException;
7 12
8 /** 13 /**
9 * 会员管理 14 * 会员管理
@@ -82,7 +87,43 @@ class User extends Backend @@ -82,7 +87,43 @@ class User extends Backend
82 $this->error(__('No Results were found')); 87 $this->error(__('No Results were found'));
83 } 88 }
84 $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker'])); 89 $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
85 - return parent::edit($ids); 90 + $adminIds = $this->getDataLimitAdminIds();
  91 + if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  92 + $this->error(__('You have no permission'));
  93 + }
  94 + if (false === $this->request->isPost()) {
  95 + $this->view->assign('row', $row);
  96 + return $this->view->fetch();
  97 + }
  98 + $params = $this->request->post('row/a');
  99 + if (empty($params)) {
  100 + $this->error(__('Parameter %s can not be empty', ''));
  101 + }
  102 + $params = $this->preExcludeFields($params);
  103 + $result = false;
  104 + Db::startTrans();
  105 + try {
  106 + //是否采用模型验证
  107 + if ($this->modelValidate) {
  108 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  109 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  110 + $row->validateFailException()->validate($validate);
  111 + }
  112 + if ($params['is_teach'] == 1){
  113 + $params['teach_phone'] = $params['mobile'];
  114 + }else{
  115 + $params['teach_phone'] = null;
  116 + }
  117 + $result = $row->allowField(true)->save($params);
  118 + Db::commit();
  119 + } catch (ValidateException|PDOException|Exception $e) {
  120 + Db::rollback();
  121 + $this->error($e->getMessage());
  122 + }
  123 + if (false === $result) {
  124 + $this->error(__('No rows were updated'));
  125 + }
  126 + $this->success();
86 } 127 }
87 128
88 /** 129 /**
@@ -40,12 +40,6 @@ @@ -40,12 +40,6 @@
40 </div> 40 </div>
41 </div> 41 </div>
42 <div class="form-group"> 42 <div class="form-group">
43 - <label for="c-mobile" class="control-label col-xs-12 col-sm-2">{:__('Teach_phone')}:</label>  
44 - <div class="col-xs-12 col-sm-4">  
45 - <input id="c-teach_phone" data-rule="" class="form-control" name="row[teach_phone]" type="text" value="{$row.teach_phone|htmlentities}">  
46 - </div>  
47 - </div>  
48 - <div class="form-group">  
49 <label for="content" class="control-label col-xs-12 col-sm-2">{:__('Is_teach')}:</label> 43 <label for="content" class="control-label col-xs-12 col-sm-2">{:__('Is_teach')}:</label>
50 <div class="col-xs-12 col-sm-8"> 44 <div class="col-xs-12 col-sm-8">
51 {:build_radios('row[is_teach]', ['0'=>__('Is_teach 0'), '1'=>__('Is_teach 1')], $row['is_teach'])} 45 {:build_radios('row[is_teach]', ['0'=>__('Is_teach 0'), '1'=>__('Is_teach 1')], $row['is_teach'])}