InstallController.class.php 8.1 KB
<?php
/**
 * 套件应用安装初始化数据
 * 活动中心
 * User: yingcai
 * Date: 2017/11/22
 * Time: 下午12:12
 */

namespace Rpc\Controller\Common;

use Common\Common\User;
use Common\Service\ActivityService;
use VcySDK\Attach;
use VcySDK\Exception;
use VcySDK\Service;

class InstallController extends AbstractController
{
    public function Index()
    {
        $activity_serv = new ActivityService();
        // 是否已经有默认数据
        $default_data = $activity_serv->get_by_conds([]);
        if (!$default_data) {
            $result = [];
            // 上传封面图片
            $attach = new Attach(Service::instance());
            try {

                $picFile = CODE_ROOT . DIRECTORY_SEPARATOR . "www/static/img/activity/default_cover.jpeg";
                $fileData = [
                    'file' => [
                        'name' => QY_DOMAIN . "default_cover.jpeg",
                        'type' => mime_content_type($picFile),
                        'size' => filesize($picFile),
                        'tmp_name' => $picFile,
                    ],
                ];
                $result = $attach->upload([
                    'atMediatype' => Attach::TYPE_IMG,
                ], $fileData);

            } catch (Exception $e) {
                \Think\Log::record('setDefaultMedal 方法内错误:::' . $e->getMessage());
            } catch (\Exception $e) {
                \Think\Log::record('setDefaultMedal 方法内错误:::' . $e->getMessage());
            }

            $userServ = &User::instance();
            $result_user = $userServ->listBasicByConds([], 1, 1);
            $unjoin_total = $result_user['total'];

            // 写入默认数据
            $data = [
                'subject' => '【系统预设】真假学霸PK│快来晒出你的考试成绩!',
                'source' => '员圈小助手',
                'cover_id' => $result['atId'],
                'begin_time' => MILLI_TIME,
                'end_time' => 1917014400000,
                'is_all' => 1,
                'activity_status' => 1,
                'publish_time' => MILLI_TIME,
                'last_time' => MILLI_TIME,
                'is_recomend' => 1,
                'join_total' => 0,
                'unjoin_total' => $unjoin_total,
                'content' => serialize('<p class="p2" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><br/></p><p class="p2" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">这次,我们晒点不一样的?</p><p class="p2" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">正所谓,成绩单是检验真假学霸的唯一标准</p><p class="p2" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">接下来,请学霸们赶紧来切磋一下吧!</p><p class="p1" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><br/></p><p class="p2" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">本次活动主题:真假学霸大<span class="s1" style="line-height: 1.5;">PK</span></p><p class="p2" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">请在回帖中晒出一张使用本系统进行考试的成绩单</p><p class="p2" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">获得点赞最多的前三名将会获得积分奖励!</p><p class="p2" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">快来参与吧!</p><p class="p1" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><br/></p><p class="p2" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);">注:此活动为预设内容,旨在帮助使用者熟悉了解活动应用。</p><p class="p2" style="margin-top: 0px; margin-bottom: 1em; padding: 0px; line-height: 1.5; color: rgb(54, 59, 66); font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;Lantinghei SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255);"><br/></p>'),
            ];

            $ac_id = $activity_serv->insert($data);

            if ($ac_id) {
                // 首页feed流推荐
                $feed_right = [];
                $url = rpcUrl('/Public/Rpc/Recommender/ArticleUpdate');
                $data_send = [
                    'app' => APP_DIR,
                    'dataCategoryId' => '',
                    'dataId' => $ac_id,
                    'title' => $data['subject'],
                    'summary' => $data['content'],
                    'attachId' => $data['cover_id'],
                    'pic' => imgUrlReal($data['cover_id']),
                    'url' => 'Activity/Frontend/Index/Msg?type=1&id=' . $ac_id,
                    'endTime' => $data['end_time'],
                    'right' => $feed_right
                ];

                \Com\Rpc::phprpc($url)->invoke('Index', $data_send);
            }
        }
    }
}