<?php
/**
 * Created by PhpStorm.
 * User: liyifei2012it
 * Date: 17/6/13
 * Time: 18:13
 */

namespace Rpc\Controller\Common;

use Think\Db;
use Think\Log;

class InstallController extends AbstractController
{
    private $qyDomain = QY_DOMAIN;
    private $nowTime = MILLI_TIME;

    /**
     * 应用默认数据安装接口
     * @author tangxingguo
     */
    public function Index()
    {
        // 添加分类
        $this->_addClass();
        // 添加素材
        $this->_addSource();
        // 添加课程
        $this->_addCourse();
    }

    /**
     * 执行sql语句
     * @param $sql
     */
    private function _exeSql($sql)
    {
        if (empty($sql)) {
            return ;
        }

        $db = Db::getInstance();
        try {
            return $db->query($sql);
        } catch (\Exception $e) {

        }
    }

    /**
     * 默认分类数据
     * @author tangxingguo
     * @return string
     */
    private function _addClass()
    {
        // 兼容多次操作
        $db = &Db::getInstance();
        $classSql = "select * from `oa_course_class` WHERE `domain` = '{$this->qyDomain}'  and `status` < 3";
        $classInfo = $db->query($classSql);
        if (!empty($classInfo)) {
            return;
        }

        // 默认分类数据
        $defaultClass = [
            [
                'class_name' => '管理常识',
                'parent_id' => 0,
                'description' => '',
                'is_open' => 2,
            ],
            [
                'class_name' => '市场营销',
                'parent_id' => 0,
                'description' => '',
                'is_open' => 2,
            ],
            [
                'class_name' => '办公技能',
                'parent_id' => 0,
                'description' => '',
                'is_open' => 2,
            ],
            [
                'class_name' => '职业发展',
                'parent_id' => 0,
                'description' => '',
                'is_open' => 2,
            ],
            [
                'class_name' => '思维框架',
                'parent_id' => 0,
                'description' => '',
                'is_open' => 2,
            ],
        ];

        // sql
        $sql = "INSERT INTO `oa_course_class` (`parent_id`, `class_name`, `description`, `is_open`, `domain`, `status`, `created`) VALUES ";
        foreach ($defaultClass as $k => $v) {
            $sql .= "('{$v['parent_id']}', '{$v['class_name']}', '{$v['description']}', '{$v['is_open']}', '{$this->qyDomain}', 1, '{$this->nowTime}')";
            if (end($defaultClass) == $v) {
                $sql .= ";";
            } else {
                $sql .= ",";
            }
        }

        $this->_exeSql($sql);
    }

