From 0e2fded96ecdeb0fd7a19d20b14b3f521e3ed9af Mon Sep 17 00:00:00 2001 From: danaisuiyuan Date: Wed, 27 May 2026 20:12:08 +0800 Subject: [PATCH] fix: preserve channel code params for miniapp signup --- .../app/services/wechat/RoutineServices.php | 46 ++++++++++++++----- pro_v3.5.1/view/uniapp_v2/App.vue | 6 +++ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/pro_v3.5.1/app/services/wechat/RoutineServices.php b/pro_v3.5.1/app/services/wechat/RoutineServices.php index 6ecde5da..541dae74 100644 --- a/pro_v3.5.1/app/services/wechat/RoutineServices.php +++ b/pro_v3.5.1/app/services/wechat/RoutineServices.php @@ -122,7 +122,7 @@ class RoutineServices extends BaseServices $wechatInfo['spread_code'] = $spread_code; $wechatInfo['session_key'] = $userInfoConfig['session_key'] ?? ''; $wechatInfo['phone'] = $phone; - $createData = [$openid, $wechatInfo, $spread_uid, 'routine', 'routine']; + [$openid, $wechatInfo, $spread_uid, $login_type, $userType] = $createData = $this->routineOauth($wechatInfo); } /** @var WechatUserServices $wechatUserServices */ $wechatUserServices = app()->make(WechatUserServices::class); @@ -268,20 +268,44 @@ class RoutineServices extends BaseServices $routineInfo['user_type'] = 'routine';//用户类型 $routineInfo['phone'] = $routine['phone'] ?? $routine['purePhoneNumber'] ?? ''; $spread_uid = (int)($routine['spread_uid'] ?? 0);//绑定关系uid - if (!$spread_uid && isset($routine['spread_code']) && $routine['spread_code']) { - //获取是否有扫码进小程序 - /** @var QrcodeServices $qrcode */ - $qrcode = app()->make(QrcodeServices::class); - $info = $qrcode->get((int)$routine['spread_code']); - if ($info) { - $spread_uid = $info['third_id']; - $routineInfo['spread_qrcode_id'] = (int)$info['id']; - $routineInfo['spread_qrcode_type'] = $info['third_type'] ?? ''; - } + $routineInfo = $this->appendSpreadQrcodeInfo($routineInfo, $routine, $spread_uid); + if (!$spread_uid && isset($routineInfo['spread_uid'])) { + $spread_uid = (int)$routineInfo['spread_uid']; } return [$routine['openid'] ?? '', $routineInfo, $spread_uid, $routine['login_type'] ?? 'routine', 'routine']; } + /** + * 尽量根据扫码参数补齐二维码信息,避免前端同时传 spread_uid / spread_code 时丢失渠道码来源。 + */ + protected function appendSpreadQrcodeInfo(array $routineInfo, array $routine, int $spread_uid = 0): array + { + $spreadCode = (int)($routine['spread_code'] ?? 0); + if ($spreadCode <= 0) { + if ($spread_uid > 0) { + $routineInfo['spread_uid'] = $spread_uid; + } + return $routineInfo; + } + + /** @var QrcodeServices $qrcode */ + $qrcode = app()->make(QrcodeServices::class); + $info = $qrcode->get($spreadCode); + if (!$info) { + if ($spread_uid > 0) { + $routineInfo['spread_uid'] = $spread_uid; + } + return $routineInfo; + } + + $qrcodeSpreadUid = (int)($info['third_id'] ?? 0); + $routineInfo['spread_qrcode_id'] = (int)($info['id'] ?? 0); + $routineInfo['spread_qrcode_type'] = $info['third_type'] ?? ''; + $routineInfo['spread_uid'] = $qrcodeSpreadUid ?: $spread_uid; + + return $routineInfo; + } + /** * 获取返回信息 * @param $user diff --git a/pro_v3.5.1/view/uniapp_v2/App.vue b/pro_v3.5.1/view/uniapp_v2/App.vue index c3681c46..5c3d82c2 100644 --- a/pro_v3.5.1/view/uniapp_v2/App.vue +++ b/pro_v3.5.1/view/uniapp_v2/App.vue @@ -44,6 +44,9 @@ this.$Cache.set('spread', queryData.query.spid); this.globalData.spid = queryData.query.spid; this.globalData.pid = queryData.query.spid; + if (queryData.query.id) { + this.globalData.code = queryData.query.id; + } silenceBindingSpread(this.globalData); } // #ifdef MP @@ -53,6 +56,9 @@ this.$Cache.set('spread', param.spid); this.globalData.spid = param.spid; } + if (param.id) { + this.globalData.code = param.id; + } /** 直播间分享**/ // const sceneList = [1007, 1008, 1014, 1044, 1045, 1046, 1047, 1048, 1049, 1073, 1154, 1155]; // if (sceneList.includes(queryData.query.scene)) {