|
|
@@ -3393,12 +3393,14 @@ async function storeRows(context,input){
|
|
|
optionalLegacyMemberSnapshot(context,input),
|
|
|
]),liveItems=legacyAccounts.available?legacyAccounts.items||[]:[],liveById=new Map(liveItems.map((row)=>[number(row.userId),row])),liveIds=new Set(liveById.keys()),coachIds=new Set((legacyAccounts.coachIds||[]).map(number).filter(Boolean)),children=new Map(),addChild=(storeId,type)=>{if(!storeId||!type)return;const current=children.get(storeId)||{members:0,coaches:0};if(type==='coach')current.coaches++;else current.members++;children.set(storeId,current);},projectedMembers=await queryUsers(context,input);
|
|
|
for(const member of projectedMembers)addChild(number(member.parentUserId),'member');
|
|
|
+ const activeStudyingCounts=new Map();
|
|
|
+ for(const member of filterMembers(projectedMembers,{filters:{learningStatus:'studying',status:'active'}})){const storeId=number(member.parentUserId);if(storeId)activeStudyingCounts.set(storeId,(activeStudyingCounts.get(storeId)||0)+1);}
|
|
|
if(legacyAccounts.available)for(const coachId of coachIds){const account=liveById.get(coachId);if(account)addChild(number(account.parentUserId),'coach');}
|
|
|
if(!legacyAccounts.available)for(const row of localChildRows){const userId=number(row.uid),storeId=number(row.sid);if(!storeId||liveIds.has(userId)||number(row.gid)===2)continue;const identity=text(row.identity_type);if(identity==='coach')addChild(storeId,'coach');else if(identity==='member'&&!projectedMembers.some((member)=>number(member.userId)===userId))addChild(storeId,'member');}
|
|
|
const coachStore=new Map(localCoaches.map((row)=>[number(row.userId),number(row.parentUserId)]));for(const coachId of coachIds){const account=liveById.get(coachId);if(account&&number(account.parentUserId))coachStore.set(coachId,number(account.parentUserId));}const appointmentMap=new Map(),today=businessDate();
|
|
|
for(const appointment of snapshot.appointments){const storeId=coachStore.get(number(appointment.coachId));if(!storeId||appointment.cancelled)continue;const entry=appointmentMap.get(storeId)||{todayAppointments:0,totalAppointments:0,lastAppointmentAt:''};entry.totalAppointments++;if(businessDate(appointment.startsAt)===today)entry.todayAppointments++;if(appointment.startsAt>entry.lastAppointmentAt)entry.lastAppointmentAt=appointment.startsAt;appointmentMap.set(storeId,entry);}
|
|
|
- const localRows=baseRows.map((row)=>{const legacy=legacyOf(row),userId=number(row.legacyUserId||legacy.UserID),account=liveById.get(userId),mobile=text(account&&account.mobile)||storeMobileOf(row),child=children.get(userId)||{},appointments=appointmentMap.get(userId)||{},parentLegacy=legacyOf({legacyUserData:row.parentLegacy}),parentStoreId=number(account&&account.parentUserId||legacy.ParentUserID),storeName=text(account&&(account.companyName||account.username||account.nickname||account.realName))||storeNameOf(row),contactName=text(account&&account.realName||account&&account.nickname||row.nickname||legacy.HoneyName),disabled=account?number(account.state,1)===0:row.isDisabled===true;return{objectId:text(row.objectId),userId,username:text(account&&account.username||row.username),storeName,contactName:contactName===storeName?'':contactName,mobile:roleOf(context)==='ops-manager'?mobile:'',mobileMasked:maskMobile(mobile),parentStoreId,parentStoreName:text(account&&account.parentDisplayName||row.parentRealName||row.parentUsername||parentLegacy.CompanyName||parentLegacy.HoneyName),memberCount:number(child.members),coachCount:number(child.coaches),todayAppointments:number(appointments.todayAppointments),totalAppointments:number(appointments.totalAppointments),lastAppointmentAt:text(appointments.lastAppointmentAt),registeredAt:text(account&&account.registeredAt)||registeredAtOf(row),lastLoginAt:text(account&&account.lastLoginAt)||firstDateIso(legacy.LastLoginTime,row.lastLoginAt),loginCount:number(account&&account.loginCount,legacy.LoginTimes||legacy.LoginCount),status:disabled?'disabled':'active',statusLabel:disabled?'已停用':'正常',updatedAt:dateIso(row.updatedAt),source:account?'hybrid':'parse',sourceLabel:account?'旧系统账号已关联':'新系统门店账号',readOnly:false};}),knownIds=new Set(localRows.map((row)=>row.userId));let rows=localRows.slice();
|
|
|
- if(legacyAccounts.available)for(const account of liveItems){const userId=number(account.userId);if(number(account.groupId)!==2||!userId||knownIds.has(userId))continue;knownIds.add(userId);const mobile=text(account.mobile),child=children.get(userId)||{},appointments=appointmentMap.get(userId)||{},storeName=text(account.companyName||account.nickname||account.realName||account.username)||'门店 '+userId,contactName=text(account.realName),disabled=number(account.state,1)===0;rows.push({objectId:'legacy-live-store:'+userId,userId,username:text(account.username),storeName,contactName:contactName===storeName?'':contactName,mobile:roleOf(context)==='ops-manager'?mobile:'',mobileMasked:maskMobile(mobile),parentStoreId:number(account.parentUserId),parentStoreName:text(account.parentDisplayName),memberCount:number(child.members),coachCount:number(child.coaches),todayAppointments:number(appointments.todayAppointments),totalAppointments:number(appointments.totalAppointments),lastAppointmentAt:text(appointments.lastAppointmentAt),registeredAt:text(account.registeredAt),lastLoginAt:text(account.lastLoginAt),loginCount:number(account.loginCount),status:disabled?'disabled':'active',statusLabel:disabled?'已停用':'正常',updatedAt:text(account.updatedAt),source:'legacy-live',sourceLabel:'旧系统实时门店 · 待同步',readOnly:true});}
|
|
|
+ const localRows=baseRows.map((row)=>{const legacy=legacyOf(row),userId=number(row.legacyUserId||legacy.UserID),account=liveById.get(userId),mobile=text(account&&account.mobile)||storeMobileOf(row),child=children.get(userId)||{},appointments=appointmentMap.get(userId)||{},parentLegacy=legacyOf({legacyUserData:row.parentLegacy}),parentStoreId=number(account&&account.parentUserId||legacy.ParentUserID),storeName=text(account&&(account.companyName||account.username||account.nickname||account.realName))||storeNameOf(row),contactName=text(account&&account.realName||account&&account.nickname||row.nickname||legacy.HoneyName),disabled=account?number(account.state,1)===0:row.isDisabled===true;return{objectId:text(row.objectId),userId,username:text(account&&account.username||row.username),storeName,contactName:contactName===storeName?'':contactName,mobile:roleOf(context)==='ops-manager'?mobile:'',mobileMasked:maskMobile(mobile),parentStoreId,parentStoreName:text(account&&account.parentDisplayName||row.parentRealName||row.parentUsername||parentLegacy.CompanyName||parentLegacy.HoneyName),memberCount:number(child.members),activeStudyingMemberCount:activeStudyingCounts.get(userId)||0,coachCount:number(child.coaches),todayAppointments:number(appointments.todayAppointments),totalAppointments:number(appointments.totalAppointments),lastAppointmentAt:text(appointments.lastAppointmentAt),registeredAt:text(account&&account.registeredAt)||registeredAtOf(row),lastLoginAt:text(account&&account.lastLoginAt)||firstDateIso(legacy.LastLoginTime,row.lastLoginAt),loginCount:number(account&&account.loginCount,legacy.LoginTimes||legacy.LoginCount),status:disabled?'disabled':'active',statusLabel:disabled?'已停用':'正常',updatedAt:dateIso(row.updatedAt),source:account?'hybrid':'parse',sourceLabel:account?'旧系统账号已关联':'新系统门店账号',readOnly:false};}),knownIds=new Set(localRows.map((row)=>row.userId));let rows=localRows.slice();
|
|
|
+ if(legacyAccounts.available)for(const account of liveItems){const userId=number(account.userId);if(number(account.groupId)!==2||!userId||knownIds.has(userId))continue;knownIds.add(userId);const mobile=text(account.mobile),child=children.get(userId)||{},appointments=appointmentMap.get(userId)||{},storeName=text(account.companyName||account.nickname||account.realName||account.username)||'门店 '+userId,contactName=text(account.realName),disabled=number(account.state,1)===0;rows.push({objectId:'legacy-live-store:'+userId,userId,username:text(account.username),storeName,contactName:contactName===storeName?'':contactName,mobile:roleOf(context)==='ops-manager'?mobile:'',mobileMasked:maskMobile(mobile),parentStoreId:number(account.parentUserId),parentStoreName:text(account.parentDisplayName),memberCount:number(child.members),activeStudyingMemberCount:activeStudyingCounts.get(userId)||0,coachCount:number(child.coaches),todayAppointments:number(appointments.todayAppointments),totalAppointments:number(appointments.totalAppointments),lastAppointmentAt:text(appointments.lastAppointmentAt),registeredAt:text(account.registeredAt),lastLoginAt:text(account.lastLoginAt),loginCount:number(account.loginCount),status:disabled?'disabled':'active',statusLabel:disabled?'已停用':'正常',updatedAt:text(account.updatedAt),source:'legacy-live',sourceLabel:'旧系统实时门店 · 待同步',readOnly:true});}
|
|
|
const allRows=rows.slice(),paging=pageInput(input),status=text(paging.filters.status||'all');if(status!=='all')rows=rows.filter((row)=>row.status===status);rows=searchRows(rows,input).sort((a,b)=>b.registeredAt.localeCompare(a.registeredAt)||b.userId-a.userId);const page=pageRows(rows,input),summary={total:allRows.length,active:allRows.filter((row)=>row.status==='active').length,disabled:allRows.filter((row)=>row.status==='disabled').length,members:allRows.reduce((sum,row)=>sum+row.memberCount,0),unboundMembers:projectedMembers.filter((row)=>!number(row.parentUserId)||!knownIds.has(number(row.parentUserId))).length,coaches:allRows.reduce((sum,row)=>sum+row.coachCount,0),todayAppointments:allRows.reduce((sum,row)=>sum+row.todayAppointments,0),liveOnly:allRows.filter((row)=>row.readOnly).length},parents=localRows.map((row)=>({objectId:row.objectId,userId:row.userId,displayName:row.storeName})).filter((row)=>row.userId);
|
|
|
const sourceMessages=[text(snapshot.live.message),text(legacyAccounts.message)].filter(Boolean);return{...page,summary,parents,canManage:roleOf(context)==='ops-manager',liveSourceAvailable:true,liveSourceMessage:sourceMessages.join(';')||'新数据库门店投影',legacyStoreCount:allRows.length,sync:await operationalSyncIndicator(context,input)};
|
|
|
}
|