shish 6 лет назад
Родитель
Сommit
57a35908c8
2 измененных файлов с 146 добавлено и 116 удалено
  1. 15 8
      app/saas/controllers/UserController.php
  2. 131 108
      common/components/qrCodeUtil.php

+ 15 - 8
app/saas/controllers/UserController.php

@@ -4,9 +4,11 @@ namespace saas\controllers;
 
 use biz\merchant\classes\MerchantExtendClass;
 use biz\merchant\services\MerchantAssetService;
+use biz\merchant\services\MerchantExtendService;
 use biz\merchant\services\ShopService;
 use biz\retail\services\RetailAssetService;
 use biz\user\services\UserService;
+use common\components\dirUtil;
 use common\components\httpUtil;
 use common\components\qrCodeUtil;
 use common\components\util;
@@ -80,16 +82,21 @@ class UserController extends BaseController
 		$id = Yii::$app->request->get('id');
 		$shop = ShopService::getById($id);
 		$merchantId = isset($shop['merchantId']) ? $shop['merchantId'] : 0;
-		if (empty($merchantId)) {
+		$extend = MerchantExtendService::getByMerchantId($merchantId);
+		if (empty($extend)) {
 			util::fail('没有找到商家');
 		}
-		$url = Yii::$app->params['mDomain'] . "/#/pages/pay/index?account={$merchantId}&shopId=" . $id;
-		//强制转成https
-		$url = httpUtil::becomeHttps($url);
-
-		$logo = !empty($this->merchant['logo']) ? $webRoot . $this->merchant['logo'] : '';
-		$gatheringQrcodeUrl = qrCodeUtil::generate($url, $unique, $logo, 10);
-
+		$applyMemberCode = isset($extend['applyMemberCode']) ? $extend['applyMemberCode'] : '';
+		$file = dirUtil::getImgDir() . $applyMemberCode;
+		if (empty($applyMemberCode) || file_exists($file) == false) {
+			$url = Yii::$app->params['mDomain'] . "/#/pages/pay/index?account={$merchantId}&shopId=" . $id;
+			//强制转成https
+			$url = httpUtil::becomeHttps($url);
+			$applyMemberCode = qrCodeUtil::generateGatheringQrCode($url, $merchantId, $id, '', 10);
+		}
+		$imgUrl = Yii::$app->params['imgHost'] . $applyMemberCode;
+		echo '会员收款码<br /><br />';
+		echo "<img width='300' src='{$imgUrl}' />";
 	}
 
 }

+ 131 - 108
common/components/qrCodeUtil.php

@@ -1,80 +1,82 @@
 <?php
+
 namespace common\components;
 
 use Yii;
 use common\components\stringUtil;
 