    /**
     * 默认素材
     * @author tangxingguo
     */
    private function _addSource()
    {
        // 兼容多次操作
        $db = &Db::getInstance();
        $sourceSql = "select * from `oa_course_source` WHERE `domain` = '{$this->qyDomain}'  and `status` < 3";
        $sourceInfo = $db->query($sourceSql);
        if (!empty($sourceInfo)) {
            return;
        }

        // 默认数据 1
        $defaultData = [
            'source_title' => '欢迎开启员圈,开始学习成长之旅',
            'source_key' => 'I' . rgmdate(MILLI_TIME, 'ymdHi') . rand(10, 99),
            'author' => '员圈小助手',
            'source_type' => 1,
            'is_download' => 1,
            'ea_id' => '',
            'ea_name' => '员圈小助手',
            'audio_imgs' => '',
            'content' => '<section style="background-color: rgb(255, 255, 255); box-sizing: border-box;">
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="font-size: 14px;letter-spacing: 1px;padding-right: 1px;padding-left: 1px;box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    员圈,是基于企业微信的企业员工学习成长生态圈。
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" margin-top: 10px;margin-bottom: 10px; box-sizing: border-box; ">
            <section class="" style="margin-bottom: -12px;text-align: center;box-sizing: border-box;">
                <section style="display: inline-block;vertical-align: bottom;width: 6px;box-sizing: border-box;">
                    <section style="width: 2px;margin: auto;height: 16px;background-color: rgb(17, 19, 22);box-sizing: border-box;"></section>
                    <section style="width: 6px;height: 6px;border-radius: 50%;background-color: rgb(17, 19, 22);box-sizing: border-box;"></section>
                </section>
                <section style="display: inline-block;vertical-align: bottom;width: 60%;box-sizing: border-box;"></section>
                <section style="display: inline-block;vertical-align: bottom;width: 6px;box-sizing: border-box;">
                    <section style="width: 2px;margin: auto;height: 16px;background-color: rgb(17, 19, 22);box-sizing: border-box;"></section>
                    <section style="width: 6px;height: 6px;border-radius: 50%;background-color: rgb(17, 19, 22);box-sizing: border-box;"></section>
                </section>
            </section>
            <section class="" style="transform: rotate(0deg);-webkit-transform: rotate(0deg);-moz-transform: rotate(0deg);-o-transform: rotate(0deg);margin-bottom: -5px;width: 5px;height: 5px;background-color: rgb(254, 255, 255);box-sizing: border-box;"></section>
            <section class="" style="border-left: 5px solid rgb(255, 222, 3);border-bottom: 5px solid rgb(255, 222, 3);border-top-color: rgb(255, 222, 3);border-right-color: rgb(255, 222, 3);box-sizing: border-box;">
                <section class="" style="background-color: rgb(214, 240, 252);padding: 10px;box-sizing: border-box;">
                    <section class="" style="box-sizing: border-box;" powered-by="xiumi.us">
                        <section class="" style="  box-sizing: border-box; ">
                            <section class="" style="font-size: 14px;line-height: 2;box-sizing: border-box;">
                                <p style="box-sizing: border-box;">
                                    <strong style="box-sizing: border-box;">完整的员工成长体系,支持随时随地学习与检验</strong>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                                </p>
                                <p style="box-sizing: border-box;">
                                    <strong style="box-sizing: border-box;">互动问答社区,打造企业内浓厚学习氛围</strong>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                                </p>
                                <p style="box-sizing: border-box;">
                                    <strong style="box-sizing: border-box;">积分与勋章,激励员工自发、主动学习提升</strong>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                                </p>
                            </section>
                        </section>
                    </section>
                </section>
            </section>
            <section class="" style="margin-left: auto;margin-top: -5px;width: 5px;height: 5px;background-color: rgb(254, 255, 255);box-sizing: border-box;"></section>
        </section>
    </section>
    <section class="" style="box-sizing: border-box;" powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    <br style="box-sizing: border-box;"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" margin-top: 10px;margin-bottom: 10px;padding-left: 0.2em;font-size: 10px; box-sizing: border-box; ">
            <section class="" style="display: inline-block;box-sizing: border-box;">
                <section class="" style="width: 3.3em;height: 3.3em;display: inline-block;vertical-align: top;margin-left: -0.2em;border-width: 3px;border-style: solid;border-color: white;margin-right: -3.3em;transform: rotate(0deg);border-radius: 100%;background-position: center center;background-repeat: no-repeat;background-size: cover;background-image: url(&quot;http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuDpDxPHXP0036Xcvqhpcp9Vayial9UQTndGJ1iagH4Wu17MeQ14YppIrw/0?wx_fmt=png&quot;);box-sizing: border-box;">
                    <section class="" style="width: 100%;height: 100%;overflow: hidden;box-sizing: border-box;">
                        <img class="" style="opacity: 0; box-sizing: border-box; width: 100% !important; height: auto !important; visibility: visible !important;" data-src="http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuDpDxPHXP0036Xcvqhpcp9Vayial9UQTndGJ1iagH4Wu17MeQ14YppIrw/0?wx_fmt=png" data-ratio="1" data-w="640" width="100%" data-type="png" _width="100%" src="http://st.vchangyi.com/yuanquan/course/default_banner_course_logo.png" data-fail="0"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                    </section>
                </section>
                <section style="padding-left: 3.4em;margin-top: -3em;border-radius: 1.5em;background-color: rgb(214, 240, 252);box-sizing: border-box;">
                    <section class="" style="display: inline-block;vertical-align: top;color: rgb(58, 55, 55);font-size: 16px;text-align: center;padding-right: 15px;padding-left: 10px;box-sizing: border-box;">
                        <p style="box-sizing: border-box;">
                            <strong style="box-sizing: border-box;">基于企业微信,打造移动学习新生态</strong>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        </p>
                    </section>
                </section>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="font-size: 14px;line-height: 2;letter-spacing: 1px;padding-right: 1px;padding-left: 1px;box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    员工可以快速加入员圈。在实际应用中,<strong style="box-sizing: border-box;">仅仅2天时间,就将全国近1000家门店,8000名员工加入员圈</strong>。
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" text-align: center;margin-top: 10px;margin-bottom: 10px;font-size: 2px; box-sizing: border-box; ">
            <section class="" style="max-width: 100%;vertical-align: middle;display: inline-block;width: 35%;overflow: hidden !important;box-sizing: border-box;">
                <img data-src="http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuN6rTS7KSolGBp7WcpHiblYy7NWBdqyssCWHEAobZic0oiaavU44VYDCIQ/0?wx_fmt=png" style="vertical-align: middle; box-sizing: border-box; width: 100% !important; height: auto !important; visibility: visible !important;" data-ratio="2.0936709" data-w="395" width="100%" data-type="png" _width="100%" class="" src="http://st.vchangyi.com/yuanquan/course/default_banner_course_1.png" data-fail="0"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            </section>
        </section>
    </section>
    <section class="" style="box-sizing: border-box;" powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    <br style="box-sizing: border-box;"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" margin-top: 10px;margin-bottom: 10px;padding-left: 0.2em;font-size: 10px; box-sizing: border-box; ">
            <section class="" style="display: inline-block;box-sizing: border-box;">
                <section class="" style="width: 3.3em;height: 3.3em;display: inline-block;vertical-align: top;margin-left: -0.2em;border-width: 3px;border-style: solid;border-color: white;margin-right: -3.3em;transform: rotate(0deg);border-radius: 100%;background-position: center center;background-repeat: no-repeat;background-size: cover;background-image: url(&quot;http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuDpDxPHXP0036Xcvqhpcp9Vayial9UQTndGJ1iagH4Wu17MeQ14YppIrw/0?wx_fmt=png&quot;);box-sizing: border-box;">
                    <section class="" style="width: 100%;height: 100%;overflow: hidden;box-sizing: border-box;">
                        <img class="" style="opacity: 0; box-sizing: border-box; width: 100% !important; height: auto !important; visibility: visible !important;" data-src="http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuDpDxPHXP0036Xcvqhpcp9Vayial9UQTndGJ1iagH4Wu17MeQ14YppIrw/0?wx_fmt=png" data-ratio="1" data-w="640" width="100%" data-type="png" _width="100%" src="http://st.vchangyi.com/yuanquan/course/default_banner_course_logo.png" data-fail="0"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                    </section>
                </section>
                <section style="padding-left: 3.4em;margin-top: -3em;border-radius: 1.5em;background-color: rgb(214, 240, 252);box-sizing: border-box;">
                    <section class="" style="display: inline-block;vertical-align: top;color: rgb(58, 55, 55);font-size: 16px;text-align: center;padding-right: 15px;padding-left: 10px;box-sizing: border-box;">
                        <p style="box-sizing: border-box;">
                            <strong style="box-sizing: border-box;">高频带动低频,员工主动学习</strong>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        </p>
                    </section>
                </section>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="font-size: 14px;letter-spacing: 1px;padding-right: 1px;padding-left: 1px;line-height: 2;box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    学习从来都是低频的,容易偷懒倦怠的。过去的线上培训往往是员工收到企业邮件/口头通知,在电脑上登陆培训平台,打开课程学习。
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="font-size: 14px;letter-spacing: 1px;padding-right: 1px;padding-left: 1px;line-height: 2;box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    现在,员圈利用企业微信高频次的打开率和消息查看率,<strong style="box-sizing: border-box;">将课程、考试直接推送到每一位员工的企业微信,员工学习频次提升,主动性增强。</strong>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" text-align: center;margin-top: 10px;margin-bottom: 10px; box-sizing: border-box; ">
            <section class="" style="max-width: 100%;vertical-align: middle;display: inline-block;overflow: hidden !important;box-sizing: border-box;">
                <img data-src="http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxudChSBhO6NWOLlSibX7JFvFDlChQwlhKc7crHKlHNXKA8YDhpSboJEaw/0?wx_fmt=png" style="vertical-align: middle; box-sizing: border-box; width: auto !important; height: auto !important; visibility: visible !important;" data-ratio="0.5546875" data-w="640" data-type="png" class="" src="http://st.vchangyi.com/yuanquan/course/default_banner_course_2.png" data-fail="0"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            </section>
        </section>
    </section>
    <section class="" style="box-sizing: border-box;" powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    <br style="box-sizing: border-box;"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" margin-top: 10px;margin-bottom: 10px;padding-left: 0.2em;font-size: 10px; box-sizing: border-box; ">
            <section class="" style="display: inline-block;box-sizing: border-box;">
                <section class="" style="width: 3.3em;height: 3.3em;display: inline-block;vertical-align: top;margin-left: -0.2em;border-width: 3px;border-style: solid;border-color: white;margin-right: -3.3em;transform: rotate(0deg);border-radius: 100%;background-position: center center;background-repeat: no-repeat;background-size: cover;background-image: url(&quot;http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuDpDxPHXP0036Xcvqhpcp9Vayial9UQTndGJ1iagH4Wu17MeQ14YppIrw/0?wx_fmt=png&quot;);box-sizing: border-box;">
                    <section class="" style="width: 100%;height: 100%;overflow: hidden;box-sizing: border-box;">
                        <img class="" style="opacity: 0; box-sizing: border-box; width: 100% !important; height: auto !important; visibility: visible !important;" data-src="http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuDpDxPHXP0036Xcvqhpcp9Vayial9UQTndGJ1iagH4Wu17MeQ14YppIrw/0?wx_fmt=png" data-ratio="1" data-w="640" width="100%" data-type="png" _width="100%" src="http://st.vchangyi.com/yuanquan/course/default_banner_course_logo.png" data-fail="0"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                    </section>
                </section>
                <section style="padding-left: 3.4em;margin-top: -3em;border-radius: 1.5em;background-color: rgb(214, 240, 252);box-sizing: border-box;">
                    <section class="" style="display: inline-block;vertical-align: top;color: rgb(58, 55, 55);font-size: 16px;text-align: center;padding-right: 15px;padding-left: 10px;box-sizing: border-box;">
                        <p style="box-sizing: border-box;">
                            <strong style="box-sizing: border-box;">完整的员工学习成长体系</strong>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        </p>
                    </section>
                </section>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" margin-top: 10px;margin-bottom: 10px;text-align: center;line-height: 1;font-size: 11px; box-sizing: border-box; ">
            <section class="" style="width: 0px;display: inline-block;border-top: 1.2em solid rgb(255, 223, 0);border-left: 0.7em solid transparent !important;border-right: 0.7em solid transparent !important;box-sizing: border-box;"></section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="box-sizing: border-box;">
                <p style="text-align: center;box-sizing: border-box;">
                    <strong style="box-sizing: border-box;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 课程</strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="font-size: 14px;line-height: 2;letter-spacing: 1px;padding-right: 1px;padding-left: 1px;box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    形式丰富的线上课堂,支持图文、音频、视频、文件、外部链接多类课程。
                </p>
                <p style="box-sizing: border-box;">
                    支持根据岗位进行课程定制,将培训精细化、个性化,落实到每一位员工。
                </p>
                <p style="box-sizing: border-box;">
                    课程可关联考试,形成学习-检测的闭环。
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" margin-top: 10px;margin-bottom: 10px;text-align: center;line-height: 1;font-size: 11px; box-sizing: border-box; ">
            <section class="" style="width: 0px;display: inline-block;border-top: 1.2em solid rgb(255, 223, 0);border-left: 0.7em solid transparent !important;border-right: 0.7em solid transparent !important;box-sizing: border-box;"></section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="box-sizing: border-box;">
                <p style="text-align: center;box-sizing: border-box;">
                    <strong style="box-sizing: border-box;">考试<br style="box-sizing: border-box;"/></strong>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="font-size: 14px;line-height: 2;letter-spacing: 1px;padding-right: 1px;padding-left: 1px;box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    自主题库配置,多种试卷组合。
                </p>
                <p style="box-sizing: border-box;">
                    支持30000+员工同时在线考试。
                </p>
                <p style="box-sizing: border-box;">
                    考试数据一键导出,成绩一目了然。
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" margin-top: 10px;margin-bottom: 10px;text-align: center;line-height: 1;font-size: 11px; box-sizing: border-box; ">
            <section class="" style="width: 0px;display: inline-block;border-top: 1.2em solid rgb(255, 223, 0);border-left: 0.7em solid transparent !important;border-right: 0.7em solid transparent !important;box-sizing: border-box;"></section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="box-sizing: border-box;">
                <p style="text-align: center;box-sizing: border-box;">
                    <strong style="box-sizing: border-box;">资料库</strong><br style="box-sizing: border-box;"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="font-size: 14px;line-height: 2;letter-spacing: 1px;padding-right: 1px;padding-left: 1px;box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    随身携带的知识宝库,充分利用碎片化时间学习充电。资料库权限明确,文件安全有保障
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" text-align: center;margin-top: 10px;margin-bottom: 10px; box-sizing: border-box; ">
            <section class="" style="max-width: 100%;vertical-align: middle;display: inline-block;overflow: hidden !important;box-sizing: border-box;">
                <img data-src="http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuXbmPmqYaFEm5RM3TBL0REy7EMH9O1JonWqvx6MrQbH3Q46ttibDfObw/0?wx_fmt=png" style="vertical-align: middle; box-sizing: border-box; width: auto !important; height: auto !important; visibility: visible !important;" data-ratio="0.58125" data-w="640" data-type="png" class="" src="http://st.vchangyi.com/yuanquan/course/default_banner_course_3.png" data-fail="0"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            </section>
        </section>
    </section>
    <section class="" style="box-sizing: border-box;" powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    <br style="box-sizing: border-box;"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" margin-top: 10px;margin-bottom: 10px;padding-left: 0.2em;font-size: 10px; box-sizing: border-box; ">
            <section class="" style="display: inline-block;box-sizing: border-box;">
                <section class="" style="width: 3.3em;height: 3.3em;display: inline-block;vertical-align: top;margin-left: -0.2em;border-width: 3px;border-style: solid;border-color: white;margin-right: -3.3em;transform: rotate(0deg);border-radius: 100%;background-position: center center;background-repeat: no-repeat;background-size: cover;background-image: url(&quot;http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuDpDxPHXP0036Xcvqhpcp9Vayial9UQTndGJ1iagH4Wu17MeQ14YppIrw/0?wx_fmt=png&quot;);box-sizing: border-box;">
                    <section class="" style="width: 100%;height: 100%;overflow: hidden;box-sizing: border-box;">
                        <img class="" style="opacity: 0; box-sizing: border-box; width: 100% !important; height: auto !important; visibility: visible !important;" data-src="http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuDpDxPHXP0036Xcvqhpcp9Vayial9UQTndGJ1iagH4Wu17MeQ14YppIrw/0?wx_fmt=png" data-ratio="1" data-w="640" width="100%" data-type="png" _width="100%" src="http://st.vchangyi.com/yuanquan/course/default_banner_course_logo.png" data-fail="0"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                    </section>
                </section>
                <section style="padding-left: 3.4em;margin-top: -3em;border-radius: 1.5em;background-color: rgb(214, 240, 252);box-sizing: border-box;">
                    <section class="" style="display: inline-block;vertical-align: top;color: rgb(58, 55, 55);font-size: 16px;text-align: center;padding-right: 15px;padding-left: 10px;box-sizing: border-box;">
                        <p style="box-sizing: border-box;">
                            <strong style="box-sizing: border-box;">你问我答,共同进步</strong>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        </p>
                    </section>
                </section>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="font-size: 14px;line-height: 2;letter-spacing: 1px;padding-right: 1px;padding-left: 1px;box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    问答社区是员工提供<strong style="box-sizing: border-box;">知识共享</strong>的天地,通过员工间问答互动,<strong style="box-sizing: border-box;">在企业内部形成知识共享的浓厚氛围,推动全员进步。</strong>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                </p>
                <p style="box-sizing: border-box;">
                    <strong style="box-sizing: border-box;">支持悬赏提问</strong>,提问者可使用积分悬赏,吸引更多优质回答,同时答题者也可以获得实际回报。
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" text-align: center;margin-top: 10px;margin-bottom: 10px; box-sizing: border-box; ">
            <section class="" style="max-width: 100%;vertical-align: middle;display: inline-block;width: 35%;overflow: hidden !important;box-sizing: border-box;">
                <img data-src="http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuqWSwBWF2jYX4WmicFedXr1NFqiatCvz5jlxeicTVBKpscxkd0RVpSeGww/0?wx_fmt=png" style="vertical-align: middle; box-sizing: border-box; width: 100% !important; height: auto !important; visibility: visible !important;" data-ratio="2.0949721" data-w="537" width="100%" data-type="png" _width="100%" class="" src="http://st.vchangyi.com/yuanquan/course/default_banner_course_4.png" data-fail="0"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            </section>
        </section>
    </section>
    <section class="" style="box-sizing: border-box;" powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    <br style="box-sizing: border-box;"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" margin-top: 10px;margin-bottom: 10px;padding-left: 0.2em;font-size: 10px; box-sizing: border-box; ">
            <section class="" style="display: inline-block;box-sizing: border-box;">
                <section class="" style="width: 3.3em;height: 3.3em;display: inline-block;vertical-align: top;margin-left: -0.2em;border-width: 3px;border-style: solid;border-color: white;margin-right: -3.3em;transform: rotate(0deg);border-radius: 100%;background-position: center center;background-repeat: no-repeat;background-size: cover;background-image: url(&quot;http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuDpDxPHXP0036Xcvqhpcp9Vayial9UQTndGJ1iagH4Wu17MeQ14YppIrw/0?wx_fmt=png&quot;);box-sizing: border-box;">
                    <section class="" style="width: 100%;height: 100%;overflow: hidden;box-sizing: border-box;">
                        <img class="" style="opacity: 0; box-sizing: border-box; width: 100% !important; height: auto !important; visibility: visible !important;" data-src="http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuDpDxPHXP0036Xcvqhpcp9Vayial9UQTndGJ1iagH4Wu17MeQ14YppIrw/0?wx_fmt=png" data-ratio="1" data-w="640" width="100%" data-type="png" _width="100%" src="http://st.vchangyi.com/yuanquan/course/default_banner_course_logo.png" data-fail="0"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                    </section>
                </section>
                <section style="padding-left: 3.4em;margin-top: -3em;border-radius: 1.5em;background-color: rgb(214, 240, 252);box-sizing: border-box;">
                    <section class="" style="display: inline-block;vertical-align: top;color: rgb(58, 55, 55);font-size: 16px;text-align: center;padding-right: 15px;padding-left: 10px;box-sizing: border-box;">
                        <p style="box-sizing: border-box;">
                            <strong style="box-sizing: border-box;">积分与勋章,激发员工主动性</strong>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        </p>
                    </section>
                </section>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style="  box-sizing: border-box; ">
            <section class="" style="font-size: 14px;line-height: 2;letter-spacing: 1px;padding-right: 1px;padding-left: 1px;box-sizing: border-box;">
                <p style="box-sizing: border-box;">
                    企业员工在完成课程学习、通过考试,积极参与问答后,可以获得积分或者勋章奖励。
                </p>
                <p style="box-sizing: border-box;">
                    积分可以在积分商城中兑换丰厚奖品,勋章彰显了员工的学习成果和能力,从而激励员工更加主动的去学习、去成长,为企业创造更高的效益。
                </p>
            </section>
        </section>
    </section>
    <section class="" style="  box-sizing: border-box; " powered-by="xiumi.us">
        <section class="" style=" text-align: center;margin-top: 10px;margin-bottom: 10px; box-sizing: border-box; ">
            <section class="" style="max-width: 100%;vertical-align: middle;display: inline-block;width: 35%;overflow: hidden !important;box-sizing: border-box;">
                <img data-src="http://mmbiz.qpic.cn/mmbiz_png/3TtZaOekb6NlkAVhyiaoqFppz9ckF3xxuVncrFncZlSphKaNNG1f9O7yyNwicpvnYW6WIfk11HBYIztclyhOlcNQ/0?wx_fmt=png" style="vertical-align: middle; box-sizing: border-box; width: 100% !important; height: auto !important; visibility: visible !important;" data-ratio="2.0949721" data-w="537" width="100%" data-type="png" _width="100%" class="" src="http://st.vchangyi.com/yuanquan/course/default_banner_course_5.png" data-fail="0"/>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            </section>
        </section>
    </section>
</section>',
            'update_time' => $this->nowTime,
            'domain' => $this->qyDomain,
            'status' => 1,
            'created' => $this->nowTime,
        ];
        // sql
        $sql = $this->_formatInsert('oa_course_source', $defaultData);
        $this->_exeSql($sql);

        // 默认数据 2
        $defaultData = [
            'source_title' => '员工如何进行课程学习',
            'source_key' => 'I' . rgmdate(MILLI_TIME, 'ymdHi') . rand(10, 99),
            'author' => '员圈小助手',
            'source_type' => 1,
            'is_download' => 1,
            'ea_id' => '',
            'ea_name' => '员圈小助手',
            'audio_imgs' => '',
            'content' => '<p style="text-align:center;line-height:150%"><strong><span style="font-size:21px;line-height:150%;font-family: &#39;微软雅黑&#39;,&#39;sans-serif&#39;">员工如何进行课程学习</span></strong></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;">&nbsp;</span></p><p style="line-height:150%"><strong><span style="line-height: 150%; font-family: 微软雅黑, sans-serif;">一、 <span style="font-variant-numeric: normal;font-weight: normal;font-stretch: normal;font-size: 9px;line-height: normal;font-family: &#39;Times New Roman&#39;">&nbsp;</span></span></strong><strong><span style="line-height: 150%; font-family: 微软雅黑, sans-serif;">功能简介</span></strong></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;">员工在手机上打开【员圈】系统,进入【课程中心】可以选择课程进行学习,获得进步与提升;还可以参与课后小测验,挑战自我,巩固学习成果。</span></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;">除此之外,员工完成指定的学习任务之后,还能 <strong><span style="color:red">获得积分或勋章奖励</span></strong>。 </span></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;">&nbsp;</span></p><p style="line-height:150%"><strong><span style="line-height: 150%; font-family: 微软雅黑, sans-serif;">二、 <span style="font-variant-numeric: normal;font-weight: normal;font-stretch: normal;font-size: 9px;line-height: normal;font-family: &#39;Times New Roman&#39;">&nbsp;</span></span></strong><strong><span style="line-height: 150%; font-family: 微软雅黑, sans-serif;">如何学习课程</span></strong></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;">打开【员圈】系统,进入【课程中心】,点击任意课程即可开始学习。</span></p><p style="line-height:150%"><span style="font-family: 微软雅黑, sans-serif;">(1) <span style="font-variant-numeric: normal;font-stretch: normal;font-size: 9px;line-height: normal;font-family: &#39;Times New Roman&#39;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="font-family: 微软雅黑, sans-serif;">课程类型有两种,分为单课程和系列课程,系列课程有多个素材内容,必须把全部内容学习完成才算学完;</span></p><p style="line-height:150%"><span style="font-family: 微软雅黑, sans-serif;">(2) <span style="font-variant-numeric: normal;font-stretch: normal;font-size: 9px;line-height: normal;font-family: &#39;Times New Roman&#39;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="font-family: 微软雅黑, sans-serif;">课程素材类型包括“图文/音图/视频/附件/外部链接”五种,附件支持在线预览学习。</span></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;"><img src="https://st.vchangyi.com/yuanquan/course/image01.png" title="image01.png" alt="image01.png"/></span></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;">(3)学习过课程内容之后,我们可以进行点赞、评论、收藏;为了保证课程内容的安全性,如果管理员开启了保密功能,则页面上将会有水印出现。 </span></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;"><img src="https://st.vchangyi.com/yuanquan/course/image02.png" title="image02.png" alt="image02.png"/></span></p><p style="line-height:150%"><strong><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;;color:red">小技巧:点赞和收藏可以通过再次点击按钮进行取消,自己发表的评论也可以删除。</span></strong></p><p style="line-height:150%"><strong><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;;color:red">&nbsp;</span></strong></p><p style="line-height:150%"><strong><span style="line-height: 150%; font-family: 微软雅黑, sans-serif;">三、 <span style="font-variant-numeric: normal;font-weight: normal;font-stretch: normal;font-size: 9px;line-height: normal;font-family: &#39;Times New Roman&#39;">&nbsp;</span></span></strong><strong><span style="line-height: 150%; font-family: 微软雅黑, sans-serif;">如何进行课后测试</span></strong></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;">如果课程设置了课后测试题目,那么必须答对全部题目才算真正完成了课程的学习,才有可能获得积分/勋章的奖励。</span></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;">(1)点击课程底部的“我要测试“按钮,开始答题;</span></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;"><img src="https://st.vchangyi.com/yuanquan/course/image03.png" title="image03.png" alt="image03.png"/></span></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;">(2)课后测试题目必须全部答对才算通过,如果有答错的,系统会提示重新答题;</span></p><p><img src="https://st.vchangyi.com/yuanquan/course/image04.jpg" title="image04.jpg" alt="image04.jpg"/></p><p style="line-height:150%"><span style="font-family:&#39;微软雅黑&#39;,&#39;sans-serif&#39;">(3)只有全部答对,才会显示通过通过测试,并且可能获得积分/勋章的奖励。</span></p><p style="line-height:150%"><img src="https://st.vchangyi.com/yuanquan/course/image05.png" title="image05.png" alt="image05.png"/></p><p><br/></p>',
            'update_time' => $this->nowTime,
            'domain' => $this->qyDomain,
            'status' => 1,
            'created' => $this->nowTime,
        ];
        // sql
        $sql = $this->_formatInsert('oa_course_source', $defaultData);
        $this->_exeSql($sql);
    }

