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

class TemaiModel extends BaseModel{
	function getInfo($id){
		global $baseUrl;
		if($id && intval($id)){
			load_class("attachment");
			$am = new AttachmentModel();
			load_class("brand");
			$bm = new BrandModel();
			$sql = "select * from qk_temai where id='$id'";
			$info = $this->db->getRow($sql);
			$info['url'] = $baseUrl."temai/view/id/".$info['id'];
			$info['banner']['url'] = $am->getUrl($info['bannerId']);
			$info['thumbnail']['url'] = $am->getUrl($info['thumbId']);
			$info['brandInfo'] = $bm->getInfo($info['brandId']);
			return $info;
		}
		return false;
	}

	function edit($params){
		return $this->query($params);
	}
	function query($params){
		$act = $params['act'];
		$id = $params['id'];

		$name = $params['name'];
		$brandId = $params['brandId'];
		$starttime = $params['starttime'];
		$endtime = $params['endtime'];
		$iStatus = $params['iStatus'];
		$sortId = $params['sortId'];
		$thumbId = $params['thumbId'];
		$bannerId = $params['bannerId'];
		$zhekou = $params['zhekou'];
		$desc = $params['desc'];

		if(!$starttime || !$starttime=strtotime($starttime)){$starttime=0;}
		if(!$endtime || !$endtime=strtotime($endtime)){$endtime=0;}
		if($name && $brandId){
			if($act=="edit" && $id && intval($id)){
				$sql = "update qk_temai set ";
				$sqlEnd = " where id='$id'";
			}else if($act=="add"){
				$sql = "insert into qk_temai set ";
				$sqlEnd = ",posttime=UNIX_TIMESTAMP()";
			}
			$sql .= " name='$name',brandId='$brandId',starttime='$starttime',endtime='$endtime',iStatus='$iStatus',sortId='$sortId',thumbId='$thumbId'";
			$sql .= ",zhekou='$zhekou',bannerId='$bannerId',`desc`='$desc'";
			$sql .= $sqlEnd;
			if($this->db->query($sql)){
				return true;
			}
		}
		return false;
	}

	function add($params){
		return $this->query($params);
	}
}
?>