作者 开飞机的舒克

接口优化

... ... @@ -337,8 +337,9 @@ class Study extends Backend
$result = $this->model->allowField(true)->save($params);
$id = $this->model->id;
$unique = time();
$barpath = Resource::StudyBar($unique);
$this->model->save(['barcode'=>$barpath,'unique'=>time()],['id'=>$id]);
$sno = $this->model->sno;
$barpath = Resource::StudyBar($sno);
$this->model->save(['barcode'=>$barpath,'unique'=>$unique],['id'=>$id]);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
... ...
... ... @@ -63,7 +63,7 @@ class Bind extends Api
/**
* @ApiTitle (扫码绑定信息)
* @ApiMethod (POST)
* @ApiParams (name="unique", type="string", required=true, description="条形码id")
* @ApiParams (name="sno", type="string", required=true, description="学号")
* @ApiReturn ({
"code":"状态码",
"msg": "提示消息",
... ... @@ -72,9 +72,9 @@ class Bind extends Api
*/
public function scanCode()
{
$unique = $this->request->param('unique');
$sno = $this->request->param('sno');
$user = $this->auth->getUserinfo();
if (empty($unique)) {
if (empty($sno)) {
$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('unique', $unique)
->where('sno', $sno)
->update([
'user_id' => $user['id'],
'updatetime' => time()
... ... @@ -100,8 +100,8 @@ class Bind extends Api
Db::rollback();
$this->error('参数错误', $e->getMessage());
}
$data = db('study')->where('unique', $unique)->field('id,grade,name,sno')->find();
$this->success('绑定成功', [$data, 'status' => 1]);
$data = db('study')->where('sno', $sno)->field('id,grade,name,sno')->find();
$this->success('绑定成功', $data);
}
/**
... ... @@ -131,7 +131,7 @@ class Bind extends Api
if (empty($data)) {
$this->error('当前还未关联项目', ['status' => 2]);
}
$this->success('获取项目成功', [$data, 'status' => 1]);
$this->success('获取项目成功', $data);
}
/**
... ... @@ -203,20 +203,17 @@ class Bind extends Api
"avatar": "学生头像",
"name": "学生名称",
"earn_score": "学生获得分数"
"study_score": 学生积分构成{
"total": 2,
"item": 雷达图项目{
"total": 1,
"per_page": 3,
"current_page": 1,
"last_page": 1,
"data": [
{
"item_id": 项目id,
"sum_score": "项目所获分数",
"item_ronda": 项目对应雷达维度名称[
{
"radar_id": 雷达维度id,
"title": "雷达维度名称"
}
"sum_score": "项目分数",
"title": "维度名称"
},
]
},}
})
... ... @@ -228,23 +225,14 @@ class Bind extends Api
$sid = \db('study')->where('user_id', $user['id'])->value('id');
//获取学生的信息
$data = \db('study')->where('id', $sid)->field('avatar,name,earn_score')->find();
//$data['avatar'] = cdnurl( $data['avatar'], true);
$data['avatar'] = cdnurl( $data['avatar'], true);
//获取雷达维度
$data['item'] = \db('study_score_log')
->distinct('item_id')
->field('item_id,SUM(score) as sum_score')
->group('item_id')
->where(['campus_id' => $campus_id, 'study_id' => $sid])
// ->limit(3)
// ->select();
// foreach ($res as $k) {
// $list = $k['sum_score'];
// $list['radar'] = \db('item i')
// ->join('radar r', 'i.radar_id = r.id')
// ->where('i.id', $k['item_id'])
// ->value('r.title');
// }
->paginate(3)
->paginate(3)
->each(function ($item, $key) {
$item['title'] = \db('item i')
->join('radar r', 'i.radar_id = r.id')
... ...
... ... @@ -6,9 +6,9 @@ use tinymeng\code\Generate;
class Resource
{
public static function StudyBar($unique){
public static function StudyBar($sno){
$generate = Generate::bar();
$file_path = $generate->create($unique,true,true);
$file_path = $generate->create($sno,true,true);
$file_path = substr($file_path,strripos($file_path,"public")+6);
return $file_path;
}
... ...
... ... @@ -2582,10 +2582,10 @@
</thead>
<tbody>
<tr>
<td>unique</td>
<td>sno</td>
<td>string</td>
<td></td>
<td>条形码id</td>
<td>学号</td>
</tr>
</tbody>
</table>
... ... @@ -2610,8 +2610,8 @@
<div class="panel-body">
<form enctype="application/x-www-form-urlencoded" role="form" action="/api/bind/scanCode" method="POST" name="form5" id="form5">
<div class="form-group">
<label class="control-label" for="unique">unique</label>
<input type="string" class="form-control input-sm" id="unique" required placeholder="条形码id" name="unique">
<label class="control-label" for="sno">sno</label>
<input type="string" class="form-control input-sm" id="sno" required placeholder="学号" name="sno">
</div>
<div class="form-group form-group-submit">
<button type="submit" class="btn btn-success send" rel="5">提交</button>
... ... @@ -3061,20 +3061,17 @@
"avatar": "学生头像",
"name": "学生名称",
"earn_score": "学生获得分数"
"study_score": 学生积分构成{
"total": 2,
"item": 雷达图项目{
"total": 1,
"per_page": 3,
"current_page": 1,
"last_page": 1,
"data": [
{
"item_id": 项目id,
"sum_score": "项目所获分数",
"item_ronda": 项目对应雷达维度名称[
{
"radar_id": 雷达维度id,
"title": "雷达维度名称"
}
"sum_score": "项目分数",
"title": "维度名称"
},
]
},}
}</pre>
... ... @@ -4973,7 +4970,7 @@
</div>
<div class="col-md-6" align="right">
Generated on 2023-03-15 17:26:25 <a href="./" target="_blank">校园活动</a>
Generated on 2023-03-16 15:52:47 <a href="./" target="_blank">校园活动</a>
</div>
</div>
... ...