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

+ 6 - 106
app/www/controllers/WxOpenController.php

@@ -2,6 +2,7 @@
 
 
 namespace www\controllers;
 namespace www\controllers;
 
 
+use biz\merchant\services\MerchantService;
 use biz\weixin\services\WxOpenService;
 use biz\weixin\services\WxOpenService;
 use common\services\xhMerchantExtendService;
 use common\services\xhMerchantExtendService;
 use Yii;
 use Yii;
@@ -44,12 +45,14 @@ class WxOpenController extends PublicController
 		$authType = Yii::$app->request->get('authType', 3);
 		$authType = Yii::$app->request->get('authType', 3);
 		echo "<a href='https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid={$appId}&pre_auth_code={$pre}&redirect_uri={$url}&auth_type={$authType}'>授权</a>";
 		echo "<a href='https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid={$appId}&pre_auth_code={$pre}&redirect_uri={$url}&auth_type={$authType}'>授权</a>";
 	}
 	}
-
+	
+	//平台没有绑定商家公众号时初始化一个商家 shish 2020.2.11
 	public function actionAddMerchant()
 	public function actionAddMerchant()
 	{
 	{
-		echo 'mmmm';
+		$return = MerchantService::initOpenMerchant();
+		dd($return);
 	}
 	}
-
+	
 	public function actionCheckMerchantName()
 	public function actionCheckMerchantName()
 	{
 	{
 		$get = Yii::$app->request->get();
 		$get = Yii::$app->request->get();
@@ -167,109 +170,6 @@ class WxOpenController extends PublicController
 		return $this->renderPartial('result', ['originalMerchant' => $originalMerchant, 'merchant' => $merchant, 'status' => $status]);
 		return $this->renderPartial('result', ['originalMerchant' => $originalMerchant, 'merchant' => $merchant, 'status' => $status]);
 	}
 	}
 	
 	
