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

namespace Shop\Model;
use Think\Model;
class GoodsAttrStockModel extends Model{
    /**
     * 检查店铺商品库存
     * @param $goodsid 商品ID
     * @param $shop_id 店铺ID
     * @param $number 检查商品是否满足这个库存
     */
	public function liststock($goodsid,$shop_id=0,$number=1){
	   $return =array('status'=>0,'msg'=>'库存不足');
	   $goodsid=intval($goodsid);$shop_id=intval($shop_id);$number=intval($number);
	   if(empty($goodsid))return $return;
       if($number==0)$number=1;
       $map=array();
       $map['goods_id']=$goodsid;
       $check=$this->where($map)->count();
       if(empty($check)){$return['status']=2;return $return;}  //无货品
       
	   if(empty($shop_id)){$shops_info=session('shops_info');$shop_id=$shops_info['id'];}
	   if(empty($shop_id))return $return;   
       $map=array();
       $map['g.goods_id']=$goodsid;
       $map['s.shop_id']=$shop_id; 
       $map['s.goods_number']=array('egt',$number);
       $list=$this->alias('g')->join('__SHOPS_GOODS_STOCK__ as s on g.attr_key=s.goods_stock')->where($map)->field('s.*')->select();
       if(empty($list))return $return;
       $return['status']=count($list)==1?3:1;
       $return['data']=$list;
       return $return;
	}
}

?>