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

课程单独设置学习时间

@@ -49,28 +49,19 @@ class User extends Backend @@ -49,28 +49,19 @@ class User extends Backend
49 if ($this->request->request('keyField')) { 49 if ($this->request->request('keyField')) {
50 return $this->selectpage(); 50 return $this->selectpage();
51 } 51 }
52 -// $study = Db::name('study')->field('id,pass_mark')->select();  
53 -// $user_ids = [];  
54 -// foreach ($study as &$v) {  
55 -// $user_ids = array_merge($user_ids,Db::name('third_exam')->where(['study_id'=>$v['id'],'score'=>['>=',$v['pass_mark']]])->column('user_id'));  
56 -// } 52 +
57 list($where, $sort, $order, $offset, $limit) = $this->buildparams('user.id,user.username,user.nickname,user.password,user.card,user.work_address,user.studynum'); 53 list($where, $sort, $order, $offset, $limit) = $this->buildparams('user.id,user.username,user.nickname,user.password,user.card,user.work_address,user.studynum');
58 $total = $this->model 54 $total = $this->model
59 ->with('group') 55 ->with('group')
60 -// ->whereIn('user.id',$user_ids)  
61 ->where($where) 56 ->where($where)
62 ->order($sort, $order) 57 ->order($sort, $order)
63 ->count(); 58 ->count();
64 $list = $this->model 59 $list = $this->model
65 ->with('group') 60 ->with('group')
66 -// ->whereIn('user.id',$user_ids)  
67 ->where($where) 61 ->where($where)
68 ->order($sort, $order) 62 ->order($sort, $order)
69 ->limit($offset, $limit) 63 ->limit($offset, $limit)
70 ->select(); 64 ->select();
71 -// foreach ($list as $k => $v) {  
72 -// $v->hidden(['password', 'salt']);  
73 -// }  
74 foreach ($list as $k => &$v) { 65 foreach ($list as $k => &$v) {
75 $v['user.mobile_exam_ids'] = Db::name('mobile_exam')->whereIn('id',$v['mobile_exam_ids'])->column('name'); 66 $v['user.mobile_exam_ids'] = Db::name('mobile_exam')->whereIn('id',$v['mobile_exam_ids'])->column('name');
76 } 67 }
@@ -84,87 +75,6 @@ class User extends Backend @@ -84,87 +75,6 @@ class User extends Backend
84 /** 75 /**
85 * 添加 76 * 添加
86 */ 77 */
87 -// public function add()  
88 -// {  
89 -// if ($this->request->isPost()) {  
90 -// $params = $this->request->post("row/a");  
91 -// if ($params) {  
92 -// $params = $this->preExcludeFields($params);  
93 -// $params['status'] = 'normal';  
94 -//  
95 -// if(empty($params['expirationtime'])){  
96 -// $this->error('有效期不能为空');  
97 -// }  
98 -// $params['expirationtime'] = strtotime($params['expirationtime']);  
99 -// if ($this->dataLimit && $this->dataLimitFieldAutoFill) {  
100 -// $params[$this->dataLimitField] = $this->auth->id;  
101 -// }  
102 -// if($this->check_identity($params['card'])) {  
103 -// $this->error('该身份证号已存在');  
104 -// }  
105 -// $study = [];  
106 -// if($params['study_id'] && $params['periodtime']) {  
107 -// $study = [  
108 -// 'study_id' => $params['study_id'],  
109 -// 'periodtime' => strtotime($params['periodtime'])  
110 -// ];  
111 -// unset($params['study_id']);  
112 -// unset($params['periodtime']);  
113 -// }  
114 -//// $result = $this->model->validate('User.add')->save($params);  
115 -//// if ($result === false) {  
116 -//// $this->error($this->model->getError());  
117 -//// }  
118 -// if (!empty($params['mobile'])) {  
119 -// if(\app\common\model\User::where('mobile', $params['mobile'])->find()){  
120 -// $this->error('注册手机号已存在');  
121 -// }  
122 -// $params['phone'] = $params['mobile'];  
123 -// }  
124 -// $result = false;  
125 -// Db::startTrans();  
126 -// try {  
127 -// //是否采用模型验证  
128 -// if ($this->modelValidate) {  
129 -// $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));  
130 -// $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;  
131 -// $this->model->validateFailException(true)->validate($validate);  
132 -// }  
133 -// $result = $this->model->allowField(true)->save($params);  
134 -// if($study) {  
135 -// $study['third_id'] = $this->model->id;  
136 -// $res['third_id'] = $study['third_id'];  
137 -// $res['study_id'] = $study['study_id'];  
138 -// $res['createtime'] = time();  
139 -// $res['playtime'] = 0;  
140 -// $classes_ids = Db::name('classes')->where('study_id',$res['study_id'])->where('is_major',1)->column('id');  
141 -// foreach ($classes_ids as $v){  
142 -// $res['class_id'] = $v;  
143 -// Db::name('study_class')->insertGetId($res);  
144 -// }  
145 -// Db::name('third_study')->insertGetId($study);  
146 -// }  
147 -// Db::commit();  
148 -// } catch (ValidateException $e) {  
149 -// Db::rollback();  
150 -// $this->error($e->getMessage());  
151 -// } catch (PDOException $e) {  
152 -// Db::rollback();  
153 -// $this->error($e->getMessage());  
154 -// } catch (Exception $e) {  
155 -// Db::rollback();  
156 -// $this->error($e->getMessage());  
157 -// }  
158 -// if ($result !== false) {  
159 -// $this->success();  
160 -// } else {  
161 -// $this->error(__('No rows were inserted'));  
162 -// }  
163 -// }  
164 -// $this->error(__('Parameter %s can not be empty', ''));  
165 -// }  
166 -// return $this->view->fetch();  
167 -// }  
168 public function add() 78 public function add()
169 { 79 {
170 if ($this->request->isPost()) { 80 if ($this->request->isPost()) {
@@ -173,10 +83,10 @@ class User extends Backend @@ -173,10 +83,10 @@ class User extends Backend
173 $params = $this->preExcludeFields($params); 83 $params = $this->preExcludeFields($params);
174 $params['status'] = 'normal'; 84 $params['status'] = 'normal';
175 85
176 - if(empty($params['expirationtime'])){  
177 - $this->error('有效期不能为空');  
178 - }  
179 - $params['expirationtime'] = strtotime($params['expirationtime']); 86 + // if(empty($params['expirationtime'])){
  87 + // $this->error('有效期不能为空');
  88 + // }
  89 + // $params['expirationtime'] = strtotime($params['expirationtime']);
180 if ($this->dataLimit && $this->dataLimitFieldAutoFill) { 90 if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
181 $params[$this->dataLimitField] = $this->auth->id; 91 $params[$this->dataLimitField] = $this->auth->id;
182 } 92 }
@@ -191,10 +101,13 @@ class User extends Backend @@ -191,10 +101,13 @@ class User extends Backend
191 } 101 }
192 102
193 // 考试数据 103 // 考试数据
194 - $study_ids = [];  
195 - if($params['study_id'] && $params['periodtime']) {  
196 - $study_ids = explode(',',$params['study_id']);  
197 - $periodtime = strtotime($params['periodtime']); 104 + $studys = [];
  105 + if(!empty($params['studys'])){
  106 + $studys = json_decode($params['studys'],true);
  107 + $study_ids = array_column($studys,'study_id');
  108 + if(count($study_ids) != count(array_unique($study_ids))){
  109 + $this->error('绑定考试,不能重复');
  110 + }
198 } 111 }
199 112
200 $result = false; 113 $result = false;
@@ -209,24 +122,33 @@ class User extends Backend @@ -209,24 +122,33 @@ class User extends Backend
209 $result = $this->model->allowField(true)->save($params); 122 $result = $this->model->allowField(true)->save($params);
210 123
211 // 考试数据-添加 124 // 考试数据-添加
212 - foreach ($study_ids as $study_id){  
213 - $third_id = $this->model->id;  
214 - Db::name('third_study')->insertGetId([ 125 + $third_id = $this->model->id;
  126 + $third_study_data = [];
  127 + $study_class_data = [];
  128 + $createtime = time();
  129 + foreach ($studys as $study){
  130 + $third_study_data[] = [
215 'third_id' => $third_id, 131 'third_id' => $third_id,
216 - 'study_id' => $study_id,  
217 - 'periodtime' => $periodtime,  
218 - ]);  
219 - $classes_ids = Db::name('classes')->where('study_id',$study_id)->where('is_major',1)->column('id'); 132 + 'study_id' => $study['study_id'],
  133 + 'periodtime' => strtotime($study['periodtime']),
  134 + ];
  135 + $classes_ids = Db::name('classes')->where('study_id',$study['study_id'])->where('is_major',1)->column('id');
220 foreach ($classes_ids as $class_id){ 136 foreach ($classes_ids as $class_id){
221 - Db::name('study_class')->insertGetId([ 137 + $study_class_data[] = [
222 'third_id' => $third_id, 138 'third_id' => $third_id,
223 - 'study_id' => $study_id, 139 + 'study_id' => $study['study_id'],
224 'class_id' => $class_id, 140 'class_id' => $class_id,
225 'playtime' => 0, 141 'playtime' => 0,
226 - 'createtime' => time(),  
227 - ]); 142 + 'createtime' => $createtime,
  143 + ];
228 } 144 }
229 } 145 }
  146 + if(!empty($third_study_data)){
  147 + Db::name('third_study')->insertAll($third_study_data);
  148 + }
  149 + if(!empty($study_class_data)){
  150 + Db::name('study_class')->insertAll($study_class_data);
  151 + }
230 152
231 Db::commit(); 153 Db::commit();
232 } catch (ValidateException $e) { 154 } catch (ValidateException $e) {
@@ -250,82 +172,9 @@ class User extends Backend @@ -250,82 +172,9 @@ class User extends Backend
250 return $this->view->fetch(); 172 return $this->view->fetch();
251 } 173 }
252 174
253 -  
254 -// public function edit($ids = NULL)  
255 -// {  
256 -// $row = $this->model->get($ids);  
257 -// if (!$row)  
258 -// $this->error(__('No Results were found'));  
259 -// $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));  
260 -// return parent::edit($ids);  
261 -// }  
262 -  
263 /** 175 /**
264 * 编辑 176 * 编辑
265 */ 177 */
266 -// public function edit($ids = null)  
267 -// {  
268 -// $row = $this->model->get($ids);  
269 -// if (!$row) {  
270 -// $this->error(__('No Results were found'));  
271 -// }  
272 -// $adminIds = $this->getDataLimitAdminIds();  
273 -// if (is_array($adminIds)) {  
274 -// if (!in_array($row[$this->dataLimitField], $adminIds)) {  
275 -// $this->error(__('You have no permission'));  
276 -// }  
277 -// }  
278 -// if ($this->request->isPost()) {  
279 -// $params = $this->request->post("row/a");  
280 -// if ($params) {  
281 -// if(empty($params['expirationtime'])){  
282 -// $this->error('有效期不能为空');  
283 -// }  
284 -// $params['expirationtime'] = strtotime($params['expirationtime']);  
285 -// if($this->check_identity($params['card'],$ids)) {  
286 -// $this->error('该身份证号已存在');  
287 -// }  
288 -//// if(strlen($params['username']) < 6 || strlen($params['username']) > 18) {  
289 -//// $this->error('用户名须为6-18位');  
290 -//// }  
291 -// if (!empty($params['mobile'])) {  
292 -// if(\app\common\model\User::where('mobile', $params['mobile'])->where('id', '<>', $row->id)->find()){  
293 -// $this->error('注册手机号已存在');  
294 -// }  
295 -// $params['phone'] = $params['mobile'];  
296 -// }  
297 -// $result = false;  
298 -// Db::startTrans();  
299 -// try {  
300 -// //是否采用模型验证  
301 -// if ($this->modelValidate) {  
302 -// $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));  
303 -// $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;  
304 -// $row->validateFailException(true)->validate($validate);  
305 -// }  
306 -// $result = $row->allowField(true)->save($params);  
307 -// Db::commit();  
308 -// } catch (ValidateException $e) {  
309 -// Db::rollback();  
310 -// $this->error($e->getMessage());  
311 -// } catch (PDOException $e) {  
312 -// Db::rollback();  
313 -// $this->error($e->getMessage());  
314 -// } catch (Exception $e) {  
315 -// Db::rollback();  
316 -// $this->error($e->getMessage());  
317 -// }  
318 -// if ($result !== false) {  
319 -// $this->success();  
320 -// } else {  
321 -// $this->error(__('No rows were updated'));  
322 -// }  
323 -// }  
324 -// $this->error(__('Parameter %s can not be empty', ''));  
325 -// }  
326 -// $this->view->assign("row", $row);  
327 -// return $this->view->fetch();  
328 -// }  
329 public function edit($ids = null) 178 public function edit($ids = null)
330 { 179 {
331 $row = $this->model->get($ids); 180 $row = $this->model->get($ids);
@@ -341,10 +190,10 @@ class User extends Backend @@ -341,10 +190,10 @@ class User extends Backend
341 if ($this->request->isPost()) { 190 if ($this->request->isPost()) {
342 $params = $this->request->post("row/a"); 191 $params = $this->request->post("row/a");
343 if ($params) { 192 if ($params) {
344 - if(empty($params['expirationtime'])){  
345 - $this->error('有效期不能为空');  
346 - }  
347 - $params['expirationtime'] = strtotime($params['expirationtime']); 193 + // if(empty($params['expirationtime'])){
  194 + // $this->error('有效期不能为空');
  195 + // }
  196 + // $params['expirationtime'] = strtotime($params['expirationtime']);
348 if($this->check_identity($params['card'],$ids)) { 197 if($this->check_identity($params['card'],$ids)) {
349 $this->error('该身份证号已存在'); 198 $this->error('该身份证号已存在');
350 } 199 }
@@ -356,10 +205,13 @@ class User extends Backend @@ -356,10 +205,13 @@ class User extends Backend
356 } 205 }
357 206
358 // 考试数据 207 // 考试数据
359 - $study_ids = [];  
360 - if($params['study_id'] && $params['periodtime']) {  
361 - $study_ids = explode(',',$params['study_id']);  
362 - $periodtime = strtotime($params['periodtime']); 208 + $studys = [];
  209 + if(!empty($params['studys'])){
  210 + $studys = json_decode($params['studys'],true);
  211 + $study_ids = array_column($studys,'study_id');
  212 + if(count($study_ids) != count(array_unique($study_ids))){
  213 + $this->error('绑定考试,不能重复');
  214 + }
363 } 215 }
364 216
365 $result = false; 217 $result = false;
@@ -373,50 +225,50 @@ class User extends Backend @@ -373,50 +225,50 @@ class User extends Backend
373 } 225 }
374 $result = $row->allowField(true)->save($params); 226 $result = $row->allowField(true)->save($params);
375 227
376 - $third_id = $row['id'];  
377 // 考试数据-编辑 228 // 考试数据-编辑
378 - foreach ($study_ids as $study_id){  
379 - $my_study = Db::name('third_study')->where('study_id',$study_id)->where('third_id',$third_id)->find(); 229 + $third_id = $row['id'];
  230 + $third_study_data = [];
  231 + $study_class_data = [];
  232 + $createtime = time();
  233 + foreach ($studys as $study){
  234 + $my_study = Db::name('third_study')->where('study_id',$study['study_id'])->where('third_id',$third_id)->find();
380 if(!$my_study){ 235 if(!$my_study){
381 - Db::name('third_study')->insertGetId([ 236 + $third_study_data[] = [
382 'third_id' => $third_id, 237 'third_id' => $third_id,
383 - 'study_id' => $study_id,  
384 - 'periodtime' => $periodtime,  
385 - ]); 238 + 'study_id' => $study['study_id'],
  239 + 'periodtime' => strtotime($study['periodtime']),
  240 + ];
386 }else{ 241 }else{
387 // 修改到期时间 242 // 修改到期时间
388 - Db::name('third_study')->where('id',$my_study['id'])->update(['periodtime'=>$periodtime]); 243 + Db::name('third_study')->where('id',$my_study['id'])->update(['periodtime'=>strtotime($study['periodtime'])]);
389 } 244 }
390 - $classes_ids = Db::name('classes')->where('study_id',$study_id)->where('is_major',1)->column('id'); 245 + $classes_ids = Db::name('classes')->where('study_id',$study['study_id'])->where('is_major',1)->column('id');
391 foreach ($classes_ids as $class_id){ 246 foreach ($classes_ids as $class_id){
392 $my_class = Db::name('study_class')->where('class_id',$class_id)->where('third_id',$third_id)->find(); 247 $my_class = Db::name('study_class')->where('class_id',$class_id)->where('third_id',$third_id)->find();
393 if(!$my_class){ 248 if(!$my_class){
394 - Db::name('study_class')->insertGetId([ 249 + $study_class_data[] = [
395 'third_id' => $third_id, 250 'third_id' => $third_id,
396 - 'study_id' => $study_id, 251 + 'study_id' => $study['study_id'],
397 'class_id' => $class_id, 252 'class_id' => $class_id,
398 'playtime' => 0, 253 'playtime' => 0,
399 - 'createtime' => time(),  
400 - ]); 254 + 'createtime' => $createtime,
  255 + ];
401 } 256 }
402 } 257 }
403 } 258 }
404 -  
405 - // 删除去掉的科目  
406 - $my_study_ids = Db::name('third_study')->where('third_id',$third_id)->column('study_id');  
407 - if($my_study_ids){  
408 - $delete_study_ids = array_diff($my_study_ids,$study_ids);  
409 - if($delete_study_ids){  
410 - Db::name('third_study')  
411 - ->where('third_id',$third_id)  
412 - ->where('study_id','in',$delete_study_ids)  
413 - ->delete();  
414 - Db::name('study_class')  
415 - ->where('third_id',$third_id)  
416 - ->where('study_id','in',$delete_study_ids)  
417 - ->delete();  
418 - } 259 + if(!empty($third_study_data)){
  260 + Db::name('third_study')->insertAll($third_study_data);
  261 + }
  262 + if(!empty($study_class_data)){
  263 + Db::name('study_class')->insertAll($study_class_data);
  264 + }
  265 + // 删除去掉的考试
  266 + $del_where['third_id'] = $third_id;
  267 + if($studys){
  268 + $del_where['study_id'] = ['not in',$study_ids];
419 } 269 }
  270 + Db::name('third_study')->where($del_where)->delete();
  271 + Db::name('study_class')->where($del_where)->delete();
420 272
421 Db::commit(); 273 Db::commit();
422 } catch (ValidateException $e) { 274 } catch (ValidateException $e) {
@@ -439,10 +291,8 @@ class User extends Backend @@ -439,10 +291,8 @@ class User extends Backend
439 } 291 }
440 292
441 // 我的科目 293 // 我的科目
442 - $my_study_list = Db::name('third_study')->where('third_id',$row['id'])->select();  
443 - $my_study_ids = array_column($my_study_list,'study_id');  
444 - $this->view->assign("study_id", $my_study_ids ? implode(',',$my_study_ids) : '');  
445 - $this->view->assign("periodtime", count($my_study_list) > 0 ? $my_study_list[0]['periodtime'] : time()); 294 + $studys = Db::name('third_study')->where('third_id',$row['id'])->field("study_id,FROM_UNIXTIME(periodtime,'%Y-%m-%d %H:%i:%s') periodtime")->select();
  295 + $row['studys'] = json_encode($studys);
