作者 开飞机的舒克

根据开关按钮修改其他值

... ... @@ -144,4 +144,60 @@ class User extends Backend
$this->success();
}
/**
* 修改
*/
public function multi($ids = NULL){
if (!$this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
$ids = $ids ?: $this->request->post('ids');
if (empty($ids)) {
$this->error(__('Parameter %s can not be empty', 'ids'));
}
if (false === $this->request->has('params')) {
$this->error(__('No rows were updated'));
}
parse_str($this->request->post('params'), $values);
$values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
if (empty($values)) {
$this->error(__('You have no permission'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$count = 0;
Db::startTrans();
try {
$list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
foreach ($list as $item) {
if ($values['is_teach'] == 1) {
$values['teach_phone'] = $item['mobile'];
} else if ($values['is_teach'] == 0){
$values['teach_phone'] = null;
}
$count += $item->allowField(true)->isUpdate(true)->save($values);
}
Db::commit();
} catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
}
$this->error(__('No rows were updated'));
// $row = $this->model->get($ids);
// if ($row['is_teach'] == 1){
// $row['teach_phone'] = $row['mobile'];
// }else{
// $row['teach_phone'] = null;
// }
// $this->success();
}
}
... ...
... ... @@ -42,7 +42,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
{field: 'is_teach', title: __('Is_teach'),searchList: {"0":__('Is_teach 0'),"1":__('Is_teach 1')},formatter:Table.api.formatter.toggle},
{field: 'teach_phone', title: __('Teach_phone'),operate: 'LIKE'},
{field: 'bind_study', title: __('Bind_study'),searchList: {"0":__('Bind_study 0'),"1":__('Bind_study 1')},formatter:Table.api.formatter.toggle},
{field: 'bind_study', title: __('Bind_study'),searchList: {0:__('Bind_study 0'),1:__('Bind_study 1')},formatter: Table.api.formatter.normal},
{field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
... ...