<?php
/* 快捷商城系统
 * 版本号：2.0
 * 官网：http://www.kjcms.cn
 * 2015-02-16
 */
class inc_mod_default extends cls_base{

	/**
	 * admin 目录 初始类，启动 : 登录检查，权限检查
	 */
	function __construct($arr_v) {
		parent::__construct($arr_v);
		$this->this_login_user = cls_obj::get("cls_user");
	}
	function get_pagebtns( $arr_info , $listnum = 10 ) {
		$arr_return = array("pre" => 0, "next" => 0,"list" => array() ,"premore" => 0 , "nextmore" => 0 , "start" => 1 , "end" => $arr_info['pages']);
		if($arr_info['total'] < 1) return $arr_return;
		$arr_return['pre'] = max(0,$arr_info['page']-1);
		$arr_return['next'] = $arr_info['page']+1;
		if($arr_return['next'] > $arr_info['pages']) $arr_return['next'] = 0;

		if($arr_info["pages"] > $listnum) {
			$ii = $listnum/2;
			if($arr_info['page'] > $ii){
				$lng_pre=$arr_info['page'] - $ii;
				$lng_next=$arr_info['page'] + $ii;
			}else{
				$lng_pre=1;
				$lng_next = $listnum;
			}
		}else{
			$lng_pre=1;
			$lng_next=$arr_info['pages'];
		}
		if($lng_pre < 1) $lng_pre = 1;
		if( $lng_next >= $arr_info['pages'] ) $lng_next = $arr_info['pages'];
		$arr_return['start'] = $lng_pre;
		$arr_return['end'] = $lng_next;

		for($i=$lng_pre;$i<=$lng_next;$i++){
			$arr_return['list'][] = $i;
		}
		return $arr_return;
	}
	function get_goods_info($id , $fields = '') {
		$str_fields = 'goods_id,goods_name,goods_shop_id,goods_price,goods_price_market,goods_pic,goods_pic_small,goods_format';
		if(!empty($fields)) $str_fields .= "," . $fields;
		$arr_fields = explode("," , $str_fields);
		$arr_fields = array_unique($arr_fields);
		$str_fields = implode("," , $arr_fields);
		//格式化id , 19-31 以 "-" 分隔，后面为规格id
		$arr = explode('-',$id);
		$id = $arr[0];
		$detail_id = 0;
		if(count($arr)>1) $detail_id = $arr[1];
		$obj_goods = cls_obj::db()->get_one("select " . $str_fields . " from " . cls_config::DB_PRE . "mall_goods where goods_id='" . $id . "'");
		if(empty($obj_goods)) {
			foreach($arr_fields as $item) {
				$arr_return[$item] = '';
			}
			return $arr_return;
		}
		$format_name = (!empty($obj_goods['goods_format']))? unserialize($obj_goods['goods_format']) : array();
		$obj_goods['format'] = $format_val = array();
		$obj_goods['detail_id'] = $detail_id;
		//是否有规格
		if(!empty($detail_id)) {
			$obj_detail = cls_obj::db()->get_one("select detail_name,detail_price,detail_price_market,detail_pic,detail_format from " . cls_config::DB_PRE . "mall_goods_detail where detail_id='" . $detail_id . "'");
			if(!empty($obj_detail)) {
				$obj_goods['goods_price'] = $obj_detail['detail_price'];
				$obj_goods['goods_price_market'] = $obj_detail['detail_price_market'];
				$obj_goods['goods_pic'] = $obj_detail['detail_pic'];
				$obj_goods['goods_name'] .= "-" . $obj_detail['detail_name'];
				if(!empty($obj_detail['detail_format'])) $format_val = unserialize($obj_detail['detail_format']);
			}
			foreach($format_name as $format) {
				if(!isset($format_val['id_' . $format['id']])) continue;
				$obj_goods['format'][] = array('name' => $format['name'] , 'val' => $format_val['id_' . $format['id']]['name']);
			}
		}
		return $obj_goods;
	}
}