<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/3/9
 * Time: 上午11:56
 */
namespace console\controllers;

use common\helpers\Cache;
use common\helpers\Form;
use common\models\forms\ConfigPeriodForm;
use common\models\forms\ShopGoodsForm;
use common\models\LogAsync;
use yii\db\Exception;

class ConfigController extends BaseController
{
    /**
     * 更新期数
     * @param $taskKey
     * @throws Exception
     */
    public function actionUpdatePeriod($taskKey){
        $params = Cache::getAsyncParams($taskKey);
        $formModel = new ConfigPeriodForm();
        if($formModel->load($params, '') && $formModel->updateAsync()){
            \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "更新期数配置成功");
        } else {
            \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "更新期数配置失败,原因：".Form::formatErrorsForApi($formModel->getErrors()), false);
        }
    }

    /**
     * 更新汇率
     * @param $taskKey
     * @throws Exception
     */
    public function actionUpdateExchangeRate($taskKey)
    {
        $params = Cache::getAsyncParams($taskKey);
        $formModel = new ShopGoodsForm();
        if ($formModel->load($params, '') && $formModel->updateAsync($params['currencyId'])) {
            \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "更新汇率配置成功");
        } else {
            \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "更新汇率配置失败,原因：".Form::formatErrorsForApi($formModel->getErrors()), false);
        }
    }
}