Kirin пре 2 година
родитељ
комит
1e57b551b0
1 измењених фајлова са 58 додато и 54 уклоњено
  1. 58 54
      app/api/controller/store/StoreProductController.php

+ 58 - 54
app/api/controller/store/StoreProductController.php

@@ -21,6 +21,7 @@ use crmeb\services\UploadService;
 use crmeb\services\UtilService;
 use crmeb\services\upload\Upload;
 use Overtrue\Pinyin\Pinyin;
+use think\Exception;
 use think\exception\DbException;
 
 /**
@@ -125,63 +126,66 @@ class StoreProductController
      */
     public function detail(Request $request, $id, $type = 0)
     {
-        if ($request->isLogin())
-            $user = $request->user();
-        if (!$id || !($storeInfo = StoreProduct::getValidProduct($id, $user['sp_user'] ?? 0))) return app('json')->fail('商品不存在或已下架');
-        $siteUrl = sys_config('site_url');
-        $storeInfo['image'] = set_file_url($storeInfo['image'], $siteUrl);
-        $storeInfo['image_base'] = set_file_url($storeInfo['image'], $siteUrl);
-        $storeInfo['code_base'] = QrcodeService::getWechatQrcodePath($id . '_product_detail_wap.jpg', '/detail/' . $id);
-        $uid = $request->uid();
-        var_dump($storeInfo);
-        $data['uid'] = $uid;
-        $storeInfo['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id));
-        //替换windows服务器下正反斜杠问题导致图片无法显示
-        $storeInfo['description'] = preg_replace_callback('#<img.*?src="([^"]*)"[^>]*>#i', function ($imagsSrc) {
-            return isset($imagsSrc[1]) && isset($imagsSrc[0]) ? str_replace($imagsSrc[1], str_replace('\\', '/', $imagsSrc[1]), $imagsSrc[0]) : '';
-        }, $storeInfo['description']);
-        $storeInfo['userCollect'] = StoreProductRelation::isProductRelation($id, $uid, 'collect');
-        $storeInfo['userLike'] = StoreProductRelation::isProductRelation($id, $uid, 'like');
-        list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($id, $uid, $type);
-        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, $uid());
-        $data['productAttr'] = $productAttr;
-        $data['productValue'] = $productValue;
-        $data['priceName'] = 0;
-        if ($uid) {
-            $user = $request->user();
-            if (!$user->is_promoter) {
-                $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $uid])->sum('pay_price');
-                $status = is_brokerage_statu($price);
-                if ($status) {
-                    User::where('uid', $uid)->update(['is_promoter' => 1]);
-                    $user->is_promoter = 1;
+        try {
+            if ($request->isLogin())
+                $user = $request->user();
+            if (!$id || !($storeInfo = StoreProduct::getValidProduct($id, $user['sp_user'] ?? 0))) return app('json')->fail('商品不存在或已下架');
+            $siteUrl = sys_config('site_url');
+            $storeInfo['image'] = set_file_url($storeInfo['image'], $siteUrl);
+            $storeInfo['image_base'] = set_file_url($storeInfo['image'], $siteUrl);
+            $storeInfo['code_base'] = QrcodeService::getWechatQrcodePath($id . '_product_detail_wap.jpg', '/detail/' . $id);
+            $uid = $request->uid();
+            $data['uid'] = $uid;
+            $storeInfo['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id));
+            //替换windows服务器下正反斜杠问题导致图片无法显示
+            $storeInfo['description'] = preg_replace_callback('#<img.*?src="([^"]*)"[^>]*>#i', function ($imagsSrc) {
+                return isset($imagsSrc[1]) && isset($imagsSrc[0]) ? str_replace($imagsSrc[1], str_replace('\\', '/', $imagsSrc[1]), $imagsSrc[0]) : '';
+            }, $storeInfo['description']);
+            $storeInfo['userCollect'] = StoreProductRelation::isProductRelation($id, $uid, 'collect');
+            $storeInfo['userLike'] = StoreProductRelation::isProductRelation($id, $uid, 'like');
+            list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($id, $uid, $type);
+            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, $uid());
+            $data['productAttr'] = $productAttr;
+            $data['productValue'] = $productValue;
+            $data['priceName'] = 0;
+            if ($uid) {
+                $user = $request->user();
+                if (!$user->is_promoter) {
+                    $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $uid])->sum('pay_price');
+                    $status = is_brokerage_statu($price);
+                    if ($status) {
+                        User::where('uid', $uid)->update(['is_promoter' => 1]);
+                        $user->is_promoter = 1;
+                    }
                 }
+                if ($user->is_promoter) {
+                    $data['priceName'] = StoreProduct::getPacketPrice($storeInfo, $productValue);
+                }
+                if (!strlen(trim($data['priceName'])))
+                    $data['priceName'] = 0;
             }
-            if ($user->is_promoter) {
-                $data['priceName'] = StoreProduct::getPacketPrice($storeInfo, $productValue);
-            }
-            if (!strlen(trim($data['priceName'])))
-                $data['priceName'] = 0;
+            $data['reply'] = StoreProductReply::getRecProductReply($storeInfo['id']);
+            $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['id'])->count();
+            if ($data['replyCount']) {
+                $goodReply = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['id'])->where('product_score', 5)->count();
+                $data['replyChance'] = $goodReply;
+                if ($goodReply) {
+                    $data['replyChance'] = bcdiv($goodReply, $data['replyCount'], 2);
+                    $data['replyChance'] = bcmul($data['replyChance'], 100, 2);
+                }
+            } else $data['replyChance'] = 0;
+            $data['mer_id'] = $storeInfo['mer_id'];
+            $data['system_store'] = ($res = SystemStore::getStoreDispose()) ? $res : [];
+            $data['good_list'] = StoreProduct::getGoodList(18, $user['sp_user'] ?? 0, 'image,store_name,price,id,ot_price');
+            $data['mapKey'] = sys_config('tengxun_map_key');
+            $data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启
+            $data['activity'] = StoreProduct::activity($data['storeInfo']['id'], false);
+            return app('json')->successful($data);
+        }catch (Exception $exception){
+            var_dump($exception->getTrace());
         }
-        $data['reply'] = StoreProductReply::getRecProductReply($storeInfo['id']);
-        $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['id'])->count();
-        if ($data['replyCount']) {
-            $goodReply = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['id'])->where('product_score', 5)->count();
-            $data['replyChance'] = $goodReply;
-            if ($goodReply) {
-                $data['replyChance'] = bcdiv($goodReply, $data['replyCount'], 2);
-                $data['replyChance'] = bcmul($data['replyChance'], 100, 2);
-            }
-        } else $data['replyChance'] = 0;
-        $data['mer_id'] = $storeInfo['mer_id'];
-        $data['system_store'] = ($res = SystemStore::getStoreDispose()) ? $res : [];
-        $data['good_list'] = StoreProduct::getGoodList(18, $user['sp_user'] ?? 0, 'image,store_name,price,id,ot_price');
-        $data['mapKey'] = sys_config('tengxun_map_key');
-        $data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;//门店自提是否开启
-        $data['activity'] = StoreProduct::activity($data['storeInfo']['id'], false);
-        return app('json')->successful($data);
     }
 
     /**