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

class PaybankModel extends BaseModel{
	public $msg="";
	function getAllTypes(){
		$sql = "select * from qk_codemap where parentId=16 and iStatus=1";
		return $this->db->getAll($sql);
	}
	function del($id){
		$sql = "delete from `qk_paybank` where id='$id' limit 1";
		return $this->db->query($sql);
	}
	function getInfo($id){
		$sql = "select * from `qk_paybank` where id='$id'";
		$info = $this->db->getRow($sql);
		if(!$info){return false;}
		if($info['userId']){ $info['userInfo'] = $this->db->getRow("select * from `qk_user` where id='".$info['userId']."'"); }
		return $info;
	}
	function edit($param){
		return $this->query($param);
	}
	function add($param){
		return $this->query($param);
	}
	function query($param){
		$act = $param['act'];
		$id = $param['id'];
		$name = $param['name'];
		$amount = $param['amount'];
		$remark = $param['remark'];
		$detail = $param['detail'];
		$iStatus = $param['iStatus'];
		$logo = $param['logo'];
	
		if($act=="add"){
			$sql = "insert into `qk_paybank` set ";
			$sqlEnd = ",posttime=UNIX_TIMESTAMP()";
		}else if($act=="edit" && $id && settype($id,"integer")){
			$config = $this->db->getOne("select config from qk_paybank where id='$id'");
			$config = unserialize($config);
			$i = 0;
			foreach($config as $item){
				$configname = $item['name'];
				$config[$i]['value'] = $param[$configname];
				$i++;
			}
			$config = serialize($config);
			$sql = "update `qk_paybank` set ";
			$sqlEnd = " where id='$id'";

		}
		$sql .= " name='$name',remark='$remark',config='$config',iStatus='$iStatus',detail='$detail',logo='$logo'";
		$sql .= $sqlEnd;
		if($this->db->query($sql)){return true;}
		return false;
	}
	function ajaxEdit($params){
		$id = $params['id'];
		$act = $params['act'];
		$col = $params['col'];
		$val = $params['val'];
		$oldval = $params['oldval'];
		if($id && is_numeric($id) && $col){
			$sql = "update `qk_paybank` set  $col='$val' where id='$id'";
			if($this->db->query($sql)){
				return true;
			}
		}
		return false;
	}
}
?>
