12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/9/29
- * Time: 15:07
- */
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class GoodsSkus extends Model
- {
- public $timestamps = false;
- protected $table = "goods_skus";
- public static function actualQuantity($sku_id){
- //计算实际库存 -还未到卖家云的量
- $sku_quantity = GoodsSkus::where('id', $sku_id)->pluck('quantity');
- $w_num = OrderGoodsSkus::where('sku_id', $sku_id)->where('is_del',0)->where('mj_status',0)->sum('num');
- $fx_num = FxOrderGoodsSkus::where('sku_id', $sku_id)->where('is_del',0)->where('mj_status',0)->sum('num');
- $quantity = $sku_quantity - $w_num - $fx_num;
- return $quantity;
- }
- public static function actualQuantityByRedis($sku_id){
- //计算实际库存 -还未到卖家云的量
- $sku_quantity = GoodsSkus::where('id', $sku_id)->pluck('quantity');
- $redisKey = config('constants.SKU_QUANTITY_TABLE');
- //货号为column
- $code = GoodsSkus::where('id', $sku_id)->pluck('code');
- $w_num = RedisModel::hGet($redisKey, $code);
- if(!$w_num) $w_num = 0;
- $quantity = $sku_quantity - $w_num;
- return ['quantity' => $quantity, 'w_num' => $w_num];
- }
- public static function actualQuantityNotNull(){
- //取出所有商品规格信息
- $skuList = GoodsSkus::all();
- $actualSkuList = array();
- //遍历商品规格信息,分别计算库用库存并判断
- foreach($skuList as $sku){
- $quantityArr = self::actualQuantityByRedis($sku['id']);
- if($quantityArr['quantity'] > 0){
- //将可用库存大于0的赋值给新数组
- $actualSkuList[] = $sku['id'];
- }
- }
- return $actualSkuList;
- }
-
- }
|