446 296
447 $this->view->assign("row", $row); 297 $this->view->assign("row", $row);
448 return $this->view->fetch(); 298 return $this->view->fetch();
@@ -568,7 +418,7 @@ class User extends Backend @@ -568,7 +418,7 @@ class User extends Backend
568 $row['sex'] = 2; 418 $row['sex'] = 2;
569 break; 419 break;
570 } 420 }
571 - $row['expirationtime'] = intval(($row['expirationtime'] - 25569) * 3600 * 24) - 28800; //转换成1970年以来的秒数 421 + // $row['expirationtime'] = intval(($row['expirationtime'] - 25569) * 3600 * 24) - 28800; //转换成1970年以来的秒数
572 $insert[] = $row; 422 $insert[] = $row;
573 } 423 }
574 } 424 }
@@ -84,22 +84,33 @@ @@ -84,22 +84,33 @@
84 <!--<ul class="row list-inline plupload-preview" id="p-image"></ul>--> 84 <!--<ul class="row list-inline plupload-preview" id="p-image"></ul>-->
85 <!--</div>--> 85 <!--</div>-->
86 <!--</div>--> 86 <!--</div>-->
87 - <div class="form-group"> 87 + <!--<div class="form-group">
88 <label class="control-label col-xs-12 col-sm-2">{:__('有效期')}:</label> 88 <label class="control-label col-xs-12 col-sm-2">{:__('有效期')}:</label>
89 <div class="col-xs-12 col-sm-8"> 89 <div class="col-xs-12 col-sm-8">
90 <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')}"> 90 <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')}">
91 </div> 91 </div>
92 - </div>  
93 - <div class="form-group">  
94 - <label class="control-label col-xs-12 col-sm-2">{:__('Study_id')}:</label>  
95 - <div class="col-xs-12 col-sm-8">  
96 - <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="">  
97 - </div>  
98 - </div>  
99 - <div class="form-group">  
100 - <label class="control-label col-xs-12 col-sm-2">{:__('Periodtime')}:</label> 92 + </div>-->
  93 + <div class="form-group row">
  94 + <label class="control-label col-xs-12 col-sm-2">{:__('绑定考试')}:</label>
