<?php
/**
 * 仓库管理
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
 
namespace Admin\Controller;
class ShopsGoodsController extends BaseController{
	
	public function _initialize(){
        parent::_initialize();
    }
    
	/**
     * 仓库商品列表
     */
	public function index(){
		$postdata = I('param.');
		$keyword = $postdata['keyword'];
        $map = array();
        if ($keyword) {
			$whereor = array();
            $whereor['id|goods_name'] = array('like', '%' . $keyword . '%');
			$goods_ids = M('Goods')->where($whereor)->getField('id',true);
			if($goods_ids){
				$map['goods_id'] = array('in',$goods_ids);
			}
        }
		
		if($postdata['data_from'])
			$map['addtime'][] = array('egt',strtotime($postdata['data_from']));
		if($postdata['data_to'])
			$map['addtime'][] = array('elt',strtotime($postdata['data_to']));
		
		$map['shop_id'] = $postdata['id'];
		$list = $this->lists('ShopsGoods', $map);
        $this->assign('list', $list);
		$this->assign($postdata);
		$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;
	}
	
}
?>