TrainController.class.php
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Created by PhpStorm.
* User: 29925
* Date: 2018/4/2
* Time: 20:13
*/
namespace Portal\Controller;
use Common\Controller\HomebaseController;
class TrainController extends HomebaseController {
protected $train_model;
protected $train_apply_model;
function _initialize() {
parent::_initialize();
$this->train_model = D("Common/Train");
$this->train_apply_model = D("Common/TrainApply");
}
// 工作坊列表
public function work(){
$this->_lists(array('sort'=>1,'is_del'=>0));
$this->display();
}
// 课程培训列表
public function lesson(){
$this->_lists(array('sort'=>2,'is_del'=>0));
$this->display();
}
// 文化之旅列表
public function cultural(){
$this->_lists(array('sort'=>3,'is_del'=>0));
$this->display();
}
/**
* 体验培训列表处理方法,根据不同条件显示不同的列表
* @param array $where 查询条件
*/
private function _lists($where=array()){
$start_time = I('request.start_time');
if(!empty($start_time)){
$where['ctime']=array(
array('EGT',$start_time)
);
}
$end_time = I('request.end_time');
if(!empty($end_time)){
if(empty($where['ctime'])){
$where['ctime']=array();
}
array_push($where['ctime'], array('ELT',$end_time));
}
$keyword = I('request.keyword');
if(!empty($keyword)){
$where['name']=array('like',"%$keyword%");
}
$this->train_model
->where($where);
$count = $this->train_model->count();
$page = $this->page($count, 20);
$posts = $this->train_model
->where($where)
->limit($page->firstRow , $page->listRows)
->order("ctime DESC")
->select();
$this->assign("page", $page->show('Admin'));
$this->assign("formget",array_merge($_GET,$_POST));
$this->assign("posts",$posts);
}
/**
* 体验培训提交
* @param post 提交的申请数据
* @param user_id 用户ID
*/
public function submit() {
if(IS_AJAX) {
$post =I('post.');
$user_id = $post['user_id'] = 1;
// $user_id = $post['user_id'] = sp_get_current_userid();
// if(!$user_id) {
// $this->ajaxReturn(array('status'=>false,'msg'=>'用户未登录'));
// }
$post['ctime'] = $post['utime'] = time();
if(!$this->train_apply_model->create($post)) {
$this->ajaxReturn(array('status'=>false,'msg'=>$this->train_apply_model->getError(),'data'=>$post));
}
$train_id = $this->train_apply_model->add($post);
if(!$train_id) {
$this->ajaxReturn(array('status'=>false,'msg'=>'提交失败'));
}
$this->ajaxReturn(array('status'=>true,'msg'=>'提交成功','data'=>$train_id));
} else {
$this->error('非法操作');
}
}
}