...
|
...
|
@@ -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();
|
...
|
...
|
|