<?php
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;

class Company extends Base
{
    protected $middleware = ['app\middleware\CheckValidata::class'];

    //公司详情
    public function companyDetail()
    {
        $where['company_id'] = Request::param('id');
        $data = Db::name('company')->where($where)->find();
        return $this->returnJson($data);
    }

    //编辑公司信息
    public function companyEdit(){
        $where['company_id'] =1;
        $data['company_name'] = Request::param('company_name');
        $data['province_id'] = Request::param('province_id');
        $data['city_id'] = Request::param('city_id');
        $data['area_id'] = Request::param('area_id');
        $data['province_name'] = Request::param('province_name');
        $data['city_name'] = Request::param('city_name');
        $data['area_name'] = Request::param('area_name');
        $data['address'] = Request::param('address');
        $data['phone'] = Request::param('phone');
        $res = Db::name('company')->where($where)->update($data);
        return $this->returnJson([],'修改成功!');
    }

    //编辑招商信息
    public function changeBusInfo()
    {
        $save['address'] = Request::param('address');
        $save['place'] = Request::param('place');
        $save['content'] = json_encode(Request::param('content'));
        $save['day'] = Request::param('day');
        $save['week'] = Request::param('week');
        $save['time_quantum'] = Request::param('time_quantum');
        $res = Db::name('bus')->where(['id'=>1])->update($save);
        if($res !== false) {
           return $this->returnJson([],'修改成功!');
        } else{
           return  $this->returnJson([],'修改失败!',400);
        }
    }

    //获取招商信息
    public function getBusInfo()
    {
        $res = Db::name('bus')->where(['id'=>1])->find();
        if($res['content']) {
            $res['content'] = json_decode($res['content'],true);
        } else {
            $res['content'] = [];
        }
        return $this->returnJson($res);

    }




}