ソースを参照

小程序收款码

shish 6 年 前
コミット
ab3b2dc247

+ 30 - 6
app/shop/controllers/ShopController.php

@@ -42,9 +42,9 @@ class ShopController extends BaseController
 		ShopService::addShop($data);
 		util::complete();
 	}
-
-	//下载收款码 shish 2020.2.29
-	public function actionDownloadGatheringCode()
+	
+	//下载微信和支付宝收款码 shish 2020.2.29
+	public function actionGatheringCode()
 	{
 		$id = Yii::$app->request->get('id', 0);
 		$shop = ShopService::getById($id);
@@ -63,8 +63,32 @@ class ShopController extends BaseController
 		readfile($file);
 	}
 	
-	//下载注册会员码 shish 2020.2.29
-	public function actionDownloadApplyMemberCode()
+	//获取小程序的收款码 shish
+	public function actionGatheringMiniCode()
+	{
+		$id = Yii::$app->request->get('id', 0);
+		$extend = MerchantExtendService::getByMerchantId($this->merchantId);
+		if ($extend['miniAuth'] == 0) {
+			util::fail('您的小程序还没有授权');
+		}
+		$shop = ShopService::getById($id);
+		ShopService::valid($shop, $this->merchantId);
+		$applyMemberCode = wxUtil::generateGatheringMiniCode($this->merchant, $id);
+		$file = dirUtil::getImgDir() . $applyMemberCode;
+		if (file_exists($file) == false) {
+			util::fail('没有找到注册会员码');
+		}
+		$fileName = "门店({$id})小程序收款码.jpg";
+		$contentType = 'image/jpeg';
+		header("Cache-control: private");
+		header("Content-type: $contentType"); //设置要下载的文件类型
+		header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
+		header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
+		readfile($file);
+	}
+	
+	//下载会员注册码 shish 2020.2.29
+	public function actionApplyMemberCode()
 	{
 		$id = Yii::$app->request->get('id', 0);
 		$extend = MerchantExtendService::getByMerchantId($this->merchantId);
@@ -96,5 +120,5 @@ class ShopController extends BaseController
 		ShopService::deleteShop($shop);
 		util::complete();
 	}
-	
+
 }

+ 5 - 4
biz/admin/services/AdminShopService.php

@@ -11,6 +11,7 @@ use biz\merchant\classes\ShopClass;
 use biz\merchant\services\MerchantService;
 use biz\user\services\UserService;
 use common\components\error;
+use common\components\miniUtil;
 use common\components\stringUtil;
 use common\components\util;
 use common\components\wxUtil;
@@ -21,8 +22,8 @@ class AdminShopService extends BaseService
 {
 	
 	public static $baseFile = '\biz\admin\classes\AdminShopClass';
-	
-	///创建管理员关联数据准备 shish 2020.4.17
+
+	///创建管理员生成小程序 shish 2020.4.17
 	public static function prepareBindAdmin($data)
 	{
 		AdminShopClass::prepareBindAdmin($data);
@@ -32,10 +33,10 @@ class AdminShopService extends BaseService
 		$shopId = $data['shopId'];
 		$scene = 'adminId=' . $adminId . '&shopId=' . $shopId;
 		$merchant = $data['merchant'];
-		$imgUrl = wxUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $isOpen);
+		$imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $isOpen);
 		return ['miniCode' => $imgUrl];
 	}
-	
+
 	public static function generateAdmin($data)
 	{
 		$recommendAdminId = isset($data['recommendAdminId']) ? $data['recommendAdminId'] : 0;

+ 1 - 1
common/components/miniUtil.php

@@ -1480,7 +1480,7 @@ class miniUtil
         return $behind . $fileName;
     }
 
-    //临时小程序码生成 shish 2020.4.17
+	//小程序码生成,数量不限 shish 2020.4.17
     public static function generateUnlimitedMiniCode($merchant, $page, $scene = '', $isOpen = 0)
     {
         $id = isset($merchant['id']) ? $merchant['id'] : 0;

+ 12 - 13
common/components/wxUtil.php

@@ -1479,13 +1479,12 @@ class wxUtil
 		file_put_contents($file, $result);
 		return $behind . $fileName;
 	}
-	
-	//临时小程序码生成 shish 2020.4.17
-	public static function generateUnlimitedMiniCode($merchant, $page, $scene = '', $isOpen = 0)
+
+	//收款小程序码
+	public static function generateGatheringMiniCode($merchant, $shopId, $isOpen = 0)
 	{
-		$id = isset($merchant['id']) ? $merchant['id'] : 0;
-		$fileName = stringUtil::shortUniqueId($id) . '.jpg';
-		$behind = '/retail/mimiCode/' . date("Ym") . '/' . date("d") . '/' . $id . '/';
+		$fileName = $merchant['id'] . '_' . $shopId . '_apply_member.jpg';
+		$behind = '/retail/gatheringMimiCode/';
 		$filePath = dirUtil::getImgDir() . $behind;
 		if (!file_exists($filePath)) {
 			mkdir($filePath, 0777, true);
@@ -1494,19 +1493,19 @@ class wxUtil
 		if (file_exists($file)) {
 			return $behind . $fileName;
 		}
+		$path = 'pages/pay/index?scan=1&shopId=' . $shopId;
 		$accessToken = self::getMiniProgramAccessToken($merchant, $isOpen);
-		$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={$accessToken}";
+		$url = "https://api.weixin.qq.com/wxa/getwxacode?access_token={$accessToken}";
 		$curl = new curl\Curl();
-		$data = [];
-		if (!empty($page)) {
-			$data["page"] = $page;
-		}
-		$data["scene"] = $scene;
+		$data = [
+			"path" => $path,
+			"width" => 1000,
+		];
 		$result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
 		file_put_contents($file, $result);
 		return $behind . $fileName;
 	}
-	
+
 	//微信开放平台获取component_access_token
 	public static function getComponentAccessToken($open)
 	{