-class qrCodeUtil{
-
+class qrCodeUtil
+{
+	
 	/**
 	 * 生成二维码
 	 * $unique 举例 userId_189 merchant_20等
-	 * $size 大小 5 195px 8 312px 
+	 * $size 大小 5 195px 8 312px
 	 */
-	public static function generate($url, $unique= '',$logo = '',$size=5)
+	public static function generate($url, $unique = '', $logo = '', $size = 5)
 	{
-		$app 					= Yii::getAlias("@app");
-		$saveDir				= $app.'/../../resource/images/qrcode/';
-		include_once Yii::getAlias("@vendor/qrcode").'/phpqrcode.php';
-		$rand					= stringUtil::buildOrderNo();
-		$random					= empty($unique) ? $rand : $unique.'_'.$rand;
+		$app = Yii::getAlias("@app");
+		$saveDir = $app . '/../../resource/images/qrcode/';
+		include_once Yii::getAlias("@vendor/qrcode") . '/phpqrcode.php';
+		$rand = stringUtil::buildOrderNo();
+		$random = empty($unique) ? $rand : $unique . '_' . $rand;
 		//表示容错率,也就是有被覆盖的区域还能识别,分别是 L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%)
-		$errorCorrectionLevel	= 'H';
-		$matrixPointSize		= $size;//生成图片大小
-		$QR						= $saveDir.$random.'.png';
+		$errorCorrectionLevel = 'H';
+		$matrixPointSize = $size;//生成图片大小
+		$QR = $saveDir . $random . '.png';
 		\QRcode::png($url, $QR, $errorCorrectionLevel, $matrixPointSize, 1);//最后的参数1表示空白间距
 		if (empty($logo) || file_exists($logo) == false) {
-			return '/qrcode/'.$random.'.png';//没有logo输出的二维码
+			return '/qrcode/' . $random . '.png';//没有logo输出的二维码
 		}
-		$QR					= imagecreatefromstring(file_get_contents($QR));
-		$logo				= imagecreatefromstring(file_get_contents($logo));
-		$QR_width			= imagesx($QR);//二维码图片宽度
-		$QR_height			= imagesy($QR);//二维码图片高度
-		$logo_width			= imagesx($logo);//logo图片宽度
-		$logo_height		= imagesy($logo);//logo图片高度
-		$logo_qr_width		= $QR_width / 5;
-		$scale				= $logo_width/$logo_qr_width;
-		$logo_qr_height		= $logo_height/$scale;
-		$from_width			= ($QR_width - $logo_qr_width) / 2;
-		imagecopyresampled($QR,$logo,$from_width,$from_width,0,0,$logo_qr_width,$logo_qr_height,$logo_width,$logo_height);//重新组合图片并调整大小
-		imagepng($QR, $saveDir.$random.'_combine.png');//输出图片
-		return '/qrcode/'.$random.'_combine.png';//组合logo后输出的二维码
+		$QR = imagecreatefromstring(file_get_contents($QR));
+		$logo = imagecreatefromstring(file_get_contents($logo));
+		$QR_width = imagesx($QR);//二维码图片宽度
+		$QR_height = imagesy($QR);//二维码图片高度
+		$logo_width = imagesx($logo);//logo图片宽度
+		$logo_height = imagesy($logo);//logo图片高度
+		$logo_qr_width = $QR_width / 5;
+		$scale = $logo_width / $logo_qr_width;
+		$logo_qr_height = $logo_height / $scale;
+		$from_width = ($QR_width - $logo_qr_width) / 2;
+		imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);//重新组合图片并调整大小
+		imagepng($QR, $saveDir . $random . '_combine.png');//输出图片
+		return '/qrcode/' . $random . '_combine.png';//组合logo后输出的二维码
 	}
-
+	
 	/**
 	 * 生成固定名称的图片二维码
 	 * $unique 举例 userId_189 merchant_20等
 	 * $size 大小 5 195px 8 312px
 	 */
-	public static function generateFixQrCode($url, $unique,$logo = '',$size=5)
+	public static function generateFixQrCode($url, $unique, $logo = '', $size = 5)
 	{
-		$app 					= Yii::getAlias("@app");
-		$saveDir				= $app.'/../resource/images/qrcode/';
-		include_once Yii::getAlias("@vendor/qrcode").'/phpqrcode.php';
-		$random					= $unique;
+		$app = Yii::getAlias("@app");
+		$saveDir = $app . '/../resource/images/qrcode/';
+		include_once Yii::getAlias("@vendor/qrcode") . '/phpqrcode.php';
+		$random = $unique;
 		//表示容错率,也就是有被覆盖的区域还能识别,分别是 L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%)
-		$errorCorrectionLevel	= 'H';
-		$matrixPointSize		= $size;//生成图片大小
-		$QR						= $saveDir.$random.'.png';
-		if(file_exists($QR)){
-			return '/qrcode/'.$random.'.png';
+		$errorCorrectionLevel = 'H';
+		$matrixPointSize = $size;//生成图片大小
+		$QR = $saveDir . $random . '.png';
+		if (file_exists($QR)) {
+			return '/qrcode/' . $random . '.png';
 		}
 		\QRcode::png($url, $QR, $errorCorrectionLevel, $matrixPointSize, 1);//最后的参数1表示空白间距
 		if (!empty($logo) && file_exists($logo)) {
-			$QR					= imagecreatefromstring(file_get_contents($QR));
-			$logo				= imagecreatefromstring(file_get_contents($logo));
-			$QR_width			= imagesx($QR);//二维码图片宽度
-			$QR_height			= imagesy($QR);//二维码图片高度
-			$logo_width			= imagesx($logo);//logo图片宽度
-			$logo_height		= imagesy($logo);//logo图片高度
-			$logo_qr_width		= $QR_width / 5;
-			$scale				= $logo_width/$logo_qr_width;
-			$logo_qr_height		= $logo_height/$scale;
-			$from_width			= ($QR_width - $logo_qr_width) / 2;
-			imagecopyresampled($QR,$logo,$from_width,$from_width,0,0,$logo_qr_width,$logo_qr_height,$logo_width,$logo_height);//重新组合图片并调整大小
-			imagepng($QR, $saveDir.$random.'.png');//输出图片
+			$QR = imagecreatefromstring(file_get_contents($QR));
+			$logo = imagecreatefromstring(file_get_contents($logo));
+			$QR_width = imagesx($QR);//二维码图片宽度
+			$QR_height = imagesy($QR);//二维码图片高度
+			$logo_width = imagesx($logo);//logo图片宽度
+			$logo_height = imagesy($logo);//logo图片高度
+			$logo_qr_width = $QR_width / 5;
+			$scale = $logo_width / $logo_qr_width;
+			$logo_qr_height = $logo_height / $scale;
+			$from_width = ($QR_width - $logo_qr_width) / 2;
+			imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);//重新组合图片并调整大小
+			imagepng($QR, $saveDir . $random . '.png');//输出图片
 		}
-		return '/qrcode/'.$random.'.png';
+		return '/qrcode/' . $random . '.png';
 	}
 	
 	/**
@@ -82,80 +84,101 @@ class qrCodeUtil{
 	 * $unique 举例 userId_189 merchant_20等
 	 * $size 大小 5 195px 8 312px
 	 */
-	public static function card($url, $unique= '',$logo = '',$size=5)
+	public static function card($url, $unique = '', $logo = '', $size = 5)
 	{
-		$app 					= Yii::getAlias("@app");
-		$saveDir				= $app.'/../../resource/images/card/';
-
-		include_once Yii::getAlias("@vendor/qrcode").'/phpqrcode.php';
-		$rand					= stringUtil::buildOrderNo();
-		$random					= empty($unique) ? $rand : $unique.'_'.$rand;
+		$app = Yii::getAlias("@app");
+		$saveDir = $app . '/../../resource/images/card/';
+		
+		include_once Yii::getAlias("@vendor/qrcode") . '/phpqrcode.php';
+		$rand = stringUtil::buildOrderNo();
+		$random = empty($unique) ? $rand : $unique . '_' . $rand;
 		//表示容错率,也就是有被覆盖的区域还能识别,分别是 L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%)
-		$errorCorrectionLevel	= 'H';
-		$matrixPointSize		= $size;//生成图片大小
-		$QR						= $saveDir.$random.'.png';
+		$errorCorrectionLevel = 'H';
+		$matrixPointSize = $size;//生成图片大小
+		$QR = $saveDir . $random . '.png';
 		\QRcode::png($url, $QR, $errorCorrectionLevel, $matrixPointSize, 1);//最后的参数1表示空白间距
 		if (empty($logo) || file_exists($logo) == false) {
-			return '/card/'.$random.'.png';//没有logo输出的二维码
+			return '/card/' . $random . '.png';//没有logo输出的二维码
 		}
-		$QR					= imagecreatefromstring(file_get_contents($QR));
-		$logo				= imagecreatefromstring(file_get_contents($logo));
-		$QR_width			= imagesx($QR);//二维码图片宽度
-		$QR_height			= imagesy($QR);//二维码图片高度
-		$logo_width			= imagesx($logo);//logo图片宽度
-		$logo_height		= imagesy($logo);//logo图片高度
-		$logo_qr_width		= $QR_width / 5;
-		$scale				= $logo_width/$logo_qr_width;
-		$logo_qr_height		= $logo_height/$scale;
-		$from_width			= ($QR_width - $logo_qr_width) / 2;
-		imagecopyresampled($QR,$logo,$from_width,$from_width,0,0,$logo_qr_width,$logo_qr_height,$logo_width,$logo_height);//重新组合图片并调整大小
-		imagepng($QR, $saveDir.$random.'_combine.png');//输出图片
-		return '/card/'.$random.'_combine.png';//组合logo后输出的二维码
+		$QR = imagecreatefromstring(file_get_contents($QR));
+		$logo = imagecreatefromstring(file_get_contents($logo));
+		$QR_width = imagesx($QR);//二维码图片宽度
+		$QR_height = imagesy($QR);//二维码图片高度
+		$logo_width = imagesx($logo);//logo图片宽度
+		$logo_height = imagesy($logo);//logo图片高度
+		$logo_qr_width = $QR_width / 5;
+		$scale = $logo_width / $logo_qr_width;
+		$logo_qr_height = $logo_height / $scale;
+		$from_width = ($QR_width - $logo_qr_width) / 2;
+		imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);//重新组合图片并调整大小
+		imagepng($QR, $saveDir . $random . '_combine.png');//输出图片
+		return '/card/' . $random . '_combine.png';//组合logo后输出的二维码
 	}
 	
