Kirin %!s(int64=3) %!d(string=hai) anos
pai
achega
59d06c7891

+ 2 - 2
app/api/controller/store/StoreProductController.php

@@ -48,7 +48,7 @@ class StoreProductController
             ['limit', 0],
             ['type', 0]
         ], $request);
-        return app('json')->successful(StoreProduct::getProductList($data, $request->uid()));
+        return app('json')->successful(StoreProduct::getProductList($data, $request->uid(), $request->store_id()));
     }
 
     /**
@@ -138,7 +138,7 @@ class StoreProductController
         }, $storeInfo['description']);
         $storeInfo['userCollect'] = StoreProductRelation::isProductRelation($id, $uid, 'collect');
         $storeInfo['userLike'] = StoreProductRelation::isProductRelation($id, $uid, 'like');
-        list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($id, $uid, $type);
+        list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($id, $uid, $type, $request->store_id());
         StoreVisit::setView($uid, $id, $storeInfo['cate_id'], 'viwe');
         $data['storeInfo'] = StoreProduct::setLevelPrice($storeInfo, $uid, true);
         $data['similarity'] = StoreProduct::cateIdBySimilarityProduct($storeInfo['cate_id'], 'id,store_name,image,price,sales,ficti', 4);

+ 9 - 4
app/models/store/StoreProduct.php

@@ -8,6 +8,7 @@
 namespace app\models\store;
 
 use app\admin\model\store\StoreProductAttrValue as StoreProductAttrValueModel;
+use app\admin\model\system\SystemStoreProductStock;
 use app\models\system\SystemUserLevel;
 use app\models\user\UserLevel;
 use crmeb\basic\BaseModel;
@@ -82,7 +83,7 @@ class StoreProduct extends BaseModel
         return self::where('is_del', 0)->where('is_show', 1)->where('mer_id', 0);
     }
 
-    public static function getProductList($data, $uid)
+    public static function getProductList($data, $uid, $store_id = 0)
     {
         $sId = $data['sid'];
         $cId = $data['cid'];
@@ -113,13 +114,17 @@ class StoreProduct extends BaseModel
         if ($salesOrder) $baseOrder = $salesOrder == 'desc' ? 'sales DESC' : 'sales ASC';//虚拟销量
         if ($baseOrder) $baseOrder .= ', ';
         $model->order($baseOrder . 'sort DESC, add_time DESC');
-        $list = $model->page((int)$page, (int)$limit)->field('id,store_name,cate_id,image,IFNULL(sales,0) + IFNULL(ficti,0) as sales,price,stock')->select()->each(function ($item) use ($uid, $type) {
+        $list = $model->page((int)$page, (int)$limit)->field('id,store_name,cate_id,image,IFNULL(sales,0) + IFNULL(ficti,0) as sales,price,stock')->select()->each(function ($item) use ($uid, $type, $store_id) {
             if ($type) {
                 $item['is_att'] = StoreProductAttrValueModel::where('product_id', $item['id'])->count() ? true : false;
                 if ($uid) $item['cart_num'] = StoreCart::where('is_pay', 0)->where('is_del', 0)->where('is_new', 0)->where('type', 'product')->where('product_id', $item['id'])->where('uid', $uid)->value('cart_num');
                 else $item['cart_num'] = 0;
                 if (is_null($item['cart_num'])) $item['cart_num'] = 0;
             }
+            if ($store_id) {
+                $stockinfo = SystemStoreProductStock::where('product_id', $item['id'])->find();
+                $item['price'] = $stockinfo ? SystemStoreProductStock::where('product_id', $item['id'])->min('price') : $item['price'];
+            }
         });
         $list = count($list) ? $list->toArray() : [];
         if (!empty($list)) {
@@ -584,7 +589,7 @@ class StoreProduct extends BaseModel
         $activity = explode(',', $activity);
         $activityId = [];
         $time = 0;
-        $seckillId = StoreSeckill::where('is_del', 0)->where('status', 1)->where('start_time', '<=', time())->where('stop_time', '>=', time()-86400)->where('product_id', $id)->field('id,time_id')->select();
+        $seckillId = StoreSeckill::where('is_del', 0)->where('status', 1)->where('start_time', '<=', time())->where('stop_time', '>=', time() - 86400)->where('product_id', $id)->field('id,time_id')->select();
         if ($seckillId) {
             foreach ($seckillId as $v) {
                 $timeInfo = GroupDataService::getDataNumber((int)$v['time_id']);
@@ -598,7 +603,7 @@ class StoreProduct extends BaseModel
         }
         $bargainId = StoreBargain::where('is_del', 0)->where('status', 1)->where('start_time', '<=', time())->where('stop_time', '>=', time())->where('product_id', $id)->value('id');
         if ($bargainId) $activityId[2] = $bargainId;
-        $combinationId = StoreCombination::where('is_del', 0)->where('is_show',1)->where('start_time', '<=', time())->where('stop_time', '>=', time())->where('product_id', $id)->value('id');
+        $combinationId = StoreCombination::where('is_del', 0)->where('is_show', 1)->where('start_time', '<=', time())->where('stop_time', '>=', time())->where('product_id', $id)->value('id');
         if ($combinationId) $activityId[3] = $combinationId;
         $data = [];
         foreach ($activity as $k => $v) {

+ 24 - 19
app/models/store/StoreProductAttr.php

@@ -8,6 +8,7 @@
 namespace app\models\store;
 
 
+use app\admin\model\system\SystemStoreProductStock;
 use crmeb\basic\BaseModel;
 use think\facade\Db;
 use crmeb\traits\ModelTrait;
@@ -29,7 +30,7 @@ class StoreProductAttr extends BaseModel
 
     protected function getAttrValuesAttr($value)
     {
-        return explode(',',$value);
+        return explode(',', $value);
     }
 
     public static function storeProductAttrValueDb()
@@ -43,49 +44,53 @@ class StoreProductAttr extends BaseModel
      * @param $productId
      * @return array
      */
