DeleteScoreRecordController.class.php
1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Created by PhpStorm.
* User: tangxingguo
* Date: 2018-3-29
* Time: 10:35:30
*/
namespace Apicp\Controller\Course;
use Com\PackageValidate;
use Common\Service\CourseItemService;
use Common\Service\CourseScoreDetailService;
use Common\Service\CourseScoreRecordService;
class DeleteScoreRecordController extends \Apicp\Controller\AbstractController
{
/**
* DeleteScoreRecord
* @author tangxingguo
* @desc 删除评分记录
* @param Int score_detail_id 评分ID
*/
public function Index_post()
{
$rules = [
'score_detail_id' => 'require|integer',
];
// 验证请求数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$scoreDetailId = $validate->postData['score_detail_id'];
// 平均分
$scoreDetailServ = new CourseScoreDetailService();
$detail = $scoreDetailServ->get($scoreDetailId);
// 删除平均分
$scoreDetailServ->delete($scoreDetailId);
// 评分记录
$scoreRecordServ = new CourseScoreRecordService();
$recordList = $scoreRecordServ->list_by_conds([
'article_id' => $detail['article_id'],
'uid' => $detail['uid']
]);
// 更新评分项
$itemServ = new CourseItemService();
foreach ($recordList as $record) {
$itemServ->update_by_conds(['item_id' => $record['item_id']], [
'score_total = score_total - ?' => $record['score_value'],
'user_total = user_total - ?' => 1
]);
}
// 删除记录
$scoreRecordServ->delete_by_conds([
'article_id' => $detail['article_id'],
'uid' => $detail['uid']]);
}
}