-	/**
-	 * 商家申请入驻
-	 */
-	public function actionAddMerchant()
-	{
-		$post = Yii::$app->request->post();
-		$session = Yii::$app->session;
-		if (isset($session['allowGenerateMerchant']) == false) {
-			//util::fail('没有经过授权的操作');
-		}
-		unset($post['_csrf']);
-		if (isset($session['wxAppId']) == false || empty($session['wxAppId'])) {
-			util::fail('公众号appId不存在');
-		}
-		$wxAppId = $session['wxAppId'];
-		if (isset($session['logo'])) {
-			$logo = xhMerchantService::logoSave($session['logo'], $wxAppId);
-			$post['logo'] = $logo;
-		}
-		if (isset($session['wxQrcodeUrl'])) {
-			$wxQrCodeUrl = xhMerchantService::qrCodeSave($session['wxQrcodeUrl'], $wxAppId);
-			$post['wxQrcodeUrl'] = $wxQrCodeUrl;
-		}
-		$date = date("Y-m-d H:i:s");
-		$inviteCode = isset($post['inviteCode']) ? $post['inviteCode'] : '';
-		$accountStyle = configDict::getConfig('accountStyle');
-		$merchantStatus = configDict::getConfig('merchantStatus');
-		$serviceAccount = $accountStyle['serviceAccount'];//认证服务号
-		$checking = $merchantStatus['checking'];//审核中
-		$merchantName = !empty($post['merchantName']) ? $post['merchantName'] : '';
-		$exists = xhMerchantService::getByMerchantName($merchantName);
-		if (!empty($exists)) {
-			util::fail('花店名称已经存在了');
-		}
-		$post['wxAppId'] = $wxAppId;
-		$post['wxUserName'] = $session['wxUserName'];
-		$post['wxAliasName'] = $session['wxAliasName'];
-		$post['wxAccessToken'] = $session['wxAccessToken'];
-		$post['wxAccessTokenTime'] = $session['wxAccessTokenTime'];
-		$post['wxRefreshToken'] = $session['wxRefreshToken'];
-		$post['accountStyle'] = $serviceAccount;//认证服务号
-		$post['status'] = $checking;//待审
-		$post['createTime'] = $date;
-		$post['updateTime'] = $date;
-		$post['shopLat'] = isset($post['shopLat']) ? (string)$post['shopLat'] : (string)0;
-		$post['shopLong'] = isset($post['shopLong']) ? (string)$post['shopLong'] : (string)0;
-		$post['shopPrecision'] = isset($post['shopPrecision']) ? (string)$post['shopPrecision'] : (string)0;
-		$account = stringUtil::buildOrderNo(0);
-		$trainDemo = configDict::getConfig('trainDemo');
-		$demoName = $trainDemo['merchant']['name'];//培训演示的公众号
-		if (isset($post['merchantName']) && $post['merchantName'] == $demoName) {
-			$account = $trainDemo['merchant']['account'];
-		}
-		$post['account'] = $account;
-		$post['adminId'] = 0;
-		$post['wxToken'] = stringUtil::buildWxToken(0);
-		$shopPhotoListString = json_encode(["outdoor" => $post['shopImg'], 'indoor' => $post['shopImg2']]);//将门店照片组合成json
-		$post['shopPhotoList'] = $shopPhotoListString;
-		$merchant = xhMerchantService::applyCreateMerchant($post);
-		$id = $merchant['id'];
-		$account = $merchant['id'];
-		unset($session['allowGenerateMerchant']);
-		xhWxMenuService::applyInit($merchant);
-		$set = xhSetMealService::getRandOne();
-		$price = $set['price'];
-		$actPrice = $price;
-		$mainMerchantId = 0;
-		$now = time();
-		$orderDeadline = 0;
-		if (!empty($inviteCode)) {
-			$invite = xhInviteService::getByCode($inviteCode);
-			if (empty($invite)) {
-				util::fail('邀请码不存在');
-			}
-			if ($invite['takeStatus'] == 1) {//邀请码未使用,并且没有过期
-				util::fail('邀请码已经使用');
-			}
-			$inviteDeadline = $invite['deadline'];
-			if ($now > $inviteDeadline) {
-				util::fail('邀请码已经过期');
-			}
-			$mainMerchantId = isset($invite['merchantId']) ? $invite['merchantId'] : 0;
-			$actPrice = stringUtil::calcSub($set['price'], $invite['save']);//扣除邀请码里的钱
-		}
-		$toPay = $actPrice <= 0 ? 'no' : 'yes';//是否需要付款
-		$inviteCodeStatus = $actPrice <= 0 ? 1 : 0;//邀请码是否已使用
-		$payStatus = $actPrice <= 0 ? 1 : 0;//付款是否成功
-		$createTime = date("Y-m-d H:i:s");
-		$orderId = 'A' . stringUtil::buildOrderNo($id);
-		$orderData = ['id' => $orderId, 'userId' => $this->userId, 'applyName' => $merchantName, 'email' => '',
-			'createTime' => $createTime, 'accountId' => 0, 'inviteCode' => $inviteCode, 'merchantId' => $mainMerchantId, 'invitedMerchantId' => $id,
-			'prePrice' => $price, 'actPrice' => $actPrice, 'deadline' => $orderDeadline, 'inviteCodeStatus' => (int)$inviteCodeStatus, 'payStatus' => $payStatus,
-		];
-		xhApplyOrderService::add($orderData);//保存订单信息
-		if ($actPrice <= 0 && !empty($inviteCode)) {
-			xhInviteService::updateByCode($inviteCode, ['targetId' => $orderId, 'takeStatus' => 1, 'invitedMerchantId' => $id, 'inviteUseTo' => 0]);
-		}
-		$openMerchant = xhWxOpenService::getMerchant();
-		$openMerchantAccount = $openMerchant['id'];
-		$newAccount = urlencode(stringUtil::authcode($account, 'ENCODE', 300));
-		util::success(['account' => $openMerchantAccount, 'newAccount' => $newAccount, 'toPay' => $toPay, 'orderId' => $orderId, 'actPrice' => $actPrice]);
-	}
-	
 	public function actionCheckInviteCode()
 	public function actionCheckInviteCode()
 	{
 	{
 		$get = Yii::$app->request->get();
 		$get = Yii::$app->request->get();

+ 21 - 1
biz/merchant/services/MerchantService.php

@@ -13,6 +13,7 @@ use biz\message\services\TMessageService;
 use biz\saas\services\SetAuthService;
 use biz\saas\services\SetAuthService;
 use biz\saas\services\SetMealService;
 use biz\saas\services\SetMealService;
 use biz\user\services\UserService;
 use biz\user\services\UserService;
+use biz\weixin\classes\WxOpenClass;
 use common\components\business;
 use common\components\business;
 use common\components\util;
 use common\components\util;
 use common\services\xhTMessageService;
 use common\services\xhTMessageService;
@@ -162,7 +163,7 @@ class MerchantService extends BaseService
 			
 			
 			//模板消息
 			//模板消息
 			xhTMessageService::init($merchant);
 			xhTMessageService::init($merchant);
-
+			
 			$transaction->commit();
 			$transaction->commit();
 			return true;
 			return true;
 			
 			
@@ -171,5 +172,24 @@ class MerchantService extends BaseService
 			return false;
 			return false;
 		}
 		}
 	}
 	}
