```mermaid
---
title: 3.代理入驻(店铺新建)流程
---
flowchart TD
    Start((开始))
    --> Login[使用超级管理员或有权限的平台账号登录]

    Login --> HasPermission{是否具备代理入驻与店铺新建权限?}
    HasPermission -->|否| NoPermission[无权限，流程终止]
    HasPermission -->|是| EnterShopPage[进入店铺管理]

    subgraph CreateShopFlow[代理入驻与店铺新建]
        EnterShopPage --> FillShopInfo[填写代理与店铺基础信息]
        FillShopInfo --> SelectParent{是否设置上级代理?}
        SelectParent -->|否| CreateTopShop[创建顶级代理店铺]
        SelectParent -->|是| CreateChildShop[创建下级代理店铺]

        CreateTopShop --> ConfirmOwner[确认店铺归属与负责人]
        CreateChildShop --> ConfirmOwner

        ConfirmOwner --> SubmitShop[提交新建店铺]
        SubmitShop --> ShopCreateResult{店铺创建是否成功?}
        ShopCreateResult -->|否| FixShopInfo[修正信息后重新提交]
        FixShopInfo --> FillShopInfo
        ShopCreateResult -->|是| ShopVerifyStart[进入店铺验收]
    end

    subgraph ShopVerifyFlow[店铺验收]
        ShopVerifyStart --> CheckShopList[在店铺列表核对店铺信息与层级关系]
        CheckShopList --> CheckDefaultAccount[核对默认店铺账号是否已生成]
        CheckDefaultAccount --> CheckDefaultLogin[使用默认账号登录并核对可见功能]
        CheckDefaultLogin --> ShopVerifyResult{店铺验收是否通过?}
    end

    subgraph ExtraAccountFlow[店铺账号补充可选流程]
        ShopVerifyResult -->|通过| NeedExtraAccount{是否需要新增店铺账号?}
        NeedExtraAccount -->|否| End([流程结束])
        NeedExtraAccount -->|是| OpenShopAccount[进入该店铺账号管理]
        OpenShopAccount --> FillExtraAccount[填写新增账号信息并分配角色]
        FillExtraAccount --> SubmitExtraAccount[提交新增账号]
        SubmitExtraAccount --> VerifyExtraAccount[验证新增账号登录与权限]
        VerifyExtraAccount --> ExtraAccountResult{新增账号验收是否通过?}
        ExtraAccountResult -->|否| FixExtraAccount[修正账号信息或角色后重试]
        FixExtraAccount --> OpenShopAccount
        ExtraAccountResult -->|是| End
    end

    ShopVerifyResult -->|不通过| HandleShopException[记录异常并回到店铺管理处理]
    HandleShopException --> EnterShopPage

    %% ==================== 样式美化 ====================
    style Start fill:#90EE90,stroke:#2E7D32,stroke-width:2px
    style End fill:#FF9999,stroke:#C62828,stroke-width:2px
    style NoPermission fill:#FFCDD2,stroke:#D32F2F
    style FixShopInfo fill:#FFCCBC,stroke:#E64A19
    style FixExtraAccount fill:#FFCCBC,stroke:#E64A19
    style HandleShopException fill:#FFCCBC,stroke:#E64A19

    classDef decision fill:#FFF3E0,stroke:#F57C00,stroke-width:2px
    class HasPermission,SelectParent,ShopCreateResult,ShopVerifyResult,NeedExtraAccount,ExtraAccountResult decision
```