-	public static function generatePayQrCode($url, $unique= '',$logo = '',$size=5)
+	public static function generatePayQrCode($url, $unique = '', $logo = '', $size = 5)
 	{
-		$app 					= Yii::getAlias("@app");
-		$saveDir				= $app.'/../resource/images/qrcode/';
-		include_once Yii::getAlias("@vendor/qrcode").'/phpqrcode.php';
-		$rand					= stringUtil::buildOrderNo();
-		$random					= empty($unique) ? $rand : $unique.'_'.$rand;
+		$app = Yii::getAlias("@app");
+		$saveDir = $app . '/../resource/images/qrcode/';
+		include_once Yii::getAlias("@vendor/qrcode") . '/phpqrcode.php';
+		$rand = stringUtil::buildOrderNo();
+		$random = empty($unique) ? $rand : $unique . '_' . $rand;
 		//表示容错率,也就是有被覆盖的区域还能识别,分别是 L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%)
-		$errorCorrectionLevel	= 'H';
-		$matrixPointSize		= $size;//生成图片大小
-		$QR						= $saveDir.$random.'.png';
+		$errorCorrectionLevel = 'H';
+		$matrixPointSize = $size;//生成图片大小
+		$QR = $saveDir . $random . '.png';
 		\QRcode::png($url, $QR, $errorCorrectionLevel, $matrixPointSize, 1);//最后的参数1表示空白间距
 		if (empty($logo) || file_exists($logo) == false) {
-			return '/qrcode/'.$random.'.png';//没有logo输出的二维码
+			return '/qrcode/' . $random . '.png';//没有logo输出的二维码
 		}
-		$QR					= imagecreatefromstring(file_get_contents($QR));
-		$logo				= imagecreatefromstring(file_get_contents($logo));
-		$QR_width			= imagesx($QR);//二维码图片宽度
-		$QR_height			= imagesy($QR);//二维码图片高度
-		$logo_width			= imagesx($logo);//logo图片宽度
-		$logo_height		= imagesy($logo);//logo图片高度
-		$logo_qr_width		= $QR_width / 5;
-		$scale				= $logo_width/$logo_qr_width;
-		$logo_qr_height		= $logo_height/$scale;
-		$from_width			= ($QR_width - $logo_qr_width) / 2;
-		imagecopyresampled($QR,$logo,$from_width,$from_width,0,0,$logo_qr_width,$logo_qr_height,$logo_width,$logo_height);//重新组合图片并调整大小
-		imagepng($QR, $saveDir.$random.'_combine.png');//输出图片
+		$QR = imagecreatefromstring(file_get_contents($QR));
+		$logo = imagecreatefromstring(file_get_contents($logo));
+		$QR_width = imagesx($QR);//二维码图片宽度
+		$QR_height = imagesy($QR);//二维码图片高度
+		$logo_width = imagesx($logo);//logo图片宽度
+		$logo_height = imagesy($logo);//logo图片高度
+		$logo_qr_width = $QR_width / 5;
+		$scale = $logo_width / $logo_qr_width;
+		$logo_qr_height = $logo_height / $scale;
+		$from_width = ($QR_width - $logo_qr_width) / 2;
+		imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);//重新组合图片并调整大小
+		imagepng($QR, $saveDir . $random . '_combine.png');//输出图片
 		//return '/qrcode/'.$random.'_combine.png';//组合logo后输出的二维码
