<?php
/**
 * @link      http://www.u-bo.com
 * @copyright 南京友博网络科技有限公司 
 * @license   http://www.u-bo.com/license/
 */

namespace console\controllers;

use Yii;
use yii\helpers\Console;

/**
 * 应用控制器
 * 
 * @author legendjw http://blog.u-bo.com
 * @since 0.1
 */
class AppController extends \yii\console\Controller
{
    /**
     * 初始化应用
     */
    public function actionInit()
    {
        $this->stdout("开始初始化项目...\n", Console::FG_RED);
        $modules = ['common', 'home', 'qcbase', 'wap'];
        //创建缓存目录
        foreach ($modules as $module) {
            $runtimePath = Yii::getAlias('@'. $module) . '/runtime';
            if (file_exists($runtimePath)) {
                rmdir($runtimePath);
            }
            if (mkdir($runtimePath, 0777)) {
                chmod($runtimePath, 0777);
                $this->stdout("创建{$runtimePath}成功...\n", Console::FG_BLUE);
            }
            else {
                $this->stdout("创建{$runtimePath}失败!\n", Console::FG_RED);
            }
        }
        
        return 0;
    }

    public function actionTest()
    {
        $this->stdout("你好...\n", Console::FG_RED);
        $this->stdout("你好...\n", Console::FG_BLUE);
    }

    public function actionZysj()
    {
        $this->stdout("开始转移数据...\n", Console::FG_RED);
        for($i = 1; $i <= 10; $i++) {
            /**
             * 具体逻辑
             */
            sleep(1);
            $this->stdout("已转移第{$i}条数据...\n", Console::FG_BLUE);
        }
        if ($this->confirm('是否要退出？')) {
            $this->stdout("你选择了是!!退出了...\n");
        }
        else {
            $this->stdout("你没有退出!!那就来玩个游戏吧？\n");
            $this->stdout("你多大了？\n", Console::FG_RED);
            $age = Console::stdin();
            if ($age > 18) {
                $this->stdout("你好老！！！不玩了...\n", Console::FG_RED);
            }
            else {
                $this->stdout("哎呀我喜欢呀!!!小鲜肉...\n", Console::FG_YELLOW);
            }
        }
    }

}
