<?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 \temmoku\admin;
use \temmoku\db;
use \admin\model\setting AS model;
use admin\public_class\cache;
use admin\public_class\renzheng AS rz;
use \temmoku\lib\pages;
class renzheng extends admin
{
	//认证设置
	public function setting(){
		$setting=(new model)->setting();
		$data=unserialize(stripslashes(stripslashes($setting['renzheng'])));
		unset($setting);
		hook_listen('admin_renzheng_setting_begin',$data);
		if($_POST['step']=='post'){
			$renzheng=$_POST['web'];
			unset($_POST['web']);
			$_POST['web']['renzheng']=addslashes(addslashes(serialize($renzheng)));
			(new model)->post();
			//生成一些必要的缓存
			cache::setting_cache();
			$this->success('设置成功');
		}
		$this->assign('data',$data);
		hook_listen('admin_renzheng_setting_end',$data);
		$this->display(tpl('renzheng/setting'));
	}
	
	public function index(){
		hook_listen('admin_renzheng_index_begin');
		if($_GET['type']=='main' || !$_GET['type']){
			$_GET['type']='main';
			!isset($_GET['page']) && $_GET['page']=1;
			$num=20;
			!isset($_GET['state']) && $_GET['state']=1;
			$where="id_rz_state='$_GET[state]'";
			$data=db::select('*')->from(jab.'user')->where($where)->calcFoundRows()->setPaging($num)->page($_GET['page'])->query();
			$getlistNUM=db::row(' SELECT FOUND_ROWS() AS allNUM');
			$Get_Page=(new pages)->pages('','','/admin/renzheng/index/type_'.$_GET['type'].'/state_'.$_GET['state'].'/',$num,$_GET['page'],$getlistNUM['allNUM']);
			$this->assign('data',$data);
			$this->assign('Get_Page',$Get_Page);
		}

		hook_listen('admin_renzheng_index_end');
		$this->display(tpl('renzheng/index'));
	}
	
	public function content(){
		hook_listen('admin_renzheng_content');
		if($_GET['type']=='main' && $_GET['uid']){
			if($_POST['step']=='post'){
				if($_POST['aciton']==1){
					$rz=(new rz)->give($_GET['uid'],'main');
					if($rz['code']){
						$this->err($rz['text']);
					}
					$log['type']=1;
					$array=['id_rz_state'=>1];
				}else{
					$log['type']='0';
					$array=['id_rz_state'=>-2];
				}
				$log['uid']=$_GET['uid'];
				$log['msg']=$_POST['msg'];
				$log['action_uid']=C('MYDB.uid');
				$log['posttime']=NOWTIME;
				db::insert(jab.'renzheng_log')->cols($log)->query();
				db::update(jab.'user')->cols($array)->where('uid='.$_GET['uid'])->query();
				hook_listen('admin_renzheng_content_post');
				$this->success('操作成功');
			}
			$where="uid='$_GET[uid]'";
			$data=db::select('*')->from(jab.'user')->where($where)->row();
			$uid=$_GET['uid'];
			$this->assign('data',$data);
			$ceil = ceil(c('mydb.uid')/1000);
			$path=Temmoku_PATH.C('UPFILES_CATALOG').'/';
			$id_array=['idcard_zheng','idcard_fan','idcard_shouchi','company_business'];
			foreach($id_array as $value){
				$file='renzheng/'.$ceil."/".$uid."/".md5(C('MD5')."_".$uid."_".$value).".png";
				if(is_file($path.$file)){
					$img[$value]=get_img_url($file);
				}
			}
			$log=db::select('*')->from(jab.'renzheng_log')->where($where)->orderByDESC(['id'])->query();
			$this->assign('log',$log);
			$this->assign('img',$img);
			$this->display(tpl('renzheng/content'));
		}
	}
}
?>