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

课程单独设置学习时间

... ... @@ -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;
}
}
... ...
... ... @@ -84,22 +84,33 @@
<!--<ul class="row list-inline plupload-preview" id="p-image"></ul>-->
<!--</div>-->
<!--</div>-->
<div class="form-group">
<!--<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('有效期')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-expirationtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[expirationtime]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
<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="" 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">
<label class="control-label col-xs-12 col-sm-2">{:__('Periodtime')}:</label>
</div>-->
<div class="form-group row">
<label class="control-label col-xs-12 col-sm-2">{:__('绑定考试')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-periodtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[periodtime]" type="text" value="{:date('Y-m-d H:i:s')}">
<dl class="fieldlist" data-template="eventtpl" data-name="row[studys]">
<dd>
<ins style="width: 300px;">{:__('科目')}</ins>
<ins style="width: 150px;">{:__('到期时间')}</ins>
</dd>
<dd><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a></dd>
<!--请注意 dd和textarea间不能存在其它任何元素,实际开发中textarea应该添加个hidden进行隐藏-->
<textarea name="row[studys]" class="form-control hide" cols="30" rows="5"></textarea>
</dl>
<script id="eventtpl" type="text/html">
<dd class="form-inline">
<ins style="width: 300px;"><input type="text" name="<%=name%>[<%=index%>][study_id]" class="form-control selectpage" data-rule="required" data-source="study/index" data-field="examname" size="50" style="width: 300px;"/></ins>
<ins style="width: 150px;"><input type="text" name="<%=name%>[<%=index%>][periodtime]" class="form-control datetimepicker" data-rule="required" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" value="{:date('Y-m-d H:i:s')}" style="width: 150px;"/></ins>
<!--下面的两个按钮务必保留-->
<span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>
<!--<span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span>-->
</dd>
</script>
</div>
</div>
<div class="form-group">
... ...
... ... @@ -42,18 +42,12 @@
<input id="c-card" class="form-control" name="row[card]" type="text" value="{$row.card}">
</div>
</div>
<!--<div class="form-group">-->
<!--<label class="control-label col-xs-12 col-sm-2">{:__('有效期')}:</label>-->
<!--<div class="col-xs-12 col-sm-8">-->
<!--<input id="c-expirationtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[expirationtime]" type="text" value="{:$row.expirationtime?datetime($row.expirationtime):''}">-->
<!--</div>-->
<!--</div>-->
<div class="form-group">
<!--<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('有效期')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-expirationtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[expirationtime]" type="text" value="{:$row.expirationtime?datetime($row.expirationtime):''}">
</div>
</div>
</div>-->
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('头像')}:</label>
<div class="col-xs-12 col-sm-8">
... ... @@ -68,16 +62,27 @@
<ul class="row list-inline plupload-preview" id="p-image"></ul>
</div>
</div>
<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="" data-source="study/index" data-field="examname" data-multiple="true" class="form-control selectpage" name="row[study_id]" type="text" value="{$study_id}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Periodtime')}:</label>
<div class="form-group row">
<label class="control-label col-xs-12 col-sm-2">{:__('绑定考试')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-periodtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[periodtime]" type="text" value="{:date('Y-m-d H:i:s',$periodtime)}">
<dl class="fieldlist" data-template="eventtpl" data-name="row[studys]">
<dd>
<ins style="width: 300px;">{:__('科目')}</ins>
<ins style="width: 150px;">{:__('到期时间')}</ins>
</dd>
<dd><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a></dd>
<!--请注意 dd和textarea间不能存在其它任何元素,实际开发中textarea应该添加个hidden进行隐藏-->
<textarea name="row[studys]" class="form-control hide" cols="30" rows="5">{$row.studys|htmlentities}</textarea>
</dl>
<script id="eventtpl" type="text/html">
<dd class="form-inline">
<ins style="width: 300px;"><input type="text" name="<%=name%>[<%=index%>][study_id]" class="form-control selectpage" data-rule="required" data-source="study/index" data-field="examname" size="50" value="<%=row.study_id%>" style="width: 300px;"/></ins>
<ins style="width: 150px;"><input type="text" name="<%=name%>[<%=index%>][periodtime]" class="form-control datetimepicker" data-rule="required" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" value="<%=row.periodtime%>" style="width: 150px;"/></ins>
<!--下面的两个按钮务必保留-->
<span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>
<!--<span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span>-->
</dd>
</script>
</div>
</div>
<div class="form-group">
... ...
... ... @@ -742,6 +742,8 @@ class Lists extends Api
foreach ($data['info'] as &$v){
if(empty($user_id)){
$v['finish_hour'] = 0;
// 截止日期
$v['expirationtime'] = date('Y-m-d H:i:s',$v['expirationtime']);
}else{
$finish_hour = Db::name('study_class')
->alias('a')
... ... @@ -756,10 +758,11 @@ class Lists extends Api
}else{
$v['finish_hour'] = $finish_hour['finsh_hour'];
}
// 截止日期
$third_study = Db::name('third_study')->where('third_id',$user_id)->field('periodtime')->find();
$v['expirationtime'] = !empty($third_study) ? date('Y-m-d H:i:s',$third_study['periodtime']) : date('Y-m-d H:i:s',$v['expirationtime']);
}
$v['image'] = $qiniu.$v['image'];
$v['expirationtime'] = date('Y-m-d H:i:s',$v['expirationtime']);
}
$this->success('success',$data);
}
... ... @@ -792,6 +795,7 @@ class Lists extends Api
if(empty($third_study)){
$this->error('您没有该场考试的权限');
}else{
$third_study['periodtime'] < time() && $this->error('学习期限已过');
$this->success('success');
}
}
... ... @@ -835,9 +839,9 @@ class Lists extends Api
$this->error('密码错误');
}
$user = Db::name('user')->where(['id'=>$result['id']])->find();
if($user['expirationtime'] < time()){
$this->error('抱歉,有效期已过');
}
// if($user['expirationtime'] < time()){
// $this->error('抱歉,有效期已过');
// }
if(!empty($user['image'])){
$user['image'] = $qiniu.$user['image'];
}else{
... ...
... ... @@ -664,7 +664,8 @@ class User extends Api
->find();
$data['exam']['is_xian'] = $third_exam ? 2 : 1;
}
$data['exam']['expirationtime'] = date('Y-m-d H:i:s',$data['exam']['expirationtime']);
// $data['exam']['expirationtime'] = date('Y-m-d H:i:s',$data['exam']['expirationtime']);
$data['exam']['expirationtime'] = date('Y-m-d H:i:s',$third_study['periodtime']);
unset($data['exam']['updatetime']);
unset($data['exam']['createtime']);
... ...
... ... @@ -78,7 +78,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
},
{field: 'studynum', title: __('学号'), operate:false},
{field: 'expirationtime', title: __('有效期'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
// {field: 'expirationtime', title: __('有效期'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
{field: 'mobile', title: __('手机号')},
{field: 'group_id', title: __('角色'), searchList: {"0":"普通用户","1":"企业管理员"},formatter: Table.api.formatter.flag},
... ... @@ -101,6 +101,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
// 绑定课程selectpage
$(document).on("fa.event.appendfieldlist", ".btn-append", function (e, obj) {
Form.events.selectpage(obj);
Form.events.datetimepicker(obj);
});
}
}
};
... ...