<?php
/**
 * lionfish 商城系统
 *
 * ==========================================================================
 * @link      http://www.liofis.com/
 * @copyright Copyright (c) 2015 liofis.com. 
 * @license   http://www.liofis.com/license.html License
 * ==========================================================================
 *
 * @author    fish
 *
 */
namespace Seller\Model;

class SpecModel{
	
	
	public function update($data,$spec_type = 'normal')
	{
		
		$ins_data = array();
		$ins_data['name'] = $data['name'];
		$ins_data['spec_type'] = $spec_type;
		$ins_data['value'] = serialize(array_filter($data['value']));
		$ins_data['addtime'] = time();
		
		$id = $data['id'];
		if( !empty($id) && $id > 0 )
		{
			M('lionfish_comshop_spec')->where( array('id' => $id) )->save($ins_data);
			$id = $data['id'];
			
		}else{
			
			M('lionfish_comshop_spec')->add($ins_data);
			$id = M('lionfish_comshop_spec')->getLastInsID();
		}
		
	}
	
	public function get_all_spec($spec_type = 'normal')
	{
		
		$specs = M('lionfish_comshop_spec')->where(' spec_type="'.$spec_type.'"')->order('id asc')->select();
		
		foreach($specs as $key => $val)
		{
			$val['value'] = unserialize($val['value']);
			if( !empty($val['value']) )
			{
				$val['value_str'] = implode('@', $val['value']);
			}else{
				$val['value_str'] = '';
			}
			
			$specs[$key] = $val;
		}
		
		return $specs;
	}
	
	
}
?>