合并分支 'dev' 到 'test'
Dev 查看合并请求 !1
正在显示
41 个修改的文件
包含
498 行增加
和
285 行删除
| 1 | -# 合伙人项目 | ||
| 2 | -vendor 文件夹如果不是迫不得已,请不要手动修改其中的文件! | ||
| 3 | -如果手动修改vendor中的文件,需自行进行版本管理。(慎重考虑!慎重考虑!慎重考虑!) | ||
| 1 | +# 服务端工作交接事项 | ||
| 2 | +## 合伙人管理后台项目 | ||
| 3 | + | ||
| 4 | +### 代码以及文档 | ||
| 5 | +- [代码地址](http://gitlab.fjmaimaimai.com/mmm-go/partnermg.git) | ||
| 6 | +- [项目原型svn](svn://218.106.157.184/repo/项目文件/项目【合伙人】) | ||
| 7 | +- [yapi-合伙人前端](http://47.97.5.102:36666/project/209/interface/api) | ||
| 8 | + | ||
| 9 | +服务端地址 | ||
| 10 | +``` | ||
| 11 | +测试开发环境pg数据库地址:114.55.200.59:31543,开发库:partner_dev,测试库:partner_test | ||
| 12 | +正式环境pg数据库地址:114.55.200.59:31544,正式库:partner | ||
| 13 | + | ||
| 14 | +服务端开发环境地址:http://mmm-partnermg-dev.fjmaimaimai.com | ||
| 15 | +服务端测试环境地址:http://mmm-partnermg-test.fjmaimaimai.com | ||
| 16 | +服务端正式环境地址:https://public-interface.fjmaimaimai.com/mmm-partnermg | ||
| 17 | +``` | ||
| 18 | +### 项目整体 | ||
| 19 | +- 项目使用框架 | ||
| 20 | + - http框架:beego | ||
| 21 | + - orm框架:go-pg | ||
| 22 | + - 数据存储:postgresql | ||
| 23 | + - 项目结构分层:DDD领域驱动 | ||
| 24 | + | ||
| 25 | +- 项目结构 | ||
| 26 | +``` | ||
| 27 | +├─conf 项目配置文件 | ||
| 28 | +├─deploy 项目部署文件 | ||
| 29 | +├─pkg | ||
| 30 | +│ ├─application | ||
| 31 | +│ │ ├─adminPermission 用户权限菜单 | ||
| 32 | +│ │ ├─businessBonus (在0.5.0后已经移除) | ||
| 33 | +│ │ ├─company 企业公司功能 | ||
| 34 | +│ │ ├─event 事件订阅以及处理 | ||
| 35 | +│ │ ├─factory 工厂类,实例具体的实现(数据仓储) | ||
| 36 | +│ │ ├─orderinfo 合伙人订单以及分红数据 | ||
| 37 | +│ │ ├─partnerCategory 合伙人分类信息 | ||
| 38 | +│ │ ├─partnerInfo 合伙人信息 | ||
| 39 | +│ │ ├─syncOrder 同步其他系统的订单数据 | ||
| 40 | +│ │ ├─unifiedUserCenter 从企业平台接收企业和管理员用户数据 | ||
| 41 | +│ │ └─users 管理员用户信息 | ||
| 42 | +│ ├─constant 变量配置(数据库等) | ||
| 43 | +│ ├─domain 领域模型(核心数据处理,接口定义) | ||
| 44 | +│ │ ├─event 领域事件定义 | ||
| 45 | +│ │ └─service 领域服务定义 | ||
| 46 | +│ ├─infrastructure 基础设施 | ||
| 47 | +│ │ ├─dao 特殊的数据库操作 | ||
| 48 | +│ │ ├─domainService 实现领域服务 | ||
| 49 | +│ │ ├─pg postgresql 数据库模型定义 | ||
| 50 | +│ │ ├─repository 数据仓储具体实现(对应domain定义数据库的数据存储接口) | ||
| 51 | +│ │ ├─serviceGateway 其他系统服务调用 | ||
| 52 | +│ │ | ||
| 53 | +│ ├─lib | ||
| 54 | +│ ├─log | ||
| 55 | +│ └─port 数据接入层(http接入,消息) | ||
| 56 | +│ ├─beego beego接入 | ||
| 57 | +│ └─consumer kafka消息订阅 | ||
| 58 | +└─vendor | ||
| 59 | +``` | ||
| 60 | +### 系统对接的外部数据 | ||
| 61 | + | ||
| 62 | +1. 外部数据来源,接收企业平台发送过来的数据。目前接收的是公司和员工的数据 | ||
| 63 | + 主要内容在文件夹 | ||
| 64 | + partnermg/pkg/application/unifiedUserCenter, | ||
| 65 | + partnermg/pkg/port/beego/controller/sync_data_controller.go, | ||
| 66 | + partnermg/pkg/port/beego/routers/routers.go, | ||
| 67 | + 具体对接需要的数据格式文档地址: | ||
| 68 | + [yapi-企业平台-子系统对接](http://47.97.5.102:36666/project/187/interface/api) | ||
| 69 | + | ||
| 70 | +2. 外部数据来源,接收香米小程序的订单,需要对接kafka消息。 | ||
| 71 | + 主要内容在 | ||
| 72 | + partnermg/pkg/application/syncOrder, | ||
| 73 | + partnermg/pkg/port/consumer, | ||
| 74 | + 具体对接需要的数据格式文档地址: | ||
| 75 | + [yapi-合伙人-后端](http://47.97.5.102:36666/project/211/interface/api/9013) | ||
| 76 | + | ||
| 77 | +3. 需要调用外部的api接口,调用企业平台,统一用户中心的接口 | ||
| 78 | + 主要内容在 | ||
| 79 | + partnermg/pkg/infrastructure/serviceGateway | ||
| 80 | + | ||
| 81 | +### 系统入口 | ||
| 82 | +- [测试环境--企业平台网站地址](https://enterprise-platform-dev.fjmaimaimai.com) | ||
| 83 | +- [开发环境--企业平台网站地址](https://enterprise-platform-local.fjmaimaimai.com) | ||
| 84 | +- 天联共创后台自身没有独立的登录入口,需要经过企业平台进行跳转登录 | ||
| 85 | + | ||
| 86 | + | ||
| 87 | +## 建议 | ||
| 88 | +1. vendor 目前作用是存放依赖,加快在容器中的构建速度。 | ||
| 89 | +2. 有"go.mod"文件存在,可以直接删除vendor文件夹。不过相应的dockerfile 也要进行一定的修改。 | ||
| 90 | +3. vendor 文件夹如果不是迫不得已,请不要手动修改其中的文件!可以使用命令 “go mod vendor”。 | ||
| 91 | +如果手动修改vendor中的文件,需自行进行版本管理。(慎重考虑!慎重考虑!慎重考虑!)。 | ||
| 92 | + | ||
| 93 | + |
| @@ -4,7 +4,6 @@ go 1.14 | @@ -4,7 +4,6 @@ go 1.14 | ||
| 4 | 4 | ||
| 5 | require ( | 5 | require ( |
| 6 | github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.1 | 6 | github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.1 |
| 7 | - github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2 | ||
| 8 | github.com/Shopify/sarama v1.23.1 | 7 | github.com/Shopify/sarama v1.23.1 |
| 9 | github.com/ajg/form v1.5.1 // indirect | 8 | github.com/ajg/form v1.5.1 // indirect |
| 10 | github.com/astaxie/beego v1.12.2 | 9 | github.com/astaxie/beego v1.12.2 |
| @@ -17,7 +17,7 @@ type CreatePartnerInfoCommand struct { | @@ -17,7 +17,7 @@ type CreatePartnerInfoCommand struct { | ||
| 17 | // 状态(1:启用或者0:禁用) | 17 | // 状态(1:启用或者0:禁用) |
| 18 | Status int `json:"status"` | 18 | Status int `json:"status"` |
| 19 | // 合伙类别 | 19 | // 合伙类别 |
| 20 | - PartnerCategory []int64 `json:"partnerCategory,omitempty"` | 20 | + PartnerCategory []*domain.PartnerCategory `json:"partnerCategory,omitempty"` |
| 21 | //合作时间 | 21 | //合作时间 |
| 22 | CooperateTime time.Time `json:"cooperateTime"` | 22 | CooperateTime time.Time `json:"cooperateTime"` |
| 23 | // 区域 | 23 | // 区域 |
| @@ -26,6 +26,8 @@ type CreatePartnerInfoCommand struct { | @@ -26,6 +26,8 @@ type CreatePartnerInfoCommand struct { | ||
| 26 | Salesman []domain.Salesman `json:"salesman,omitempty"` | 26 | Salesman []domain.Salesman `json:"salesman,omitempty"` |
| 27 | //公司id | 27 | //公司id |
| 28 | CompanyId int64 `json:"companyId"` | 28 | CompanyId int64 `json:"companyId"` |
| 29 | + //备注 | ||
| 30 | + Remark string `json:"remark"` | ||
| 29 | } | 31 | } |
| 30 | 32 | ||
| 31 | func (command CreatePartnerInfoCommand) ValidateCommand() error { | 33 | func (command CreatePartnerInfoCommand) ValidateCommand() error { |
| 1 | +/** | ||
| 2 | + @author: stevechan | ||
| 3 | + @date: 2020/12/29 | ||
| 4 | + @note: | ||
| 5 | +**/ | ||
| 6 | + | ||
| 7 | +package command | ||
| 8 | + | ||
| 9 | +import ( | ||
| 10 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +// 移除合伙人 | ||
| 14 | +type RemovePartnerInfoCommand struct { | ||
| 15 | + // 合伙人Id | ||
| 16 | + Id int64 `json:"id" valid:"Required"` | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func (command *RemovePartnerInfoCommand) ValidateCommand() error { | ||
| 20 | + if command.Id == 0 { | ||
| 21 | + return lib.ThrowError(lib.ARG_ERROR, "合伙人id错误") | ||
| 22 | + } | ||
| 23 | + return nil | ||
| 24 | +} |
| @@ -13,7 +13,7 @@ type UpdatePartnerInfoCommand struct { | @@ -13,7 +13,7 @@ type UpdatePartnerInfoCommand struct { | ||
| 13 | // 状态(1:启用或者0:禁用) | 13 | // 状态(1:启用或者0:禁用) |
| 14 | Status int `json:"status"` | 14 | Status int `json:"status"` |
| 15 | // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) | 15 | // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) |
| 16 | - PartnerCategory []int64 `json:"partnerCategory,omitempty"` | 16 | + PartnerCategory []*domain.PartnerCategory `json:"partnerCategory,omitempty"` |
| 17 | // 区域 | 17 | // 区域 |
| 18 | RegionInfo *domain.RegionInfo `json:"regionInfo"` | 18 | RegionInfo *domain.RegionInfo `json:"regionInfo"` |
| 19 | //关联业务员 | 19 | //关联业务员 |
| @@ -22,6 +22,8 @@ type UpdatePartnerInfoCommand struct { | @@ -22,6 +22,8 @@ type UpdatePartnerInfoCommand struct { | ||
| 22 | CooperateTime time.Time `json:"cooperateTime"` | 22 | CooperateTime time.Time `json:"cooperateTime"` |
| 23 | //公司id | 23 | //公司id |
| 24 | CompanyId int64 `json:"companyId"` | 24 | CompanyId int64 `json:"companyId"` |
| 25 | + //备注 | ||
| 26 | + Remark string `json:"remark"` | ||
| 25 | } | 27 | } |
| 26 | 28 | ||
| 27 | func (command *UpdatePartnerInfoCommand) ValidateCommand() error { | 29 | func (command *UpdatePartnerInfoCommand) ValidateCommand() error { |
| @@ -2,11 +2,12 @@ package query | @@ -2,11 +2,12 @@ package query | ||
| 2 | 2 | ||
| 3 | type ListPartnerInfoQuery struct { | 3 | type ListPartnerInfoQuery struct { |
| 4 | // 合伙人类别 | 4 | // 合伙人类别 |
| 5 | - Partnertype int `json:"partnerType"` | 5 | + PartnerType int `json:"partnerType"` |
| 6 | //所属区域 | 6 | //所属区域 |
| 7 | RegionInfo string `json:"regionInfo"` | 7 | RegionInfo string `json:"regionInfo"` |
| 8 | // 合伙人姓名 | 8 | // 合伙人姓名 |
| 9 | PartnerName string `json:"partnerName"` | 9 | PartnerName string `json:"partnerName"` |
| 10 | + // 公司id | ||
| 10 | CompanyId int64 `json:"companyId"` | 11 | CompanyId int64 `json:"companyId"` |
| 11 | // 查询偏离量 | 12 | // 查询偏离量 |
| 12 | Offset int `json:"offset"` | 13 | Offset int `json:"offset"` |
| @@ -15,6 +16,5 @@ type ListPartnerInfoQuery struct { | @@ -15,6 +16,5 @@ type ListPartnerInfoQuery struct { | ||
| 15 | } | 16 | } |
| 16 | 17 | ||
| 17 | func (q *ListPartnerInfoQuery) ValidateQuery() error { | 18 | func (q *ListPartnerInfoQuery) ValidateQuery() error { |
| 18 | - | ||
| 19 | return nil | 19 | return nil |
| 20 | } | 20 | } |
| @@ -21,7 +21,13 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService { | @@ -21,7 +21,13 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService { | ||
| 21 | return newPartnerInfoService | 21 | return newPartnerInfoService |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | -// CreatePartnerInfo 创建合伙人 | 24 | +/** |
| 25 | + * @Author SteveChan | ||
| 26 | + * @Description // 创建合伙人 | ||
| 27 | + * @Date 15:42 2020/12/29 | ||
| 28 | + * @Param | ||
| 29 | + * @return | ||
| 30 | + **/ | ||
| 25 | func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.CreatePartnerInfoCommand) (data *domain.PartnerInfo, err error) { | 31 | func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.CreatePartnerInfoCommand) (data *domain.PartnerInfo, err error) { |
| 26 | var ( | 32 | var ( |
| 27 | transactionContext, _ = factory.CreateTransactionContext(nil) | 33 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| @@ -35,16 +41,18 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre | @@ -35,16 +41,18 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre | ||
| 35 | defer func() { | 41 | defer func() { |
| 36 | transactionContext.RollbackTransaction() | 42 | transactionContext.RollbackTransaction() |
| 37 | }() | 43 | }() |
| 44 | + | ||
| 38 | //检查账号是否存在 | 45 | //检查账号是否存在 |
| 39 | var ( | 46 | var ( |
| 40 | - partnerinfoDao *dao.PartnerInfoDao | 47 | + partnerInfoDao *dao.PartnerInfoDao |
| 41 | ) | 48 | ) |
| 42 | - if partnerinfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{ | 49 | + if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{ |
| 43 | "transactionContext": transactionContext, | 50 | "transactionContext": transactionContext, |
| 44 | }); err != nil { | 51 | }); err != nil { |
| 45 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 52 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
| 46 | } | 53 | } |
| 47 | - ok, err := partnerinfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId) | 54 | + |
| 55 | + ok, err := partnerInfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId) | ||
| 48 | if err != nil { | 56 | if err != nil { |
| 49 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 57 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
| 50 | } | 58 | } |
| @@ -52,10 +60,19 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre | @@ -52,10 +60,19 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre | ||
| 52 | return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在") | 60 | return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在") |
| 53 | } | 61 | } |
| 54 | 62 | ||
| 63 | + // 编号去重 | ||
| 64 | + for _, partnerCategory := range cmd.PartnerCategory { | ||
| 65 | + if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, 0); err != nil { | ||
| 66 | + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
| 67 | + } else if ok { | ||
| 68 | + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "合伙类型"+""+"编号"+partnerCategory.Code+"已存在") | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + | ||
| 55 | var ( | 72 | var ( |
| 56 | partnerInfoRepository domain.PartnerInfoRepository | 73 | partnerInfoRepository domain.PartnerInfoRepository |
| 57 | categoryRepository domain.PartnerCategoryRepository | 74 | categoryRepository domain.PartnerCategoryRepository |
| 58 | - categorys []domain.PartnerCategory | 75 | + categories []domain.PartnerCategory |
| 59 | ) | 76 | ) |
| 60 | if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | 77 | if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ |
| 61 | "transactionContext": transactionContext, | 78 | "transactionContext": transactionContext, |
| @@ -67,13 +84,26 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre | @@ -67,13 +84,26 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre | ||
| 67 | }); err != nil { | 84 | }); err != nil { |
| 68 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 85 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
| 69 | } | 86 | } |
| 70 | - _, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{ | ||
| 71 | - Ids: cmd.PartnerCategory, | 87 | + |
| 88 | + var ids []int64 | ||
| 89 | + for _, partnerCategory := range cmd.PartnerCategory { | ||
| 90 | + ids = append(ids, partnerCategory.Id) | ||
| 91 | + } | ||
| 92 | + _, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{ | ||
| 93 | + Ids: ids, | ||
| 72 | }) | 94 | }) |
| 73 | if err != nil { | 95 | if err != nil { |
| 74 | e := fmt.Sprintf("获取合伙人分类数据失败:%s", err) | 96 | e := fmt.Sprintf("获取合伙人分类数据失败:%s", err) |
| 75 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) | 97 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) |
| 76 | } | 98 | } |
| 99 | + for i, category := range categories { | ||
| 100 | + for _, partnerCategory := range cmd.PartnerCategory { | ||
| 101 | + if category.Id == partnerCategory.Id { | ||
| 102 | + categories[i].Code = partnerCategory.Code | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + | ||
| 77 | newPartnerInfo := domain.PartnerInfo{ | 107 | newPartnerInfo := domain.PartnerInfo{ |
| 78 | Partner: domain.Partner{ | 108 | Partner: domain.Partner{ |
| 79 | Account: cmd.Account, | 109 | Account: cmd.Account, |
| @@ -86,7 +116,8 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre | @@ -86,7 +116,8 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre | ||
| 86 | Salesman: cmd.Salesman, | 116 | Salesman: cmd.Salesman, |
| 87 | CooperateTime: cmd.CooperateTime, | 117 | CooperateTime: cmd.CooperateTime, |
| 88 | CompanyId: cmd.CompanyId, | 118 | CompanyId: cmd.CompanyId, |
| 89 | - PartnerCategoryInfos: categorys, | 119 | + PartnerCategoryInfos: categories, |
| 120 | + Remark: cmd.Remark, | ||
| 90 | } | 121 | } |
| 91 | if err = partnerInfoRepository.Save(&newPartnerInfo); err != nil { | 122 | if err = partnerInfoRepository.Save(&newPartnerInfo); err != nil { |
| 92 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 123 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
| @@ -106,11 +137,18 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre | @@ -106,11 +137,18 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre | ||
| 106 | return &newPartnerInfo, nil | 137 | return &newPartnerInfo, nil |
| 107 | } | 138 | } |
| 108 | 139 | ||
| 109 | -// GetPartnerInfo 返回合伙人 | 140 | +/** |
| 141 | + * @Author SteveChan | ||
| 142 | + * @Description // 返回合伙人,增加合伙人编号字段 | ||
| 143 | + * @Date 15:43 2020/12/29 | ||
| 144 | + * @Param | ||
| 145 | + * @return | ||
| 146 | + **/ | ||
| 110 | func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) { | 147 | func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) { |
| 111 | var ( | 148 | var ( |
| 112 | transactionContext, _ = factory.CreateTransactionContext(nil) | 149 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| 113 | ) | 150 | ) |
| 151 | + | ||
| 114 | if err = q.ValidateQuery(); err != nil { | 152 | if err = q.ValidateQuery(); err != nil { |
| 115 | return nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) | 153 | return nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) |
| 116 | } | 154 | } |
| @@ -120,17 +158,21 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI | @@ -120,17 +158,21 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI | ||
| 120 | defer func() { | 158 | defer func() { |
| 121 | transactionContext.RollbackTransaction() | 159 | transactionContext.RollbackTransaction() |
| 122 | }() | 160 | }() |
| 161 | + | ||
| 123 | var ( | 162 | var ( |
| 124 | PartnerInfoRepository domain.PartnerInfoRepository | 163 | PartnerInfoRepository domain.PartnerInfoRepository |
| 125 | categoryRepository domain.PartnerCategoryRepository | 164 | categoryRepository domain.PartnerCategoryRepository |
| 126 | - categorys []domain.PartnerCategory | 165 | + categories []domain.PartnerCategory |
| 127 | partnerData *domain.PartnerInfo | 166 | partnerData *domain.PartnerInfo |
| 128 | ) | 167 | ) |
| 168 | + | ||
| 129 | if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | 169 | if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ |
| 130 | "transactionContext": transactionContext, | 170 | "transactionContext": transactionContext, |
| 131 | }); err != nil { | 171 | }); err != nil { |
| 132 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 172 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
| 133 | } | 173 | } |
| 174 | + | ||
| 175 | + // 获取合伙人数据 | ||
| 134 | partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{ | 176 | partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{ |
| 135 | UserId: q.Id, CompanyId: q.CompanyId, | 177 | UserId: q.Id, CompanyId: q.CompanyId, |
| 136 | }) | 178 | }) |
| @@ -140,33 +182,49 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI | @@ -140,33 +182,49 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI | ||
| 140 | if !partnerData.IsCompany(q.CompanyId) { | 182 | if !partnerData.IsCompany(q.CompanyId) { |
| 141 | return nil, lib.ThrowError(lib.BUSINESS_ERROR, "企业信息异常操作") | 183 | return nil, lib.ThrowError(lib.BUSINESS_ERROR, "企业信息异常操作") |
| 142 | } | 184 | } |
| 185 | + | ||
| 186 | + // 获取合伙人类别 | ||
| 143 | if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{ | 187 | if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{ |
| 144 | "transactionContext": transactionContext, | 188 | "transactionContext": transactionContext, |
| 145 | }); err != nil { | 189 | }); err != nil { |
| 146 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 190 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
| 147 | } | 191 | } |
| 148 | - categoryIds := []int64{} | 192 | + var categoryIds []int64 |
| 149 | for _, v := range partnerData.PartnerCategoryInfos { | 193 | for _, v := range partnerData.PartnerCategoryInfos { |
| 150 | categoryIds = append(categoryIds, v.Id) | 194 | categoryIds = append(categoryIds, v.Id) |
| 151 | } | 195 | } |
| 152 | if len(categoryIds) > 0 { | 196 | if len(categoryIds) > 0 { |
| 153 | - _, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{ | 197 | + _, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{ |
| 154 | Ids: categoryIds, | 198 | Ids: categoryIds, |
| 155 | }) | 199 | }) |
| 156 | if err != nil { | 200 | if err != nil { |
| 157 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 201 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
| 158 | } | 202 | } |
| 203 | + for i, category := range categories { | ||
| 204 | + for _, partnerCategory := range partnerData.PartnerCategoryInfos { | ||
| 205 | + if category.Id == partnerCategory.Id { | ||
| 206 | + categories[i].Code = partnerCategory.Code | ||
| 207 | + } | ||
| 208 | + } | ||
| 209 | + } | ||
| 159 | } | 210 | } |
| 160 | - partnerData.PartnerCategoryInfos = categorys | 211 | + partnerData.PartnerCategoryInfos = categories |
| 161 | err = transactionContext.CommitTransaction() | 212 | err = transactionContext.CommitTransaction() |
| 162 | return partnerData, nil | 213 | return partnerData, nil |
| 163 | } | 214 | } |
| 164 | 215 | ||
| 165 | -//UpdatePartnerInfo 更新合伙人 | 216 | +/** |
| 217 | + * @Author SteveChan | ||
| 218 | + * @Description // 更新合伙人 | ||
| 219 | + * @Date 00:07 2020/12/30 | ||
| 220 | + * @Param | ||
| 221 | + * @return | ||
| 222 | + **/ | ||
| 166 | func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.UpdatePartnerInfoCommand) (err error) { | 223 | func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.UpdatePartnerInfoCommand) (err error) { |
| 167 | var ( | 224 | var ( |
| 168 | transactionContext, _ = factory.CreateTransactionContext(nil) | 225 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| 169 | ) | 226 | ) |
| 227 | + | ||
| 170 | if err = cmd.ValidateCommand(); err != nil { | 228 | if err = cmd.ValidateCommand(); err != nil { |
| 171 | return application.ThrowError(application.ARG_ERROR, err.Error()) | 229 | return application.ThrowError(application.ARG_ERROR, err.Error()) |
| 172 | } | 230 | } |
| @@ -176,30 +234,65 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd | @@ -176,30 +234,65 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd | ||
| 176 | defer func() { | 234 | defer func() { |
| 177 | transactionContext.RollbackTransaction() | 235 | transactionContext.RollbackTransaction() |
| 178 | }() | 236 | }() |
| 237 | + | ||
| 179 | var ( | 238 | var ( |
| 180 | partnerInfoRepository domain.PartnerInfoRepository | 239 | partnerInfoRepository domain.PartnerInfoRepository |
| 181 | categoryRepository domain.PartnerCategoryRepository | 240 | categoryRepository domain.PartnerCategoryRepository |
| 182 | - categorys []domain.PartnerCategory | 241 | + categories []domain.PartnerCategory |
| 242 | + partnerInfoDao *dao.PartnerInfoDao | ||
| 183 | ) | 243 | ) |
| 244 | + | ||
| 245 | + if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{ | ||
| 246 | + "transactionContext": transactionContext, | ||
| 247 | + }); err != nil { | ||
| 248 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
| 249 | + } | ||
| 250 | + | ||
| 184 | if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | 251 | if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ |
| 185 | "transactionContext": transactionContext, | 252 | "transactionContext": transactionContext, |
| 186 | }); err != nil { | 253 | }); err != nil { |
| 187 | return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 254 | return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
| 188 | } | 255 | } |
| 256 | + | ||
| 189 | if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{ | 257 | if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{ |
| 190 | "transactionContext": transactionContext, | 258 | "transactionContext": transactionContext, |
| 191 | }); err != nil { | 259 | }); err != nil { |
| 192 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 260 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
| 193 | } | 261 | } |
| 194 | - _, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{ | ||
| 195 | - Ids: cmd.PartnerCategory, | 262 | + |
| 263 | + // 编号去重 | ||
| 264 | + for _, partnerCategory := range cmd.PartnerCategory { | ||
| 265 | + if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, cmd.Id); err != nil { | ||
| 266 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
| 267 | + } else if ok { | ||
| 268 | + return lib.ThrowError(lib.BUSINESS_ERROR, "编号"+partnerCategory.Code+"已存在") | ||
| 269 | + } | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + var ids []int64 | ||
| 273 | + for _, partnerCategory := range cmd.PartnerCategory { | ||
| 274 | + ids = append(ids, partnerCategory.Id) | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + _, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{ | ||
| 278 | + Ids: ids, | ||
| 196 | }) | 279 | }) |
| 197 | if err != nil { | 280 | if err != nil { |
| 198 | e := fmt.Sprintf("获取合伙人分类数据失败:%s", err) | 281 | e := fmt.Sprintf("获取合伙人分类数据失败:%s", err) |
| 199 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) | 282 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) |
| 200 | } | 283 | } |
| 284 | + | ||
| 285 | + for i, category := range categories { | ||
| 286 | + for _, partnerCategory := range cmd.PartnerCategory { | ||
| 287 | + if category.Id == partnerCategory.Id { | ||
| 288 | + categories[i].Code = partnerCategory.Code | ||
| 289 | + } | ||
| 290 | + } | ||
| 291 | + } | ||
| 292 | + | ||
| 201 | partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{ | 293 | partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{ |
| 202 | - UserId: cmd.Id, CompanyId: cmd.CompanyId, | 294 | + UserId: cmd.Id, |
| 295 | + CompanyId: cmd.CompanyId, | ||
| 203 | }) | 296 | }) |
| 204 | if err != nil { | 297 | if err != nil { |
| 205 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 298 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
| @@ -207,11 +300,14 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd | @@ -207,11 +300,14 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd | ||
| 207 | if !partnerInfo.IsCompany(cmd.CompanyId) { | 300 | if !partnerInfo.IsCompany(cmd.CompanyId) { |
| 208 | return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作") | 301 | return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作") |
| 209 | } | 302 | } |
| 303 | + | ||
| 210 | partnerInfo.Salesman = cmd.Salesman | 304 | partnerInfo.Salesman = cmd.Salesman |
| 211 | partnerInfo.Status = cmd.Status | 305 | partnerInfo.Status = cmd.Status |
| 212 | partnerInfo.RegionInfo = *cmd.RegionInfo | 306 | partnerInfo.RegionInfo = *cmd.RegionInfo |
| 213 | partnerInfo.CooperateTime = cmd.CooperateTime | 307 | partnerInfo.CooperateTime = cmd.CooperateTime |
| 214 | - partnerInfo.PartnerCategoryInfos = categorys | 308 | + partnerInfo.PartnerCategoryInfos = categories |
| 309 | + partnerInfo.Remark = cmd.Remark | ||
| 310 | + | ||
| 215 | if err = partnerInfoRepository.Save(partnerInfo); err != nil { | 311 | if err = partnerInfoRepository.Save(partnerInfo); err != nil { |
| 216 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 312 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
| 217 | } | 313 | } |
| @@ -231,7 +327,13 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd | @@ -231,7 +327,13 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd | ||
| 231 | return | 327 | return |
| 232 | } | 328 | } |
| 233 | 329 | ||
| 234 | -// ListPartnerInfo 合伙人列表 | 330 | +/** |
| 331 | + * @Author SteveChan | ||
| 332 | + * @Description //合伙人列表,返回合伙人编号 | ||
| 333 | + * @Date 00:07 2020/12/30 | ||
| 334 | + * @Param | ||
| 335 | + * @return | ||
| 336 | + **/ | ||
| 235 | func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (int, []domain.PartnerInfo, error) { | 337 | func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (int, []domain.PartnerInfo, error) { |
| 236 | var ( | 338 | var ( |
| 237 | transactionContext, _ = factory.CreateTransactionContext(nil) | 339 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| @@ -246,14 +348,13 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue | @@ -246,14 +348,13 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue | ||
| 246 | return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 348 | return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
| 247 | } | 349 | } |
| 248 | defer func() { | 350 | defer func() { |
| 249 | - | ||
| 250 | transactionContext.RollbackTransaction() | 351 | transactionContext.RollbackTransaction() |
| 251 | - | ||
| 252 | }() | 352 | }() |
| 353 | + | ||
| 253 | var ( | 354 | var ( |
| 254 | partnerInfoRepository domain.PartnerInfoRepository | 355 | partnerInfoRepository domain.PartnerInfoRepository |
| 255 | categoryRepository domain.PartnerCategoryRepository | 356 | categoryRepository domain.PartnerCategoryRepository |
| 256 | - categorys []domain.PartnerCategory | 357 | + categories []domain.PartnerCategory |
| 257 | ) | 358 | ) |
| 258 | if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | 359 | if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ |
| 259 | "transactionContext": transactionContext, | 360 | "transactionContext": transactionContext, |
| @@ -271,8 +372,8 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue | @@ -271,8 +372,8 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue | ||
| 271 | PartnerName: listPartnerInfoQuery.PartnerName, | 372 | PartnerName: listPartnerInfoQuery.PartnerName, |
| 272 | CompanyId: listPartnerInfoQuery.CompanyId, | 373 | CompanyId: listPartnerInfoQuery.CompanyId, |
| 273 | } | 374 | } |
| 274 | - if listPartnerInfoQuery.Partnertype > 0 { | ||
| 275 | - queryOption.PartnerCategory = []int{listPartnerInfoQuery.Partnertype} | 375 | + if listPartnerInfoQuery.PartnerType > 0 { |
| 376 | + queryOption.PartnerCategory = []int{listPartnerInfoQuery.PartnerType} | ||
| 276 | } | 377 | } |
| 277 | // RegionInfo | 378 | // RegionInfo |
| 278 | if len(listPartnerInfoQuery.RegionInfo) > 0 { | 379 | if len(listPartnerInfoQuery.RegionInfo) > 0 { |
| @@ -284,18 +385,19 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue | @@ -284,18 +385,19 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue | ||
| 284 | if count, err = partnerInfoRepository.CountAll(queryOption); err != nil { | 385 | if count, err = partnerInfoRepository.CountAll(queryOption); err != nil { |
| 285 | return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 386 | return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
| 286 | } | 387 | } |
| 287 | - _, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{}) | 388 | + _, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{}) |
| 288 | if err != nil { | 389 | if err != nil { |
| 289 | return count, partnerInfos, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 390 | return count, partnerInfos, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
| 290 | } | 391 | } |
| 291 | - categorysMap := make(map[int64]domain.PartnerCategory) | ||
| 292 | - for i := range categorys { | ||
| 293 | - categorysMap[categorys[i].Id] = categorys[i] | 392 | + categoriesMap := make(map[int64]domain.PartnerCategory) |
| 393 | + for i := range categories { | ||
| 394 | + categoriesMap[categories[i].Id] = categories[i] | ||
| 294 | } | 395 | } |
| 295 | for i := range partnerInfos { | 396 | for i := range partnerInfos { |
| 296 | - categoryInPartner := []domain.PartnerCategory{} | 397 | + var categoryInPartner []domain.PartnerCategory |
| 297 | for _, vv := range partnerInfos[i].PartnerCategoryInfos { | 398 | for _, vv := range partnerInfos[i].PartnerCategoryInfos { |
| 298 | - if categoryData, ok := categorysMap[vv.Id]; ok { | 399 | + if categoryData, ok := categoriesMap[vv.Id]; ok { |
| 400 | + categoryData.Code = vv.Code | ||
| 299 | categoryInPartner = append(categoryInPartner, categoryData) | 401 | categoryInPartner = append(categoryInPartner, categoryData) |
| 300 | } | 402 | } |
| 301 | } | 403 | } |
| @@ -307,6 +409,47 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue | @@ -307,6 +409,47 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue | ||
| 307 | return count, partnerInfos, nil | 409 | return count, partnerInfos, nil |
| 308 | } | 410 | } |
| 309 | 411 | ||
| 412 | +/** | ||
| 413 | + * @Author SteveChan | ||
| 414 | + * @Description //TODO 移除合伙人 | ||
| 415 | + * @Date 16:40 2020/12/29 | ||
| 416 | + * @Param | ||
| 417 | + * @return | ||
| 418 | + **/ | ||
| 419 | +func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.RemovePartnerInfoCommand) (err error) { | ||
| 420 | + var ( | ||
| 421 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 422 | + ) | ||
| 423 | + if err = cmd.ValidateCommand(); err != nil { | ||
| 424 | + return application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 425 | + } | ||
| 426 | + if err = transactionContext.StartTransaction(); err != nil { | ||
| 427 | + return err | ||
| 428 | + } | ||
| 429 | + defer func() { | ||
| 430 | + transactionContext.RollbackTransaction() | ||
| 431 | + }() | ||
| 432 | + | ||
| 433 | + var ( | ||
| 434 | + partnerInfoRepository domain.PartnerInfoRepository | ||
| 435 | + ) | ||
| 436 | + | ||
| 437 | + if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | ||
| 438 | + "transactionContext": transactionContext, | ||
| 439 | + }); err != nil { | ||
| 440 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 441 | + } | ||
| 442 | + | ||
| 443 | + // 判断合伙人是否有业务数据 | ||
| 444 | + | ||
| 445 | + if err = partnerInfoRepository.Remove(cmd.Id); err != nil { | ||
| 446 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 447 | + } | ||
| 448 | + | ||
| 449 | + transactionContext.CommitTransaction() | ||
| 450 | + return nil | ||
| 451 | +} | ||
| 452 | + | ||
| 310 | func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPartnerInfoCommand) (err error) { | 453 | func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPartnerInfoCommand) (err error) { |
| 311 | if len(cmd.Ids) == 0 { | 454 | if len(cmd.Ids) == 0 { |
| 312 | return nil | 455 | return nil |
| @@ -324,14 +467,14 @@ func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPar | @@ -324,14 +467,14 @@ func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPar | ||
| 324 | transactionContext.RollbackTransaction() | 467 | transactionContext.RollbackTransaction() |
| 325 | }() | 468 | }() |
| 326 | var ( | 469 | var ( |
| 327 | - partnerinfoDao *dao.PartnerInfoDao | 470 | + partnerInfoDao *dao.PartnerInfoDao |
| 328 | ) | 471 | ) |
| 329 | - if partnerinfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{ | 472 | + if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{ |
| 330 | "transactionContext": transactionContext, | 473 | "transactionContext": transactionContext, |
| 331 | }); err != nil { | 474 | }); err != nil { |
| 332 | return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 475 | return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
| 333 | } | 476 | } |
| 334 | - err = partnerinfoDao.UpdatePartnerStatus(cmd.Ids, cmd.CompanyId, cmd.Status) | 477 | + err = partnerInfoDao.UpdatePartnerStatus(cmd.Ids, cmd.CompanyId, cmd.Status) |
| 335 | if err != nil { | 478 | if err != nil { |
| 336 | e := fmt.Sprintf("更新合伙人(id=%v)的数据失败;%s", cmd.Ids, err) | 479 | e := fmt.Sprintf("更新合伙人(id=%v)的数据失败;%s", cmd.Ids, err) |
| 337 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) | 480 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) |
| @@ -8,14 +8,14 @@ var LOG_LEVEL = "debug" | @@ -8,14 +8,14 @@ var LOG_LEVEL = "debug" | ||
| 8 | var LOG_File = "./logs/partnermg.log" | 8 | var LOG_File = "./logs/partnermg.log" |
| 9 | 9 | ||
| 10 | var ( | 10 | var ( |
| 11 | - UCENTER_HOST = "https://suplus-ucenter-dev.fjmaimaimai.com" //统一用户中心地址 | 11 | + UCENTER_HOST = "https://suplus-ucenter-test.fjmaimaimai.com" //统一用户中心地址 |
| 12 | UCENTER_SECRET = "cykbjnfqgctn" | 12 | UCENTER_SECRET = "cykbjnfqgctn" |
| 13 | UCENTER_APP_KEY = "39aefef9e22744a3b2d2d3791824ae7b" | 13 | UCENTER_APP_KEY = "39aefef9e22744a3b2d2d3791824ae7b" |
| 14 | UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735" | 14 | UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735" |
| 15 | ) | 15 | ) |
| 16 | 16 | ||
| 17 | var ( | 17 | var ( |
| 18 | - BUSINESS_ADMIN_HOST = "http://suplus-business-admin-dev.fjmaimaimai.com" //企业平台的地址 | 18 | + BUSINESS_ADMIN_HOST = "http://suplus-business-admin-test.fjmaimaimai.com" //企业平台的地址 |
| 19 | ) | 19 | ) |
| 20 | 20 | ||
| 21 | func init() { | 21 | func init() { |
| @@ -34,9 +34,7 @@ func init() { | @@ -34,9 +34,7 @@ func init() { | ||
| 34 | if os.Getenv("UCENTER_CHECK_ALT") != "" { | 34 | if os.Getenv("UCENTER_CHECK_ALT") != "" { |
| 35 | UCENTER_CHECK_ALT = os.Getenv("UCENTER_CHECK_ALT") | 35 | UCENTER_CHECK_ALT = os.Getenv("UCENTER_CHECK_ALT") |
| 36 | } | 36 | } |
| 37 | - | ||
| 38 | if os.Getenv("BUSINESS_ADMIN_HOST") != "" { | 37 | if os.Getenv("BUSINESS_ADMIN_HOST") != "" { |
| 39 | BUSINESS_ADMIN_HOST = os.Getenv("BUSINESS_ADMIN_HOST") | 38 | BUSINESS_ADMIN_HOST = os.Getenv("BUSINESS_ADMIN_HOST") |
| 40 | } | 39 | } |
| 41 | - | ||
| 42 | } | 40 | } |
| @@ -14,7 +14,7 @@ var KafkaCfg KafkaConfig | @@ -14,7 +14,7 @@ var KafkaCfg KafkaConfig | ||
| 14 | 14 | ||
| 15 | func init() { | 15 | func init() { |
| 16 | KafkaCfg = KafkaConfig{ | 16 | KafkaCfg = KafkaConfig{ |
| 17 | - Servers: []string{""}, | 17 | + Servers: []string{"127.0.0.1:9092"}, |
| 18 | ConsumerId: "partnermg_local", | 18 | ConsumerId: "partnermg_local", |
| 19 | } | 19 | } |
| 20 | if os.Getenv("KAFKA_HOST") != "" { | 20 | if os.Getenv("KAFKA_HOST") != "" { |
| @@ -2,11 +2,11 @@ package constant | @@ -2,11 +2,11 @@ package constant | ||
| 2 | 2 | ||
| 3 | import "os" | 3 | import "os" |
| 4 | 4 | ||
| 5 | -var POSTGRESQL_DB_NAME = "partner_dev" | 5 | +var POSTGRESQL_DB_NAME = "partner_test" |
| 6 | var POSTGRESQL_USER = "postgres" | 6 | var POSTGRESQL_USER = "postgres" |
| 7 | -var POSTGRESQL_PASSWORD = "eagle1010" | ||
| 8 | -var POSTGRESQL_HOST = "114.55.200.59" | ||
| 9 | -var POSTGRESQL_PORT = "31543" | 7 | +var POSTGRESQL_PASSWORD = "1993618jack" // eagle1010 |
| 8 | +var POSTGRESQL_HOST = "127.0.0.1" // 114.55.200.59 | ||
| 9 | +var POSTGRESQL_PORT = "5432" // 31543 | ||
| 10 | var DISABLE_CREATE_TABLE = true | 10 | var DISABLE_CREATE_TABLE = true |
| 11 | var DISABLE_SQL_GENERATE_PRINT = false | 11 | var DISABLE_SQL_GENERATE_PRINT = false |
| 12 | 12 |
| @@ -114,7 +114,7 @@ type OrderBase struct { | @@ -114,7 +114,7 @@ type OrderBase struct { | ||
| 114 | DataFrom OrderDataFrom `json:"dataFrom"` | 114 | DataFrom OrderDataFrom `json:"dataFrom"` |
| 115 | //备注 | 115 | //备注 |
| 116 | Remark OrderBaseRemark `json:"remark"` | 116 | Remark OrderBaseRemark `json:"remark"` |
| 117 | - | 117 | + //合伙人类型 |
| 118 | PartnerCategory PartnerCategory `json:"partnerCategory"` | 118 | PartnerCategory PartnerCategory `json:"partnerCategory"` |
| 119 | } | 119 | } |
| 120 | 120 | ||
| @@ -182,16 +182,16 @@ func (order *OrderBase) AddGoods(goods []OrderGood) { | @@ -182,16 +182,16 @@ func (order *OrderBase) AddGoods(goods []OrderGood) { | ||
| 182 | order.Compute() | 182 | order.Compute() |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | -func (order *OrderBase) ModifyGoodNumber(goodid int64, number int64) { | ||
| 186 | - for i := range order.Goods { | ||
| 187 | - if order.Goods[i].Id != goodid { | ||
| 188 | - continue | ||
| 189 | - } | ||
| 190 | - // thisGood := order.Goods[i] | 185 | +// func (order *OrderBase) ModifyGoodNumber(goodid int64, number int64) { |
| 186 | +// for i := range order.Goods { | ||
| 187 | +// if order.Goods[i].Id != goodid { | ||
| 188 | +// continue | ||
| 189 | +// } | ||
| 190 | +// // thisGood := order.Goods[i] | ||
| 191 | 191 | ||
| 192 | - } | ||
| 193 | - order.Compute() | ||
| 194 | -} | 192 | +// } |
| 193 | +// order.Compute() | ||
| 194 | +// } | ||
| 195 | 195 | ||
| 196 | //Compute 数据汇总核算 | 196 | //Compute 数据汇总核算 |
| 197 | func (order *OrderBase) Compute() error { | 197 | func (order *OrderBase) Compute() error { |
| @@ -6,6 +6,8 @@ type PartnerCategory struct { | @@ -6,6 +6,8 @@ type PartnerCategory struct { | ||
| 6 | Id int64 `json:"id"` | 6 | Id int64 `json:"id"` |
| 7 | // 名称 | 7 | // 名称 |
| 8 | Name string `json:"name,omitempty"` | 8 | Name string `json:"name,omitempty"` |
| 9 | + // 合伙人编码 | ||
| 10 | + Code string `json:"code"` | ||
| 9 | } | 11 | } |
| 10 | 12 | ||
| 11 | type PartnerCategoryFindQuery struct { | 13 | type PartnerCategoryFindQuery struct { |
| @@ -48,6 +48,8 @@ type PartnerInfo struct { | @@ -48,6 +48,8 @@ type PartnerInfo struct { | ||
| 48 | PartnerCategory int `json:"partnerCategory"` | 48 | PartnerCategory int `json:"partnerCategory"` |
| 49 | //公司id | 49 | //公司id |
| 50 | CompanyId int64 `json:"companyId"` | 50 | CompanyId int64 `json:"companyId"` |
| 51 | + //备注 | ||
| 52 | + Remark string `json:"remark"` | ||
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | func (p *PartnerInfo) IsUsable() bool { | 55 | func (p *PartnerInfo) IsUsable() bool { |
| @@ -72,11 +74,13 @@ type PartnerFindQuery struct { | @@ -72,11 +74,13 @@ type PartnerFindQuery struct { | ||
| 72 | PartnerName string //合伙人姓名 | 74 | PartnerName string //合伙人姓名 |
| 73 | CompanyId int64 | 75 | CompanyId int64 |
| 74 | Ids []int64 | 76 | Ids []int64 |
| 77 | + PartnerType []*PartnerCategory | ||
| 75 | } | 78 | } |
| 76 | 79 | ||
| 77 | type PartnerInfoRepository interface { | 80 | type PartnerInfoRepository interface { |
| 78 | Save(dm *PartnerInfo) error | 81 | Save(dm *PartnerInfo) error |
| 79 | FindOne(queryOptions PartnerFindOneQuery) (*PartnerInfo, error) | 82 | FindOne(queryOptions PartnerFindOneQuery) (*PartnerInfo, error) |
| 80 | Find(queryOptions PartnerFindQuery) ([]PartnerInfo, error) | 83 | Find(queryOptions PartnerFindQuery) ([]PartnerInfo, error) |
| 84 | + Remove(Id int64) error | ||
| 81 | CountAll(queryOptions PartnerFindQuery) (int, error) | 85 | CountAll(queryOptions PartnerFindQuery) (int, error) |
| 82 | } | 86 | } |
| @@ -2,7 +2,7 @@ package dao | @@ -2,7 +2,7 @@ package dao | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | - | 5 | + "github.com/go-pg/pg/v10" |
| 6 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" |
| 7 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" |
| 8 | ) | 8 | ) |
| @@ -28,7 +28,6 @@ func (dao PartnerInfoDao) PartnerAccountExist(account string, companyId int64) ( | @@ -28,7 +28,6 @@ func (dao PartnerInfoDao) PartnerAccountExist(account string, companyId int64) ( | ||
| 28 | Where("account=?", account). | 28 | Where("account=?", account). |
| 29 | Where("company_id=?", companyId). | 29 | Where("company_id=?", companyId). |
| 30 | Exists() | 30 | Exists() |
| 31 | - | ||
| 32 | return ok, err | 31 | return ok, err |
| 33 | } | 32 | } |
| 34 | 33 | ||
| @@ -42,3 +41,21 @@ func (dao PartnerInfoDao) UpdatePartnerStatus(ids []int64, companyId int64, stat | @@ -42,3 +41,21 @@ func (dao PartnerInfoDao) UpdatePartnerStatus(ids []int64, companyId int64, stat | ||
| 42 | Update() | 41 | Update() |
| 43 | return err | 42 | return err |
| 44 | } | 43 | } |
| 44 | + | ||
| 45 | +/** | ||
| 46 | + * @Author SteveChan | ||
| 47 | + * @Description // 编号查重 | ||
| 48 | + * @Date 17:55 2020/12/28 | ||
| 49 | + * @Param | ||
| 50 | + * @return | ||
| 51 | + **/ | ||
| 52 | +func (dao PartnerInfoDao) PartnerCodeExist(categoryId int64, code string, companyId int64, id int64) (bool, error) { | ||
| 53 | + tx := dao.transactionContext.PgDd | ||
| 54 | + m := &models.PartnerInfo{} | ||
| 55 | + ok, err := tx.Model(m). | ||
| 56 | + Where(`partner_category_infos@> '[{"id":?,"code":?}]'`, categoryId, pg.Ident(code)). | ||
| 57 | + Where("company_id=?", companyId). | ||
| 58 | + Where("id <> ?", id). | ||
| 59 | + Exists() | ||
| 60 | + return ok, err | ||
| 61 | +} |
| @@ -36,6 +36,8 @@ type PartnerInfo struct { | @@ -36,6 +36,8 @@ type PartnerInfo struct { | ||
| 36 | PartnerCategoryInfos []domain.PartnerCategory | 36 | PartnerCategoryInfos []domain.PartnerCategory |
| 37 | //公司id | 37 | //公司id |
| 38 | CompanyId int64 | 38 | CompanyId int64 |
| 39 | + //备注 | ||
| 40 | + Remark string | ||
| 39 | } | 41 | } |
| 40 | 42 | ||
| 41 | var _ pg.BeforeUpdateHook = (*PartnerInfo)(nil) | 43 | var _ pg.BeforeUpdateHook = (*PartnerInfo)(nil) |
| @@ -43,6 +43,7 @@ func (respository OrderBestshopRepository) transformPgModelToDomainModel(orderMo | @@ -43,6 +43,7 @@ func (respository OrderBestshopRepository) transformPgModelToDomainModel(orderMo | ||
| 43 | PartnerId: orderModel.PartnerId, | 43 | PartnerId: orderModel.PartnerId, |
| 44 | IsCopy: orderModel.IsCopy, | 44 | IsCopy: orderModel.IsCopy, |
| 45 | CompanyId: orderModel.CompanyId, | 45 | CompanyId: orderModel.CompanyId, |
| 46 | + OrderArea: orderModel.OrderArea, | ||
| 46 | }, nil | 47 | }, nil |
| 47 | } | 48 | } |
| 48 | 49 | ||
| @@ -65,6 +66,7 @@ func (respository OrderBestshopRepository) Add(order *domain.OrderBestShop) erro | @@ -65,6 +66,7 @@ func (respository OrderBestshopRepository) Add(order *domain.OrderBestShop) erro | ||
| 65 | PartnerId: order.PartnerId, | 66 | PartnerId: order.PartnerId, |
| 66 | IsCopy: order.IsCopy, | 67 | IsCopy: order.IsCopy, |
| 67 | CompanyId: order.CompanyId, | 68 | CompanyId: order.CompanyId, |
| 69 | + OrderArea: order.OrderArea, | ||
| 68 | } | 70 | } |
| 69 | _, err := tx.Model(&m).Insert() | 71 | _, err := tx.Model(&m).Insert() |
| 70 | order.Id = m.Id | 72 | order.Id = m.Id |
| @@ -91,6 +93,7 @@ func (respository OrderBestshopRepository) Edit(order *domain.OrderBestShop) err | @@ -91,6 +93,7 @@ func (respository OrderBestshopRepository) Edit(order *domain.OrderBestShop) err | ||
| 91 | PartnerId: order.PartnerId, | 93 | PartnerId: order.PartnerId, |
| 92 | IsCopy: order.IsCopy, | 94 | IsCopy: order.IsCopy, |
| 93 | CompanyId: order.CompanyId, | 95 | CompanyId: order.CompanyId, |
| 96 | + OrderArea: order.OrderArea, | ||
| 94 | } | 97 | } |
| 95 | _, err := tx.Model(&m).Where("id=?", order.Id).Update() | 98 | _, err := tx.Model(&m).Where("id=?", order.Id).Update() |
| 96 | order.Id = m.Id | 99 | order.Id = m.Id |
| @@ -12,21 +12,6 @@ type PartnerCategoryRepository struct { | @@ -12,21 +12,6 @@ type PartnerCategoryRepository struct { | ||
| 12 | transactionContext *transaction.TransactionContext | 12 | transactionContext *transaction.TransactionContext |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | -func (repository PartnerCategoryRepository) transformPgModelToDomainModel(m *models.PartnerCategoryInfo) (domain.PartnerCategory, error) { | ||
| 16 | - pc := domain.PartnerCategory{ | ||
| 17 | - Id: m.Id, | ||
| 18 | - Name: m.Name, | ||
| 19 | - } | ||
| 20 | - return pc, nil | ||
| 21 | -} | ||
| 22 | - | ||
| 23 | -func NewPartnerCategoryRepository(transactionContext *transaction.TransactionContext) (*PartnerCategoryRepository, error) { | ||
| 24 | - if transactionContext == nil { | ||
| 25 | - return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 26 | - } | ||
| 27 | - return &PartnerCategoryRepository{transactionContext: transactionContext}, nil | ||
| 28 | -} | ||
| 29 | - | ||
| 30 | func (repository PartnerCategoryRepository) Find(queryOptions domain.PartnerCategoryFindQuery) (int, []domain.PartnerCategory, error) { | 15 | func (repository PartnerCategoryRepository) Find(queryOptions domain.PartnerCategoryFindQuery) (int, []domain.PartnerCategory, error) { |
| 31 | tx := repository.transactionContext.PgTx | 16 | tx := repository.transactionContext.PgTx |
| 32 | var ( | 17 | var ( |
| @@ -48,3 +33,19 @@ func (repository PartnerCategoryRepository) Find(queryOptions domain.PartnerCate | @@ -48,3 +33,19 @@ func (repository PartnerCategoryRepository) Find(queryOptions domain.PartnerCate | ||
| 48 | } | 33 | } |
| 49 | return cnt, partnerCategoryInfos, nil | 34 | return cnt, partnerCategoryInfos, nil |
| 50 | } | 35 | } |
| 36 | + | ||
| 37 | +func (repository PartnerCategoryRepository) transformPgModelToDomainModel(m *models.PartnerCategoryInfo) (domain.PartnerCategory, error) { | ||
| 38 | + pc := domain.PartnerCategory{ | ||
| 39 | + Id: m.Id, | ||
| 40 | + Name: m.Name, | ||
| 41 | + Code: m.Code, | ||
| 42 | + } | ||
| 43 | + return pc, nil | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +func NewPartnerCategoryRepository(transactionContext *transaction.TransactionContext) (*PartnerCategoryRepository, error) { | ||
| 47 | + if transactionContext == nil { | ||
| 48 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 49 | + } | ||
| 50 | + return &PartnerCategoryRepository{transactionContext: transactionContext}, nil | ||
| 51 | +} |
| @@ -18,50 +18,18 @@ var ( | @@ -18,50 +18,18 @@ var ( | ||
| 18 | _ domain.PartnerInfoRepository = (*PartnerInfoRepository)(nil) | 18 | _ domain.PartnerInfoRepository = (*PartnerInfoRepository)(nil) |
| 19 | ) | 19 | ) |
| 20 | 20 | ||
| 21 | -func (repository *PartnerInfoRepository) transformPgModelToDomainModel(partnerInfoModel *models.PartnerInfo) (domain.PartnerInfo, error) { | ||
| 22 | - m := domain.PartnerInfo{ | ||
| 23 | - Partner: domain.Partner{ | ||
| 24 | - Id: partnerInfoModel.Id, | ||
| 25 | - PartnerName: partnerInfoModel.PartnerName, | ||
| 26 | - Account: partnerInfoModel.Account, | ||
| 27 | - }, | ||
| 28 | - PartnerCategory: partnerInfoModel.PartnerCategory, | ||
| 29 | - Password: partnerInfoModel.Password, | ||
| 30 | - Status: partnerInfoModel.Status, | ||
| 31 | - CreateAt: partnerInfoModel.CreateAt, | ||
| 32 | - Salesman: partnerInfoModel.Salesman, | ||
| 33 | - RegionInfo: partnerInfoModel.RegionInfo, | ||
| 34 | - CooperateTime: partnerInfoModel.CooperateTime, | ||
| 35 | - CompanyId: partnerInfoModel.CompanyId, | ||
| 36 | - } | ||
| 37 | - p := []domain.PartnerCategory{} | ||
| 38 | - for _, v := range partnerInfoModel.PartnerCategoryInfos { | ||
| 39 | - catagory := domain.PartnerCategory{ | ||
| 40 | - Id: v.Id, | ||
| 41 | - } | ||
| 42 | - p = append(p, catagory) | ||
| 43 | - } | ||
| 44 | - m.PartnerCategoryInfos = p | ||
| 45 | - return m, nil | ||
| 46 | -} | ||
| 47 | - | ||
| 48 | -func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext) (*PartnerInfoRepository, error) { | ||
| 49 | - if transactionContext == nil { | ||
| 50 | - return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 51 | - } | ||
| 52 | - return &PartnerInfoRepository{transactionContext: transactionContext}, nil | ||
| 53 | -} | ||
| 54 | - | ||
| 55 | func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error { | 21 | func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error { |
| 56 | var ( | 22 | var ( |
| 57 | err error | 23 | err error |
| 58 | tx = repository.transactionContext.PgTx | 24 | tx = repository.transactionContext.PgTx |
| 59 | ) | 25 | ) |
| 60 | 26 | ||
| 61 | - categorys := []domain.PartnerCategory{} | 27 | + var categories []domain.PartnerCategory |
| 62 | for _, v := range dm.PartnerCategoryInfos { | 28 | for _, v := range dm.PartnerCategoryInfos { |
| 63 | - categorys = append(categorys, domain.PartnerCategory{ | 29 | + categories = append(categories, domain.PartnerCategory{ |
| 64 | Id: v.Id, | 30 | Id: v.Id, |
| 31 | + Name: v.Name, | ||
| 32 | + Code: v.Code, | ||
| 65 | }) | 33 | }) |
| 66 | } | 34 | } |
| 67 | m := &models.PartnerInfo{ | 35 | m := &models.PartnerInfo{ |
| @@ -75,7 +43,8 @@ func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error { | @@ -75,7 +43,8 @@ func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error { | ||
| 75 | RegionInfo: dm.RegionInfo, | 43 | RegionInfo: dm.RegionInfo, |
| 76 | CooperateTime: dm.CooperateTime, | 44 | CooperateTime: dm.CooperateTime, |
| 77 | CompanyId: dm.CompanyId, | 45 | CompanyId: dm.CompanyId, |
| 78 | - PartnerCategoryInfos: categorys, | 46 | + PartnerCategoryInfos: categories, |
| 47 | + Remark: dm.Remark, | ||
| 79 | } | 48 | } |
| 80 | if m.Id == 0 { | 49 | if m.Id == 0 { |
| 81 | err = tx.Insert(m) | 50 | err = tx.Insert(m) |
| @@ -86,7 +55,7 @@ func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error { | @@ -86,7 +55,7 @@ func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error { | ||
| 86 | } else { | 55 | } else { |
| 87 | _, err = tx.Model(m).WherePK(). | 56 | _, err = tx.Model(m).WherePK(). |
| 88 | Column("partner_name", "account", "password", "status", "partner_category", "salesman", | 57 | Column("partner_name", "account", "password", "status", "partner_category", "salesman", |
| 89 | - "region_info", "cooperate_time", "update_at", "partner_category_infos"). | 58 | + "region_info", "cooperate_time", "update_at", "partner_category_infos", "remark"). |
| 90 | Update() | 59 | Update() |
| 91 | if err != nil { | 60 | if err != nil { |
| 92 | return err | 61 | return err |
| @@ -124,7 +93,7 @@ func (repository *PartnerInfoRepository) FindOne(queryOptions domain.PartnerFind | @@ -124,7 +93,7 @@ func (repository *PartnerInfoRepository) FindOne(queryOptions domain.PartnerFind | ||
| 124 | 93 | ||
| 125 | func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuery) ([]domain.PartnerInfo, error) { | 94 | func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuery) ([]domain.PartnerInfo, error) { |
| 126 | db := repository.transactionContext.PgTx | 95 | db := repository.transactionContext.PgTx |
| 127 | - partnerModels := []models.PartnerInfo{} | 96 | + var partnerModels []models.PartnerInfo |
| 128 | query := db.Model(&partnerModels) | 97 | query := db.Model(&partnerModels) |
| 129 | if len(queryOption.PartnerName) > 0 { | 98 | if len(queryOption.PartnerName) > 0 { |
| 130 | query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%") | 99 | query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%") |
| @@ -174,7 +143,28 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer | @@ -174,7 +143,28 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer | ||
| 174 | return partnerReturn, nil | 143 | return partnerReturn, nil |
| 175 | } | 144 | } |
| 176 | 145 | ||
| 177 | -func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQuery) (int, error) { | 146 | +/** |
| 147 | + * @Author SteveChan | ||
| 148 | + * @Description //TODO 移除合伙人 | ||
| 149 | + * @Date 15:33 2020/12/29 | ||
| 150 | + * @Param | ||
| 151 | + * @return | ||
| 152 | + **/ | ||
| 153 | +func (repository *PartnerInfoRepository) Remove(id int64) error { | ||
| 154 | + var ( | ||
| 155 | + err error | ||
| 156 | + tx = repository.transactionContext.PgTx | ||
| 157 | + ) | ||
| 158 | + m := &models.PartnerInfo{ | ||
| 159 | + Id: id, | ||
| 160 | + } | ||
| 161 | + _, err = tx.Model(m). | ||
| 162 | + Where("id=?", id). | ||
| 163 | + Delete() | ||
| 164 | + return err | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +func (repository *PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQuery) (int, error) { | ||
| 178 | db := repository.transactionContext.PgTx | 168 | db := repository.transactionContext.PgTx |
| 179 | partnerModels := models.PartnerInfo{} | 169 | partnerModels := models.PartnerInfo{} |
| 180 | query := db.Model(&partnerModels) | 170 | query := db.Model(&partnerModels) |
| @@ -202,3 +192,40 @@ func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQ | @@ -202,3 +192,40 @@ func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQ | ||
| 202 | cnt, err := query.Count() | 192 | cnt, err := query.Count() |
| 203 | return cnt, err | 193 | return cnt, err |
| 204 | } | 194 | } |
| 195 | + | ||
| 196 | +func (repository *PartnerInfoRepository) transformPgModelToDomainModel(partnerInfoModel *models.PartnerInfo) (domain.PartnerInfo, error) { | ||
| 197 | + m := domain.PartnerInfo{ | ||
| 198 | + Partner: domain.Partner{ | ||
| 199 | + Id: partnerInfoModel.Id, | ||
| 200 | + PartnerName: partnerInfoModel.PartnerName, | ||
| 201 | + Account: partnerInfoModel.Account, | ||
| 202 | + }, | ||
| 203 | + PartnerCategory: partnerInfoModel.PartnerCategory, | ||
| 204 | + Password: partnerInfoModel.Password, | ||
| 205 | + Status: partnerInfoModel.Status, | ||
| 206 | + CreateAt: partnerInfoModel.CreateAt, | ||
| 207 | + Salesman: partnerInfoModel.Salesman, | ||
| 208 | + RegionInfo: partnerInfoModel.RegionInfo, | ||
| 209 | + CooperateTime: partnerInfoModel.CooperateTime, | ||
| 210 | + CompanyId: partnerInfoModel.CompanyId, | ||
| 211 | + Remark: partnerInfoModel.Remark, | ||
| 212 | + } | ||
| 213 | + var p []domain.PartnerCategory | ||
| 214 | + for _, v := range partnerInfoModel.PartnerCategoryInfos { | ||
| 215 | + category := domain.PartnerCategory{ | ||
| 216 | + Id: v.Id, | ||
| 217 | + Name: v.Name, | ||
| 218 | + Code: v.Code, | ||
| 219 | + } | ||
| 220 | + p = append(p, category) | ||
| 221 | + } | ||
| 222 | + m.PartnerCategoryInfos = p | ||
| 223 | + return m, nil | ||
| 224 | +} | ||
| 225 | + | ||
| 226 | +func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext) (*PartnerInfoRepository, error) { | ||
| 227 | + if transactionContext == nil { | ||
| 228 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 229 | + } | ||
| 230 | + return &PartnerInfoRepository{transactionContext: transactionContext}, nil | ||
| 231 | +} |
| @@ -64,6 +64,7 @@ func (gateway MmmBusinessAdminServiceGateway) httpDo(reqURL string, mathod strin | @@ -64,6 +64,7 @@ func (gateway MmmBusinessAdminServiceGateway) httpDo(reqURL string, mathod strin | ||
| 64 | return body, nil | 64 | return body, nil |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | +// GetUserAuth 请求企业平台确认用户是否可以使用天联共创后台 | ||
| 67 | func (gateway MmmBusinessAdminServiceGateway) GetUserAuth(userId int64) (*ResponseGetUserAuth, error) { | 68 | func (gateway MmmBusinessAdminServiceGateway) GetUserAuth(userId int64) (*ResponseGetUserAuth, error) { |
| 68 | param := map[string]interface{}{ | 69 | param := map[string]interface{}{ |
| 69 | "userId": fmt.Sprint(userId), | 70 | "userId": fmt.Sprint(userId), |
| @@ -36,13 +36,14 @@ func (c *PartnerInfoController) CreatePartnerInfo() { | @@ -36,13 +36,14 @@ func (c *PartnerInfoController) CreatePartnerInfo() { | ||
| 36 | //用与适配前端定义的数据结构 | 36 | //用与适配前端定义的数据结构 |
| 37 | type Parameter struct { | 37 | type Parameter struct { |
| 38 | PartnerName string `json:"partnerName"` | 38 | PartnerName string `json:"partnerName"` |
| 39 | - PartnerType []int64 `json:"partnerType"` | 39 | + PartnerType []*domain.PartnerCategory `json:"partnerType"` |
| 40 | Area string `json:"area"` | 40 | Area string `json:"area"` |
| 41 | Account string `json:"account"` | 41 | Account string `json:"account"` |
| 42 | State int `json:"state"` | 42 | State int `json:"state"` |
| 43 | CooperationTime string `json:"cooperationTime"` | 43 | CooperationTime string `json:"cooperationTime"` |
| 44 | SalesmanName string `json:"salesmanName"` | 44 | SalesmanName string `json:"salesmanName"` |
| 45 | Phone string `json:"phone"` | 45 | Phone string `json:"phone"` |
| 46 | + Remark string `json:"remark"` | ||
| 46 | } | 47 | } |
| 47 | var ( | 48 | var ( |
| 48 | param Parameter | 49 | param Parameter |
| @@ -69,6 +70,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() { | @@ -69,6 +70,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() { | ||
| 69 | PartnerCategory: param.PartnerType, | 70 | PartnerCategory: param.PartnerType, |
| 70 | CooperateTime: cooperateTime, | 71 | CooperateTime: cooperateTime, |
| 71 | CompanyId: companyId, | 72 | CompanyId: companyId, |
| 73 | + Remark: param.Remark, | ||
| 72 | } | 74 | } |
| 73 | if len(param.SalesmanName) > 0 || len(param.Phone) > 0 { | 75 | if len(param.SalesmanName) > 0 || len(param.Phone) > 0 { |
| 74 | cmd.Salesman = []domain.Salesman{ | 76 | cmd.Salesman = []domain.Salesman{ |
| @@ -104,12 +106,13 @@ func (c *PartnerInfoController) UpdatePartnerInfo() { | @@ -104,12 +106,13 @@ func (c *PartnerInfoController) UpdatePartnerInfo() { | ||
| 104 | //用与适配前端定义的数据结构 | 106 | //用与适配前端定义的数据结构 |
| 105 | type Parameter struct { | 107 | type Parameter struct { |
| 106 | ID int64 `json:"id"` | 108 | ID int64 `json:"id"` |
| 107 | - PartnerType []int64 `json:"partnerType"` | 109 | + PartnerType []*domain.PartnerCategory `json:"partnerType"` |
| 108 | Area string `json:"area"` | 110 | Area string `json:"area"` |
| 109 | State int `json:"state"` | 111 | State int `json:"state"` |
| 110 | CooperationTime string `json:"cooperationTime"` | 112 | CooperationTime string `json:"cooperationTime"` |
| 111 | SalesmanName string `json:"salesmanName"` | 113 | SalesmanName string `json:"salesmanName"` |
| 112 | Phone string `json:"phone"` | 114 | Phone string `json:"phone"` |
| 115 | + Remark string `json:"remark"` | ||
| 113 | } | 116 | } |
| 114 | var ( | 117 | var ( |
| 115 | param Parameter | 118 | param Parameter |
| @@ -142,6 +145,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() { | @@ -142,6 +145,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() { | ||
| 142 | }, | 145 | }, |
| 143 | }, | 146 | }, |
| 144 | CompanyId: companyId, | 147 | CompanyId: companyId, |
| 148 | + Remark: param.Remark, | ||
| 145 | } | 149 | } |
| 146 | serve := partnerInfoService.NewPartnerInfoService(nil) | 150 | serve := partnerInfoService.NewPartnerInfoService(nil) |
| 147 | err = serve.UpdatePartnerInfo(&cmd) | 151 | err = serve.UpdatePartnerInfo(&cmd) |
| @@ -190,16 +194,18 @@ func (c *PartnerInfoController) GetPartnerInfo() { | @@ -190,16 +194,18 @@ func (c *PartnerInfoController) GetPartnerInfo() { | ||
| 190 | "cooperationTime": partnerInfo.CooperateTime.Local().Format("2006-01-02"), | 194 | "cooperationTime": partnerInfo.CooperateTime.Local().Format("2006-01-02"), |
| 191 | "state": partnerInfo.Status, | 195 | "state": partnerInfo.Status, |
| 192 | "id": partnerInfo.Partner.Id, | 196 | "id": partnerInfo.Partner.Id, |
| 197 | + "remark": partnerInfo.Remark, | ||
| 193 | } | 198 | } |
| 194 | if len(partnerInfo.Salesman) > 0 { | 199 | if len(partnerInfo.Salesman) > 0 { |
| 195 | rspResult["salesmanName"] = partnerInfo.Salesman[0].Name | 200 | rspResult["salesmanName"] = partnerInfo.Salesman[0].Name |
| 196 | rspResult["phone"] = partnerInfo.Salesman[0].Telephone | 201 | rspResult["phone"] = partnerInfo.Salesman[0].Telephone |
| 197 | } | 202 | } |
| 198 | - partnerTypes := []map[string]interface{}{} | 203 | + var partnerTypes []map[string]interface{} |
| 199 | for _, v := range partnerInfo.PartnerCategoryInfos { | 204 | for _, v := range partnerInfo.PartnerCategoryInfos { |
| 200 | m := map[string]interface{}{ | 205 | m := map[string]interface{}{ |
| 201 | "id": v.Id, | 206 | "id": v.Id, |
| 202 | "name": v.Name, | 207 | "name": v.Name, |
| 208 | + "code": v.Code, | ||
| 203 | } | 209 | } |
| 204 | partnerTypes = append(partnerTypes, m) | 210 | partnerTypes = append(partnerTypes, m) |
| 205 | } | 211 | } |
| @@ -208,6 +214,40 @@ func (c *PartnerInfoController) GetPartnerInfo() { | @@ -208,6 +214,40 @@ func (c *PartnerInfoController) GetPartnerInfo() { | ||
| 208 | return | 214 | return |
| 209 | } | 215 | } |
| 210 | 216 | ||
| 217 | +/** | ||
| 218 | + * @Author SteveChan | ||
| 219 | + * @Description //TODO 移除合伙人 | ||
| 220 | + * @Date 15:31 2020/12/29 | ||
| 221 | + * @Param | ||
| 222 | + * @return | ||
| 223 | + **/ | ||
| 224 | +func (c *PartnerInfoController) RemovePartnerInfo() { | ||
| 225 | + //用与适配前端定义的数据结构 | ||
| 226 | + type Parameter struct { | ||
| 227 | + ID int64 `json:"id"` | ||
| 228 | + } | ||
| 229 | + var ( | ||
| 230 | + param Parameter | ||
| 231 | + err error | ||
| 232 | + ) | ||
| 233 | + if err = c.BindJsonData(¶m); err != nil { | ||
| 234 | + logs.Error(err) | ||
| 235 | + c.ResponseError(errors.New("json数据解析失败")) | ||
| 236 | + return | ||
| 237 | + } | ||
| 238 | + cmd := partnerInfoCmd.RemovePartnerInfoCommand{ | ||
| 239 | + Id: param.ID, | ||
| 240 | + } | ||
| 241 | + serve := partnerInfoService.NewPartnerInfoService(nil) | ||
| 242 | + err = serve.RemovePartnerInfo(cmd) | ||
| 243 | + if err != nil { | ||
| 244 | + c.ResponseError(err) | ||
| 245 | + return | ||
| 246 | + } | ||
| 247 | + c.ResponseData(nil) | ||
| 248 | + return | ||
| 249 | +} | ||
| 250 | + | ||
| 211 | //PartnerInfoSetState 合伙人批量禁用.启用 | 251 | //PartnerInfoSetState 合伙人批量禁用.启用 |
| 212 | func (c *PartnerInfoController) PartnerInfoSetState() { | 252 | func (c *PartnerInfoController) PartnerInfoSetState() { |
| 213 | //用与适配前端定义的数据结构 | 253 | //用与适配前端定义的数据结构 |
| @@ -224,19 +264,19 @@ func (c *PartnerInfoController) PartnerInfoSetState() { | @@ -224,19 +264,19 @@ func (c *PartnerInfoController) PartnerInfoSetState() { | ||
| 224 | c.ResponseError(errors.New("json数据解析失败")) | 264 | c.ResponseError(errors.New("json数据解析失败")) |
| 225 | return | 265 | return |
| 226 | } | 266 | } |
| 227 | - comanyId := c.GetUserCompany() | 267 | + companyId := c.GetUserCompany() |
| 228 | var cmd partnerInfoCmd.StatusPartnerInfoCommand | 268 | var cmd partnerInfoCmd.StatusPartnerInfoCommand |
| 229 | switch param.Status { | 269 | switch param.Status { |
| 230 | case 0: | 270 | case 0: |
| 231 | cmd = partnerInfoCmd.StatusPartnerInfoCommand{ | 271 | cmd = partnerInfoCmd.StatusPartnerInfoCommand{ |
| 232 | Ids: param.Id, | 272 | Ids: param.Id, |
| 233 | - CompanyId: comanyId, | 273 | + CompanyId: companyId, |
| 234 | Status: domain.PARTNER_STATUS_NO, | 274 | Status: domain.PARTNER_STATUS_NO, |
| 235 | } | 275 | } |
| 236 | case 1: | 276 | case 1: |
| 237 | cmd = partnerInfoCmd.StatusPartnerInfoCommand{ | 277 | cmd = partnerInfoCmd.StatusPartnerInfoCommand{ |
| 238 | Ids: param.Id, | 278 | Ids: param.Id, |
| 239 | - CompanyId: comanyId, | 279 | + CompanyId: companyId, |
| 240 | Status: domain.PARTNER_STATUS_YES, | 280 | Status: domain.PARTNER_STATUS_YES, |
| 241 | } | 281 | } |
| 242 | default: | 282 | default: |
| @@ -256,7 +296,7 @@ func (c *PartnerInfoController) PartnerInfoSetState() { | @@ -256,7 +296,7 @@ func (c *PartnerInfoController) PartnerInfoSetState() { | ||
| 256 | //ListPartnerInfo 合伙人列表 | 296 | //ListPartnerInfo 合伙人列表 |
| 257 | func (c *PartnerInfoController) ListPartnerInfo() { | 297 | func (c *PartnerInfoController) ListPartnerInfo() { |
| 258 | type Parameter struct { | 298 | type Parameter struct { |
| 259 | - Partnertype int `json:"partnerType"` | 299 | + PartnerType int `json:"partnerType"` |
| 260 | Area string `json:"area"` | 300 | Area string `json:"area"` |
| 261 | PartnerName string `json:"partnerName"` | 301 | PartnerName string `json:"partnerName"` |
| 262 | PageSize int `json:"pageSize"` | 302 | PageSize int `json:"pageSize"` |
| @@ -280,7 +320,7 @@ func (c *PartnerInfoController) ListPartnerInfo() { | @@ -280,7 +320,7 @@ func (c *PartnerInfoController) ListPartnerInfo() { | ||
| 280 | } | 320 | } |
| 281 | companyId := c.GetUserCompany() | 321 | companyId := c.GetUserCompany() |
| 282 | query := partnerQuery.ListPartnerInfoQuery{ | 322 | query := partnerQuery.ListPartnerInfoQuery{ |
| 283 | - Partnertype: param.Partnertype, | 323 | + PartnerType: param.PartnerType, |
| 284 | PartnerName: param.PartnerName, | 324 | PartnerName: param.PartnerName, |
| 285 | RegionInfo: param.Area, | 325 | RegionInfo: param.Area, |
| 286 | Limit: param.PageSize, | 326 | Limit: param.PageSize, |
| @@ -294,7 +334,7 @@ func (c *PartnerInfoController) ListPartnerInfo() { | @@ -294,7 +334,7 @@ func (c *PartnerInfoController) ListPartnerInfo() { | ||
| 294 | c.ResponseError(err) | 334 | c.ResponseError(err) |
| 295 | return | 335 | return |
| 296 | } | 336 | } |
| 297 | - resp := []map[string]interface{}{} | 337 | + var resp []map[string]interface{} |
| 298 | indexBegin := query.Offset | 338 | indexBegin := query.Offset |
| 299 | for i := range partners { | 339 | for i := range partners { |
| 300 | m := map[string]interface{}{ | 340 | m := map[string]interface{}{ |
| @@ -309,6 +349,7 @@ func (c *PartnerInfoController) ListPartnerInfo() { | @@ -309,6 +349,7 @@ func (c *PartnerInfoController) ListPartnerInfo() { | ||
| 309 | "partnerType": partners[i].PartnerCategoryInfos, | 349 | "partnerType": partners[i].PartnerCategoryInfos, |
| 310 | "salesmanName": "", | 350 | "salesmanName": "", |
| 311 | "phone": "", | 351 | "phone": "", |
| 352 | + "remark": partners[i].Remark, | ||
| 312 | } | 353 | } |
| 313 | if len(partners[i].Salesman) > 0 { | 354 | if len(partners[i].Salesman) > 0 { |
| 314 | m["salesmanName"] = partners[i].Salesman[0].Name | 355 | m["salesmanName"] = partners[i].Salesman[0].Name |
| @@ -32,7 +32,7 @@ func (c *UserController) ListUser() { | @@ -32,7 +32,7 @@ func (c *UserController) ListUser() { | ||
| 32 | //用与适配前端定义的数据结构 | 32 | //用与适配前端定义的数据结构 |
| 33 | type Paramter struct { | 33 | type Paramter struct { |
| 34 | SearchText string `json:"searchText"` | 34 | SearchText string `json:"searchText"` |
| 35 | - PageSize int `json::"pageSize"` | 35 | + PageSize int `json:"pageSize"` |
| 36 | PageNumber int `json:"pageNumber"` | 36 | PageNumber int `json:"pageNumber"` |
| 37 | } | 37 | } |
| 38 | var ( | 38 | var ( |
| @@ -23,6 +23,7 @@ func init() { | @@ -23,6 +23,7 @@ func init() { | ||
| 23 | beego.NSRouter("/edit", &controllers.PartnerInfoController{}, "POST:UpdatePartnerInfo"), | 23 | beego.NSRouter("/edit", &controllers.PartnerInfoController{}, "POST:UpdatePartnerInfo"), |
| 24 | beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"), | 24 | beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"), |
| 25 | beego.NSRouter("/batchDisabled", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"), | 25 | beego.NSRouter("/batchDisabled", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"), |
| 26 | + beego.NSRouter("/remove", &controllers.PartnerInfoController{}, "POST:RemovePartnerInfo"), | ||
| 26 | ), | 27 | ), |
| 27 | beego.NSNamespace("/dividends", | 28 | beego.NSNamespace("/dividends", |
| 28 | beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"), | 29 | beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"), |
| @@ -8,7 +8,9 @@ import ( | @@ -8,7 +8,9 @@ import ( | ||
| 8 | //外部调用,企业平台,总后台调用 | 8 | //外部调用,企业平台,总后台调用 |
| 9 | func init() { | 9 | func init() { |
| 10 | nsPlatform := beego.NewNamespace("/platform", | 10 | nsPlatform := beego.NewNamespace("/platform", |
| 11 | + //同步企业相关数据 | ||
| 11 | beego.NSRouter("/action", &controllers.SyncDataController{}, "post:SyncData"), | 12 | beego.NSRouter("/action", &controllers.SyncDataController{}, "post:SyncData"), |
| 13 | + //更换公司管理员 | ||
| 12 | beego.NSRouter("/admins_change", &controllers.SyncDataController{}, "post:CompanyAdminChance"), | 14 | beego.NSRouter("/admins_change", &controllers.SyncDataController{}, "post:CompanyAdminChance"), |
| 13 | ) | 15 | ) |
| 14 | nsUcenter := beego.NewNamespace("/ucenter", | 16 | nsUcenter := beego.NewNamespace("/ucenter", |
| @@ -51,6 +51,7 @@ func (c *MessageConsumer) ConsumeClaim(groupSession sarama.ConsumerGroupSession, | @@ -51,6 +51,7 @@ func (c *MessageConsumer) ConsumeClaim(groupSession sarama.ConsumerGroupSession, | ||
| 51 | } | 51 | } |
| 52 | if err = topicHandle(message); err != nil { | 52 | if err = topicHandle(message); err != nil { |
| 53 | logs.Error("Message claimed: kafka消息处理错误 topic =", message.Topic, message.Offset, err) | 53 | logs.Error("Message claimed: kafka消息处理错误 topic =", message.Topic, message.Offset, err) |
| 54 | + | ||
| 54 | } | 55 | } |
| 55 | groupSession.MarkMessage(message, "") | 56 | groupSession.MarkMessage(message, "") |
| 56 | } | 57 | } |
| @@ -30,6 +30,9 @@ func init() { | @@ -30,6 +30,9 @@ func init() { | ||
| 30 | if runEnv == "partnermg_prd" { | 30 | if runEnv == "partnermg_prd" { |
| 31 | initHandleRoutersProd() | 31 | initHandleRoutersProd() |
| 32 | } | 32 | } |
| 33 | + if runEnv == "partnermg_dev" { | ||
| 34 | + initHandleRoutersDev() | ||
| 35 | + } | ||
| 33 | } | 36 | } |
| 34 | 37 | ||
| 35 | func initHandleRoutersTest() { | 38 | func initHandleRoutersTest() { |
| @@ -39,3 +42,7 @@ func initHandleRoutersTest() { | @@ -39,3 +42,7 @@ func initHandleRoutersTest() { | ||
| 39 | func initHandleRoutersProd() { | 42 | func initHandleRoutersProd() { |
| 40 | TopicHandleRouters["xiangmi_project"] = handles.DataFromXiangMi | 43 | TopicHandleRouters["xiangmi_project"] = handles.DataFromXiangMi |
| 41 | } | 44 | } |
| 45 | + | ||
| 46 | +func initHandleRoutersDev() { | ||
| 47 | + TopicHandleRouters["xiangmi_project_dev"] = handles.DataFromXiangMi | ||
| 48 | +} |
| 1 | -package geetest | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "crypto/md5" | ||
| 5 | - "encoding/hex" | ||
| 6 | - "encoding/json" | ||
| 7 | - "errors" | ||
| 8 | - "io/ioutil" | ||
| 9 | - "net/http" | ||
| 10 | - "net/url" | ||
| 11 | - "strings" | ||
| 12 | - "time" | ||
| 13 | -) | ||
| 14 | - | ||
| 15 | -type GeetestLib struct { | ||
| 16 | - CaptchaID string | ||
| 17 | - PrivateKey string | ||
| 18 | - Client *http.Client | ||
| 19 | -} | ||
| 20 | - | ||
| 21 | -type FailbackRegisterRespnse struct { | ||
| 22 | - Success int `json:"success"` | ||
| 23 | - GT string `json:"gt"` | ||
| 24 | - Challenge string `json:"challenge"` | ||
| 25 | - NewCaptcha int `json:"new_captcha"` | ||
| 26 | -} | ||
| 27 | - | ||
| 28 | -const ( | ||
| 29 | - geetestHost = "http://api.geetest.com" | ||
| 30 | - registerURL = geetestHost + "/register.php" | ||
| 31 | - validateURL = geetestHost + "/validate.php" | ||
| 32 | -) | ||
| 33 | - | ||
| 34 | -func MD5Encode(input string) string { | ||
| 35 | - md5Instant := md5.New() | ||
| 36 | - md5Instant.Write([]byte(input)) | ||
| 37 | - return hex.EncodeToString(md5Instant.Sum(nil)) | ||
| 38 | -} | ||
| 39 | - | ||
| 40 | -// 初始化 GeetestLib | ||
| 41 | -func NewGeetestLib(capthcaID string, privateKey string, timeOut time.Duration) (geetest GeetestLib){ | ||
| 42 | - client := &http.Client{Timeout: timeOut} | ||
| 43 | - geetest = GeetestLib{capthcaID, privateKey, client} | ||
| 44 | - return | ||
| 45 | -} | ||
| 46 | - | ||
| 47 | -func (g *GeetestLib) getFailBackRegisterResponse(success int, challenge string) []byte { | ||
| 48 | - if challenge == "" { | ||
| 49 | - challenge = hex.EncodeToString(md5.New().Sum(nil)) | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - response := FailbackRegisterRespnse{ | ||
| 53 | - success, | ||
| 54 | - g.CaptchaID, | ||
| 55 | - challenge, | ||
| 56 | - 1, | ||
| 57 | - } | ||
| 58 | - res, _ := json.Marshal(response) | ||
| 59 | - return res | ||
| 60 | -} | ||
| 61 | - | ||
| 62 | -func (g *GeetestLib) do(req *http.Request) (body []byte, err error) { | ||
| 63 | - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") | ||
| 64 | - var resp *http.Response | ||
| 65 | - if resp, err = g.Client.Do(req); err != nil { | ||
| 66 | - return | ||
| 67 | - } | ||
| 68 | - defer resp.Body.Close() | ||
| 69 | - if resp.StatusCode >= http.StatusInternalServerError { | ||
| 70 | - err = errors.New("http status code 5xx") | ||
| 71 | - return | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - if body, err = ioutil.ReadAll(resp.Body); err != nil { | ||
| 75 | - return | ||
| 76 | - } | ||
| 77 | - return | ||
| 78 | -} | ||
| 79 | - | ||
| 80 | -func (g *GeetestLib) PreProcess(userID string, userIP string) (int8, []byte) { | ||
| 81 | - params := url.Values{} | ||
| 82 | - params.Add("gt", g.CaptchaID) | ||
| 83 | - params.Add("new_captcha", "1") | ||
| 84 | - if userID != "" { | ||
| 85 | - params.Add("user_id", userID) | ||
| 86 | - } | ||
| 87 | - if userIP != "" { | ||
| 88 | - params.Add("ip_adress", userIP) | ||
| 89 | - } | ||
| 90 | - req, _ := http.NewRequest("GET", registerURL+"?"+params.Encode(), nil) | ||
| 91 | - body, err := g.do(req) | ||
| 92 | - if err != nil { | ||
| 93 | - return 0, g.getFailBackRegisterResponse(0, "") | ||
| 94 | - } | ||
| 95 | - challenge := string(body) | ||
| 96 | - if len(challenge) != 32 { | ||
| 97 | - return 0, g.getFailBackRegisterResponse(0, "") | ||
| 98 | - } else { | ||
| 99 | - challenge = MD5Encode(challenge + g.PrivateKey) | ||
| 100 | - return 1, g.getFailBackRegisterResponse(1, challenge) | ||
| 101 | - } | ||
| 102 | -} | ||
| 103 | - | ||
| 104 | -func (g *GeetestLib) checkParas(challenge string, validate string, seccode string) bool { | ||
| 105 | - if challenge == "" || validate == "" || seccode == "" { | ||
| 106 | - return false | ||
| 107 | - } | ||
| 108 | - return true | ||
| 109 | -} | ||
| 110 | - | ||
| 111 | -func (g *GeetestLib) checkSuccessRes(challenge string, validate string) bool { | ||
| 112 | - return MD5Encode(g.PrivateKey+"geetest"+challenge) == validate | ||
| 113 | -} | ||
| 114 | - | ||
| 115 | -func (g *GeetestLib) checkFailbackRes(challenge string, validate string) bool { | ||
| 116 | - return MD5Encode(challenge) == validate | ||
| 117 | -} | ||
| 118 | - | ||
| 119 | -func (g *GeetestLib) SuccessValidate(challenge string, validate string, seccode string, userID string, userIP string) bool { | ||
| 120 | - if !g.checkParas(challenge, validate, seccode) { | ||
| 121 | - return false | ||
| 122 | - } | ||
| 123 | - if !g.checkSuccessRes(challenge, validate) { | ||
| 124 | - return false | ||
| 125 | - } | ||
| 126 | - params := url.Values{} | ||
| 127 | - params.Add("seccode", seccode) | ||
| 128 | - params.Add("challenge", challenge) | ||
| 129 | - params.Add("captchaid", g.CaptchaID) | ||
| 130 | - params.Add("sdk", "golang_v1.0.0") | ||
| 131 | - if userID != "" { | ||
| 132 | - params.Add("user_id", userID) | ||
| 133 | - } | ||
| 134 | - if userIP != "" { | ||
| 135 | - params.Add("ip_adress", userIP) | ||
| 136 | - } | ||
| 137 | - req, _ := http.NewRequest("POST", validateURL, strings.NewReader(params.Encode())) | ||
| 138 | - body, err := g.do(req) | ||
| 139 | - if err != nil { | ||
| 140 | - return false | ||
| 141 | - } | ||
| 142 | - res := string(body) | ||
| 143 | - return res == MD5Encode(seccode) | ||
| 144 | -} | ||
| 145 | - | ||
| 146 | -func (g *GeetestLib) FailbackValidate(challenge string, validate string, seccode string) bool { | ||
| 147 | - if !g.checkParas(challenge, validate, seccode) { | ||
| 148 | - return false | ||
| 149 | - } | ||
| 150 | - if !g.checkFailbackRes(challenge, validate) { | ||
| 151 | - return false | ||
| 152 | - } | ||
| 153 | - return true | ||
| 154 | -} |
| @@ -3,9 +3,6 @@ | @@ -3,9 +3,6 @@ | ||
| 3 | github.com/360EntSecGroup-Skylar/excelize/v2 | 3 | github.com/360EntSecGroup-Skylar/excelize/v2 |
| 4 | # github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798 | 4 | # github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798 |
| 5 | github.com/DataDog/zstd | 5 | github.com/DataDog/zstd |
| 6 | -# github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2 | ||
| 7 | -## explicit | ||
| 8 | -github.com/GeeTeam/gt3-golang-sdk/geetest | ||
| 9 | # github.com/Shopify/sarama v1.23.1 | 6 | # github.com/Shopify/sarama v1.23.1 |
| 10 | ## explicit | 7 | ## explicit |
| 11 | github.com/Shopify/sarama | 8 | github.com/Shopify/sarama |
-
请 注册 或 登录 后发表评论