<?php
/*
 +----------------------------------------------------------------------
 | TEMMOKUMVC [ NO BEST , ONLY BETTER ]
 +----------------------------------------------------------------------
 | Copyright (c) 2018~2019 https://www.temmoku.cn All rights reserved.
 +----------------------------------------------------------------------
 | Author: 张宗强 Email:webmaster@temmoku.cn QQ:158726877 516669373 TEL:17895221001 微信:temmokumvc
 +---------------------------------------------------------------------- 
*/
namespace admin\controller;
use admin\model\comment AS Model;
use \admin\home;
use \temmoku\lib\pages;
use \temmoku\db;
use \admin\public_class\comment AS comment_class;
class comment extends home{
	
	public function index(){
		!isset($_GET['page']) && $_GET['page']=1;
		$rows='20';
		
		if($_GET['state']==='-1' || $_GET['state']==='1'){
			if ($_GET['state']==='-1' ) $_GET['state']=0;
			$WHERE="state = '$_GET[state]'";
			$url='state_'.$_GET['state'].'/';
		}else{
			$WHERE="1";
		}
		$listdb=db::select('*')->from(jab."comment")->where($WHERE)->orderByDESC(['id'])->setPaging($rows)->page($_GET['page'])->query();
		$Get_Page=(new Pages)->Pages(jab."comment",$WHERE,"/admin/comment/index/{$url}",$rows,$_GET['page']);
		$this->assign('listdb', $listdb);
    	$this->assign('Get_Page', $Get_Page);
    	$this->display(tpl('comment/index'));
	}
	
	public function state(){
		if(is_array($_POST['iddb'])){
			foreach($_POST['iddb'] AS $id){
				db::update(jab."comment")->cols(['state'=>$_POST['state']])->where("id='$id'")->query();
			}
			$this->Success('操作成功', FromUrl);
		}else{
			db::update(jab."comment")->cols(['state'=>$_POST['state']])->where("id='$_POST[id]'")->query();
			echo json_encode(['Result'=>'1','content'=>'操作成功']);
		}
	}
	
	public function del(){
		if(is_array($_POST['iddb'])){
			foreach($_POST['iddb'] AS $key=>$id){
				(new comment_class)->comment_del($id);
			}
			$this->Success('删除成功', FromUrl);
		}else{
			echo (new comment_class)->comment_del($_POST['id']);
		}
	}
}
?>
