Ajax.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
<?php
namespace app\index\controller;
use app\common\controller\Frontend;
use app\school\model\basic\Clazz;
use app\school\model\basic\College;
use app\school\model\basic\Specialty;
use app\school\model\ManystoreShop;
use think\Db;
use think\Lang;
/**
* Ajax异步请求接口
* @internal
*/
class Ajax extends Frontend
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $layout = '';
/**
* 加载语言包
*/
public function lang()
{
header('Content-Type: application/javascript');
header("Cache-Control: public");
header("Pragma: cache");
$offset = 30 * 60 * 60 * 24; // 缓存一个月
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
$controllername = input("controllername");
$this->loadlang($controllername);
//强制输出JSON Object
$result = jsonp(Lang::get(), 200, [], ['json_encode_param' => JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE]);
return $result;
}
/**
* 上传文件
*/
public function upload()
{
return action('api/common/upload');
}
public function getCollege($type="college",$college = 0){
if ($type == 'college'){
$CollegeVo = new College();
$colleges = $CollegeVo->field('id as value,college_name as name')->where('school_id',$this->school_id)->select();
$this->success('',null,$colleges);
}else if($type == 'specialty'){
$SpecialtyVo = new Specialty();
$specialty = $SpecialtyVo->field('id as value,specialty_name as name')->where('school_id',$this->school_id)->where('college_id',$college)->select();
$this->success('',null,$specialty);
}else if($type == 'clazz'){
$ClazzVo = new Clazz();
$clazz = $ClazzVo->field('id as value,clazz_name as name')->where('school_id',$this->school_id)->where('specialty_id',$college)->select();
$this->success('',null,$clazz);
}else{
$this->error("没有可选");
}
}
public function getSubject($type = 'project_lv1_subject',$project_lv1_subject = 0)
{
$data = [];
$query = Db::name('project_subject')->field('id as value,subject_name as name');
if($project_lv1_subject) {
$query->where(['pid' => $project_lv1_subject]);
}else{
$query->where(['pid' => 0]);
}
$data = $query->select();
$this->success('',null,$data);
}
/**
* 获取学校院校专业树状图
*/
public function getSchoolList()
{
$type = request()->param('activeIndex');
$model = new ManystoreShop();
$list = $model->alias('sh')->with([ 'college' ,'college.specialty'])->where(['sh.id' => $this->auth->school_id])->select();
$arr = [];
$list = collection($list)->toArray();
if($list && $type != 2) {
foreach ($list as $first => $firstVal) {
$arr[$first]['school_id'] = $firstVal['id'];
$arr[$first]['title'] = $firstVal['name'];
$arr[$first]['flag'] = true;
if(!empty($firstVal['college'])) {
foreach ($firstVal['college'] as $second => $secondVal) {
$arr[$first]['children'][$second]['college_id'] = $secondVal['id'];
$arr[$first]['children'][$second]['title'] = $secondVal['college_name'];
$arr[$first]['children'][$second]['flag'] = false;
if($type == 0) {
if(!empty($secondVal['specialty'])) {
foreach ($secondVal['specialty'] as $third => $thirdVal) {
$arr[$first]['children'][$second]['children'][$third]['specialty_id'] = $thirdVal['id'];
$arr[$first]['children'][$second]['children'][$third]['title'] = $thirdVal['specialty_name'];
$arr[$first]['children'][$second]['children'][$third]['flag'] = false;
}
}
}
}
}
}
$result = array('code' => 1,"lists" => $arr);
return json($result);
}
$result = array('code' => 0,"lists" => $arr);
return json($result);
}
}