<?php
namespace app\admin\controller\life;

use app\admin\controller\BaseController;
use app\admin\server\life\FarmLandServer;

class FarmLand extends BaseController
{

    /**
     * Notes:获取地块列表
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/17
     */
    public function getlandList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $result         = FarmLandServer::getlandList($page, $limit, $keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:获取所有
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/17
     */
    public function getlandAll()
    {
        $result         = FarmLandServer::getlandAll();
        return json_success($result, '成功');
    }

    /**
     * Notes:修改地块
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/17
     */
    public function updateland()
    {
        $land_id      = $this->request->post('land_id');
        $land_name    = $this->request->post('land_name');
        $land_price = $this->request->post('land_price');
        $land_longitude = $this->request->post('land_longitude');
        $land_latitude = $this->request->post('land_latitude');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\FarmLandValidate', ['land_id' => $land_id], 'update');
        $result       = FarmLandServer::updateland($land_id, $land_name, $land_price, $land_longitude, $land_latitude, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除地块
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/17
     */
    public function delland()
    {
        $land_id = $this->request->get('land_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\FarmLandValidate', ['land_id' => $land_id], 'info');
        $result         = FarmLandServer::delland($land_id,$admin_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }

    /**
     * Notes:添加地块
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/17
     */
    public function addland()
    {
        $land_name    = $this->request->post('land_name');
        $land_price = $this->request->post('land_price');
        $land_longitude = $this->request->post('land_longitude');
        $land_latitude = $this->request->post('land_latitude');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\FarmLandValidate', ['land_name' => $land_name, 'land_price' => $land_price, 'land_longitude' => $land_longitude, 'land_latitude' => $land_latitude], 'create');
        $result         = FarmLandServer::insertland($land_name, $land_price, $land_longitude, $land_latitude, $admin_id);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询地块详情
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/17
     */
    public function landInfo()
    {
        $land_id = $this->request->get('land_id');
        $this->validateCheck('life\FarmLandValidate', ['land_id' => $land_id], 'info');
        $result         = FarmLandServer::landInfo($land_id);
        return json_success($result, '成功');
    }


}
