<?php
/**
 * 菜单模型类 关联表名：mall_goods
 * 
 */
class mod_mall_goods_format extends inc_mod_admin {
	function on_show() {
		$arr_return = array();
		$obj_db = cls_obj::db();
		$obj_result = $obj_db->select("SELECT format_id,format_val,format_name FROM ".cls_config::DB_PRE."mall_goods_format");
		while( $obj_rs = $obj_db->fetch_array($obj_result) ) {
			if(empty($obj_rs["format_val"])) {
				$obj_rs["format_val"] = array();
			} else {
				$obj_rs["format_val"] = unserialize($obj_rs["format_val"]);
			}
			$arr_return[] = $obj_rs;
		}
		return $arr_return;
	}
	/* 查询指定id信息
	 * msg_id : 唯一标识
	 */
	function get_editinfo($msg_id) {
		$obj_rs = cls_obj::db()->edit(cls_config::DB_PRE."mall_goods_format" , "format_id='" . $msg_id . "'");
		if(empty($obj_rs["format_val"])) {
			$obj_rs["format_val"] = array();
		} else {
			$obj_rs["format_val"] = unserialize($obj_rs["format_val"]);
		}
		return $obj_rs;
	}
	/* 保存数据
	 * 
	 */
	function on_save() {
		$arr_return = array("code" => 0 , "id"=>0 , "msg" => cls_language::get("save_ok"));
		$arr_fields = array(
			"format_id"=>fun_get::post("id"),
			"format_name"=>fun_get::post("format_name"),
		);
		$val_name = fun_get::post("val_name" , array());
		$val_pic = fun_get::post("val_pic" , array());
		$arr_slide1 = array();
		$lng_c = count($val_name);
		for($i = 0; $i < $lng_c ; $i++) {
			if(empty($val_name[$i])) continue;
			$arr_slide1[] = array("name" => $val_name[$i] , "pic" => $val_pic[$i]);
		}
		$arr_fields["format_val"] = $arr_slide1;
		$arr = tab_mall_goods_format::on_save($arr_fields);
		if($arr['code']==0) {
			if(isset($arr['id'])) $arr_return['id'] = $arr['id'];
		} else {
			$arr_return['code'] = $arr['code'];
			$arr_return['msg']  = $arr['msg'];
		}
		return $arr_return;
	}
	/* 删除指定  id 数据
	 */
	function on_delete() {
		$arr_return = array("code"=>0 , "msg"=> cls_language::get("delete_ok"));
		$str_id = fun_get::get("id");
		$arr_id = fun_get::get("selid");
		if( empty($arr_id) && empty($str_id) ) {
			$arr_return['code'] = 22;//见参数说明表
			$arr_return['msg']  = cls_language::get("delete_no_id");
			return $arr_return;
		}
		if(!empty($arr_id)) $str_id = $arr_id; //优先考虑 arr_id
		$arr = tab_mall_goods_format::on_delete($str_id);
		if($arr['code'] != 0) {
			$arr_return['code'] = $arr['code'];
			$arr_return['msg']  = $arr['msg'];
		}
		return $arr_return;
	}

}
?>