<?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 \plugin\wechat\admin\model\index AS model;
use \temmoku\controller;
use \temmoku\db;
use plugin\wechat\public_class\cache;
class index extends controller{
	//微信设置
	public function set(){
		if($_POST['step']=='post'){
			(new model)->setting();
			cache::setting_cache();
			if(!$_POST['from_to']){
				$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/weixin'));
	}
	public function attention(){
		$_settingDB=db::select('*')->from(P_jab."set")->query();
    	foreach($_settingDB AS $row){
    		$settingDB[$row['u_key']]=$row['u_value'];
    	}
		if($_POST['step']=='post'){
			$attention=$_POST['wechat']['attention'];
			if($attention['list']){
				if($settingDB['attention']){
					$list=unserialize($settingDB['attention'])['list'];
				}
				
				foreach($attention['list'] as $key=>$row){
					if($row['picurl']){
						if($list[$key]['picurl'] !=$row['picurl'] && $list[$key]['picurl']){
							$purl=Temmoku_PATH.C('UPFILES_CATALOG').'/'.$list[$key]['picurl'];
		    				//删除备份文件
							del_file($purl);
		    				
						}
						$row['picurl']=UploadFiles_MOVE($row['picurl'],strtolower(P_MODULE),TRUE);
					}else{
						if($list[$key]['picurl']){
							$purl=Temmoku_PATH.C('UPFILES_CATALOG').'/'.$list[$key]['picurl'];
		    				//删除备份文件
							del_file($purl);
		    				
						}
					}
					$keydb[]=$key;
					$_list[]=$row;
				}
				//删除多余的图片
				foreach($list as $_key=>$_row){
					if(!in_array($_key,$keydb)){
						if($_row['picurl']){
							$purl=Temmoku_PATH.C('UPFILES_CATALOG').'/'.$_row['picurl'];
		    				//删除备份文件
							del_file($purl);
						}
					}
				}
				$attention['list']=$_list;
			}
			unset($_POST['wechat']['attention']);
			$_POST['wechat']['attention']=serialize($attention);
			(new model)->setting();
			cache::setting_cache();
			$this->success('设置成功');
		}

		$this->assign('settingDB',$settingDB);
		$this->display(tpl('set/attention'));
	}
	//核心缓存
}
?>