|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace www\controllers;
|
|
|
|
|
|
+use biz\merchant\services\MerchantService;
|
|
|
use biz\weixin\services\WxOpenService;
|
|
|
use common\services\xhMerchantExtendService;
|
|
|
use Yii;
|
|
|
@@ -44,12 +45,14 @@ class WxOpenController extends PublicController
|
|
|
$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>";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ //平台没有绑定商家公众号时初始化一个商家 shish 2020.2.11
|
|
|
public function actionAddMerchant()
|
|
|
{
|
|
|
- echo 'mmmm';
|
|
|
+ $return = MerchantService::initOpenMerchant();
|
|
|
+ dd($return);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function actionCheckMerchantName()
|
|
|
{
|
|
|
$get = Yii::$app->request->get();
|
|
|
@@ -167,109 +170,6 @@ class WxOpenController extends PublicController
|
|
|
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()
|
|
|
{
|
|
|
$get = Yii::$app->request->get();
|