    /**
     * 添加课程
     */
    private function _addCourse()
    {
        // 兼容多次操作
        $db = &Db::getInstance();
        $courseSql = "select * from `oa_course_article` WHERE `domain` = '{$this->qyDomain}'  and `status` < 3";
        $courseInfo = $db->query($courseSql);
        if (!empty($courseInfo)) {
            return;
        }

        // 分类
        $classSql = "select * from `oa_course_class` WHERE `class_name` = '办公技能' and `domain` = '{$this->qyDomain}'  and `status` < 3";
        $classInfo = $db->query($classSql);
        if (empty($classInfo)) {
            Log::record('---Add Course fail info:没有找到分类信息', Log::ERR);
            return;
        }

        // 后来发现顺序不对 但内容对的 就不更换 注释 和 命名了
        // 课程数据2
        $this->addCourseTwo($classInfo);
        // 课程数据1
        $this->addCourseOne($classInfo);

        return ;
    }

    /**
     * 添加 第一条 默认课程数据
     * @param $classInfo
     * @return bool
     */
    private function addCourseOne($classInfo)
    {
        $db = &Db::getInstance();

        $courseData = [
            'article_title' => '【系统预设】欢迎开启员圈,开始学习成长之旅',
            'article_type' => 1,
            'summary' => '员圈【课程中心】旨在帮助企业将最优质的培训内容跨时空的传递给员工伙伴,帮助员工系统化的成长;功能上,支持5种素材/2种课程类型/10余种特性,真正实现企业生态化赋能,提高经营管理效率,降低企业管理成本。',
            'is_show_cover' => 1,
            'is_secret' => 2,
            'is_share' => 1,
            'is_notice' => 1,
            'is_comment' => 2,
            'is_like' => 2,
            'is_recommend' => 2,
            'is_exam' => 1,
            'is_step' => 1,
            'course_type' => 1,
            'author' => '员圈小助手',
            'article_status' => 2,
            'class_id' => $classInfo[0]['class_id'],
            'cover_id' => 'course-install-pic',
            'cover_url' => 'https://st.vchangyi.com/yuanquan/course/default_banner_1.png',
            'strategy_setting' => 2,
            'strategys' => '',
            'source_type' => 1,
            'ea_id' => '',
            'ea_name' => '系统默认',
            'et_ids' => '',
            'update_time' => $this->nowTime,
            'data_id' => md5(sprintf('%s_%s_%s', QY_DOMAIN, APP_DIR, MILLI_TIME)),
            'content' => '',
            'status' => 1,
            'domain' => $this->qyDomain,
            'created' => $this->nowTime,
            'cm_id' => 0,
            'rand_num' => 0,
            'study_total' => 0,
            'unstudy_total' => 0,
            'comment_total' => 0,
            'like_total' => 0,
        ];
        $sql = $this->_formatInsert('oa_course_article', $courseData);
        $this->_exeSql($sql);
        // 章节数据
        $articleSql = "select * from `oa_course_article` WHERE `article_title` = '【系统预设】欢迎开启员圈,开始学习成长之旅' and `domain` = '{$this->qyDomain}'  and `status` < 3";
        $articleInfo = $db->query($articleSql);
        if (empty($articleInfo)) {
            Log::record('---Add Course fail info:没有找到课程数据', Log::ERR);
            return true;
        }
        $chapterData = [
            'article_id' => $articleInfo[0]['article_id'],
            'parent_id' => 0,
            'source_id' => 0,
            'chapter_name' => '章节',
            'et_ids' => '',
            'rand_num' => 0,
            'order' => 1,
            'domain' => $this->qyDomain,
            'status' => 1,
            'created' => $this->nowTime,
        ];
        $courseChapterSql = $this->_formatInsert('oa_course_article_chapter', $chapterData);
        $this->_exeSql($courseChapterSql);
        // 子章节数据
        $chapterSql = "select * from `oa_course_article_chapter` WHERE `article_id` = '{$articleInfo[0]['article_id']}' AND `domain` = '{$this->qyDomain}'  and `status` < 3";
        $chapterInfo = $db->query($chapterSql);
        if (empty($chapterInfo)) {
            Log::record('---Add Course fail info:没有找到章节数据', Log::ERR);
            return true;
        }
        $sourceSql = "select * from `oa_course_source` WHERE `source_title` = '欢迎开启员圈,开始学习成长之旅' AND `domain` = '{$this->qyDomain}'  and `status` < 3";
        $sourceInfo = $db->query($sourceSql);
        if (empty($sourceInfo)) {
            Log::record('---Add Course fail info:没有找到素材数据', Log::ERR);
            return true;
        }
        $chapterChildData = [
            'article_id' => $articleInfo[0]['article_id'],
            'parent_id' => $chapterInfo[0]['article_chapter_id'],
            'source_id' => $sourceInfo[0]['source_id'],
            'chapter_name' => '章节',
            'et_ids' => '',
            'rand_num' => 0,
            'order' => 1,
            'domain' => $this->qyDomain,
            'status' => 1,
            'created' => $this->nowTime,
        ];
        $chapterChildSql = $this->_formatInsert('oa_course_article_chapter', $chapterChildData);
        $this->_exeSql($chapterChildSql);
        // 课程权限数据
        $rightData = [
            'class_id' => $classInfo[0]['class_id'],
            'article_id' => $articleInfo[0]['article_id'],
            'award_id' => 0,
            'obj_type' => 1,
            'obj_id' => 2,
            'domain' => $this->qyDomain,
            'status' => 1,
        ];
        $rightSql = $this->_formatInsert('oa_course_right', $rightData);
        $this->_exeSql($rightSql);
        // 添加运营中心首页数据
        $this->_addRecommend($articleInfo[0]);
        // 添加运营中心 Banner
        $this->addBanner($courseData, $classInfo, $articleInfo);
    }

