<?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 plugin\wechat\admin\controller;
use \temmoku\db;
use \temmoku\controller;
use \temmoku\lib\pages;
class reply extends controller{
	
	public function setting(){
		if($_POST['step']=='post'){
			$id=$_POST['id'];
			unset($_POST['id']);
			$row=$_POST['add'];
			if($row['picurl']){
					if($id){
						$rows=db::select('*')->from(jab.'plugin_wechat_reply')->where("id= '$id' ")->row();
						if($rows && $rows['picurl'] && $rows['picurl'] !=$row['picurl']){
							$purl=Temmoku_PATH.C('UPFILES_CATALOG').'/'.$rows['picurl'];
		    				//删除文件
							del_file($purl);
							$row['picurl']=UploadFiles_MOVE($row['picurl'],strtolower(P_MODULE),TRUE);
						}
					}else{
						$row['picurl']=UploadFiles_MOVE($row['picurl'],strtolower(P_MODULE),TRUE);
					}
			}else{
				if($id){
					$rows=db::select('*')->from(jab.'plugin_wechat_reply')->where("id= '$id' ")->row();
					if($rows && $rows['picurl']){
						$purl=Temmoku_PATH.C('UPFILES_CATALOG').'/'.$rows['picurl'];
		    			//删除文件
						del_file($purl);
					}
				}
			}
			$row['uid']=C('mydb.uid');
			$row['username']=C('mydb.username');
			$row['posttime']=NOWTIME;
			if($id){
				db::update(jab.'plugin_wechat_reply')->cols($row)->where("id='$id'")->query();
				$this->success('修改成功',PLUGIN_ACTION."reply/setting/");
			}
			$data=db::insert(jab.'plugin_wechat_reply')->cols($row)->query();
			$this->success('添加成功');
		}
		if($_GET['id']){
			$data=db::select('*')->from(jab.'plugin_wechat_reply')->where("id= '$_GET[id]' ")->row();
			$this->assign('data', $data);
		}
		$keyword='关键词';
		
		$rows='20';
		!isset($_GET['page']) && $_GET['page']=1;
		$dataDB=db::select('*')->from(jab."plugin_wechat_reply")->where('1')->orderByDESC(['id'])->setPaging($rows)->page($_GET['page'])->query();
		$Get_Page=(new Pages)->Pages(P_jab."reply",$WHERE,PLUGIN_ACTION."reply/setting/",$rows,$_GET['page']);
		$this->assign('dataDB', $dataDB);
		$this->assign('Get_Page', $Get_Page);
		$this->display(tpl('reply/set'));
	}
	
	public function del(){
		db::delete(jab.'plugin_wechat_reply')->where("id='$_GET[id]'")->query();
		$this->success('删除成功');
	}
	
	public function noanswer(){
		if($_POST['step']=='post'){
			(new \plugin\wechat\admin\model\index)->setting();
			\plugin\wechat\public_class\cache::setting_cache();
			$this->success('设置成功');
		}
		$_settingDB=db::select('*')->from(P_jab."set")->query();
    	foreach($_settingDB AS $row){
    		$settingDB[$row['u_key']]=$row['u_value'];
    	}
		$this->assign('settingDB',$settingDB);
		$this->display(tpl('set/noanswer'));
	}
}
?>