shish 6 лет назад
Родитель
Сommit
c93a06d481

+ 2 - 2
app/business/controllers/UploadController.php

@@ -26,7 +26,7 @@ class UploadController extends BaseController
 			$merchantId = 12358;
 			$month = date("Ym");
 			$date = date("d");
-			$path = dirUtil::imgUploadDir() . "/{$merchantId}/{$month}/{$date}/";
+			$path = dirUtil::getImgUploadDir() . "/{$merchantId}/{$month}/{$date}/";
 			if (!file_exists($path)) {
 				//检查是否有该文件夹,如果没有就创建,并给予最高权限
 				mkdir($path, 0700, true);
@@ -81,7 +81,7 @@ class UploadController extends BaseController
 			$merchantId = 12358;
 			$month = date("Ym");
 			$date = date("d");
-			$path = dirUtil::imgUploadDir() . "/{$merchantId}/{$month}/{$date}/";
+			$path = dirUtil::getImgUploadDir() . "/{$merchantId}/{$month}/{$date}/";
 			if (!file_exists($path)) {
 				//检查是否有该文件夹,如果没有就创建,并给予最高权限
 				mkdir($path, 0700, true);

+ 17 - 4
common/components/business.php

@@ -56,10 +56,23 @@ class business
 		$imgList = [];
 		$smallImgList = [];
 		$prefixImgUrl = Yii::$app->params['imgUrl'];
+		$imageRoot = dirUtil::getImgUploadDir();
 		foreach ($arr as $imgUrl) {
 			$smallImg = self::getSmallImg($imgUrl);
-			$normal = $prefixImgUrl . $imgUrl;
 			$small = $prefixImgUrl . $smallImg;
+			$normal = $prefixImgUrl . $imgUrl;
+			//没有小图则生成小图,兼容旧系统
+			if (file_exists($imageRoot . $smallImg) == false) {
+				$preImg = $imageRoot . $imgUrl;
+				$imgInfo = getimagesize($preImg);
+				$width = $imgInfo[0];
+				$height = $imgInfo[1];
+				//生成小图 200px
+				$smallWidth = 200;
+				$smallHeight = ceil((200 * $height) / $width);
+				$smallFullPathFile = $imageRoot . $smallImg;
+				Image::thumbnail($preImg, $smallWidth, $smallHeight)->save($smallFullPathFile, ['quality' => 100]);
+			}
 			$imgList[] = $normal;
 			$smallImgList[] = $small;
 		}
@@ -127,7 +140,7 @@ class business
 		$info['avatarUrl'] = $prefixImgUrl . $imgUrl;
 		return $info;
 	}
-
+	
 	//
 	public static function formatOrderGoodsCover($info)
 	{
@@ -144,7 +157,7 @@ class business
 		$info['coverUrl'] = $prefixImgUrl . $imgUrl;
 		return $info;
 	}
-
+	
 	//商家公众号logo处理 shish 2019.12.20
 	public static function formatMerchantLogo($info)
 	{
@@ -199,5 +212,5 @@ class business
 		$info['avatarUrl'] = $prefixImgUrl . $imgUrl;
 		return $info;
 	}
-
+	
 }

+ 1 - 1
common/components/dirUtil.php

@@ -14,7 +14,7 @@ class dirUtil
 	}
 
 	//图片上传保存的目录 shish 2020.1.7
-	public static function imgUploadDir()
+	public static function getImgUploadDir()
 	{
 		return Yii::getAlias('@vendor') . '/../../resource/images/uploads';
 	}

+ 1 - 1
common/services/ImageService.php

@@ -15,7 +15,7 @@ class ImageService
 	{
 		$month = date("Ym");
 		$date = date("d");
-		$path = dirUtil::imgUploadDir();
+		$path = dirUtil::getImgUploadDir();
 		$middle = "/weixin/avatar/{$merchantId}/{$month}/{$date}/";
 		if (!file_exists($path . $middle)) {
 			mkdir($path . $middle, 0777, true);