<?php


namespace App\Http\Controllers\Api;


use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class NoticeController
{
    public function systemMaintenance()
    {
        $list = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'SUSPENSION_NOTICE')->where('StatusValue', 1)->first();
        return apiReturnSuc($list);
    }

    // 大厅活动公告
    public function hallAnnouncement()
    {
        $list = DB::connection('write')->table('QPAccountsDB.dbo.HallNotice')
            ->where('Status', 1)
            ->orderByDesc('Sort')
            ->get();

        foreach ($list as &$value){
            $value->Title = base64_decode($value->Title);
            if ($value->Type == 1) $value->Content = base64_decode($value->Content);
        }
        return apiReturnSuc($list);
    }

    // 大厅活动公告-- 详情
    public function hallAnnouncementInfo($ID)
    {
        $info = DB::connection('write')->table('QPAccountsDB.dbo.HallNotice')
            ->where('Status', 1)
            ->where('ID', $ID)
            ->first();
        $info->Title = base64_decode($info->Title);
        if ($info->Type == 1) $info->Content = base64_decode($info->Content);
        return apiReturnSuc($info);
    }

    // 试玩场提醒
    public function remind(Request $request)
    {
        $UserID = $request->UserID ?: '';

        $config = config('games.remind');

        $first = DB::connection('read')->table('QPAccountsDB.dbo.UserTabData')
            ->where('UserID', $UserID)
            ->where('RMInning', '>=', $config['contact_limit'])
            ->first();

        $State = 1;     // 需要提示

        if ($first) {
            $State = 0; // 不需要提示
        }

        $dayCount = $config['dayCount'];
        $limitCount = $config['limitCount'];

        $data = compact('State', 'dayCount', 'limitCount');
        return apiReturnSuc($data);
    }
}

