<?php
namespace app\admin\controller;
use think\App;
use think\facade\Session;
use think\facade\View;
use think\facade\Request;
 
class images extends Base{

	//Images首页
    public function index(){
		$tdata=Request::param();
		$info['pid']=$tdata['pid'];
		$info['typename']=tq_value($tdata['pid'],'title','images_type');

		View::assign(['info'=>$info]);
		return View::fetch();
    }

    public function add(){
		$tdata=Request::param();
		$sort=\app\admin\model\Images::where('pid',$tdata['pid'])->order('sort desc')->limit(1)->select();
		if($sort->isEmpty()){
			$sort=1;
		}else{
			$sort=$sort[0]['sort']+1;
		}
		
		View::assign(['pid'=>$tdata['pid'],'sort'=>$sort]);
		return View::fetch();
    }
	
    public function create(){
		IS_AJAX(Request::isAjax());
		$tdata=Request::param();
		if(trim($tdata['title']=='')){
			$data =['type' =>1,'msg' =>'请填写标题'];
			return json($data);
		}
		
		//插入数据
		$images_id=\app\admin\model\Images::strict(false)->insertGetId($tdata);
		
		$data =['type' =>2,'msg' =>'添加成功'];
		return json($data);
    }

    public function edit(){
		$tdata=Request::param();
		$info=\app\admin\model\Images::where('id',$tdata['id'])->find()->toArray();
		
		View::assign(['pid'=>$tdata['pid'],'info'=>$info]);
		return View::fetch();
    }

    public function update(){
		IS_AJAX(Request::isAjax());
		$tdata=Request::param();
		if(trim($tdata['title']=='')){
			$data =['type' =>1,'msg' =>'请填写标题'];
			return json($data);
		}
		$images_id=\app\admin\model\Images::strict(false)->update($tdata);
		
		$data =['type' =>2,'msg' =>'修改成功'];
		return json($data);
	}


	//ads页面
    public function ads(){
		$tdata=Request::param();
		$info['pid']=$tdata['pid'];
		$info['typename']=tq_value($tdata['pid'],'title','images_type');

		View::assign(['info'=>$info]);
		return View::fetch();
    }


	//列表数据		
    public function list_data(){
		IS_AJAX(Request::isAjax());
		$tdata=Request::param();
				
		$list=\app\admin\model\Images::where('pid',$tdata['pid'])->order('sort asc')->select()->toArray();

		$data['code']=0;
		$data['data']=$list;
		return json($data);
    }
	
}