101 <div class="col-xs-12 col-sm-8"> 95 <div class="col-xs-12 col-sm-8">
102 - <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')}"> 96 + <dl class="fieldlist" data-template="eventtpl" data-name="row[studys]">
  97 + <dd>
  98 + <ins style="width: 300px;">{:__('科目')}</ins>
  99 + <ins style="width: 150px;">{:__('到期时间')}</ins>
  100 + </dd>
  101 + <dd><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a></dd>
  102 + <!--请注意 dd和textarea间不能存在其它任何元素,实际开发中textarea应该添加个hidden进行隐藏-->
  103 + <textarea name="row[studys]" class="form-control hide" cols="30" rows="5"></textarea>
  104 + </dl>
  105 + <script id="eventtpl" type="text/html">
  106 + <dd class="form-inline">
  107 + <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>
  108 + <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>
  109 + <!--下面的两个按钮务必保留-->
  110 + <span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>
  111 + <!--<span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span>-->
  112 + </dd>
  113 + </script>
103 </div> 114 </div>
104 </div> 115 </div>
105 <div class="form-group"> 116 <div class="form-group">
@@ -42,18 +42,12 @@ @@ -42,18 +42,12 @@
42 <input id="c-card" class="form-control" name="row[card]" type="text" value="{$row.card}"> 42 <input id="c-card" class="form-control" name="row[card]" type="text" value="{$row.card}">
43 </div> 43 </div>
44 </div> 44 </div>
45 - <!--<div class="form-group">-->  
46 - <!--<label class="control-label col-xs-12 col-sm-2">{:__('有效期')}:</label>-->  
47 - <!--<div class="col-xs-12 col-sm-8">-->  
48 - <!--<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):''}">-->  
49 - <!--</div>-->  
50 - <!--</div>-->  
51 - <div class="form-group"> 45 + <!--<div class="form-group">
52 <label class="control-label col-xs-12 col-sm-2">{:__('有效期')}:</label> 46 <label class="control-label col-xs-12 col-sm-2">{:__('有效期')}:</label>
53 <div class="col-xs-12 col-sm-8"> 47 <div class="col-xs-12 col-sm-8">
54 <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):''}"> 48 <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):''}">
55 </div> 49 </div>
56 - </div> 50 + </div>-->
57 <div class="form-group"> 51 <div class="form-group">
58 <label class="control-label col-xs-12 col-sm-2">{:__('头像')}:</label> 52 <label class="control-label col-xs-12 col-sm-2">{:__('头像')}:</label>
59 <div class="col-xs-12 col-sm-8"> 53 <div class="col-xs-12 col-sm-8">
@@ -68,16 +62,27 @@ @@ -68,16 +62,27 @@
68 <ul class="row list-inline plupload-preview" id="p-image"></ul> 62 <ul class="row list-inline plupload-preview" id="p-image"></ul>
69 </div> 63 </div>
70 </div> 64 </div>
71 - <div class="form-group">  
72 - <label class="control-label col-xs-12 col-sm-2">{:__('Study_id')}:</label>  
73 - <div class="col-xs-12 col-sm-8">  
74 - <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}">  
75 - </div>  
76 - </div>  
77 - <div class="form-group">  
78 - <label class="control-label col-xs-12 col-sm-2">{:__('Periodtime')}:</label> 65 + <div class="form-group row">
  66 + <label class="control-label col-xs-12 col-sm-2">{:__('绑定考试')}:</label>