    /**
     * 添加 第二条 默认课程数据
     * @param $classInfo
     * @return bool
     */
    private function addCourseTwo($classInfo)
    {
        $db = &Db::getInstance();

        $courseData = [
            'article_title' => '【系统预设】员工如何进行课程学习',
            'article_type' => 1,
            'summary' => '员圈【课程中心】旨在帮助企业将最优质的培训内容跨时空的传递给员工伙伴,帮助员工系统化的成长;功能上,支持5种素材/2种课程类型/10余种特性,真正实现企业生态化赋能,提高经营管理效率,降低企业管理成本。',
            'is_show_cover' => 1,
            'is_secret' => 2,
            'is_share' => 1,
            'is_notice' => 1,
            'is_comment' => 2,
            'is_like' => 2,
            'is_recommend' => 2,
            'is_exam' => 1,
            'is_step' => 1,
            'course_type' => 1,
            'author' => '员圈小助手',
            'article_status' => 2,
            'class_id' => $classInfo[0]['class_id'],
            'cover_id' => 'course-install-pic',
            'cover_url' => 'https://st.vchangyi.com/yuanquan/course/default_banner_2.png',
            'strategy_setting' => 2,
            'strategys' => '',
            'source_type' => 1,
            'ea_id' => '',
            'ea_name' => '系统默认',
            'et_ids' => '',
            'update_time' => $this->nowTime,
            // 数据标识 +1 为了 跟上一个 区别开来
            'data_id' => md5(sprintf('%s_%s_%s', QY_DOMAIN, APP_DIR, MILLI_TIME + 1)),
            'content' => '',
            'status' => 1,
            'domain' => $this->qyDomain,
            'created' => $this->nowTime,
            'cm_id' => 0,
            'rand_num' => 0,
            'study_total' => 0,
            'unstudy_total' => 0,
            'comment_total' => 0,
            'like_total' => 0,
        ];
        $sql = $this->_formatInsert('oa_course_article', $courseData);
        $this->_exeSql($sql);
        // 章节数据
        $articleSql = "select * from `oa_course_article` WHERE `article_title` = '【系统预设】员工如何进行课程学习' and `domain` = '{$this->qyDomain}'  and `status` < 3";
        $articleInfo = $db->query($articleSql);
        if (empty($articleInfo)) {
            Log::record('---Add Course fail info:没有找到课程数据', Log::ERR);
            return true;
        }
        $chapterData = [
            'article_id' => $articleInfo[0]['article_id'],
            'parent_id' => 0,
            'source_id' => 0,
            'chapter_name' => '章节',
            'et_ids' => '',
            'rand_num' => 0,
            'order' => 1,
            'domain' => $this->qyDomain,
            'status' => 1,
            'created' => $this->nowTime,
        ];
        $courseChapterSql = $this->_formatInsert('oa_course_article_chapter', $chapterData);
        $this->_exeSql($courseChapterSql);
        // 子章节数据
        $chapterSql = "select * from `oa_course_article_chapter` WHERE `article_id` = '{$articleInfo[0]['article_id']}' AND `domain` = '{$this->qyDomain}'  and `status` < 3";
        $chapterInfo = $db->query($chapterSql);
        if (empty($chapterInfo)) {
            Log::record('---Add Course fail info:没有找到章节数据', Log::ERR);
            return true;
        }
        $sourceSql = "select * from `oa_course_source` WHERE `source_title` = '员工如何进行课程学习' AND `domain` = '{$this->qyDomain}'  and `status` < 3";
        $sourceInfo = $db->query($sourceSql);
        if (empty($sourceInfo)) {
            Log::record('---Add Course fail info:没有找到素材数据', Log::ERR);
            return true;
        }
        $chapterChildData = [
            'article_id' => $articleInfo[0]['article_id'],
            'parent_id' => $chapterInfo[0]['article_chapter_id'],
            'source_id' => $sourceInfo[0]['source_id'],
            'chapter_name' => '章节',
            'et_ids' => '',
            'rand_num' => 0,
            'order' => 1,
            'domain' => $this->qyDomain,
            'status' => 1,
            'created' => $this->nowTime,
        ];
        $chapterChildSql = $this->_formatInsert('oa_course_article_chapter', $chapterChildData);
        $this->_exeSql($chapterChildSql);
        // 课程权限数据
        $rightData = [
            'class_id' => $classInfo[0]['class_id'],
            'article_id' => $articleInfo[0]['article_id'],
            'award_id' => 0,
            'obj_type' => 1,
            'obj_id' => 2,
            'domain' => $this->qyDomain,
            'status' => 1,
        ];
        $rightSql = $this->_formatInsert('oa_course_right', $rightData);
        $this->_exeSql($rightSql);
        // 添加运营中心 Banner
        $this->addBanner($courseData, $classInfo, $articleInfo);
    }