-		$weixinImg			= $app.'/web/images/merchant/wxPay.png';
-		$combineQR			= $saveDir.$random.'_combine.png';
+		$weixinImg = $app . '/web/images/merchant/wxPay.png';
+		$combineQR = $saveDir . $random . '_combine.png';
 		
-		$weixinImgSource	= imagecreatefromstring(file_get_contents($weixinImg));
-		$combineQRSource	= imagecreatefromstring(file_get_contents($combineQR));
+		$weixinImgSource = imagecreatefromstring(file_get_contents($weixinImg));
+		$combineQRSource = imagecreatefromstring(file_get_contents($combineQR));
 		
-		$weixinWidth		= imagesx($weixinImgSource);
-		$weixinHeight		= imagesy($weixinImgSource);
-
-		$combineQRWidth		= imagesx($combineQRSource);
-		$combineQRHeight	= imagesy($combineQRSource);
-		$combineQRQRWidth	= $weixinWidth / 5;
-		$scale				= $combineQRWidth / $combineQRQRHeight;
-		$combineQRQRWidth	= '';
+		$weixinWidth = imagesx($weixinImgSource);
+		$weixinHeight = imagesy($weixinImgSource);
+		
+		$combineQRWidth = imagesx($combineQRSource);
+		$combineQRHeight = imagesy($combineQRSource);
+		$combineQRQRWidth = $weixinWidth / 5;
+		$scale = $combineQRWidth / $combineQRQRHeight;
+		$combineQRQRWidth = '';
 		
 	}
 	
+	/**
+	 * 生成收款二维码
+	 * $unique 举例 userId_189 merchant_20等
+	 * $size 大小 5 195px 8 312px
+	 */
+	public static function generateGatheringQrCode($url, $merchantId, $shopId, $logo = '', $size = 5)
+	{
+		include_once Yii::getAlias("@vendor/qrcode") . '/phpqrcode.php';
+		
+		//表示容错率,也就是有被覆盖的区域还能识别,分别是 L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%)
+		$errorCorrectionLevel = 'H';
+		$matrixPointSize = $size;//生成图片大小
+		
+		$behind = '/retail/qrCode/gathering/' . $merchantId . '_' . $shopId . '.png';
+		$saveFile = dirUtil::getImgDir() . $behind;
+		
+		\QRcode::png($url, $saveFile, $errorCorrectionLevel, $matrixPointSize, 1);//最后的参数1表示空白间距
+
+		return $behind;
+	}
+
 }