<?php
 /**
 *      [QKSHOP] (C) QIKEWEB Inc.
 *      This is NOT a freeware, use is subject to license terms
 */

class TaokeModel extends BaseModel{
	public $msg = '';
	function getchild($parent_cid=0){
			load_class("top","action");
			$top = new TopAction();
			$param['parent_cid'] = $parent_cid;
			$pcat = $top->getCat($param);
			if($pcat){
				foreach($pcat as $pitem){
					$sql = "insert into qk_taobao_cat set cid='".$pitem['cid']."',is_parent='".$pitem['is_parent']."',name='".$pitem['name']."',parent_cid='".$pitem['parent_cid']."'";
					$sql .= ",posttime=UNIX_TIMESTAMP()";
					$this->db->query($sql);
					//$this->getchild($pitem['cid']);
				}
			}else{
				return false;
			}
	}
	function updateCat(){
		load_class("top","action");
		$top = new TopAction();
		$cats = $top->getCat();
		if(!$cats){return false;}
		$this->db->query("truncate table qk_taobao_cat");
		foreach($cats as $item){
			$sql = "insert into qk_taobao_cat set cid='".$item['cid']."',is_parent='".$item['is_parent']."',name='".$item['name']."',parent_cid='".$item['parent_cid']."'";
			$sql .= ",posttime=UNIX_TIMESTAMP()";
			$this->db->query($sql);
			//$this->getchild($item['cid']);

		}

		//$sql = "select * from qk_taobao_cat where parent_cid!=0";

		return true;

	}
	function getCat(){
		$sql = "select * from qk_taobao_shop order by id asc";
		return $this->db->getAll($sql);
	}
	function add($params){
		return $this->query($params);
	}
	function query($params){
		$act = $params['act'];
		$seller_nick =  getgpc('seller_nick','P');
		$user_id =  getgpc('user_id','P');
		$shop_title =  getgpc('shop_title','P');
		$click_url =  getgpc('click_url','P');
		$commission_rate =  getgpc('commission_rate','P');
		$seller_credit =  getgpc('seller_credit','P');
		$shop_type =  getgpc('shop_type','P');
		$total_auction =  getgpc('total_auction','P');
		$auction_count =  getgpc('auction_count','P');
		if($seller_nick && $user_id && $shop_title && $click_url){
			if($act=="add"){
				if($this->db->getOne("select id from qk_taobao_shop where seller_nick='$seller_nick' or user_id='$user_id'")){
					$this->msg = '店铺重复';
					return false;
				}
				$sql = "insert into qk_taobao_shop set ";
				$sqlEnd = ",posttime=UNIX_TIMESTAMP()";
			}
			$sql .= "seller_nick='$seller_nick',user_id='$user_id',shop_title='$shop_title',click_url='$click_url',commission_rate='$commission_rate',seller_credit='$seller_credit'";
			$sql .= ",shop_type='$shop_type',total_auction='$total_auction',auction_count='$auction_count'";
			$sql .= $sqlEnd;
			if($this->db->query($sql)){
				return true;
			}
		}
		return false;
	}
}

// shop\['(.*)', => $\1 =  getgpc('\1',

?>