迁移合作订单完整能力,并统一 AppRoleCode 角色权限与首页菜单展示。

新增 CooperationOrder 模块(双 Tab 列表、获客员绑定、主 Tab 扫码)、订单来源/带客单绑定及配套 API 测试;同步引入 roleCode 权限匹配与相关单元测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-29 13:33:00 +08:00
parent d310d26293
commit 1970572edd
66 changed files with 4247 additions and 201 deletions

View File

@ -0,0 +1,70 @@
//
// BindAcquirerViewModel.swift
// suixinkan
//
// Created by Codex on 2026/6/29.
//
import Foundation
import Combine
/// ViewModel
@MainActor
final class BindAcquirerViewModel: ObservableObject {
@Published var inviteInfo: SaleUserInviteInfo?
@Published var isLoading = false
@Published var isAlreadyBound = false
@Published var errorMessage: String?
private var saleUserId = 0
///
func load(api: CooperationOrderServing, saleUserId: Int) async {
guard saleUserId > 0 else {
errorMessage = "获客员信息无效"
return
}
if self.saleUserId == saleUserId && (inviteInfo != nil || isAlreadyBound) { return }
self.saleUserId = saleUserId
isAlreadyBound = false
isLoading = true
errorMessage = nil
defer { isLoading = false }
do {
var info = try await api.saleUserInviteInfo(saleUserId: saleUserId)
if info.saleUserId <= 0 {
info = SaleUserInviteInfo(
saleUserId: saleUserId,
isBound: info.isBound,
photographerName: info.photographerName,
photographerPhone: info.photographerPhone,
salerName: info.salerName,
salerPhone: info.salerPhone,
shareCode: info.shareCode,
subtitle: info.subtitle,
title: info.title
)
}
if info.isBound {
isAlreadyBound = true
}
inviteInfo = info
} catch {
handleBindError(error.localizedDescription.isEmpty ? "获取邀请信息失败" : error.localizedDescription)
}
}
///
func acceptBind(api: CooperationOrderServing) async throws {
guard saleUserId > 0, !isAlreadyBound else { return }
try await api.saleUserAcceptBind(saleUserId: saleUserId)
}
///
func handleBindError(_ message: String) {
errorMessage = message
if message.contains("已绑定") {
isAlreadyBound = true
}
}
}