<?php

namespace App\Modules\Activity\Services;

use App\Modules\Activity\Models\Activity;
use App\Modules\Activity\Models\ActivitySwitch;
use App\Modules\Statistic\Services\WapVisitStatService;
use App\Modules\Subscribe\Models\Order;
use App\Modules\Trade\Services\OrderService;
use DB;
use Redis;

class ActivitySwitchService
{
    /**
     * 更新活动控制开关
     * @param $activity_id
     * @param $params
     * @return mixed
     */
    static function updateShowSwitch($activity_id, $distribution_channel_id, $is_reader_page_show, $is_sign_message_show)
    {
        return ActivitySwitch::updateShowSwitch($activity_id, $distribution_channel_id, $is_reader_page_show, $is_sign_message_show);
    }

    /**
     * 更新活动控制开关
     * @param $activity_id
     * @param $params
     * @return mixed
     */
    static function add($data)
    {
        return ActivitySwitch::add($data);
    }

    /**
     * 获取活动开关信息
     * @param $activity_id
     * @param $distribution_channel_id
     * @return mixed
     */
    static function getInfo($activity_id, $distribution_channel_id)
    {
        return ActivitySwitch::getInfo($activity_id, $distribution_channel_id);
    }

    /**
     * 活动展示情况
     * @param $activity_id
     * @param $distribution_channel_id
     * @param string $type
     * @return int
     */
    static function isShowInPage($activity_id,$distribution_channel_id,$type='reader'){
        $info = self::getInfo($activity_id,$distribution_channel_id);
        if(!$info){
            //默认显示
            return 1;
        }
        if($type == 'reader'){
            return $info->is_reader_page_show;
        }

        if($type == 'sign'){
            return $info->is_sign_message_show;
        }
        return 1;
    }
}
