<?php
 /**
 *      [XCECP] (C) COLNET Inc.
 *      This is NOT a freeware, use is subject to license terms
 */
if(!defined("IN_QKWEB")){exit("Access Denied");}
class AdminAction{
	function __construct(){ if(ACTION_NAME!="login" && ACTION_NAME!="logout"){ BaseAction::checkAdmin(); } }
	function logout(){ $_SESSION['adminId']="";$_SESSION['adminName'] = "";header("Location:/\n"); }
	function init(){ $this->index(); }
	function index(){
		global $db,$cfg_lang;
		$sql = "select * from qk_role where userId='".$_SESSION['adminId']."'";
		$actions = $db->getAll($sql);
		$action="";
		$i=0;
		foreach($actions as $item){
			$action .= $item['actionId'];
			$i++;
			if($i<count($actions)){$action .= ",";}
		}
		if(!$action){Msg::show('未分配管理权限');}
		$sql = "select * from qk_role_page where actionId in($action) order by sortId asc,id asc";
		$allmenus = $db->getAll($sql);
		$menu = array();
		$i=0;;
		foreach($allmenus as $item){
			if($item['parentId']==0){
				$menu[$i]["menu"] = $item;
				if($cfg_lang!="zh-cn"){$menu[$i]["menu"]['name']=$item['nameEn'];}
				$j=0;
				foreach($allmenus as $sub){
					if($sub['parentId']==$item['id']){
						$menu[$i]["sub"][] = $sub;
						if($cfg_lang!="zh-cn"){$menu[$i]["sub"][$j]['name']=$sub['nameEn'];}
						$j++;
					}
				}
			}
			$i++;
		}
		assign("menus",$menu);
		$tmpl = getgpc("act");
		$tmp = "";
		if($tmpl=="top"){$tmp="top";}
		$inajax = getgpc('inajax','P');
		$act = getgpc('act','P');
		if($inajax==1){
			$ret = array('success'=>false,'message'=>'非法访问');
			if($act=='createIndexHtml'){
				$html = '<!--Start Time : '.date('Y-m-d H:i:s').'-->';$html='';
				$index='';
				 $ret['message'] = '生成失败';
					$sm = new SeoModel();$pageInfo = $sm->pageInfo(1);
					$pageInfo['title'] = $pageInfo['title']?$pageInfo['title']:$GLOBALS['siteConf']['siteName'];
					assign("pageInfo",$pageInfo);
					$GLOBALS['smarty']->setTemplateDir(ROOT_PATH."/templates/".$GLOBALS['siteConf']['template']."/");
					$index = $GLOBALS['smarty']->fetch('index.html');
				if($index){
					$html.=$index.'<!--Creating Time : '.date('Y-m-d H:i:s').'-->';
					$fp = @fopen(ROOT_PATH.'index.html','w+');if($fp && @fwrite($fp,$html)){$ret = array('success'=>false,'message'=>'静态首页 index.html 生成成功');fclose($fp);}
				}
			}else if($act=='deleteIndexHtml'){
				$ret['message'] = '删除失败';
				if(@unlink(ROOT_PATH.'index.html')){$ret = array('success'=>false,'message'=>'删除静态首页 index.html 成功');}
			}else if($act=='clearGoods'){
				load_class('goods');
				$gm = new GoodsModel();
				$ret['success']=$gm->clearGoods();
				$ret['message']=$gm->msg;
			}else if($act=='clearCategory'){
				load_class('goods');
				$gm = new GoodsModel();
				$ret['success']=$gm->clearCategory();
				$ret['message']=$gm->msg;
			}else if($act=='clearBrand'){
				load_class('goods');
				$gm = new GoodsModel();
				$ret['success']=$gm->clearBrand();
				$ret['message']=$gm->msg;
			}else if($act=='clearAttr'){
				load_class('goods');
				$gm = new GoodsModel();
				$ret['success']=$gm->clearAttr();
				$ret['message']=$gm->msg;
			}else if($act=='clearType'){
				load_class('goods');
				$gm = new GoodsModel();
				$ret['success']=$gm->clearType();
				$ret['message']=$gm->msg;
			}else if($act=='clearLogs'){
				$sql = "delete from qk_log where 1";$GLOBALS['db']->query($sql);
				$ret=array('success'=>true,'message'=>'日志数据清空成功');
			}
			echo json_encode($ret);exit;
		}
		display($tmpl);
	}
	function site(){
		load_class("site");
		$sm = new SiteModel();
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax",'P');
		if($inajax==1){
			$ret = array("success"=>false,"message"=>"参数错误");
			if($act=="edit" && $id && settype($id,"integer")){
				if($sm->edit($_POST)){$ret = array("success"=>true,"message"=>"修改成功");}else{$ret = array("success"=>false,"message"=>"修改失败");}
			}
			echo json_encode($ret);exit();
		}
		$siteInfo = $sm->getInfo();
		assign("siteInfo",$siteInfo);
		display("site");
	}
	function seo(){display("seo");}
	function seourl(){
		load_class("seo");
		$seo = new SeoModel();
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");		
		if($inajax==1){
			$ret = array("success"=>false,"message"=>"参数错误");
			$id = getgpc("id","P");
			$col = getgpc("col","P");
			$val = getgpc("val","P");
			if($act=="edit" && $col && $id && settype($id,"integer")){
				$params['id'] = $id;
				$params[$col] = $val;
				$ret['success'] = $seo->ajaxEdit($params);
			}else if($act=="del" && $id && settype($id,"integer")){
				$ret['success'] = $seo->delUrl($id);
			}
			if($seo->msg){$ret['message'] = $seo->msg;}
			echo json_encode($ret);
			exit();
		}
		display("seourl");
	}
	function seopage(){
		global $_G;
		load_class("seo");
		$sm = new SeoModel();
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$ret = array("success"=>false,"message"=>"参数错误");
			if($act=="add"){
				if($sm->addSeoPage($_POST)){
					$ret = array("success"=>true,"message"=>"添加成功");
				}else{
					$ret = array("success"=>false,"message"=>"添加失败");
				}
			}else if($act=="edit" && $id && settype($id,"integer")){
				$ret['success'] = $sm->setSeoPageInfo($_POST);
			}else if($act=="del"){
				$ret['success'] = $sm->delSeoPage($id);
			}
			if($sm->msg){$ret['message']=$sm->msg;}
			echo json_encode($ret);exit;
		}
		$act = getgpc("act");
		$id = getgpc("id");
		if($act=="edit" && $id && settype($id,"integer")){
			$seoPageInfo = $sm->getSeoPageInfo($id);
			assign("seoPageInfo",$seoPageInfo);
		}
		display("seopage");
	}
	function servicecat(){
		load_class("service");
		$sm = new ServiceModel();
		$act = getgpc("act","P");
		if($act=="add"){$sm->addCategory($_POST);}
		assign("category",$sm->getCategory());
		display("servicecat");
	}
	function industry(){
		load_class("industry");
		$im = new IndustryModel();
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$act=getgpc("act","P");
			if($act=="edit"){
				$res = $im->ajaxColEdit($_POST);
				exit($res);
			}
			exit();
		}
		if($act=="add"){
			$im->addCategory($_POST);
		}
		$act=getgpc("act");
		$id = getgpc("id");
		assign("category",$im->getCategory());
		display("industry");
	}
	function login(){
		global $db;
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");
		if($inajax=='1'){
			$ret=array('success'=>false,'message'=>'Forbidden');
			if($act=="login"){
				$adminName = getgpc("loginName","P");
				$loginPwd = getgpc("loginPwd","P");
				if($adminName && $loginPwd){
					$sql = "select * from qk_user where (email='$adminName' or mobile='$adminName') and loginPwd='".md5($loginPwd)."' and groupId=1";
					if($userInfo = $db->getRow($sql)){
						$adminId = $userInfo['id'];
						$_SESSION['adminName'] = $adminName;
						$_SESSION['adminId'] = $adminId;
						$ret=array('success'=>true,'message'=>'登录成功，正在转向管理中心');
					}else{
						$ret['message']='账号或密码错误';
					}
				}else{
					$ret['message']='账号密码不能为空';
				}
			}
			echo json_encode($ret);exit;
		}
		display("login");
	}
	function goods(){
		global $_G;
		$key = getgpc("key","GP");
		assign("key",$key);
		load_class("goods");
		$gm = new GoodsModel();
		$act=getgpc("act","P");
		$inajax = getgpc("inajax","P");
		$id = getgpc("id","P");
		if($inajax==1){
			$ret = array('success'=>false,'message'=>'操作失败');
			if($act=="ajaxEdit"){
				if($gm->ajaxColEdit($_POST)){
					$ret = array('success'=>true,'message'=>'修改成功');
				}
			}else if($act=="clear"){
				if($gm->clear()){
					$ret = array('success'=>true,'message'=>'清空成功');
				}
			}else if($act=="edit"  && settype($id,"integer")){
				if($gm->edit($_POST)){
					$ret = array('success'=>true,'message'=>'修改成功');
				}
			}else if($act=="add"  && settype($id,"integer")){
				if($gm->add($_POST)){
					$ret = array('success'=>true,'message'=>'添加商品成功');
				}else{
					$ret = array('success'=>false,'message'=>'添加商品失败');
				}
			}else if($act=="upurl"){
				$url = getgpc("url","P");
				if(!$url){
					$ret['message'] = '图片URL地址错误';
				}else{
					$up = new Uploader();
					$u = $up->goodsPicSave($url);
					if($u['success']){
						$ret['success'] = true;
						$ret['url'] = $u['url'];
						$ret['data'] = $u['data'];
					}else{
						if($up->msg){
							$ret['message'] = $up->msg;
						}
					}
				}
			}else if($act=="check"){
				if($id = $gm->check($_POST)){
					$ret = array('success'=>true,'message'=>'操作成功','data'=>array('id'=>$id));
				}
			}else if($act=="del"){
				if($gm->del($id)){
					$ret = array('success'=>true,'message'=>'删除成功');
				}
			}
			if(!$ret['success'] && $gm->msg){
					$ret['message'] = $gm->msg;	
			}
			echo json_encode($ret);
			exit();
		}
		$id = getgpc("id","P");
		
		if($act=="export"){ $gm->export($_POST); }
		if($act=="import"){ $gm->import($_POST); }

		$act=getgpc("act","G");
		$id = getgpc("id","G");
		if($act=="edit" && settype($id,"integer")!=false){
			$goodsInfo = $gm->getInfo($id);
		}

		$act = getgpc("act");
		$id = getgpc("id");
		load_class("category");
		$cm = new CategoryModel();
		$category = $cm->getList();
		$brand = getBrand();

		if($act=="add" || $act=="edit"){
			$commonAttr = $gm->getAttr(0);
			assign("commonAttr",$commonAttr);
		}

		assign("brand",$brand);
		assign("category",$category);
		assign("goodsInfo",$goodsInfo);
		display("goods");
	}

	function category(){
		global $db;
		load_class("category");
		$cm = new CategoryModel();
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax");
		if($inajax==1){
			$ret = array("success"=>false,"message"=>"参数错误");
			if($act=="del" && settype($id,"integer")){
				$sql = "select count(id) from qk_category where parentId='".$id."'";
				$p = $db->getOne($sql);
				if($p){
					exit('{"success":false,"message":"错误：该分类有下级分类，请先删除下级分类"}');
				}else{
					$ret['success']=$cm->del($id);
				}
			}else if($act=="ajaxEdit"){
				$ret['success']=$cm->ajaxColEdit($_POST);
			}else if($act=="add"){
					if($id=$cm->add($_POST)){
						$ret = array("success"=>true,"message"=>"添加分类成功","data"=>array("id"=>$id));
					}else{
						$ret = array("success"=>false,"message"=>"添加分类失败");
					}
			}
				if($cm->msg){$ret['message']=$cm->msg;}
				echo json_encode($ret);
			exit();
		}
		
		if($act=="add"){
			$cm->add($_POST);
		}
		if(($act=="edit" && settype($id,"integer"))){
			$cm->edit($_POST);
		}
		$act = getgpc("act");
		$id = getgpc("id");
		if($act=="edit" && settype($id,"integer")){
			$catInfo = $cm->getInfo($id);
		}
		$category = $cm->getList();
		assign("catInfo",$catInfo);
		assign("category",$category);		
		display("category");
	}

	function post(){
		global $db;
		$adminId  = $_SESSION['adminId'];
		$act=getgpc("act","P");
		$inajax = getgpc("inajax","P");
		$id = getgpc("id","P");
		if($inajax==1){
			$act=getgpc("act","P");
			if($act=="ajaxEdit"){
				$col = getgpc("col","P");
				$val = getgpc("val","P");
				if($col && settype($id,"integer")){
					$sql = "update qk_post set `$col`='$val' where id='".$id."'";
					$db->query($sql);
						echo "{\"success\":true}";
				}
			}else if($act=="replay"){
				$content = getgpc("content","P");
					if($id && settype($id,"integer")){
						$sql = "insert into qk_post set content='$content',userId='$adminId',iStatus=1,parentId='$id',posttime=UNIX_TIMESTAMP()";
						if($db->query($sql)){
							exit('{"success":true,"message":"success","data":{"adminName":"'.$_SESSION['adminName'].'","posttime":"'.date("Y-m-d H:i").'"}}');
						}
					}
			}else if($act=="del"){
				if($id && settype($id,"integer")){
						$sql = "delete from qk_post where id='$id'";
						if($db->query($sql)){
							exit('{"success":true,"message":"删除成功"}');
						}
				}
			}
			exit();
		}
		assign("postConfig",getConfig('post'));
		display("post");
	}
	function brand(){
		global $db;
		load_class("brand");
		$bm = new BrandModel();
		$act = getgpc("act",'P');
		$id = getgpc("id");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$ret = array("success"=>false,"message"=>"参数错误");
			if($act=="del" && $id && settype($id,"integer")){
				if($bm->del($id)){
					$ret = array("success"=>true,"message"=>"删除成功");
				}
			}else if($act=="add"){
				if($id=$bm->add($_POST)){
					$ret = array("success"=>true,"message"=>"添加成功","data"=>array("id"=>$id));
				}
			}else if($act=="edit"){
				$ret['success']=$bm->add($_POST);
			}
			if($bm->msg){$ret['message']=$bm->msg;}
			echo json_encode($ret);exit;
		}
		$act = getgpc("act",'GP');
		if($act=="edit" && settype($id,"integer")){
			$sql = "select * from qk_brand where id='$id'";
			$brandInfo = $db->getRow($sql);
		}
		
		$act = getgpc("act");
		$id = getgpc("id");
		
		load_class("category");
		$cm = new CategoryModel();
		$category = $cm->getList();
		assign("category",$category);		
		assign("brandInfo",$brandInfo);		
		display("brand");
	}

	function tuan(){
		global $db;
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");//exit('{"success":true,"message":"操作成功"}');
		$id = getgpc("id","P");
		if($inajax==1){
			if($act=="edit"){
				$col = getgpc("col","P");
				$val = getgpc("val","P");
				if($col && $val!="" && settype($id,"integer")){
					$sql = "update qk_tuan set `$col`='$val' where id='$id'";
					$db->query($sql);
					exit('{"success":true,"message":"操作成功"}');
				}
			}
			if($act=="del" && settype($id,"integer")){
					$sql = "delete from qk_tuan where id='".$id."'";
					$db->query($sql);
					exit('{"success":true,"message":"删除成功"}');
			}
			exit();
		}
		$id = getgpc("id","P");
		if($act=="add" || ($act=="edit" && settype($id,"integer"))){
		
			$title = getgpc("title","P");
			$marketPrice = getgpc("marketPrice","P");
			$price = getgpc("price","P");
			$externalLink = getgpc("externalLink","P");
			$thumbId = getgpc("thumbId","P");
			$sortId = getgpc("sortId","P");
			if(settype($thumbId,"integer")==false){$thumbId=0;}
			if(settype($sortId,"integer")==false){$sortId=0;}
			if($title){
				if($act=="add"){
					$sql = "insert into qk_tuan set ";
					$sqlEnd = ",posttime=UNIX_TIMESTAMP()";
				}else if($act=="edit"){
					$sql = "update qk_tuan set ";
					$sqlEnd = " where id='$id'";
				}
				$sql .= " title='$title',marketPrice='$marketPrice',price='$price',externalLink='$externalLink',thumbId='$thumbId',sortId='$sortId'";
				$sql .= $sqlEnd;
				$db->query($sql);
			}
		}
		$act = getgpc("act");
		$id = getgpc("id");
		if($act=="edit" && settype($id,"integer")){
			$sql = "select * from qk_tuan where id='$id'";
			$tuanInfo = $db->getRow($sql);
			assign("tuanInfo",$tuanInfo);
		}
		
		display("tuan");
	}

	function article(){
		global $_G;
		$key = getgpc("key");
		assign("key",$key);
		load_class("Article");
		$am = new ArticleModel();
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		$inajax= getgpc("inajax","P");
		if($inajax==1){
			$ret = array('success'=>false,'message'=>'参数不完整');
			if($act=="ajaxEdit"){
				if($am->ajaxColEdit($_POST)){
					$ret = array('success'=>true,'message'=>'修改成功');
				}
			}else if($act=="del"){
				if($am->del($id)){
					$ret = array('success'=>true,'message'=>'删除成功');
				}
			}else if($act=='add'){
				$ret['success'] = $am->add($_POST);
			}else if($act=='edit' && is_numeric($id)){
				$ret['success'] = $am->edit($_POST);
			}
			if($am->msg){$ret['message']=$am->msg;}
			echo json_encode($ret);
			exit();
		}
		$act = getgpc("act");
		$id = getgpc("id");
		if(settype($id,"integer")){
				$articleInfo = $am->getInfo($id);
				assign("articleInfo",$articleInfo);				
		}
		$category = $am->getArticleCategory();
		assign("category",$category);		
		display("article");
	}
	
	function articlecat(){
		global $_G;
		load_class("Article");
		$am = new ArticleModel();
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");
		$id = getgpc("id","P");
		if($inajax==1){
			$ret=array('success'=>false,'message'=>'参数错误');
			if($act=="del" && $id && is_numeric($id)){
				$ret['success']=$am->delCat($id);
			}else if($act=="add"){
				$ret['success']=$am->addCat($_POST);
			}else if($act=="edit" && $id && is_numeric($id)){
				$ret['success']=$am->editCat($_POST);
			}else if($act=="ajaxEdit" && $id && is_numeric($id)){
				$ret['success']=$am->ajaxEditCat($_POST);
			}
			$ret['message']=$am->msg?$am->msg:$ret['message'];
			echo json_encode($ret);exit();
		}
		
		$act = getgpc("act");
		$id = getgpc("id");
		if($act=="edit" && $id && settype($id,"integer")){
			$catInfo = $am->getCatInfo($id);if(!$catInfo){Msg::show('分类不存在');}
			assign("catInfo",$catInfo);
		}
		assign("articleCat",$am->getCats());
		display("articlecat");
	}
	function payment(){
		load_class("payment");
		$pay = new PaymentModel();
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=="del"){
				if($pay->del($id)){ $ret = array('success'=>true,'message'=>'删除成功'); }
			}else if($act=="ajaxEdit"){
				if($pay->ajaxEdit($_POST)){ $ret = array('success'=>true,'message'=>'修改成功'); }
			}else if($act=="edit" && $id && is_numeric($id)){
				if($pay->edit($_POST)){ $ret = array('success'=>true,'message'=>'修改成功'); }
			}
			$ret['message']=$pay->msg?$pay->msg:$ret['message'];
			echo json_encode($ret);exit;
		}
		$act=getgpc("act");
		$id = getgpc("id");
		if($act=="edit" && $id){
			assign("paymentInfo",$pay->getInfo($id));
		}
		display("payment");
	}

	function onlinepay(){
		load_class("onlinepay");
		$pay = new OnlinepayModel();
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=="del"){
				if($pay->del($id)){ $ret = array('success'=>true,'message'=>'删除成功'); }
			}else if($act=="query"){
				$pm = new Pay();$ret['success'] = $pm->query($id);$ret['message'] = $pm->msg;
			}
			echo json_encode($ret);
			exit;
		}
		display("onlinepay");
	}
	function finance(){
		load_class("finance");
		$fm = new FinanceModel();
		$types = $fm->getAllTypes();
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax","P");
		if($inajax=='1'){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=="del"){
				if($fm->del($id)){ $ret = array('success'=>true,'message'=>'删除成功'); }
			}else if($act=="add"){
				if($fm->add($_POST)){$ret = array('success'=>true,'message'=>'添加成功');}
			}else if($act=="edit" && is_numeric($id)){
				if($fm->edit($_POST)){$ret = array('success'=>true,'message'=>'修改成功');}
			}if($act=="ajaxEdit"){
				if($fm->ajaxColEdit($_POST)){
					$ret = array('success'=>true,'message'=>'修改成功');
				}
			}
			if($fm->msg){ $ret['message']=$fm->msg; }
			echo json_encode($ret);
			exit;
		}
		
		$id = getgpc("id");
		if($id && is_numeric($id)){
			$financeInfo = $fm->getInfo($id);
			assign("financeInfo",$financeInfo);
		}
		assign("types",$types);
		display("finance");
	}
	function user(){
		global $db,$_G;
		$key = getgpc("key","P");
		if(!$key){
			$key = getgpc("key","G");
			if($key){
				$key = mb_convert_encoding($key,"UTF-8","GBK");
			}
		}
		assign("key",$key);
		load_class("user");
		$um = new UserModel();
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=="add"){
				$_POST['loginPwd2'] = $_POST['loginPwd'];
				$userId = $um->add($_POST,false);
				if($userId && intval($userId)){ $ret = array('success'=>true,'message'=>$_G['lang']['admin']['success']); }
			}else if($act=="del" && $id && is_numeric($id)){
				if($um->del($id)){$ret = array('success'=>true,'message'=>'用户删除成功');}
			}else if($act=="sendActivationEmail"){
				if($um->sendActivationEmail($_SESSION['userId'])){
					$ret = array('success'=>true,'message'=>'邮件发送成功');
				}else{
					$ret = array('success'=>false,'message'=>'邮件发送失败');
				}
			}else if($act=="edit" && settype($id,"integer")){
				$ret['success']=$um->edit($_POST);
			}
			if($um->msg){$ret['message']=$um->msg;}
			echo json_encode($ret);
			exit();
		}
		
		$act = getgpc("act");
		$id = getgpc("id");
		if($id && settype($id,"integer")){
			if($act=="del"){
			
			}else if($act=="quicklogin"){
				global $baseUrl;
				$um->quickLogin($id,false);
				header("Location:".$baseUrl."user");
			}
		}
		

		if($id && settype($id,"integer")){
			$userInfo = $um->getInfo($id);
			assign("userInfo",$userInfo);
		}
		display("user");
	}

	function hotkey(){
		global $db;
		$inajax = getgpc("inajax",'P');
		$act = getgpc("act",'P');
		$id = getgpc("id",'P');
		load_class("hotkey");
		$hot = new HotkeyModel();
		if($inajax=='1'){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=='edit' || $act=='add' || $act=='del'){$ret['success']=$hot->$act($_POST);}
			if($hot->msg){$ret['message']=$hot->msg;}
			echo json_encode($ret);exit();
		}
		$id = getgpc("id");
		$act = getgpc("act");
		if($id && settype($id,"integer")){
			if($act=="edit"){
			$sql = "select * from qk_hotkey where id='$id'";
			$hotkeyInfo = $db->getRow($sql);
			assign("hotkeyInfo",$hotkeyInfo);
			}
		}
		display("hotkey");
	}

	function adplace(){
		global $db;
		$act = getgpc("act");
		$id = getgpc("id");
		$inajax = getgpc("inajax","P");
		load_class("adplace");
		$ap = new AdplaceModel();
		if($inajax==1){
			$ret=array('success'=>false,'message'=>'参数错误');
			if($act=="del"){
				if($ap->del($id)){
					$ret['success']=true;
				}
			}
			$ret['message'] = $ap->msg?$ap->msg:'参数错误';
			echo json_encode($ret);
			exit;
		}
		if($act=="add" || ($act=="edit" && settype($id,"integer"))){
			$name = getgpc("name","P");
			$iStatus = getgpc("iStatus","P");
			$width = getgpc("width","P");
			$height = getgpc("height","P");
			if(settype($iStatus,"integer")===false){$iStatus=1;}
			if($name){
				if($act=="edit"){
					$sql = "update qk_ad_place set ";
					$sqlEnd = " where id='".$id."'";
				}else if($act=="add"){
					$sql = "insert into qk_ad_place set ";
					$sqlEnd = ",posttime=UNIX_TIMESTAMP()";
				}
				$sql .= " name='$name',iStatus='$iStatus',width='$width',height='$height'";
				if(defined("SITE_ID") && is_numeric(SITE_ID)){$sql.=",siteId='".SITE_ID."'";}
				$sql .= $sqlEnd;
				$db->query($sql);
			}
		}
		$id = getgpc("id");
		$act = getgpc("act");
		if($id && settype($id,"integer")){
			if($act=="edit"){
			$sql = "select * from qk_ad_place where id='$id'";
			$adplaceInfo = $db->getRow($sql);
			assign("adplaceInfo",$adplaceInfo);
			}
		}
		display("adplace");
	}

	function ad(){
		global $db;
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax","P");
		load_class('ad');
		$adm = new AdModel();
		if($inajax==1){
			$ret=array('success'=>false,'message'=>'非法访问');
			if($act=="ajaxEdit" && $id && settype($id,"integer")){
				$col = getgpc("col","P");
				$val = getgpc("val","P");
				if($col){
					$sql = "update qk_ad set `$col`='$val' where id='$id'";
					if($db->query($sql)){
						exit('{"success":true,"message":"修改成功"}');
					}
				}
			}else if($act=="del" && $id){
				if($db->query("delete from qk_ad where id='$id' limit 1")){
					exit('{"success":true,"message":"删除成功"}');			
				}
			}else if($act=='edit' || $act=='add'){$ret['success']=$adm->$act($_POST);}
			if(!$adm->msg){$adm->msg='参数错误';}
			$ret['message']=$adm->msg;
			echo json_encode($ret);exit;
		}
		global $_G;
		$id = getgpc("id");
		$act = getgpc("act");
		if($id && settype($id,"integer")){
			if($act=="edit"){
			$sql = "select * from qk_ad where id='$id'";
			$adInfo = $db->getRow($sql);
			assign("adInfo",$adInfo);
			}else if($act=="del"){
				$db->query("delete from qk_ad where id='$id'");
			}
		}
		display("ad");
	}

	function attachment(){
		global $db;
		$act=getgpc("act","P");
		$inajax = getgpc("inajax","P");
		$id = getgpc("id","P");
		if($inajax==1){
			$act=getgpc("act","P");
			if($act=="edit"){
				$col = getgpc("col","P");
				$val = getgpc("val","P");
				if($col && settype($id,"integer")){
					$sql = "update qk_attachment set `$col`='$val' where id='".$id."'";
					if($db->query($sql)){
						echo '{"success":true}';
					}
				}
			}
			exit();
		}		
	}

	function variable(){
		global $db;
		load_class("variable");
		$vm = new VariableModel();
		$act = getgpc("act","P");
		if($act=="add" || $act=="edit"){
			$vm->$act($_POST);
		}
		$act = getgpc("act");
		$id = getgpc("id");
		if(($act=="edit" || $act=="del") && $id && settype($id,"integer")){
			if($act=="edit"){
				$variableInfo = $vm->variableInfo($id);
				assign("variableInfo",$variableInfo);
			}else if($act=="del"){
				$vm->del($_GET);
			}
		}
		display("variable");
	}
	function event(){
		load_class('event','admin');
		$event = new EventAdmin();
		$opr = $_GET['PATH_INFO'][2];
		if(!$opr){$opr='index';}
		if($opr && method_exists($event,$opr)){$event->$opr();}
	}
	function order(){
		load_class('order','admin');
		$chong = new OrderAdmin();
		$opr = $_GET['PATH_INFO'][2];
		if(!$opr){$opr='index';}
		if($opr && method_exists($chong,$opr)){$chong->$opr();}
	}
	function roleaction(){
		load_class("role");
		$rm = new RoleModel();
		$action = $rm->action();
		assign("action",$action);
		display("roleaction");
	}

	function rolepage(){
		load_class("role");
		$rm = new RoleModel();
		$menus = $rm->page();
		assign("menus",$menus);
		display("rolepage");
	}
	function role(){
		load_class("role");
		$rm = new RoleModel();
		$act = getgpc("act","P");
		$userId = getgpc("userId","P");
		$inajax = getgpc("inajax",'P');
		if($inajax=='1'){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=="edit" && $userId && settype($userId,"integer")){
				if($rm->edit($_POST)){$ret = array('success'=>true,'message'=>'权限设置成功');}else{$ret['message']='权限设置失败';}
			}
			$ret['message']=$rm->msg?$rm->msg:$ret['message'];
			echo json_encode($ret);exit;
		}
		$menus = $rm->page();
		assign("menus",$menus);
		$action = $rm->action();
		assign("action",$action);
		$roles = $rm->role();
		assign("roles",$roles);
		display("role");
	}

	function nav(){
		global $_G;
		load_class("nav");
		$nm = new NavModel();
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$ret=array('success'=>false,'message'=>'非法访问');
			if($act=="del" && $id && settype($id,"integer")){
				$ret['success'] = $nm->del($id);
			}else if($act=='edit' || $act=='add'){
				$ret['success'] = $nm->$act($_POST);
			}
			$ret['message']=$nm->msg;echo json_encode($ret);exit;
		}
		$id = getgpc("id");
		if($id && settype($id,"integer")){
			$navInfo = $nm->getInfo($id);
			assign("navInfo",$navInfo);
		}
		display("nav");
	}
	
	function links(){
		global $_G;
		load_class("links");
		$lm = new LinksModel();
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");		
		if($inajax==1){
			$ret = array("success"=>false,"message"=>"参数错误");
			$id = getgpc("id","P");
			$col = getgpc("col","P");
			$val = getgpc("val","P");
			if($act=="edit" && $col && $id && settype($id,"integer")){
				$params['id'] = $id;
				$params[$col] = $val;
				$ret['success'] = $lm->ajaxEdit($params);
			}else if($act=="del" && $id && settype($id,"integer")){
				$ret['success'] = $lm->del($id);
			}
			if($lm->msg){$ret['message'] = $lm->msg;}
			echo json_encode($ret);exit();
		}
		if($act=="add" || $act=="edit"){if($lm->$act($_POST)){$msg = $_G['lang']['admin']['success'];}}
		$act = getgpc("act");
		$id = getgpc("id");
		if($id && settype($id,"integer")){if($act=="edit"){$linksInfo = $lm->getInfo($id);assign("linksInfo",$linksInfo);}}
		display("links");
	}
	function linkscat(){
		global $_G;
		load_class("links");
		$lm = new LinksModel();
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");		
		if($inajax==1){
			$ret = array("success"=>false,"message"=>"参数错误");
			$id = getgpc("id","P");
			$col = getgpc("col","P");
			$val = getgpc("val","P");
			if($act=="edit" && $col && $id && settype($id,"integer")){
				$params['id'] = $id;
				$params[$col] = $val;
				$ret['success'] = $lm->ajaxEditCat($params);
			}else if($act=="del" && $id && settype($id,"integer")){
				$ret['success'] = $lm->delCat($id);
			}
			if($lm->msg){$ret['message'] = $lm->msg;}
			echo json_encode($ret);exit();
		}
		if($act=="add" || $act=="edit"){$act=$act.'Cat';if($lm->$act($_POST)){$msg = $_G['lang']['admin']['success'];}}
		$act = getgpc("act");
		$id = getgpc("id");
		if($id && settype($id,"integer")){if($act=="edit"){$linksInfo = $lm->getCatInfo($id);assign("linksInfo",$linksInfo);}}
		display("linkscat");
	}

	function deliverytype(){
		global $_G;
		load_class("delivery");
		$dm = new DeliveryModel();
		$id = getgpc("id","P");
		$act = getgpc("act","P");
		$inajax = getgpc('inajax','P');
		if($inajax==1){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=="add"){
				$ret['success']=$dm->addType($_POST);		
			}else if($act=="edit" && $id && settype($id,"integer")){
				$ret['success']=$dm->editType($_POST);
			}
			if($dm->msg){$ret['message']=$dm->msg;}
			echo json_encode($ret);exit;
		}
		$id = getgpc("id");
		$act= getgpc("act");
		if($act=="edit" && $id && settype($id,"integer")){
			$deliveryTypeInfo = $dm->getTypeInfo($id);
			assign("deliveryTypeInfo",$deliveryTypeInfo);
		}
		if($act=="del" && $id && settype($id,"integer")){
			if($dm->delType($id)){$msg=$_G['lang']['admin']['success'];}
		}
		display("deliverytype");
	}

	function useraddr(){
		$key = getgpc("key","P");
		if(!$key){
			$key = getgpc("key","G");
			if($key){
				$key = mb_convert_encoding($key,"UTF-8","GBK");
			}
		}
		assign("key",$key);
		load_class("user");
		$um = new UserModel();
		$id = getgpc("id","P");
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");
		if($inajax=='1'){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=="del"){
				if($um->delAddr($id)){ $ret = array('success'=>true,'message'=>'删除成功'); }
			}
			if($um->msg){ $ret['message']=$um->msg; }
			echo json_encode($ret);
			exit;
		}

		if($act=="edit" && $id && settype($id,"integer")){
			$um->editAddr($_POST);
		}

		$id = getgpc("id");
		if($id && settype($id,"integer")){
			$addrInfo = $um->getAddrInfo($id);
			assign("addrInfo",$addrInfo);
		}
		display("useraddr");
	}

	function temai(){
		load_class("temai");
		$tm = new TemaiModel();
		
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		if(($act=="edit" && $id && settype($id,"integer")) || $act=="add"){
			if($tm->$act($_POST)){
				$msg = "操作成功";
			}else{
				$msg = "操作失败";
			}
		}
		$id = getgpc("id");
		if($id && settype($id,"integer")){
			$temaiInfo = $tm->getInfo($id);
			assign("temaiInfo",$temaiInfo);
		}
		assign("msg",$msg);
		display("temai");
	}

	function userscore(){
		$key = getgpc("key","P");
		if(!$key){
			$key = getgpc("key","G");
			if($key){
				$key = mb_convert_encoding($key,"UTF-8","GBK");
			}
		}
		assign("key",$key);
		load_class("user");
		$um = new UserModel();

		$id = getgpc("id","P");
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");
		if($inajax=='1'){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=="add"){
				echo $um->addScore($_POST);
			}else if($act=="del"){
				if($um->delScore($id)){ $ret = array('success'=>true,'message'=>'删除成功'); }
			}
			if($um->msg){ $ret['message']=$um->msg; }
			echo json_encode($ret);
			exit;
		}


		display("userscore");
	}

	function myorder(){
		$userId = $_SESSION['userId'];
		load_class("user");
		$um = new UserModel();
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$msg = array("success"=>false,"message"=>"操作失败");
			if($act=="add"){
				if($um->addMyOrder($_POST)){
					$msg = array("success"=>true,"message"=>"添加成功");
				}
			}else if($act=="edit"){
				if($um->editMyOrder($_POST)){
					$msg = array("success"=>true,"message"=>"修改成功");			
				}
			}else if($act=="audit"){
				$col = "iStatus";
				$val = getgpc("iStatus","P");
				$id = getgpc("id","P");
				$params['id'] = $id;
				$params[$col] = $val;
				if($um->ajaxEditMyOrder($params)){
					$msg = array("success"=>true,"message"=>"操作成功","data"=>array("id"=>$id,"iStatus"=>$val));
				}
			}
			$msg = json_encode($msg);
			exit($msg);
		}

		$act=getgpc("act");
		$id = getgpc("id");
		if($id && settype($id,"integer")){
			if($act=="edit"){
			$myorderInfo = $um->getMyOrderInfo($id);
			assign("myorderInfo",$myorderInfo);
			}else if($act=="del"){
				$um->delMyOrder($id);
			}
		}
		display("myorder");
	}

	function taoke(){
		load_class("taoke","action");
		$m = $_GET['PATH_INFO'][2];
		if(!$m){
			//Msg::show('动作未定义');
			$m="search";
		}
		$tk = new TaokeAction();
		$tk->$m();

	}

	function log(){
		$act  =getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=="del"){
				if($GLOBALS['db']->query("delete from qk_log where id='$id'")){ $ret = array('success'=>true,'message'=>'删除成功'); }
			}
			echo json_encode($ret);exit;
		}
		display("log");
	}

	function config(){
		load_class("config");
		$config = new ConfigModel();
		$act  =getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=="del"){
				if($config->del($id)){ $ret = array('success'=>true,'message'=>'删除成功'); }
			}else if($act=="ajaxEdit"){
				if($config->ajaxEdit($_POST)){ $ret = array('success'=>true,'message'=>'修改成功'); }
			}else if($act=="edit"){
				$ret['success']=$config->edit($_POST);
			}
			if($config->msg)$ret['message']=$config->msg;
			echo json_encode($ret);
			exit;
		}
		$id = getgpc("id");
		if($id && is_numeric($id)){
			assign("configInfo",$config->getInfo($id));
		}
		display("config");
	}

	function coupon(){
		load_class("coupon");
		$cm = new CouponModel();
		$inajax = getgpc("inajax","P");
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		if($inajax==1){
			$ret = array("success"=>false,"message"=>"参数错误");
			if($act=="ajaxEdit"){
				$ret['success'] = $cm->ajaxEdit($_POST);
			}else if($act=="del"){
				$ret['success'] = $cm->del($id);	
			}else if($act=="add" || $act=="edit"){
				$ret['success'] = $cm->$act($_POST);
			}else if($act=="addType"){
				if($id = $cm->addType($_POST)){
					$ret['success']=true;
					$ret['data']=array("id"=>$id);
				}
			}
			if($cm->msg){ $ret['message'] = $cm->msg; }
			echo json_encode($ret);exit();
		}
		$act= getgpc("act","GP");
		$id = getgpc("id","GP");
		if($act=="edit" && $id && is_numeric($id)){
			assign("couponInfo",$cm->getInfo($id));
		}
		display("coupon");
	}

	function com(){
		load_class("com");
		$com = new ComModel();
		$act = getgpc("act","P");
		$id = getgpc("id","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$ret=array("success"=>false,"message"=>"参数错误");
			if($act=="ajaxEdit"){
				global $db;
				$val = getgpc("val");
				$column= getgpc("col");
				$sql = "update `qk_com` set ".$column."='".$val."' where id=".$id;
				$db->query($sql);
				echo '{"success":true,"message":"","error":0,"content":"'.$val.'"}';
				exit;
			}else if($act=="edit" || $act=="add"){
				$ret['success'] = $com->$act($_POST);
			}
			if($com->msg){$ret['message']=$com->msg;}
			echo json_encode($ret);exit();
		}
		$act = getgpc("act");
		$id = getgpc("id");
		if($act=="edit" && $id && is_numeric($id)){
			assign("comInfo",$com->getInfo($id));
		}
		display("com");
	}

	function attr(){
		load_class('category');
		$cat = new CategoryModel();
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			global $db;
			$ret = array("success"=>false,"message"=>"参数错误");
			if($act=="addExtValue"){
				$attrId = getgpc("attrId","P");
				$attrValue = getgpc("attrValue","P");
				if($attrId && $attrValue){
					$sql = "select id from qk_goods_attr_ext where value='$attrValue' and attrId='$attrId'";
					if(!$db->getOne($sql)){
						$sql = "insert into qk_goods_attr_ext set attrId='$attrId',value='$attrValue',iStatus=1,posttime=UNIX_TIMESTAMP()";
						$db->query($sql);
						$id=$db->insert_id();
						$ret = array("success"=>true,"message"=>"添加属性值成功","data"=>array("id"=>$id));
						$cat->flushattr();
					}else{
						$ret['message'] = '该属性值已经存在';
					}
				}
			}else if($act=="delExt"){
				$id = getgpc("id","P");
				if($id && is_numeric($id)){
					$db->query("delete from qk_goods_attr_ext where id='$id'");
					$ret['success'] = true;
					$ret['message'] = '属性值删除成功';
				}else{
					$ret['message'] = '属性值ID不能为空';
				}
			}else if($act=="addAttr"){
				$typeId = getgpc("typeId","P");
				$attrName = getgpc("attrName","P");
				if($typeId && $attrName){
					if(!$db->getOne("select id from qk_goods_attr where typeId='$typeId' and name='$attrName'")){
						$sql = "insert into qk_goods_attr set typeId='$typeId',name='$attrName',`type`='checkbox',posttime=UNIX_TIMESTAMP()";
						$db->query($sql);
						$id = $db->insert_id();
						$ret['success'] = true;
						$ret['message'] = '添加商品属性成功';
						$ret['data'] = array("id"=>$id);
					}else{
						$ret['message'] = '该属性已经存在';
					}

				}else{
					$ret['message'] = '类型不存在或属性名错误';
				}
			}else if($act=="addType"){
				$name = getgpc("name","P");
				if($name){
					if(!$db->getOne("select id from qk_goods_type where name='$name'")){
						$sql = "insert into `qk_goods_type` set name='$name',posttime=UNIX_TIMESTAMP()";
						$db->query($sql);
						$id = $db->insert_id();
						$ret['success'] = true;
						$ret['message'] = '添加商品类型成功';
						$ret['data'] = array("id"=>$id);
					}else{
						$ret['message'] = '该商品类型已经存在';
					}
				}else{
					$ret['message'] = '商品类型名不能为空';
				}
			}else if($act=="delType"){
				$id = getgpc("id","P");
				if($id && is_numeric($id)){
					$db->query("delete from qk_goods_type where id='$id'");
					$ret = array("success"=>true,"message"=>'删除成功');
				}else{
					$ret['message'] = '删除失败，ID不能为空';
				}
			}else if($act=="delAttr"){
				$id = getgpc("id","P");
				if($id && is_numeric($id)){
					$db->query("delete from qk_goods_attr where id='$id'");
					$ret = array("success"=>true,"message"=>'删除成功');
				}else{
					$ret['message'] = '删除失败，ID不能为空';
				}
			}
			echo json_encode($ret);
			exit;
		}
		display("attr");
	}

	function password(){
		load_class('user');
		$um = new UserModel();
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");
		if($inajax=="1"){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=='edit'){
				$id = getgpc("id","P");
				if($id && is_numeric($id) && $id==$_SESSION['adminId']){
					$ret['success'] = $um->changePwd($_POST);
				}else{
					$ret['message'] = '用户不存在';
				}
			}
			if($um->msg){ $ret['message']=$um->msg; }
			echo json_encode($ret);exit;
		}
		assign("userInfo",$um->getInfo($_SESSION['adminId']));
		display('password');
	}

	function deliverycorp(){
		load_class("delivery");
		$dm = new DeliveryModel();
		$id = getgpc("id","P");
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");
		if($inajax=='1'){
			$ret = array('success'=>false,'message'=>'参数错误');
			if($act=="del"){
				if($dm->delDeliveryCorp($id)){ $ret = array('success'=>true,'message'=>'删除成功'); }
			}else if($act=="ajaxEdit"){
				if($dm->ajaxColEditDeliveryCorp($_POST)){
					$ret = array('success'=>true,'message'=>'修改成功');
				}
			}else if($act=="add"){
				if($id=$dm->addDeliveryCorp($_POST)){
					$ret = array('success'=>true,'message'=>'添加成功','data'=>array('id'=>$id));
				}
			}
			if($dm->msg){ $ret['message']=$dm->msg; }
			echo json_encode($ret);
			exit;
		}
		display('deliverycorp');
	}
	function qqauth(){
		$id = getgpc("id","P");
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");		
		if($inajax==1){
			$ret = array("success"=>false,"message"=>"参数错误");
			if($act=="del" && $id && settype($id,"integer")){
				$GLOBALS['db']->query("delete from `qk_qq_auth` where id='$id'");
				$ret = array("success"=>true,"message"=>"删除成功");
			}
			echo json_encode($ret);
			exit();
		}
		display('qqauth');
	}
	function weiboauth(){
			$id = getgpc("id","P");
			$act = getgpc("act","P");
			$inajax = getgpc("inajax","P");		
			if($inajax==1){
				$ret = array("success"=>false,"message"=>"参数错误");
				if($act=="del" && $id && settype($id,"integer")){
					$GLOBALS['db']->query("delete from `qk_weibo_auth` where id='$id'");
					$ret = array("success"=>true,"message"=>"删除成功");
				}
				echo json_encode($ret);
				exit();
			}
			display('weiboauth');
		}
	function prepaidcard(){
			$id = getgpc("id","P");
			$act = getgpc("act","P");
			$inajax = getgpc("inajax","P");		
			load_class('prepaidcard');$pm = new PrepaidcardModel();
			if($inajax==1){
				$ret = array("success"=>false,"message"=>"参数错误");
				if($act=="del" && $id && settype($id,"integer")){
					$ret['success']=$pm->del($id);
				}else if($act=='ajaxEdit'){
					if($pm->ajaxColEdit($_POST)){
						$ret = array('success'=>true,'message'=>'修改成功');
					}
				}else if($act=='add'){
					$ret['success']=$pm->add($_POST);
				}
				if($pm->msg){ $ret['message']=$pm->msg; }
				echo json_encode($ret);
				exit();
			}
			display('prepaidcard');
	}
	function withdraw(){
			$id = getgpc("id","P");
			$act = getgpc("act","P");
			$inajax = getgpc("inajax","P");		
			load_class('withdraw');$wm = new WithdrawModel();
			if($inajax==1){
				$ret = array("success"=>false,"message"=>"参数错误");
				if($act=="del" && $id && settype($id,"integer")){
					$ret['success']=$wm->del($id);
				}else if($act=='ajaxEdit'){
					if($wm->ajaxColEdit($_POST)){
						$ret = array('success'=>true,'message'=>'修改成功');
					}
				}else if($act=='add'){
					$ret['success']=$wm->add($_POST);
				}
				if($pm->msg){ $ret['message']=$wm->msg; }
				echo json_encode($ret);
				exit();
			}
			display('withdraw');
	}
	function usercoupon(){
			$id = getgpc("id","P");
			$act = getgpc("act","P");
			$inajax = getgpc("inajax","P");		
			load_class('coupon');$cm = new CouponModel();
			if($inajax==1){
				$ret = array("success"=>false,"message"=>"参数错误");
				if($act=="del" && $id && settype($id,"integer")){
					$ret['success']=$cm->delUserCoupon($id);
				}else if($act=='ajaxEdit'){
					if($cm->ajaxColEditUserCoupon($_POST)){
						$ret = array('success'=>true,'message'=>'修改成功');
					}
				}else if($act=='add'){
					$ret['success']=$cm->addUserCoupon($_POST);
				}
				if($cm->msg){ $ret['message']=$cm->msg; }
				echo json_encode($ret);
				exit();
			}
		display('usercoupon');
	}
	function appraise(){
		display('appraise');
	}
	function upload(){
		display('upload');
	}
}

?>