作者 开飞机的舒克

根据开关按钮修改其他值

@@ -144,4 +144,60 @@ class User extends Backend @@ -144,4 +144,60 @@ class User extends Backend
144 $this->success(); 144 $this->success();
145 } 145 }
146 146
  147 + /**
  148 + * 修改
  149 + */
  150 + public function multi($ids = NULL){
  151 + if (!$this->request->isPost()) {
  152 + $this->error(__("Invalid parameters"));
  153 + }
  154 + $ids = $ids ? $ids : $this->request->post("ids");
  155 + $ids = $ids ?: $this->request->post('ids');
  156 + if (empty($ids)) {
  157 + $this->error(__('Parameter %s can not be empty', 'ids'));
  158 + }
  159 +
  160 + if (false === $this->request->has('params')) {
  161 + $this->error(__('No rows were updated'));
  162 + }
  163 + parse_str($this->request->post('params'), $values);
  164 + $values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
  165 + if (empty($values)) {
  166 + $this->error(__('You have no permission'));
  167 + }
  168 + $adminIds = $this->getDataLimitAdminIds();
  169 + if (is_array($adminIds)) {
  170 + $this->model->where($this->dataLimitField, 'in', $adminIds);
  171 + }
  172 + $count = 0;
  173 + Db::startTrans();
  174 + try {
  175 + $list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
  176 + foreach ($list as $item) {
  177 + if ($values['is_teach'] == 1) {
  178 + $values['teach_phone'] = $item['mobile'];
  179 + } else if ($values['is_teach'] == 0){
  180 + $values['teach_phone'] = null;
  181 + }
  182 + $count += $item->allowField(true)->isUpdate(true)->save($values);
  183 + }
  184 + Db::commit();
  185 + } catch (PDOException|Exception $e) {
  186 + Db::rollback();
  187 + $this->error($e->getMessage());
  188 + }
  189 + if ($count) {
  190 + $this->success();
  191 + }
  192 + $this->error(__('No rows were updated'));
  193 +// $row = $this->model->get($ids);
  194 +// if ($row['is_teach'] == 1){
  195 +// $row['teach_phone'] = $row['mobile'];
  196 +// }else{
  197 +// $row['teach_phone'] = null;
  198 +// }
  199 +// $this->success();
  200 +
  201 + }
  202 +
147 } 203 }
@@ -42,7 +42,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -42,7 +42,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
42 // {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search}, 42 // {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
43 {field: 'is_teach', title: __('Is_teach'),searchList: {"0":__('Is_teach 0'),"1":__('Is_teach 1')},formatter:Table.api.formatter.toggle}, 43 {field: 'is_teach', title: __('Is_teach'),searchList: {"0":__('Is_teach 0'),"1":__('Is_teach 1')},formatter:Table.api.formatter.toggle},
44 {field: 'teach_phone', title: __('Teach_phone'),operate: 'LIKE'}, 44 {field: 'teach_phone', title: __('Teach_phone'),operate: 'LIKE'},
45 - {field: 'bind_study', title: __('Bind_study'),searchList: {"0":__('Bind_study 0'),"1":__('Bind_study 1')},formatter:Table.api.formatter.toggle}, 45 + {field: 'bind_study', title: __('Bind_study'),searchList: {0:__('Bind_study 0'),1:__('Bind_study 1')},formatter: Table.api.formatter.normal},
46 {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}}, 46 {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
47 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} 47 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
48 ] 48 ]