<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 应用配置
 */
namespace app\citys\controller;
use app\citys\model\CitysConfig;

class Setting extends Common{

   
    /**
     *  同城信息配置
     * @return void
     */
    public function info(){
        if(request()->isAjax()){
            $data = [
                'today'  => $this->request->param('today/a'),
                'money'  => $this->request->param('money/a'),
                'vip'    => $this->request->param('vip/d'),
                'charge' => $this->request->param('charge/d'),
                'phone'  => $this->request->param('phone/f',0),
                'mch_id' => $this->request->param('mch_id/d',0),
            ];
            $validate = $this->validate($data,'info.config');
            if(true !== $validate){
                return json(['code'=>0,'msg'=>$validate]);
            }
            if(empty($data['today'])){
                return json(['code'=>0,'msg'=>'请设置城市号配置']);
            }
            $result =  CitysConfig::edit($data,$this->member_miniapp_id);
            if($result){
                return json(['code'=>200,'data' => ['url' => url('setting/info')],'msg'=>'操作成功']);
            }else{
                return json(['code'=>0,'msg'=>'操作失败']);
            }
        }else{
            $view['config'] = CitysConfig::Config($this->member_miniapp_id);
            $view['pathMaps'] = [['name' =>'推广设置','url' => url("citys/setting/info")]];
            $view['tabs']  = [
                ['name' =>'主题管理','url' =>url('citys/cate/index')],
                ['name' =>'模板库','url' =>url('citys/tpl/index')],
                ['name' =>'应用设置','url' =>url('citys/setting/info'),'action' => 1],
            ];
            return view()->assign($view);
        }
    } 
}