作者 开飞机的舒克

修改分数不能插入的问题

... ... @@ -164,10 +164,10 @@ class Bind extends Api
->where('user_id', $user['id'])
->value('id');
$data = \db('study_score_log l')
->distinct('campus_id')
->join('campus c','c.id = l.campus_id')
->distinct('campus_ids')
->join('campus c','c.id = l.campus_ids')
->where('study_id',$sid)
->field('campus_id,c.title as campus_title')
->field('campus_ids,c.title as campus_title')
->select();
if (empty($data)){
$this->error('当前学生还未有项目关联校区',['status'=>2]);
... ...
... ... @@ -3,7 +3,10 @@
namespace app\common\model;
use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\Model;
class StudyScoreLog extends Model
... ... @@ -22,30 +25,30 @@ class StudyScoreLog extends Model
//加分
public function addScore($id,$unique){
public function addScore($id, $unique)
{
$study = new Study();
$team = new Team();
$item = new Item();
$stu = $study->where('unique',$unique)->find()->toArray();
$xm = $item->where('id',$id)->find()->toArray();
$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']);
$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){
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 = [
... ... @@ -57,34 +60,33 @@ class StudyScoreLog extends Model
'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){
$this->allowField(true)->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)){
$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()
'study_id' => $stu['id'],
'radar_id' => $value['radar'],
'campus_ids' => $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']]);
} 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
... ...
... ... @@ -6324,7 +6324,7 @@
</div>
<div class="col-md-6" align="right">
Generated on 2023-04-13 09:24:23 <a href="./" target="_blank">校园活动</a>
Generated on 2023-04-20 10:37:30 <a href="./" target="_blank">校园活动</a>
</div>
</div>
... ...