<?php
namespace app\adminapi\controller;

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

class ContactController extends BaseController
{    
    public function getContactList(Request $request)
    {
        $param = $request->post();
        $page       = isset($param['page']) ? $param['page'] : 1;
        $pageSize   = isset($param['pageSize']) ? $param['pageSize'] : 10;
        $search     = isset($param['search']) ? $param['search'] : [];

        $where = [
        ];

        $list = Db::name('contact')
            ->where($where)
            ->order('id', 'desc')
            ->page($page, $pageSize)
            ->select()
            ->toArray();

        $total = Db::name('contact')
            ->where($where)
            ->count();

        foreach($list as $key => $val){

        }

        $result = [
            'list' => $list,
            'total' => $total
        ];

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

    public function deleteContact(Request $request){
        $id = $request->get('id');

        try{
            $result = Db::name('contact')
            ->where('id',$id)
            ->delete();
    
            AdminLog($this->uid, '刪除聯絡內容 ['. $id .']');
            return $this->Success('操作成功');    
        }catch(\Exception $e){
            AdminLog($this->uid, '刪除聯絡內容 ['.$id.'] 失敗');
            return $this->Error('操作失敗');                
        }
    }


}