<?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\CitysPage;
use think\facade\Request;

class Page extends Common {

    public function initialize() {
        parent::initialize();
        $this->assign('pathMaps', [['name'=>'权益声明','url'=>'javascript:;']]);
    }
    /**
     * 免责申明
     */
    public function index(){
        $companyInfo = CitysPage::where($this->mini_program)->find();
        $this->assign('companyInfo',$companyInfo);
        return $this->fetch();
    }
    /**
     * 关于我们
     */
    public function about(){
        $companyInfo = CitysPage::where($this->mini_program)->find();
        $this->assign('companyInfo',$companyInfo);
        return $this->fetch();
    }
    /**
     * 服务协议
     */
    public function agreement(){
        $companyInfo = CitysPage::where($this->mini_program)->find();
        $this->assign('companyInfo',$companyInfo);
        return $this->fetch();
    }
    /**
     * 防骗警示
     */
    public function fraud(){
        $companyInfo = CitysPage::where($this->mini_program)->find();
        $this->assign('companyInfo',$companyInfo);
        return $this->fetch();
    }

    /**
     * 客服电话
     */
    public function tel(){
        $companyInfo = CitysPage::where($this->mini_program)->find();
        $this->assign('companyInfo',$companyInfo);
        return $this->fetch();
    }
    
    /**
     * 信息修改
     */
    public function update(){
        if(Request::instance()->isPost()){
            switch ($this->request->param('type/d')) {
                case 1:
                    $data['disclaimer'] = $this->request->param('disclaimer');
                    break;
                case 2:
                    $data['about'] = $this->request->param('about');
                    break;
                case 3:
                    $data['agreement'] = $this->request->param('agreement');
                    break;
                case 4:
                    $param['title'] = $this->request->param('title/a');
                    $param['phone'] = $this->request->param('phone/a');
                    $phone = [];
                    foreach ($param['title'] as $key => $value) {
                        $phone[$key]['title'] = $value;
                        $phone[$key]['phone'] = $param['phone'][$key] ?: 0;
                    }
                    $data['phone']    = $phone;
                    break;
                case 5:
                    $data['fraud'] = $this->request->param('fraud');
                    break;
                default:
                    return enjson(401,'设置失败');
                    break;
            }
            $res = CitysPage::where($this->mini_program)->find();
            if($res){
                $res = CitysPage::where($this->mini_program)->update($data);
            }else{
                $data['member_miniapp_id'] = $this->member_miniapp_id;
                $res = CitysPage::create($data);
            }
            return enjson($res?200:0);
        }
    }
}