-    public static function getProductAttrDetail($productId,$uid=0,$type = 0,$type_id=0)
+    public static function getProductAttrDetail($productId, $uid = 0, $type = 0, $type_id = 0, $store_id = 0)
     {
-        $attrDetail = self::where('product_id',$productId)->where('type',$type_id)->order('id asc')->select()->toArray()?:[];
-        $_values = self::storeProductAttrValueDb()->where('product_id',$productId)->where('type',$type_id)->select();
+        $attrDetail = self::where('product_id', $productId)->where('type', $type_id)->order('id asc')->select()->toArray() ?: [];
+        $_values = self::storeProductAttrValueDb()->where('product_id', $productId)->where('type', $type_id)->select();
         $values = [];
-        foreach ($_values as $value){
-            if($type){
+        foreach ($_values as $value) {
+            if ($type) {
                 if ($uid)
-                    $value['cart_num'] = StoreCart::where('product_attr_unique',$value['unique'])->where('is_pay', 0)->where('is_del', 0)->where('is_new', 0)->where('type', 'product')->where('product_id', $productId)->where('uid', $uid)->value('cart_num');
+                    $value['cart_num'] = StoreCart::where('product_attr_unique', $value['unique'])->where('is_pay', 0)->where('is_del', 0)->where('is_new', 0)->where('type', 'product')->where('product_id', $productId)->where('uid', $uid)->value('cart_num');
                 else
                     $value['cart_num'] = 0;
                 if (is_null($value['cart_num'])) $value['cart_num'] = 0;
             }
+            if ($store_id && $type_id == 0) {
+                $stockinfo = SystemStoreProductStock::where('unique', $value['unique'])->find();
+                $value['price'] = $stockinfo ? $stockinfo['price'] : $value['price'];
+            }
             $values[$value['suk']] = $value;
         }
-        foreach ($attrDetail as $k=>$v){
+        foreach ($attrDetail as $k => $v) {
             $attr = $v['attr_values'];
 //            unset($productAttr[$k]['attr_values']);
-            foreach ($attr as $kk=>$vv){
-                $attrDetail[$k]['attr_value'][$kk]['attr'] =  $vv;
-                $attrDetail[$k]['attr_value'][$kk]['check'] =  false;
+            foreach ($attr as $kk => $vv) {
+                $attrDetail[$k]['attr_value'][$kk]['attr'] = $vv;
+                $attrDetail[$k]['attr_value'][$kk]['check'] = false;
             }
         }
-        return [$attrDetail,$values];
+        return [$attrDetail, $values];
     }
 
     public static function uniqueByStock($unique)
     {
-        return self::storeProductAttrValueDb()->where('unique',$unique)->value('stock')?:0;
+        return self::storeProductAttrValueDb()->where('unique', $unique)->value('stock') ?: 0;
     }
 
     public static function uniqueByAttrInfo($unique, $field = '*')
     {
-        return self::storeProductAttrValueDb()->field($field)->where('unique',$unique)->find();
+        return self::storeProductAttrValueDb()->field($field)->where('unique', $unique)->find();
     }
 
-    public static function issetProductUnique($productId,$unique)
+    public static function issetProductUnique($productId, $unique)
     {
 //        $res = self::be(['product_id'=>$productId]);
-        $res = self::where('product_id',$productId)->where('type',0)->find();
-        if($unique){
-            return $res && self::storeProductAttrValueDb()->where('product_id',$productId)->where('unique',$unique)->where('type',0)->count() > 0;
-        }else{
+        $res = self::where('product_id', $productId)->where('type', 0)->find();
+        if ($unique) {
+            return $res && self::storeProductAttrValueDb()->where('product_id', $productId)->where('unique', $unique)->where('type', 0)->count() > 0;
+        } else {
             return !$res;
         }
     }