...
|
...
|
@@ -49,28 +49,19 @@ class User extends Backend |
|
|
if ($this->request->request('keyField')) {
|
|
|
return $this->selectpage();
|
|
|
}
|
|
|
// $study = Db::name('study')->field('id,pass_mark')->select();
|
|
|
// $user_ids = [];
|
|
|
// foreach ($study as &$v) {
|
|
|
// $user_ids = array_merge($user_ids,Db::name('third_exam')->where(['study_id'=>$v['id'],'score'=>['>=',$v['pass_mark']]])->column('user_id'));
|
|
|
// }
|
|
|
|
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams('user.id,user.username,user.nickname,user.password,user.card,user.work_address,user.studynum');
|
|
|
$total = $this->model
|
|
|
->with('group')
|
|
|
// ->whereIn('user.id',$user_ids)
|
|
|
->where($where)
|
|
|
->order($sort, $order)
|
|
|
->count();
|
|
|
$list = $this->model
|
|
|
->with('group')
|
|
|
// ->whereIn('user.id',$user_ids)
|
|
|
->where($where)
|
|
|
->order($sort, $order)
|
|
|
->limit($offset, $limit)
|
|
|
->select();
|
|
|
// foreach ($list as $k => $v) {
|
|
|
// $v->hidden(['password', 'salt']);
|
|
|
// }
|
|
|
foreach ($list as $k => &$v) {
|
|
|
$v['user.mobile_exam_ids'] = Db::name('mobile_exam')->whereIn('id',$v['mobile_exam_ids'])->column('name');
|
|
|
}
|
...
|
...
|
@@ -84,87 +75,6 @@ class User extends Backend |
|
|
/**
|
|
|
* 添加
|
|
|
*/
|
|
|
// public function add()
|
|
|
// {
|
|
|
// if ($this->request->isPost()) {
|
|
|
// $params = $this->request->post("row/a");
|
|
|
// if ($params) {
|
|
|
// $params = $this->preExcludeFields($params);
|
|
|
// $params['status'] = 'normal';
|
|
|
//
|
|
|
// if(empty($params['expirationtime'])){
|
|
|
// $this->error('有效期不能为空');
|
|
|
// }
|
|
|
// $params['expirationtime'] = strtotime($params['expirationtime']);
|
|
|
// if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
|
|
// $params[$this->dataLimitField] = $this->auth->id;
|
|
|
// }
|
|
|
// if($this->check_identity($params['card'])) {
|
|
|
// $this->error('该身份证号已存在');
|
|
|
// }
|
|
|
// $study = [];
|
|
|
// if($params['study_id'] && $params['periodtime']) {
|
|
|
// $study = [
|
|
|
// 'study_id' => $params['study_id'],
|
|
|
// 'periodtime' => strtotime($params['periodtime'])
|
|
|
// ];
|
|
|
// unset($params['study_id']);
|
|
|
// unset($params['periodtime']);
|
|
|
// }
|
|
|
//// $result = $this->model->validate('User.add')->save($params);
|
|
|
//// if ($result === false) {
|
|
|
//// $this->error($this->model->getError());
|
|
|
//// }
|
|
|
// if (!empty($params['mobile'])) {
|
|
|
// if(\app\common\model\User::where('mobile', $params['mobile'])->find()){
|
|
|
// $this->error('注册手机号已存在');
|
|
|
// }
|
|
|
// $params['phone'] = $params['mobile'];
|
|
|
// }
|
|
|
// $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 . '.add' : $name) : $this->modelValidate;
|
|
|
// $this->model->validateFailException(true)->validate($validate);
|
|
|
// }
|
|
|
// $result = $this->model->allowField(true)->save($params);
|
|
|
// if($study) {
|
|
|
// $study['third_id'] = $this->model->id;
|
|
|
// $res['third_id'] = $study['third_id'];
|
|
|
// $res['study_id'] = $study['study_id'];
|
|
|
// $res['createtime'] = time();
|
|
|
// $res['playtime'] = 0;
|
|
|
// $classes_ids = Db::name('classes')->where('study_id',$res['study_id'])->where('is_major',1)->column('id');
|
|
|
// foreach ($classes_ids as $v){
|
|
|
// $res['class_id'] = $v;
|
|
|
// Db::name('study_class')->insertGetId($res);
|
|
|
// }
|
|
|
// Db::name('third_study')->insertGetId($study);
|
|
|
// }
|
|
|
// Db::commit();
|
|
|
// } catch (ValidateException $e) {
|
|
|
// Db::rollback();
|
|
|
// $this->error($e->getMessage());
|
|
|
// } catch (PDOException $e) {
|
|
|
// Db::rollback();
|
|
|
// $this->error($e->getMessage());
|
|
|
// } catch (Exception $e) {
|
|
|
// Db::rollback();
|
|
|
// $this->error($e->getMessage());
|
|
|
// }
|
|
|
// if ($result !== false) {
|
|
|
// $this->success();
|
|
|
// } else {
|
|
|
// $this->error(__('No rows were inserted'));
|
|
|
// }
|
|
|
// }
|
|
|
// $this->error(__('Parameter %s can not be empty', ''));
|
|
|
// }
|
|
|
// return $this->view->fetch();
|
|
|
// }
|
|
|
public function add()
|
|
|
{
|
|
|
if ($this->request->isPost()) {
|
...
|
...
|
@@ -173,10 +83,10 @@ class User extends Backend |
|
|
$params = $this->preExcludeFields($params);
|
|
|
$params['status'] = 'normal';
|
|
|
|
|
|
if(empty($params['expirationtime'])){
|
|
|
$this->error('有效期不能为空');
|
|
|
}
|
|
|
$params['expirationtime'] = strtotime($params['expirationtime']);
|
|
|
// if(empty($params['expirationtime'])){
|
|
|
// $this->error('有效期不能为空');
|
|
|
// }
|
|
|
// $params['expirationtime'] = strtotime($params['expirationtime']);
|
|
|
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
|
|
$params[$this->dataLimitField] = $this->auth->id;
|
|
|
}
|
...
|
...
|
@@ -191,10 +101,13 @@ class User extends Backend |
|
|
}
|
|
|
|
|
|
// 考试数据
|
|
|
$study_ids = [];
|
|
|
if($params['study_id'] && $params['periodtime']) {
|
|
|
$study_ids = explode(',',$params['study_id']);
|
|
|
$periodtime = strtotime($params['periodtime']);
|
|
|
$studys = [];
|
|
|
if(!empty($params['studys'])){
|
|
|
$studys = json_decode($params['studys'],true);
|
|
|
$study_ids = array_column($studys,'study_id');
|
|
|
if(count($study_ids) != count(array_unique($study_ids))){
|
|
|
$this->error('绑定考试,不能重复');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$result = false;
|
...
|
...
|
@@ -209,24 +122,33 @@ class User extends Backend |
|
|
$result = $this->model->allowField(true)->save($params);
|
|
|
|
|
|
// 考试数据-添加
|
|
|
foreach ($study_ids as $study_id){
|
|
|
$third_id = $this->model->id;
|
|
|
Db::name('third_study')->insertGetId([
|
|
|
$third_id = $this->model->id;
|
|
|
$third_study_data = [];
|
|
|
$study_class_data = [];
|
|
|
$createtime = time();
|
|
|
foreach ($studys as $study){
|
|
|
$third_study_data[] = [
|
|
|
'third_id' => $third_id,
|
|
|
'study_id' => $study_id,
|
|
|
'periodtime' => $periodtime,
|
|
|
]);
|
|
|
$classes_ids = Db::name('classes')->where('study_id',$study_id)->where('is_major',1)->column('id');
|
|
|
'study_id' => $study['study_id'],
|
|
|
'periodtime' => strtotime($study['periodtime']),
|
|
|
];
|
|
|
$classes_ids = Db::name('classes')->where('study_id',$study['study_id'])->where('is_major',1)->column('id');
|
|
|
foreach ($classes_ids as $class_id){
|
|
|
Db::name('study_class')->insertGetId([
|
|
|
$study_class_data[] = [
|
|
|
'third_id' => $third_id,
|
|
|
'study_id' => $study_id,
|
|
|
'study_id' => $study['study_id'],
|
|
|
'class_id' => $class_id,
|
|
|
'playtime' => 0,
|
|
|
'createtime' => time(),
|
|
|
]);
|
|
|
'createtime' => $createtime,
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
if(!empty($third_study_data)){
|
|
|
Db::name('third_study')->insertAll($third_study_data);
|
|
|
}
|
|
|
if(!empty($study_class_data)){
|
|
|
Db::name('study_class')->insertAll($study_class_data);
|
|
|
}
|
|
|
|
|
|
Db::commit();
|
|
|
} catch (ValidateException $e) {
|
...
|
...
|
@@ -250,82 +172,9 @@ class User extends Backend |
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
|
|
|
// public function edit($ids = NULL)
|
|
|
// {
|
|
|
// $row = $this->model->get($ids);
|
|
|
// if (!$row)
|
|
|
// $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);
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 编辑
|
|
|
*/
|
|
|
// public function edit($ids = null)
|
|
|
// {
|
|
|
// $row = $this->model->get($ids);
|
|
|
// 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");
|
|
|
// if ($params) {
|
|
|
// if(empty($params['expirationtime'])){
|
|
|
// $this->error('有效期不能为空');
|
|
|
// }
|
|
|
// $params['expirationtime'] = strtotime($params['expirationtime']);
|
|
|
// if($this->check_identity($params['card'],$ids)) {
|
|
|
// $this->error('该身份证号已存在');
|
|
|
// }
|
|
|
//// if(strlen($params['username']) < 6 || strlen($params['username']) > 18) {
|
|
|
//// $this->error('用户名须为6-18位');
|
|
|
//// }
|
|
|
// if (!empty($params['mobile'])) {
|
|
|
// if(\app\common\model\User::where('mobile', $params['mobile'])->where('id', '<>', $row->id)->find()){
|
|
|
// $this->error('注册手机号已存在');
|
|
|
// }
|
|
|
// $params['phone'] = $params['mobile'];
|
|
|
// }
|
|
|
// $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(true)->validate($validate);
|
|
|
// }
|
|
|
// $result = $row->allowField(true)->save($params);
|
|
|
// Db::commit();
|
|
|
// } catch (ValidateException $e) {
|
|
|
// Db::rollback();
|
|
|
// $this->error($e->getMessage());
|
|
|
// } catch (PDOException $e) {
|
|
|
// Db::rollback();
|
|
|
// $this->error($e->getMessage());
|
|
|
// } catch (Exception $e) {
|
|
|
// Db::rollback();
|
|
|
// $this->error($e->getMessage());
|
|
|
// }
|
|
|
// if ($result !== false) {
|
|
|
// $this->success();
|
|
|
// } else {
|
|
|
// $this->error(__('No rows were updated'));
|
|
|
// }
|
|
|
// }
|
|
|
// $this->error(__('Parameter %s can not be empty', ''));
|
|
|
// }
|
|
|
// $this->view->assign("row", $row);
|
|
|
// return $this->view->fetch();
|
|
|
// }
|
|
|
public function edit($ids = null)
|
|
|
{
|
|
|
$row = $this->model->get($ids);
|
...
|
...
|
@@ -341,10 +190,10 @@ class User extends Backend |
|
|
if ($this->request->isPost()) {
|
|
|
$params = $this->request->post("row/a");
|
|
|
if ($params) {
|
|
|
if(empty($params['expirationtime'])){
|
|
|
$this->error('有效期不能为空');
|
|
|
}
|
|
|
$params['expirationtime'] = strtotime($params['expirationtime']);
|
|
|
// if(empty($params['expirationtime'])){
|
|
|
// $this->error('有效期不能为空');
|
|
|
// }
|
|
|
// $params['expirationtime'] = strtotime($params['expirationtime']);
|
|
|
if($this->check_identity($params['card'],$ids)) {
|
|
|
$this->error('该身份证号已存在');
|
|
|
}
|
...
|
...
|
@@ -356,10 +205,13 @@ class User extends Backend |
|
|
}
|
|
|
|
|
|
// 考试数据
|
|
|
$study_ids = [];
|
|
|
if($params['study_id'] && $params['periodtime']) {
|
|
|
$study_ids = explode(',',$params['study_id']);
|
|
|
$periodtime = strtotime($params['periodtime']);
|
|
|
$studys = [];
|
|
|
if(!empty($params['studys'])){
|
|
|
$studys = json_decode($params['studys'],true);
|
|
|
$study_ids = array_column($studys,'study_id');
|
|
|
if(count($study_ids) != count(array_unique($study_ids))){
|
|
|
$this->error('绑定考试,不能重复');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$result = false;
|
...
|
...
|
@@ -373,50 +225,50 @@ class User extends Backend |
|
|
}
|
|
|
$result = $row->allowField(true)->save($params);
|
|
|
|
|
|
$third_id = $row['id'];
|
|
|
// 考试数据-编辑
|
|
|
foreach ($study_ids as $study_id){
|
|
|
$my_study = Db::name('third_study')->where('study_id',$study_id)->where('third_id',$third_id)->find();
|
|
|
$third_id = $row['id'];
|
|
|
$third_study_data = [];
|
|
|
$study_class_data = [];
|
|
|
$createtime = time();
|
|
|
foreach ($studys as $study){
|
|
|
$my_study = Db::name('third_study')->where('study_id',$study['study_id'])->where('third_id',$third_id)->find();
|
|
|
if(!$my_study){
|
|
|
Db::name('third_study')->insertGetId([
|
|
|
$third_study_data[] = [
|
|
|
'third_id' => $third_id,
|
|
|
'study_id' => $study_id,
|
|
|
'periodtime' => $periodtime,
|
|
|
]);
|
|
|
'study_id' => $study['study_id'],
|
|
|
'periodtime' => strtotime($study['periodtime']),
|
|
|
];
|
|
|
}else{
|
|
|
// 修改到期时间
|
|
|
Db::name('third_study')->where('id',$my_study['id'])->update(['periodtime'=>$periodtime]);
|
|
|
Db::name('third_study')->where('id',$my_study['id'])->update(['periodtime'=>strtotime($study['periodtime'])]);
|
|
|
}
|
|
|
$classes_ids = Db::name('classes')->where('study_id',$study_id)->where('is_major',1)->column('id');
|
|
|
$classes_ids = Db::name('classes')->where('study_id',$study['study_id'])->where('is_major',1)->column('id');
|
|
|
foreach ($classes_ids as $class_id){
|
|
|
$my_class = Db::name('study_class')->where('class_id',$class_id)->where('third_id',$third_id)->find();
|
|
|
if(!$my_class){
|
|
|
Db::name('study_class')->insertGetId([
|
|
|
$study_class_data[] = [
|
|
|
'third_id' => $third_id,
|
|
|
'study_id' => $study_id,
|
|
|
'study_id' => $study['study_id'],
|
|
|
'class_id' => $class_id,
|
|
|
'playtime' => 0,
|
|
|
'createtime' => time(),
|
|
|
]);
|
|
|
'createtime' => $createtime,
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 删除去掉的科目
|
|
|
$my_study_ids = Db::name('third_study')->where('third_id',$third_id)->column('study_id');
|
|
|
if($my_study_ids){
|
|
|
$delete_study_ids = array_diff($my_study_ids,$study_ids);
|
|
|
if($delete_study_ids){
|
|
|
Db::name('third_study')
|
|
|
->where('third_id',$third_id)
|
|
|
->where('study_id','in',$delete_study_ids)
|
|
|
->delete();
|
|
|
Db::name('study_class')
|
|
|
->where('third_id',$third_id)
|
|
|
->where('study_id','in',$delete_study_ids)
|
|
|
->delete();
|
|
|
}
|
|
|
if(!empty($third_study_data)){
|
|
|
Db::name('third_study')->insertAll($third_study_data);
|
|
|
}
|
|
|
if(!empty($study_class_data)){
|
|
|
Db::name('study_class')->insertAll($study_class_data);
|
|
|
}
|
|
|
// 删除去掉的考试
|
|
|
$del_where['third_id'] = $third_id;
|
|
|
if($studys){
|
|
|
$del_where['study_id'] = ['not in',$study_ids];
|
|
|
}
|
|
|
Db::name('third_study')->where($del_where)->delete();
|
|
|
Db::name('study_class')->where($del_where)->delete();
|
|
|
|
|
|
Db::commit();
|
|
|
} catch (ValidateException $e) {
|
...
|
...
|
@@ -439,10 +291,8 @@ class User extends Backend |
|
|
}
|
|
|
|
|
|
// 我的科目
|
|
|
$my_study_list = Db::name('third_study')->where('third_id',$row['id'])->select();
|
|
|
$my_study_ids = array_column($my_study_list,'study_id');
|
|
|
$this->view->assign("study_id", $my_study_ids ? implode(',',$my_study_ids) : '');
|
|
|
$this->view->assign("periodtime", count($my_study_list) > 0 ? $my_study_list[0]['periodtime'] : time());
|
|
|
$studys = Db::name('third_study')->where('third_id',$row['id'])->field("study_id,FROM_UNIXTIME(periodtime,'%Y-%m-%d %H:%i:%s') periodtime")->select();
|
|
|
$row['studys'] = json_encode($studys);
|
|
|
|
|
|
$this->view->assign("row", $row);
|
|
|
return $this->view->fetch();
|
...
|
...
|
@@ -568,7 +418,7 @@ class User extends Backend |
|
|
$row['sex'] = 2;
|
|
|
break;
|
|
|
}
|
|
|
$row['expirationtime'] = intval(($row['expirationtime'] - 25569) * 3600 * 24) - 28800; //转换成1970年以来的秒数
|
|
|
// $row['expirationtime'] = intval(($row['expirationtime'] - 25569) * 3600 * 24) - 28800; //转换成1970年以来的秒数
|
|
|
$insert[] = $row;
|
|
|
}
|
|
|
}
|
...
|
...
|
|