<?php
namespace app\appapi\controller;

use app\appapi\BaseController;
use support\Request;
use think\facade\Db;

class ContactController extends BaseController
{
    public function getBranchList(Request $request)
    {
        $param = $request->get();
        // $where[] = ['lang', $param['lang']];

        $list = Db::name('branch')
            ->where('lang',$param['lang'])
            ->order('sort_order', 'asc')
            ->order('id', 'asc')
            ->select()
            ->toArray();

        return $this->Success($list);
    }

    public function addContact(Request $request)
    {
        $param = $request->post();
        // $where[] = ['lang', $param['lang']];
        $data = [
            'company' => $param['company'],
            'name' => $param['name'],
            'tel' => $param['tel'],
            'email' => $param['email'],
            'content' => $param['content'],
        ];

        try{
            Db::name('contact')
            ->insert($data);

            return $this->Success('新增成功');
        }catch(\Exception $e){
            return $this->Error('新增失败');
        }

    }

}
