<?php

namespace app\admin\controller\ContactUs;

use app\BaseController;
use app\common\model\ContactUs\ContactInfo as ModelContactInfo;
use app\Request;
use think\Validate;
use think\exception\ValidateException;
use think\facade\Filesystem;
use app\common\exception\Tool;


class ContactInfo extends BaseController
{
    /**
     * 获取联系方式内容
     */
    public function getContactInfo(Request $request): array
    {
        $params = $request->param();

        $query = ModelContactInfo::field([
            'contact_info_id',
            'contact_info_guid',
            'contact_info_location',
            'longitude',
            'latitude',
            'contact_info_content',
        ])->where(1)->find();

        return [
            'code' => 0,
            'data' => $query,
            'msg' => 'ok'
        ];
    }

    /**
     * 编辑联系方式
     */
    public function editContactInfo(Request $request): array
    {
        $params = $request->param();
        $this->validate($params, [

            'contact_info_content|联系我们简介' => 'require',
        ]);
        $model = ModelContactInfo::where(1)->find();
        $model->allowField([
            'contact_info_update_user_guid',
            'contact_info_location',
            'longitude',
            'latitude',
            'contact_info_content',
        ])->save($params);
        return msg('编辑成功!');
    }
}
