DoubleChoose.php
4.4 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
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace app\index\controller;
use app\common\controller\Frontend;
use app\school\model\project_common\ProjectDoubleApply;
use app\school\model\setting\ProjectType;
use think\Db;
class DoubleChoose extends Frontend
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
protected $layout = 'default';
public function index()
{
// if(!$this->auth->isLogin()){
// $user = $this->auth->getUserinfo();
// }else{
// $user = [];
// }
$userId = $this->auth->id;
$where = [];
$container_id = $this->request->param('container_id');
$where['project_container_id'] = $container_id;
$type_where['container_id'] = $container_id;
$type = $this->request->param('type');
$type = isset($type) ? $type :0;
switch ($type){
case 1://教师
$where['captain_type'] = 1;
break;
case 2://学生
$where['captain_type'] = 0;
break;
}
$page = null;
//TODO 区分学校 $type_where 加 school_id
$category_list = (new ProjectType())->where($type_where)->select();
$model = new ProjectDoubleApply();
$list = Db::name("project_double")->where($where)->paginate(10,false,['query'=>request()->param()]);
foreach ($list as $k=>$v){
$v["is_can"] =0;
if($v['is_complete'] ==1){
$v["is_can"] = 2;
}else{
$info_apply = $model->where(["project_double_id" => $v['id'], "proposer_id" => $userId, "proposer_type" => 0])->find();
if ($info_apply) {
$v["is_can"] = 1;
} else {
$v["is_can"] = 0;
}
}
if($type == 0) {
if($v['is_recruit'] ==0){
$v["is_can"] = -1;
}
}
$list[$k] = $v;
}
if(!empty($list)){
$page = $list->render();
}
// dump($type);die;
$this->assign("count",count($list));
$this->assign("category_list",$category_list);
$this->assign("container_id",$container_id);
$this->assign("page",$page);
$this->assign("list",$list);
$this->assign("type",$type);
return $this->view->fetch();
}
public function add_apply(){
if($this->request->isAjax()){
if($this->auth->isLogin()){
$user = $this->auth->getUserinfo();
}else{
$this->error("请登录",url('student_login/index'));
}
$param = $this->request->param("row/a");
$data = Db::name('project_double_apply')->where("project_double_id",$param['double_id'])->where("proposer_id",$user['id'])->where("proposer_type",0)->find();
if(!empty($data)){
$this->error("请勿重复申报");
}else{
if(empty($param['mobile'])) {
$this->error("请填写手机号码");
}
if(!checkMobile($param['mobile'])) {
$this->error("请填写正确的手机号码");
}
if(empty($param['proposer_details'])) {
$this->error("请填写申请理由和个人简介");
}
$sort = Db::name('project_double_apply')->where("project_double_id",$param['double_id'])->where('proposer_type',0)->max("sort");
if($sort){
$sort += 1;
}else{
$sort = 1;
}
$insert["project_double_id"] = $param['double_id'];;
$insert["proposer_id"] = $user['id'];
$insert["proposer_type"] = 0;
$insert["proposer_state"] = 0;
$insert["proposer_details"] = $param['proposer_details'];
$insert["mobile"] = $param['mobile'];
$insert["container_id"] = $param['container_id'];
$insert["sort"] = $sort;
$insert["createtime"] = time();
$status = Db::name('project_double_apply')->insert($insert);
if($status){
$this->success("申请成功",url('index',['container_id'=>$param['container_id']]));
}else{
$this->error("申请失败,请联系系统管理员");
}
}
}
}
}