<?php
/** 店铺商品
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <zhaoh@qq.com>
 */

namespace Shop\Model;
use Think\Model;
class ShopsGoodsStockModel extends Model{
    /**
     * 检查店铺商品库存
     * @param $goodsid 商品ID
     * @param $stock_id 货品ID
     * @param $shop_id 店铺ID
     * @param $number 检查商品是否满足这个库存
     * @return $type 0时返回booler 1时返回 int 具体库存数
     */
	public function checkstock($goodsid,$stock_id=0,$shop_id=0,$number=1,$type=0){
	   $goodsid=intval($goodsid);$stock_id=intval($stock_id);$shop_id=intval($shop_id);$number=intval($number);
	   if(empty($goodsid))return false;
	   if(empty($shop_id)){$shops_info=session('shops_info');$shop_id=$shops_info['id'];}
	   if(empty($shop_id))return false;
       if($number<=0)$number=1;
       $map=array();
       $map['status']=1;
       $map['goods_id']=$goodsid;
       $map['shop_id']=$shop_id;        
       $map['goods_stock']=$stock_id;
       if($type==0){
           $map['goods_number']=array('egt',$number);
           $check=$this->where($map)->count();
           return $check>0?true:false;
       }else{
           $num=$this->where($map)->getField('goods_number');
           return intval($num);
       }     
	}
}

?>