作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

合并分支 'heshupeng' 到 'master'

后台用户报考多选



查看合并请求 !266
... ... @@ -90,6 +90,66 @@ class ThirdStudy extends Backend
/**
* 添加
*/
// public function add()
// {
// if ($this->request->isPost()) {
// $params = $this->request->post("row/a");
// if ($params) {
// $params = $this->preExcludeFields($params);
//
// $is_have = Db::name('third_study')
// ->where('third_id',$params['third_id'])
// ->where('study_id',$params['study_id'])
// ->find();
// if(!empty($is_have)){
// $this->error('您已经绑定过该考试了');
// }
//
//
// $res['third_id'] = $params['third_id'];
// $res['study_id'] = $params['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);
// }
//
// if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
// $params[$this->dataLimitField] = $this->auth->id;
// }
// $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);
// 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()) {
... ... @@ -97,28 +157,25 @@ class ThirdStudy extends Backend
if ($params) {
$params = $this->preExcludeFields($params);
$is_have = Db::name('third_study')
->where('third_id',$params['third_id'])
->where('study_id',$params['study_id'])
->find();
if(!empty($is_have)){
$this->error('您已经绑定过该考试了');
}
$study_ids = explode(',',$params['study_id']);
$paramsAll = [];
foreach ($study_ids as $study_id) {
$is_have = Db::name('third_study')
->where('third_id', $params['third_id'])
->where('study_id', $study_id)
->find();
if (!empty($is_have)) {
$examname = Db::name('study')->where('id', $study_id)->value('examname');
$this->error('您已经绑定过《' . $examname . '》了');
}
$res['third_id'] = $params['third_id'];
$res['study_id'] = $params['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);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$params['study_id'] = $study_id;
$paramsAll[] = $params;
}
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
... ... @@ -128,7 +185,19 @@ class ThirdStudy extends Backend
$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);
// 添加必修课
foreach ($study_ids as $study_id) {
$res['third_id'] = $params['third_id'];
$res['study_id'] = $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);
}
}
$result = $this->model->allowField(true)->saveAll($paramsAll);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
... ...
... ... @@ -9,7 +9,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Study_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-study_id" data-rule="required" data-source="study/index" data-field="examname" class="form-control selectpage" name="row[study_id]" type="text" value="">
<input id="c-study_id" data-rule="required" data-source="study/index" data-field="examname" data-multiple="true" class="form-control selectpage" name="row[study_id]" type="text" value="">
</div>
</div>
<div class="form-group">
... ...