+	
+	//初始化平台的商家 shish 2020.2.11
+	public static function initOpenMerchant()
+	{
+		$open = WxOpenClass::getOpen();
+		if (isset($open['merchantId']) && !empty($open['merchantId'])) {
+			return false;
+		}
+		$merchantName = '花卉宝';
+		$data = [
+			'merchantName' => $merchantName,
+			'shopProvince' => '福建',
+			'shopCity' => '厦门',
+			'shopDist' => '思明区',
+			'alipayAccount' => 'shishaohua8879@sina.com',
+			'alipayAccountName' => '石少华'
+		];
+		return MerchantClass::generateMerchant($data);
+	}
 
 
 }
 }

+ 4 - 2
biz/saas/services/ApplyService.php

@@ -3,6 +3,7 @@
 namespace biz\saas\services;
 namespace biz\saas\services;
 
 
 use biz\base\services\BaseService;
 use biz\base\services\BaseService;
+use biz\merchant\classes\MerchantClass;
 use biz\merchant\services\MerchantService;
 use biz\merchant\services\MerchantService;
 use biz\saas\classes\ApplyClass;
 use biz\saas\classes\ApplyClass;
 use biz\user\services\UserService;
 use biz\user\services\UserService;
@@ -49,13 +50,14 @@ class ApplyService extends BaseService
 	//审核通过
 	//审核通过
 	public static function pass($id)
 	public static function pass($id)
 	{
 	{
+
 		$appData['merchantName'] = $nick_name;
 		$appData['merchantName'] = $nick_name;
 		$appData['shopProvince'] = '福建';
 		$appData['shopProvince'] = '福建';
 		$appData['shopCity'] = '厦门';
 		$appData['shopCity'] = '厦门';
 		$appData['shopDist'] = '思明区';
 		$appData['shopDist'] = '思明区';
 		$appData['alipayAccount'] = 'shish@zhhinc.com';
 		$appData['alipayAccount'] = 'shish@zhhinc.com';
 		$appData['alipayAccountName'] = '石少华';
 		$appData['alipayAccountName'] = '石少华';
-		xhMerchantService::applyCreateMerchant($appData);
+		MerchantClass::generateMerchant($appData);
 	}
 	}
-
+	
 }
 }

+ 6 - 0
biz/weixin/classes/WxOpenClass.php

@@ -10,4 +10,10 @@ class WxOpenClass extends BaseClass
 	
 	
 	public static $baseFile = '\biz\weixin\models\WxOpen';
 	public static $baseFile = '\biz\weixin\models\WxOpen';
 	
 	
+	//获取开放平台 shish 2020.2.11
+	public static function getOpen()
+	{
+		return self::getById(1);
+	}
+	
 }
 }

+ 2 - 2
biz/weixin/services/WxOpenService.php

@@ -14,7 +14,7 @@ class WxOpenService extends BaseService
 	//获取当前开放平台信息 shish 2020.2.11
 	//获取当前开放平台信息 shish 2020.2.11
 	public static function getOpen()
 	public static function getOpen()
 	{
 	{
-		return WxOpenClass::getById(1);
+		return WxOpenClass::getOpen();
 	}
 	}
-
+	
 }
 }