<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 联盟城市
 */
namespace app\ais\controller\admin;
use app\common\controller\Admin;
use app\ais\model\AisCity;
use think\facade\Validate;

class City extends Admin{


    /**
     * 列表
     */
    public function index(){
        $view['parent_id'] = $this->request->param('parent_id/d',0);
        $view['pathMaps']  = AisCity::selectPath($view['parent_id']);  
        $view['lists']     = AisCity::where(['parent_id' => $view['parent_id']])->order('sort asc,id asc')->paginate(20);
        $this->view->engine->layout('admin/layout');
        return view()->assign($view);
    }
    
    /**
     * 排序
     */
    public function sort(){
        if(request()->isAjax()){
            $param = [
                'sort' => $this->request->param('sort/d',0),
                'id'   => $this->request->param('id/d'),
            ];
            $validate = $this->validate($param,'Category.sort');
            if(true !== $validate){
                return json(['code'=>0,'msg'=>$validate]);
            }
            $result = AisCity::where(['id'=>$param['id']])->update(['sort' => $param['sort']]);
            if($result){
                return enjson(200);
            }
            return enjson(0);
        }
    }
}