shish před 5 roky
rodič
revize
c5492f2df8

+ 31 - 16
app-pt/controllers/WxController.php

@@ -54,21 +54,16 @@ class WxController extends PublicController
         $encryptMsg = $postData;
 
         //取开放平台信息
-        $style = $get['style'] ?? \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD;
+        $style = $get['style'] ?? dict::getDict('ptStyle', 'hd');
         $open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => $style]);
         if (empty($open)) {
             util::stop('没有找到平台信息');
         }
         $wxBaseId = $open['wxBaseId'] ?? 0;
-
         //零售appId
         $wxBase = WxBaseService::getById($wxBaseId);
         $wxBaseAppId = isset($wxBase['wxAppId']) ? $wxBase['wxAppId'] : '';
 
-        //供货商appId
-        $wxGhsBase = WxBaseClass::getById($wxBaseId);
-        $wxGhsBaseAppId = $wxGhsBase['wxAppId'] ?? 0;
-
         $encodingAesKey = $open['aesKey'];
         $openToken = $open['token'];
         $openAppId = $open['appId'];
@@ -116,8 +111,7 @@ class WxController extends PublicController
 
         Yii::info('$wxBaseAppId:' . $wxBaseAppId . " $appId:" . $appId);
 
-        if ($wxBaseAppId == $appId) {
-            Yii::info('1111111');
+        if ($style == dict::getDict('ptStyle', 'hd')) {
             //零售
             if ($this->msgType == 'event') {
                 switch ($Event) {
@@ -148,8 +142,7 @@ class WxController extends PublicController
                     default:
                 }
             }
-        } elseif ($wxGhsBaseAppId == $appId) {
-            Yii::info('2222222222');
+        } elseif ($style == dict::getDict('ptStyle', 'ghs')) {
             //供货商
             if ($this->msgType == 'event') {
                 switch ($Event) {
@@ -177,6 +170,34 @@ class WxController extends PublicController
                     default:
                 }
             }
+        } elseif ($style == dict::getDict('ptStyle', 'mall')) {
+            //商城
+            if ($this->msgType == 'event') {
+                switch ($Event) {
+                    //关注
+                    case 'subscribe':
+                        $merchant = WxOpenClass::getGhsWxInfo();
+                        $getUserInfo = wxUtil::userInfo($this->fromUsername, $merchant, 3);
+                        $source = UserClass::$userSourceId['official']['name'];
+                        $getUserInfo['subscribe'] = 1;
+                        UserService::replaceUser($getUserInfo, $source, 0);
+                        $text = $this->replyTextContent("等您好久,终于等到您 /::)");
+                        $pc = new \WXBizMsgCrypt($openToken, $encodingAesKey, $openAppId);
+                        $encryptMsg = '';
+                        $pc->encryptMsg($text, $timestamp, $nonce, $encryptMsg);//加密
+                        echo $encryptMsg;
+                        break;
+                    //取消关注
+                    case 'unsubscribe':
+                        $admin = UserService::getByOpenId($this->fromUsername);
+                        if (!empty($admin)) {
+                            $adminId = $admin['id'];
+                            UserService::unFocus($adminId);
+                        }
+                        break;
+                    default:
+                }
+            }
         } else {
             //其它
             $merchant = xhMerchantService::getByAppId($appId);
@@ -197,7 +218,6 @@ class WxController extends PublicController
                 $userAsset = xhUserAssetService::getByUserId($userId);
             }
 
-
             if ($this->msgType == 'event') {
                 /*
                             //全网发布,1 事件消息响应
@@ -244,15 +264,10 @@ class WxController extends PublicController
                         //获得新优惠券通知
                         CouponAssetService::hasNewCouponNotice($user, $merchant);
 
-
                         break;
                     //取消关注
                     case 'unsubscribe':
 
-
-                        UserService::unFocus($userId, $sjId);
-
-
                         break;
                     //自定义菜单回复
                     case 'click':

+ 6 - 18
biz-hd/admin/classes/AdminClass.php

@@ -6,6 +6,7 @@ use bizHd\user\classes\UserClass;
 use bizGhs\custom\classes\CustomClass;
 use biz\sj\classes\MerchantClass;
 use common\components\imgUtil;
+use common\components\noticeUtil;
 use common\components\sms;
 use common\components\util;
 use common\services\ImageService;
@@ -183,26 +184,13 @@ class AdminClass extends BaseClass
     public static function replaceAdmin($wxInfo, $source)
     {
         $wxInfo = self::switchAdminInfo($wxInfo, $source);
-        $adminSource = UserClass::$userSourceId;
-        switch ($source) {
-            case $adminSource['mini']['name']:
-                $sourceId = $adminSource['mini']['id'];
-                $miniOpenId = $wxInfo['miniOpenId'];
-                $admin = self::getByMiniOpenId($miniOpenId);
-                break;
-            case $adminSource['official']['name']:
-                $sourceId = $adminSource['official']['id'];
-                $openId = isset($wxInfo['openId']) ? $wxInfo['openId'] : '';
-                $admin = [];
-                if (!empty($openId)) {
-                    $admin = self::getByOpenId($openId);
-                }
-                break;
-            default:
-                throw new \Exception('未知来源');
+        $unionId = $wxInfo['unionId'] ?? 0;
+        if (empty($unionId)) {
+            noticeUtil::push("创建用户时没有找到unionId,参数:" . json_encode($wxInfo), '15280215347');
+            util::fail('没有找到unionId');
         }
+        $admin = self::getByUnionId($unionId);
         if (empty($admin)) {
-            $wxInfo['sourceType'] = $sourceId;
             $admin = self::generateAdmin($wxInfo);
         } else {
             $admin = self::updateAdmin($admin, $wxInfo);

+ 7 - 75
biz-hd/user/classes/UserClass.php

@@ -107,7 +107,6 @@ class UserClass extends BaseClass
         $getUserInfo['identity'] = 0;
         $subscribe = isset($getUserInfo['subscribe']) ? $getUserInfo['subscribe'] : 0;
         $getUserInfo['subscribe'] = $subscribe;
-        $getUserInfo['sjId'] = $sjId;
         $getUserInfo['status'] = 0;
         //默认没有完整用户信息
         $isFull = isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl']) ? 1 : 0;
@@ -125,7 +124,7 @@ class UserClass extends BaseClass
         $user = self::add($getUserInfo);
         $userId = $user['id'];
 
-        $assetData = ['userId' => $userId, 'sjId' => $sjId, 'createTime' => $date];
+        $assetData = ['userId' => $userId, 'createTime' => $date];
         //生成用户资产信息
         UserAssetClass::add($assetData);
 
@@ -133,21 +132,18 @@ class UserClass extends BaseClass
         if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
             if (empty($preUser) || (isset($preUser['avatar']) && empty($preUser['avatar']))) {
                 $imgUrl = $getUserInfo['headImgUrl'];
-                $currentImg = ImageService::generateAvatar($sjId, $imgUrl);
+                $currentImg = ImageService::generateAvatar(0, $imgUrl);
                 if (!empty($currentImg)) {
                     self::updateById($userId, ['avatar' => $currentImg]);
                 }
             }
         }
-        //客户数粉丝数增加
-        MerchantAssetClass::addUser($sjId, $subscribe, true);
         return $user;
     }
 
     public static function updateUser($originalUser, $getUserInfo, $sjId)
     {
         $data = [];
-        $assetData = [];
         $userId = $originalUser['id'];
         //替换掉微信不支持的图片
         $userName = isset($getUserInfo['userName']) ? preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $getUserInfo['userName']) : '';
@@ -173,7 +169,6 @@ class UserClass extends BaseClass
         if (isset($getUserInfo['subscribeTime'])) {
             $data['subscribeTime'] = $getUserInfo['subscribeTime'];
         }
-        $data['sjId'] = $sjId;
         if (isset($getUserInfo['alipayId']) && !empty($getUserInfo['alipayId'])) {
             $data['alipayId'] = $getUserInfo['alipayId'];
         }
@@ -187,20 +182,13 @@ class UserClass extends BaseClass
         if (isset($originalUser['avatar']) == false || empty($originalUser['avatar'])) {
             if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
                 $imgUrl = $getUserInfo['headImgUrl'];
-                $name = ImageService::generateAvatar($sjId, $imgUrl);
+                $name = ImageService::generateAvatar(0, $imgUrl);
                 if (!empty($name)) {
                     $data['avatar'] = $name;
                 }
             }
         }
-        //增加粉丝数
-        if (isset($originalUser['subscribe']) && $originalUser['subscribe'] == 0 && isset($getUserInfo['subscribe']) && $getUserInfo['subscribe'] == 1) {
-            MerchantAssetClass::addUser($sjId, 1, false);
-        }
         self::updateById($userId, $data);
-        if (!empty($assetData)) {
-            UserAssetClass::updateByUserId($userId, $assetData);
-        }
         $user = self::getById($userId);
         return $user;
     }
@@ -248,7 +236,7 @@ class UserClass extends BaseClass
             ]);
             $targetId = $return['id'];
 
-            $capitalType = dict::getDict('capitalType','xhMergeUser','id');
+            $capitalType = dict::getDict('capitalType', 'xhMergeUser', 'id');
             $now = time();
             $date = date("Y-m-d H:i:s");
 
@@ -485,67 +473,11 @@ class UserClass extends BaseClass
     {
         $userInfo = self::switchUserInfo($userInfo, $source);
         $unionId = isset($userInfo['unionId']) && !empty($userInfo['unionId']) ? $userInfo['unionId'] : '';
-        $unionUser = [];
-        if (!empty($unionId)) {
-            $unionUser = self::getByUnionId($unionId);
-        }
-        $userSource = self::$userSourceId;
-        switch ($source) {
-            case $userSource['mini']['name']:
-                $sourceId = $userSource['mini']['id'];
-                $miniOpenId = $userInfo['miniOpenId'];
-                $user = self::getByMiniOpenId($miniOpenId);
-                break;
-            case $userSource['alipay']['name']:
-                $sourceId = $userSource['alipay']['id'];
-                $alipayId = $userInfo['alipayId'];
-                $user = self::getByAlipayId($alipayId, $sjId);
-                break;
-            case $userSource['official']['name']:
-                $sourceId = $userSource['official']['id'];
-                //后台添加的客户没有openId
-                $openId = isset($userInfo['openId']) ? $userInfo['openId'] : '';
-                $user = [];
-                if (!empty($openId)) {
-                    $user = self::getByOpenId($openId, $sjId);
-                }
-                break;
-            case $userSource['system']['name']:
-                $sourceId = $userSource['system']['id'];
-                $mobile = isset($userInfo['mobile']) && !empty($userInfo['mobile']) ? $userInfo['mobile'] : '';
-                $user = [];
-                if (!empty($mobile)) {
-                    $user = self::getByCondition(['sjId' => $sjId, 'mobile' => $mobile]);
-                }
-                break;
-            default:
-                throw new \Exception('未知来源的用户');
-        }
-
-        //支付宝暂时获取不到很多客户信息不进行更新
-        if ($source == $userSource['alipay']['name']) {
-            if (!empty($user)) {
-                return $user;
-            }
-        }
+        $user = UserClass::getByUnionId($unionId);
         if (empty($user)) {
-            if (!empty($unionUser)) {
-                //1、在小程序端已经授权用户信息和unionId之后,关注公众号时走这里
-                //2、关注了公众号或者H5已经授权时,并首次访问小程序
-                $user = self::updateUser($unionUser, $userInfo, $sjId);
-            } else {
-                $userInfo['sourceType'] = $sourceId;
-                $userInfo['sjId'] = $sjId;
-                $user = self::generateUser($userInfo, $sjId);
-            }
+            $user = self::generateUser($userInfo, 0);
         } else {
-            if (!empty($unionUser)) {
-                if (isset($unionUser['id']) && isset($user['id']) && $user['id'] != $unionUser['id']) {
-                    //合并相同客户
-                    $user = self::mergeUser($unionUser, $user);
-                }
-            }
-            $user = self::updateUser($user, $userInfo, $sjId);
+            $user = self::updateUser($user, $userInfo, 0);
         }
         return $user;
     }

+ 1 - 3
biz-hd/user/services/UserService.php

@@ -178,11 +178,9 @@ class UserService extends BaseService
     }
 
     //取消关注 ssh 2019.9.8
-    public static function unFocus($userId, $sjId)
+    public static function unFocus($userId)
     {
         self::updateById($userId, ['subscribe' => 0, 'hasSubscribe' => 1]);
-        //商家粉丝减少
-        MerchantAssetClass::reduceFans($sjId);
     }
 
     //关注公众号的后续 ssh 2020.5.5

+ 0 - 4
biz/wx/classes/WxOpenClass.php

@@ -9,10 +9,6 @@ class WxOpenClass extends BaseClass
 
     public static $baseFile = '\biz\wx\models\WxOpen';
 
-    const OPEN_STYLE_HD = 1;
-    const OPEN_STYLE_GHS = 2;
-    const OPEN_STYLE_MALL = 3;
-
     //获取所有的小程序信息 ssh 2021.2.25
     public static function getMiniInfo()
     {

+ 6 - 5
common/components/dict.php

@@ -57,9 +57,10 @@ class dict
 
         //所属平台类型
         'ptStyle' => [
-            'hd' => 1,
-            'ghs' => 2,
-            'kmGhs' => 3,
+            'hd' => 1,//零售花店
+            'ghs' => 2,//供货商
+            'mall' => 3,//商城
+            'kmGhs' => 4,//昆明供货商
         ],
 
         'merchantStatus' => ['checking' => 0, 'pass' => 1, 'noPass' => 2, 'freeze' => 3, 'unfreeze' => 4, 'shut' => 5],
@@ -136,9 +137,9 @@ class dict
             //供货商采购
             'ghsPurchase' => ['id' => 25, 'name' => 'ghsPurchase'],
             //供货商出库
-            'ghsCheckOut' => ['id'=>26, 'name'=>'ghsCheckOut'],
+            'ghsCheckOut' => ['id' => 26, 'name' => 'ghsCheckOut'],
             //供货商入库
-            'ghsCheckIn' => ['id'=>27, 'name'=>'ghsCheckIn'],
+            'ghsCheckIn' => ['id' => 27, 'name' => 'ghsCheckIn'],
         ],
         "capitalTypeList" => [//流水类型的对应链接,后台收支明细查看时跳转的链接
             0 => ['link' => '/capital/order-detail', 'name' => '网店', 'orderLink' => '/order/detail', 'id' => 0,],

+ 1 - 0
common/services/ImageService.php

@@ -19,6 +19,7 @@ class ImageService
         $month = date("Ym");
         $date = date("d");
         $path = dirUtil::getImgDir();
+        $sjId = substr(md5($url), 0, 5);
         $middle = "wx/avatar/{$sjId}/{$month}/{$date}/";
         if (!file_exists($path . $middle)) {
             mkdir($path . $middle, 0777, true);