作者 开飞机的舒克

接口优化

... ... @@ -20,18 +20,18 @@ class Bind extends Api
/**
* @ApiTitle (输入学号绑定信息)
* @ApiMethod (POST)
* @ApiParams (name="xh", type="string", required=true, description="学号")
* @ApiParams (name="unique", type="string", required=true, description="手环id")
* @ApiReturn ({
"code":"状态码",
"msg": "提示消息",
"data": {}
})
*/
public function inputSno()
public function inputUnique()
{
$sno = $this->request->param('sno');
$unique = $this->request->param('unique');
$user = $this->auth->getUserinfo();
if (empty($sno)) {
if (empty($unique)) {
$this->error('参数错误', ['status' => 2]);
}
$is_bind = db('user')->where('id', $user['id'])->value('bind_study');
... ... @@ -41,7 +41,7 @@ class Bind extends Api
Db::startTrans();
try {
db('study')
->where('sno', $sno)
->where('unique', $unique)
->update([
'user_id' => $user['id'],
'updatetime' => time()
... ... @@ -63,7 +63,7 @@ class Bind extends Api
/**
* @ApiTitle (扫码绑定信息)
* @ApiMethod (POST)
* @ApiParams (name="sno", type="string", required=true, description="学号")
* @ApiParams (name="unique", type="string", required=true, description="手环id[条形码编号]")
* @ApiReturn ({
"code":"状态码",
"msg": "提示消息",
... ... @@ -72,9 +72,9 @@ class Bind extends Api
*/
public function scanCode()
{
$sno = $this->request->param('sno');
$unique = $this->request->param('unique');
$user = $this->auth->getUserinfo();
if (empty($sno)) {
if (empty($unique)) {
$this->error('参数错误', ['status' => 2]);
}
$is_bind = db('user')->where('id', $user['id'])->value('bind_study');
... ... @@ -84,7 +84,7 @@ class Bind extends Api
Db::startTrans();
try {
db('study')
->where('sno', $sno)
->where('unique', $unique)
->update([
'user_id' => $user['id'],
'updatetime' => time()
... ... @@ -100,7 +100,7 @@ class Bind extends Api
Db::rollback();
$this->error('参数错误', $e->getMessage());
}
$data = db('study')->where('sno', $sno)->field('id,grade,name,sno')->find();
$data = db('study')->where('unique', $unique)->field('id,grade,name')->find();
$this->success('绑定成功', $data);
}
... ... @@ -145,7 +145,6 @@ class Bind extends Api
"data": {
"name": "姓名",
"gender": "性别",
"sno": "学号"
}
})
*/
... ... @@ -156,7 +155,7 @@ class Bind extends Api
if (empty($unique) && empty($items_id)) {
$this->error('参数错误', ['status' => 2]);
}
$study = db('study')->where('unique', $unique)->field('id,grade_id,name,sno,team_id,earn_score')->find();
$study = db('study')->where('unique', $unique)->field('id,grade_id,name,team_id,earn_score')->find();
$item = db('item')->where('id', $items_id)->field('score,title,campus_id')->find();
$team = \db('team')->where('id', $study['team_id'])->field('title,score')->find();
$sum1 = $team['score'] + $item['score']; //合计战队总分
... ... @@ -188,7 +187,7 @@ class Bind extends Api
Db::rollback();
$this->error('连接错误', ['status' => 3]);
}
$data = db('study')->where('unique', $unique)->field('name,gender,sno')->find();
$data = db('study')->where('unique', $unique)->field('name,gender')->find();
$this->success('扫码成功', $data);
}
... ...
<?php
namespace app\api\controller;
use app\common\controller\Api;
/**
* 定时任务
* @ApiWeigh (94)
*/
class Crontab extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (首页)
*/
public function index(){
$res = db('study')->field('earn_score')->select();
function sort($res){
$len = count($res);
for ($i = 0; $i < $len - 1; $i++) {//循环比对的轮数
for ($j = 0; $j < $len - $i - 1; $j++) {//当前轮相邻元素循环对比
if ($res[$j] < $res[$j + 1]) {//如果前边的小于后边的
$tmp = $res[$j];//交换数据
$res[$j] = $res[$j + 1];
$res[$j + 1] = $tmp;
}
}
}
return $res;
}
$this->success('',sort($res));
}
}
\ No newline at end of file
此 diff 太大无法显示。