Browse Source

判断是否可以出售

sugar1569 6 năm trước cách đây
mục cha
commit
cd3c319304

+ 12 - 2
application/routine/model/store/StoreProduct.php

@@ -25,7 +25,6 @@ class StoreProduct extends ModelBasic
     {
         return self::where('is_del',0)->where('is_show',1)->where('id',$productId)->field($field)->find();
     }
-
     public static function validWhere()
     {
         return self::where('is_del',0)->where('is_show',1)->where('mer_id',0);
@@ -46,7 +45,6 @@ class StoreProduct extends ModelBasic
         return $model->select();
     }
 
-
     /**
      * 热卖产品
      * @param string $field
@@ -146,4 +144,16 @@ class StoreProduct extends ModelBasic
         return $res;
     }
 
+    /**
+     * TODO  判断是否可以出售
+     * @param $id
+     * @param int $cartNum
+     * @return int|string
+     * @throws \think\Exception
+     */
+    public static function isValidCartProduct($id,$cartNum =1){
+        return self::where('is_del',0)->where('is_show',1)->where('id',$id)->where('stock','>',$cartNum)->count();
+    }
+
+
 }

+ 13 - 0
application/routine/model/store/StoreSeckill.php

@@ -106,4 +106,17 @@ class StoreSeckill extends ModelBasic
         $res = false !== self::where('id',$seckillId)->dec('stock',$num)->inc('sales',$num)->update();
         return $res;
     }
+
+    /**
+     * TODO  判断是否可以出售
+     * @param $id
+     * @param int $cartNum
+     * @return int|string
+     * @throws \think\Exception
+     */
+    public static function isValidCartSeckill($id,$cartNum = 1){
+        if(!$id) return false;
+        $time = time();
+        return self::where('id',$id)->where('is_del',0)->where('status',1)->where('stock','>',$cartNum)->where('start_time','<',$time)->where('stop_time','>',$time)->count();
+    }
 }