    // 营运中心首页
    private function _addRecommend($articleInfo)
    {
        $db = &Db::getInstance();
        $recommendSql = "select `recommender_id` from `oa_common_recommender` WHERE `status` < 3 ORDER BY `recommender_id` DESC LIMIT 1";
        $recommendNum = $db->query($recommendSql);

        // 首页推荐数据
        $defaultData = [
            'type' => 3,
            'displayorder' => $recommendNum[0]['recommender_id'] + 1,
            'hide' => 1,
            'system' => 2,
            'title' => $articleInfo['article_title'],
            'attach_id' => $articleInfo['cover_id'],
            'pic' => $articleInfo['cover_url'],
            'url' => 'Course/Frontend/Index/Detail/Index?article_id=' . $articleInfo['article_id'] . '&data_id=' . $articleInfo['data_id'] . '&article_type=' . $articleInfo['article_type'],
            'description' => $articleInfo['summary'],
            'app_dir' => 'Course',
            'app_identifier' => APP_IDENTIFIER,
            'data_id' => $articleInfo['article_id'],
            'data_category_id' => $articleInfo['class_id'],
            'data_type' => '图文',
            'data' => '',
            'dateline' => $articleInfo['update_time'],
            'adminer_id' => '',
            'adminer' => '员圈小助手',
            'domain' => $this->qyDomain,
            'status' => 1,
            'created' => $this->nowTime,
        ];
        $defaultSql = $this->_formatInsert('oa_common_recommender', $defaultData);
        $this->_exeSql($defaultSql);

        // 添加权限数据
        $recommendSql = "select * from `oa_common_recommender` WHERE `title` = '{$articleInfo['article_title']}' and `domain` = '{$this->qyDomain}'  and `status` < 3";
        $recommendInfo = $db->query($recommendSql);
        if (empty($recommendInfo)) {
            Log::record('---Add Course fail info:没有找到推荐数据', Log::ERR);
            return;
        }
        $rightData = [
            'recommender_id' => $recommendInfo[0]['recommender_id'],
            'obj_type' => 1,
            'obj_id' => -1,
            'type' => 3,
            'displayorder' => $recommendNum[0]['recommender_id'] + 1,
            'hide' => 1,
            'system' => 2,
            'app_dir' => 'Course',
            'app_identifier' => APP_IDENTIFIER,
            'data_id' => $articleInfo['article_id'],
            'data_category_id' => $articleInfo['class_id'],
            'dateline' => $articleInfo['update_time'],
            'adminer_id' => '',
            'adminer' => '员圈小助手',
            'domain' => $this->qyDomain,
            'status' => 1,
            'created' => $this->nowTime,
        ];
        $rightSql = $this->_formatInsert('oa_common_recommender_right', $rightData);
        $this->_exeSql($rightSql);
    }

