作者 开飞机的舒克

学生参加项目得分

... ... @@ -198,38 +198,6 @@ class Bind extends Api
}
$model = new StudyScoreLog();
$model->addScore($id,$unique);
$study = db('study')->where('unique', $unique)->field('id,grade,name,team,earn_score')->find();
$item = db('item')->where('id', $id)->field('score,title,campus_id')->find();
$team = \db('team')->where('title', $study['team'])->field('title,score')->find();
$sum1 = $team['score'] + $item['score']; //合计战队总分
$sum2 = $study['earn_score'] + $item['score']; //合计个人总分
Db::startTrans();
try {
db('study_score_log')->insert([
'item_id' => $id,
'campus_id' => $item['campus_id'],
'study_id' => $study['id'],
'team' => $study['team'],
'score' => $item['score'],
'memo' => $study['name'] . '参加' . $item['title'] . '加分',
'createtime' => time()
]);
db('study')
->where('id', $study['id'])
->update([
'earn_score' => $sum2,
]);
\db('team')
->where('title', $study['team'])
->update([
'score' => $sum1,
'updatetime' => time()
]);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error('连接错误', ['status' => 3]);
}
$data = db('study')->where('unique', $unique)->field('name,gender')->find();
if ($data['gender'] == 1){
$data['gender'] = '男';
... ...
<?php
namespace app\common\model;
use think\Model;
class RadarScore extends Model
{
// 表名
protected $name = 'radar_score';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,8 @@
namespace app\common\model;
use think\Db;
use think\Exception;
use think\Model;
class StudyScoreLog extends Model
... ... @@ -26,7 +28,63 @@ class StudyScoreLog extends Model
$item = new Item();
$stu = $study->where('unique',$unique)->find()->toArray();
$xm = $item->where('id',$id)->find()->toArray();
$team = $team->where('title', $stu['team'])->field('title,score')->find();
$radar = explode(',',$xm['radar_ids']);
$score = explode(',',$xm['score']);
$sum_score = 0;
$list = [];
foreach ($score as $k) {
$sum_score += $k;
}
//halt($sum_score);
foreach ($radar as $k1 => $v1){
foreach ($score as $k2 => $v2){
if ($k1 == $k2){
$list[$k1]['radar'] = $v1;
$list[$k1]['score'] = $v2;
}
}
}
//halt($list);
$sum1 = $team['score'] + $sum_score; //合计战队总分
$sum2 = $stu['earn_score'] + $sum_score; //合计个人总分
$data = [
'item_id' => $id,
'campus_ids' => $xm['campus_ids'],
'study_id' => $stu['id'],
'team' => $stu['team'],
'score' => $sum_score,
'memo' => $stu['name'] . '参加' . $xm['title'] . '加分',
'createtime' => time()
];
Db::startTrans();
try {
$this->save($data);
$study->save(['earn_score' => $sum2],['id'=>$stu['id']]);
$team->save(['score' => $sum1,'updatetime' => time()],['title'=>$stu['team']]);
foreach ($list as $key => $value){
$ronda_score = new RadarScore();
$res = $ronda_score->where(['study_id'=>$stu['id'],'radar_id'=>$value['radar']])->find();
if (empty($res)){
$resc = [
'study_id'=>$stu['id'],
'radar_id'=>$value['radar'],
'campus_id'=>$xm['campus_ids'],
'score'=>$value['score'],
'createtime'=>time()
];
$ronda_score->save($resc);
}else{
$ronda_score->where(['study_id'=>$stu['id'],'radar_id'=>$value['radar']])->update(['updatetime'=>time(),
'score'=>$res['score']+$value['score']]);
}
}
Db::commit();
} catch (Exception $e) {
Db::rollback();
$e->getMessage();
}
}
}
\ No newline at end of file
... ...