<?php
/**
 * 仓库管理
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
 
namespace Admin\Controller;
class ShopsGoodsStockController extends BaseController{
	
	public function _initialize(){
        parent::_initialize();
    }
    
	/**
     * 仓库商品详情列表
     */
	public function index(){
		$goods_id = I('get.goods_id');
		$shop_id = I('get.shop_id');
		
		$map['shop_id'] = $shop_id;
		$map['goods_id'] = $goods_id;
	
		$goods_huopin=D('Shop/GoodsAttrStock')->liststock($goods_id,$shop_id,'-1');
        if($goods_huopin['status']==1){//有货品 需要前台选择
            foreach($goods_huopin['data'] as $key => $vo){
                $goods_attr=attr_key2name($vo['goods_stock'],$vo['goods_id']);
                $goods_huopin['data'][$key]['goods_attr']=$goods_attr;
            }
        }elseif($goods_huopin['status']==2){
            $goods_huopin['data'][0]['goods_attr'] = idtoname($goods_id,'Goods','goods_name');
            $goods_huopin['data'][0]['goods_number'] = M('ShopsGoodsStock')->where($stock_map)->getField('goods_number');
        }elseif($goods_huopin['status']==3){
            $stock_info=$goods_huopin['data'][0];
            $stock_id=$stock_info['goods_stock'];
            $goods_huopin['data'][0]['goods_attr']=attr_key2name($stock_id,$stock_info['goods_id']);
        }
		
        $this->assign('list', $goods_huopin['data']);
		$this->display();
	}
	
	public function _before_delete(){
		$model = CONTROLLER_NAME;
		$id=I('id');
		if(isset($id)&&is_array($id)){
			foreach($id as $k=>$v){
				$result=check_delete($v,7,$model);
				if(!$result['status'])unset($id[$k]);
			}
			if(empty($id)){$this->error($result['info']);exit;}
		}else{
			$result=check_delete($id,7,$model);
			if(!$result['status']){$this->error($result['info']);exit;}
		}
		$this->id=$id;
	}
	
}
?>