    const TYPE_BANNER = 1;
    const VALUE_DISPLAYORDER_MIN = 1;
    const HIDE_NO = 1;
    const SYSTEM_NO = 2;

    /**
     * 添加运营中心 Banner
     */
    private function addBanner($courseData, $classInfo, $articleInfo)
    {
        $banner = [
            'type' => self::TYPE_BANNER,
            'displayorder' => self::VALUE_DISPLAYORDER_MIN,
            'hide' => self::HIDE_NO,
            'system' => self::SYSTEM_NO,
            'title' => $courseData['article_title'],
            'attach_id' => $courseData['cover_id'],
            'pic' => $courseData['cover_url'],
            'url' => 'Course/Frontend/Index/Detail/Index?article_id=' . $articleInfo[0]['article_id'] . '&data_id=' . $courseData['data_id'] . '&article_type=1',
            'description' => '',
            'app_dir' => 'Course',
            'app_identifier' => APP_IDENTIFIER,
            'data_id' => $articleInfo[0]['article_id'],
            'data_category_id' => $articleInfo[0]['class_id'],
            'data' => serialize([[
                'id' => $classInfo[0]['class_id'],
                'name' => $classInfo[0]['class_name'],
                'upId' => 0,
                'url' => frontUrl('/app/page/course/list/list', ['class_id' => $classInfo[0]['class_id']], 'Course'),
            ]]),
            'dateline' => MILLI_TIME,
            'adminer_id' => '',
            'adminer' => '员圈小助手',
            'domain' => $this->qyDomain,
            'status' => 1,
            'created' => $this->nowTime
        ];

        $defaultSql = $this->_formatInsert('oa_common_recommender', $banner);
        $this->_exeSql($defaultSql);

        // 更新 displayorder
        $id = Db::getInstance()->getLastLinkID()->lastInsertId();
        $this->_exeSql("UPDATE `oa_common_recommender` SET `displayorder` = {$id} WHERE `recommender_id` = {$id}");
    }

    /**
     * 根据数组数据格式化为添加sql语句
     * @author tangxingguo
     * @param string $tableName 表名
     * @param array $data 数据
     * @return string|void
     */
    private function _formatInsert($tableName, $data)
    {
        if (empty($data) && !is_array($data)) {
            return;
        }

        // 拼接sql
        $sql = "INSERT INTO `{$tableName}` ";
        $keys = "(";
        $values = "(";
        foreach ($data as $k => $v) {
            if (array_slice($data, -1, 1) == [$k => $v]) {
                $symbol = "";
            } else {
                $symbol = ",";
            }
            $keys .= "`{$k}`{$symbol} ";
            if (is_numeric($v)) {
                $values .= "{$v}{$symbol} ";
            } else {
                $values .= "'{$v}'{$symbol} ";
            }
        }
        $keys .= ") VALUES ";
        $values .= ");";

        $sql .= $keys . $values;

        return $sql;
    }
}