79 <div class="col-xs-12 col-sm-8"> 67 <div class="col-xs-12 col-sm-8">
80 - <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)}"> 68 + <dl class="fieldlist" data-template="eventtpl" data-name="row[studys]">
  69 + <dd>
  70 + <ins style="width: 300px;">{:__('科目')}</ins>
  71 + <ins style="width: 150px;">{:__('到期时间')}</ins>
  72 + </dd>
  73 + <dd><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a></dd>
  74 + <!--请注意 dd和textarea间不能存在其它任何元素,实际开发中textarea应该添加个hidden进行隐藏-->
  75 + <textarea name="row[studys]" class="form-control hide" cols="30" rows="5">{$row.studys|htmlentities}</textarea>
  76 + </dl>
  77 + <script id="eventtpl" type="text/html">
  78 + <dd class="form-inline">
  79 + <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>
  80 + <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>
  81 + <!--下面的两个按钮务必保留-->
  82 + <span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>
  83 + <!--<span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span>-->
  84 + </dd>
  85 + </script>
81 </div> 86 </div>
82 </div> 87 </div>
83 <div class="form-group"> 88 <div class="form-group">
@@ -742,6 +742,8 @@ class Lists extends Api @@ -742,6 +742,8 @@ class Lists extends Api
742 foreach ($data['info'] as &$v){ 742 foreach ($data['info'] as &$v){
743 if(empty($user_id)){ 743 if(empty($user_id)){
744 $v['finish_hour'] = 0; 744 $v['finish_hour'] = 0;
  745 + // 截止日期
  746 + $v['expirationtime'] = date('Y-m-d H:i:s',$v['expirationtime']);
745 }else{ 747 }else{
746 $finish_hour = Db::name('study_class') 748 $finish_hour = Db::name('study_class')
747 ->alias('a') 749 ->alias('a')
@@ -756,10 +758,11 @@ class Lists extends Api @@ -756,10 +758,11 @@ class Lists extends Api
756 }else{ 758 }else{
757 $v['finish_hour'] = $finish_hour['finsh_hour']; 759 $v['finish_hour'] = $finish_hour['finsh_hour'];
758 } 760 }
759 - 761 + // 截止日期
  762 + $third_study = Db::name('third_study')->where('third_id',$user_id)->field('periodtime')->find();
  763 + $v['expirationtime'] = !empty($third_study) ? date('Y-m-d H:i:s',$third_study['periodtime']) : date('Y-m-d H:i:s',$v['expirationtime']);
760 } 764 }
761 $v['image'] = $qiniu.$v['image']; 765 $v['image'] = $qiniu.$v['image'];
762 - $v['expirationtime'] = date('Y-m-d H:i:s',$v['expirationtime']);  
763 } 766 }
764 $this->success('success',$data); 767 $this->success('success',$data);
765 } 768 }
@@ -792,6 +795,7 @@ class Lists extends Api @@ -792,6 +795,7 @@ class Lists extends Api
792 if(empty($third_study)){ 795 if(empty($third_study)){
793 $this->error('您没有该场考试的权限'); 796 $this->error('您没有该场考试的权限');
794 }else{ 797 }else{
  798 + $third_study['periodtime'] < time() && $this->error('学习期限已过');
795 $this->success('success'); 799 $this->success('success');
796 } 800 }
797 } 801 }
@@ -835,9 +839,9 @@ class Lists extends Api @@ -835,9 +839,9 @@ class Lists extends Api
835 $this->error('密码错误'); 839 $this->error('密码错误');
836 } 840 }
837 $user = Db::name('user')->where(['id'=>$result['id']])->find(); 841 $user = Db::name('user')->where(['id'=>$result['id']])->find();
838 - if($user['expirationtime'] < time()){  
839 - $this->error('抱歉,有效期已过');  
840 - } 842 + // if($user['expirationtime'] < time()){
  843 + // $this->error('抱歉,有效期已过');
  844 + // }
