<?php
/**
 * Created by PhpStorm.
 * User: z-yang
 * Date: 2020/10/27
 * Time: 15:22
 */

namespace App\Console\Commands\Tool;

use DB;
use Redis;
use Illuminate\Console\Command;

class ConfigSetting extends Command
{

    const SPLIT_BOOK_PRIMARY_CHAPTER_NAME = 'config:split_book_primary_chapter_name';

    const INNER_SITE_ACTIVITY = 'config:inner_site_activity';

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'Tool:ConfigSetting';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '站点配置';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }


    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->splitBookShowPrimaryConfig();
        $this->innerActivity();
    }

    //切割章节后，章节名的显示配置
    private function splitBookShowPrimaryConfig(){
        $sql = "SELECT id FROM distribution_channels WHERE channel_user_id IN (SELECT id FROM channel_users WHERE phone in (
'18668420256'))";
        $result = DB::select($sql);
        foreach ($result as $item){
            Redis::sadd(self::SPLIT_BOOK_PRIMARY_CHAPTER_NAME,$item->id);
        }
    }

    //内部活动
    private function innerActivity(){
         $sql = "SELECT id FROM distribution_channels WHERE channel_user_id IN (SELECT id FROM channel_users WHERE phone in (
'18668420256'))";
        $result = DB::select($sql);
        foreach ($result as $item){
            if(in_array($item->id, [])){
                continue;
            }
            Redis::sadd(self::INNER_SITE_ACTIVITY,$item->id);
        }
    }
}