<?php
/**
 * Author: luzheng.liu
 * Time: 2020/10/27 23:19
 */

namespace app\index\controller;


use app\index\BaseController;
use app\index\model\SettingModel;
use app\common\until\Until;
use think\Request;

class Setting extends BaseController {

    /**
     * 显示指定的资源
     *
     * @param int $id
     * @return \think\Response
     */
    public function read() {
        $model = new SettingModel();
        $data = $model::where(['id' => 1])->find();
        Until::output(['info' => Until::modelToArray($data)]);
    }

    /**
     * 保存更新的资源
     *
     * @return \think\Response
     */
    public function update() {
        $input = Until::getInput();
        $rule = [
            'site_id'                 => 'require',
            'unique_key'              => 'require',
            'domain|域名'               => 'require',
            'channel_id|频道id'         => 'require',
            'channel_auth_code|频道授权码' => 'require',
            'redirct_url|跳转链接'        => 'require',
        ];
        Until::check($rule, $input);
        (new SettingModel())::where(['id' => 1])->update([
            'site_id'           => $input['site_id'],
            'unique_key'        => $input['unique_key'],
            'domain'            => $input['domain'],
            'channel_id'        => $input['channel_id'],
            'channel_auth_code' => $input['channel_auth_code'],
            'redirct_url'       => $input['redirct_url'],
        ]);
        Until::output(['id' => $input['id']]);
    }


}