841 if(!empty($user['image'])){ 845 if(!empty($user['image'])){
842 $user['image'] = $qiniu.$user['image']; 846 $user['image'] = $qiniu.$user['image'];
843 }else{ 847 }else{
@@ -664,7 +664,8 @@ class User extends Api @@ -664,7 +664,8 @@ class User extends Api
664 ->find(); 664 ->find();
665 $data['exam']['is_xian'] = $third_exam ? 2 : 1; 665 $data['exam']['is_xian'] = $third_exam ? 2 : 1;
666 } 666 }
667 - $data['exam']['expirationtime'] = date('Y-m-d H:i:s',$data['exam']['expirationtime']); 667 + // $data['exam']['expirationtime'] = date('Y-m-d H:i:s',$data['exam']['expirationtime']);
  668 + $data['exam']['expirationtime'] = date('Y-m-d H:i:s',$third_study['periodtime']);
668 669
669 unset($data['exam']['updatetime']); 670 unset($data['exam']['updatetime']);
670 unset($data['exam']['createtime']); 671 unset($data['exam']['createtime']);
@@ -78,7 +78,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -78,7 +78,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
78 }, 78 },
79 {field: 'studynum', title: __('学号'), operate:false}, 79 {field: 'studynum', title: __('学号'), operate:false},
80 80
81 - {field: 'expirationtime', title: __('有效期'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, 81 + // {field: 'expirationtime', title: __('有效期'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
82 {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}}, 82 {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
83 {field: 'mobile', title: __('手机号')}, 83 {field: 'mobile', title: __('手机号')},
84 {field: 'group_id', title: __('角色'), searchList: {"0":"普通用户","1":"企业管理员"},formatter: Table.api.formatter.flag}, 84 {field: 'group_id', title: __('角色'), searchList: {"0":"普通用户","1":"企业管理员"},formatter: Table.api.formatter.flag},
@@ -101,6 +101,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -101,6 +101,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
101 api: { 101 api: {
102 bindevent: function () { 102 bindevent: function () {
103 Form.api.bindevent($("form[role=form]")); 103 Form.api.bindevent($("form[role=form]"));
  104 + // 绑定课程selectpage
  105 + $(document).on("fa.event.appendfieldlist", ".btn-append", function (e, obj) {
  106 + Form.events.selectpage(obj);
  107 + Form.events.datetimepicker(obj);
  108 + });
104 } 109 }
105 } 110 }
106 }; 111 };