UpdateCourseController.class.php
2.16 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
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 17/10/26
* Time: 18:25
*/
namespace Frontend\Controller\UpdateDB;
use Common\Model\CommonModel;
use Common\Model\ContentModel;
class UpdateCourseController extends AbstractController
{
/**
* 线下培训迭代,讲师授课记录建表,将关联了讲师的课程数据,升级到授课记录表
* @author tangxingguo
*/
public function Index()
{
// 线上课程类别的授课记录
$contentModel = new ContentModel();
$contentList = $contentModel->listWithOutDomian(['app' => 'course', 'data_type' => 1]);
// 当前已经设置了讲师的课程
$articleModel = new CommonModel('Article', 'oa_course_');
$articleList = $articleModel->listWithOutDomian(['teacher_id > ?' => 0]);
if (empty($articleList)) {
exit('没有找到课程数据!');
}
// 授课记录与线上课程差集
if (!empty($contentList)) {
// 数据对比
$appDataIds = array_column($contentList, 'app_data_id');
$articleIds = array_column($articleList, 'article_id');
$diffIds = array_diff($articleIds, $appDataIds);
if (empty($diffIds)) {
exit('没有需要升级的数据!');
}
// 差值数据拼接
$articleList = array_combine_by_key($articleList, 'article_id');
$diffList = [];
foreach ($diffIds as $id) {
$diffList[] = $articleList[$id];
}
$articleList = $diffList;
}
// 数据格式化
$data = [];
foreach ($articleList as $k => $v) {
$data[] = [
'app' => 'course',
'data_type' => 1,
'app_data_id' => $v['article_id'],
'title' => $v['article_title'],
'cover_url' => $v['cover_url'],
'teacher_id' => $v['teacher_id'],
'teacher_task_id' => $v['teacher_task_id'],
'domain' => $v['domain'],
];
}
$contentModel->insert_all($data);
exit('SUCCESS');
}
}