作者 开飞机的舒克

接口优化

@@ -20,18 +20,18 @@ class Bind extends Api @@ -20,18 +20,18 @@ class Bind extends Api
20 /** 20 /**
21 * @ApiTitle (输入学号绑定信息) 21 * @ApiTitle (输入学号绑定信息)
22 * @ApiMethod (POST) 22 * @ApiMethod (POST)
23 - * @ApiParams (name="xh", type="string", required=true, description="学号") 23 + * @ApiParams (name="unique", type="string", required=true, description="手环id")
24 * @ApiReturn ({ 24 * @ApiReturn ({
25 "code":"状态码", 25 "code":"状态码",
26 "msg": "提示消息", 26 "msg": "提示消息",
27 "data": {} 27 "data": {}
28 }) 28 })
29 */ 29 */
30 - public function inputSno() 30 + public function inputUnique()
31 { 31 {
32 - $sno = $this->request->param('sno'); 32 + $unique = $this->request->param('unique');
33 $user = $this->auth->getUserinfo(); 33 $user = $this->auth->getUserinfo();
34 - if (empty($sno)) { 34 + if (empty($unique)) {
35 $this->error('参数错误', ['status' => 2]); 35 $this->error('参数错误', ['status' => 2]);
36 } 36 }
37 $is_bind = db('user')->where('id', $user['id'])->value('bind_study'); 37 $is_bind = db('user')->where('id', $user['id'])->value('bind_study');
@@ -41,7 +41,7 @@ class Bind extends Api @@ -41,7 +41,7 @@ class Bind extends Api
41 Db::startTrans(); 41 Db::startTrans();
42 try { 42 try {
43 db('study') 43 db('study')
44 - ->where('sno', $sno) 44 + ->where('unique', $unique)
45 ->update([ 45 ->update([
46 'user_id' => $user['id'], 46 'user_id' => $user['id'],
47 'updatetime' => time() 47 'updatetime' => time()
@@ -63,7 +63,7 @@ class Bind extends Api @@ -63,7 +63,7 @@ class Bind extends Api
63 /** 63 /**
64 * @ApiTitle (扫码绑定信息) 64 * @ApiTitle (扫码绑定信息)
65 * @ApiMethod (POST) 65 * @ApiMethod (POST)
66 - * @ApiParams (name="sno", type="string", required=true, description="学号") 66 + * @ApiParams (name="unique", type="string", required=true, description="手环id[条形码编号]")
67 * @ApiReturn ({ 67 * @ApiReturn ({
68 "code":"状态码", 68 "code":"状态码",
69 "msg": "提示消息", 69 "msg": "提示消息",
@@ -72,9 +72,9 @@ class Bind extends Api @@ -72,9 +72,9 @@ class Bind extends Api
72 */ 72 */
73 public function scanCode() 73 public function scanCode()
74 { 74 {
75 - $sno = $this->request->param('sno'); 75 + $unique = $this->request->param('unique');
76 $user = $this->auth->getUserinfo(); 76 $user = $this->auth->getUserinfo();
77 - if (empty($sno)) { 77 + if (empty($unique)) {
78 $this->error('参数错误', ['status' => 2]); 78 $this->error('参数错误', ['status' => 2]);
79 } 79 }
80 $is_bind = db('user')->where('id', $user['id'])->value('bind_study'); 80 $is_bind = db('user')->where('id', $user['id'])->value('bind_study');
@@ -84,7 +84,7 @@ class Bind extends Api @@ -84,7 +84,7 @@ class Bind extends Api
84 Db::startTrans(); 84 Db::startTrans();
85 try { 85 try {
86 db('study') 86 db('study')
87 - ->where('sno', $sno) 87 + ->where('unique', $unique)
88 ->update([ 88 ->update([
89 'user_id' => $user['id'], 89 'user_id' => $user['id'],
90 'updatetime' => time() 90 'updatetime' => time()
@@ -100,7 +100,7 @@ class Bind extends Api @@ -100,7 +100,7 @@ class Bind extends Api
100 Db::rollback(); 100 Db::rollback();
101 $this->error('参数错误', $e->getMessage()); 101 $this->error('参数错误', $e->getMessage());
102 } 102 }
103 - $data = db('study')->where('sno', $sno)->field('id,grade,name,sno')->find(); 103 + $data = db('study')->where('unique', $unique)->field('id,grade,name')->find();
104 $this->success('绑定成功', $data); 104 $this->success('绑定成功', $data);
105 } 105 }
106 106
@@ -145,7 +145,6 @@ class Bind extends Api @@ -145,7 +145,6 @@ class Bind extends Api
145 "data": { 145 "data": {
146 "name": "姓名", 146 "name": "姓名",
147 "gender": "性别", 147 "gender": "性别",
148 - "sno": "学号"  
149 } 148 }
150 }) 149 })
151 */ 150 */
@@ -156,7 +155,7 @@ class Bind extends Api @@ -156,7 +155,7 @@ class Bind extends Api
156 if (empty($unique) && empty($items_id)) { 155 if (empty($unique) && empty($items_id)) {
157 $this->error('参数错误', ['status' => 2]); 156 $this->error('参数错误', ['status' => 2]);
158 } 157 }
159 - $study = db('study')->where('unique', $unique)->field('id,grade_id,name,sno,team_id,earn_score')->find(); 158 + $study = db('study')->where('unique', $unique)->field('id,grade_id,name,team_id,earn_score')->find();
160 $item = db('item')->where('id', $items_id)->field('score,title,campus_id')->find(); 159 $item = db('item')->where('id', $items_id)->field('score,title,campus_id')->find();
161 $team = \db('team')->where('id', $study['team_id'])->field('title,score')->find(); 160 $team = \db('team')->where('id', $study['team_id'])->field('title,score')->find();
162 $sum1 = $team['score'] + $item['score']; //合计战队总分 161 $sum1 = $team['score'] + $item['score']; //合计战队总分
@@ -188,7 +187,7 @@ class Bind extends Api @@ -188,7 +187,7 @@ class Bind extends Api
188 Db::rollback(); 187 Db::rollback();
189 $this->error('连接错误', ['status' => 3]); 188 $this->error('连接错误', ['status' => 3]);
190 } 189 }
191 - $data = db('study')->where('unique', $unique)->field('name,gender,sno')->find(); 190 + $data = db('study')->where('unique', $unique)->field('name,gender')->find();
192 $this->success('扫码成功', $data); 191 $this->success('扫码成功', $data);
193 } 192 }
194 193
1 -<?php  
2 -  
3 -namespace app\api\controller;  
4 -  
5 -  
6 -use app\common\controller\Api;  
7 -  
8 -/**  
9 - * 定时任务  
10 - * @ApiWeigh (94)  
11 - */  
12 -class Crontab extends Api  
13 -{  
14 - protected $noNeedLogin = ['*'];  
15 - protected $noNeedRight = ['*'];  
16 -  
17 -  
18 - /**  
19 - * @ApiTitle (首页)  
20 - */  
21 - public function index(){  
22 - $res = db('study')->field('earn_score')->select();  
23 - function sort($res){  
24 - $len = count($res);  
25 - for ($i = 0; $i < $len - 1; $i++) {//循环比对的轮数  
26 - for ($j = 0; $j < $len - $i - 1; $j++) {//当前轮相邻元素循环对比  
27 - if ($res[$j] < $res[$j + 1]) {//如果前边的小于后边的  
28 - $tmp = $res[$j];//交换数据  
29 - $res[$j] = $res[$j + 1];  
30 - $res[$j + 1] = $tmp;  
31 - }  
32 - }  
33 - }  
34 - return $res;  
35 - }  
36 - $this->success('',sort($res));  
37 - }  
38 -}  
此 diff 太大无法显示。