作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !1
正在显示 41 个修改的文件 包含 498 行增加285 行删除
# 合伙人项目
vendor 文件夹如果不是迫不得已,请不要手动修改其中的文件!
如果手动修改vendor中的文件,需自行进行版本管理。(慎重考虑!慎重考虑!慎重考虑!)
\ No newline at end of file
# 服务端工作交接事项
## 合伙人管理后台项目
### 代码以及文档
- [代码地址](http://gitlab.fjmaimaimai.com/mmm-go/partnermg.git)
- [项目原型svn](svn://218.106.157.184/repo/项目文件/项目【合伙人】)
- [yapi-合伙人前端](http://47.97.5.102:36666/project/209/interface/api)
服务端地址
```
测试开发环境pg数据库地址:114.55.200.59:31543,开发库:partner_dev,测试库:partner_test
正式环境pg数据库地址:114.55.200.59:31544,正式库:partner
服务端开发环境地址:http://mmm-partnermg-dev.fjmaimaimai.com
服务端测试环境地址:http://mmm-partnermg-test.fjmaimaimai.com
服务端正式环境地址:https://public-interface.fjmaimaimai.com/mmm-partnermg
```
### 项目整体
- 项目使用框架
- http框架:beego
- orm框架:go-pg
- 数据存储:postgresql
- 项目结构分层:DDD领域驱动
- 项目结构
```
├─conf 项目配置文件
├─deploy 项目部署文件
├─pkg
│ ├─application
│ │ ├─adminPermission 用户权限菜单
│ │ ├─businessBonus (在0.5.0后已经移除)
│ │ ├─company 企业公司功能
│ │ ├─event 事件订阅以及处理
│ │ ├─factory 工厂类,实例具体的实现(数据仓储)
│ │ ├─orderinfo 合伙人订单以及分红数据
│ │ ├─partnerCategory 合伙人分类信息
│ │ ├─partnerInfo 合伙人信息
│ │ ├─syncOrder 同步其他系统的订单数据
│ │ ├─unifiedUserCenter 从企业平台接收企业和管理员用户数据
│ │ └─users 管理员用户信息
│ ├─constant 变量配置(数据库等)
│ ├─domain 领域模型(核心数据处理,接口定义)
│ │ ├─event 领域事件定义
│ │ └─service 领域服务定义
│ ├─infrastructure 基础设施
│ │ ├─dao 特殊的数据库操作
│ │ ├─domainService 实现领域服务
│ │ ├─pg postgresql 数据库模型定义
│ │ ├─repository 数据仓储具体实现(对应domain定义数据库的数据存储接口)
│ │ ├─serviceGateway 其他系统服务调用
│ │
│ ├─lib
│ ├─log
│ └─port 数据接入层(http接入,消息)
│ ├─beego beego接入
│ └─consumer kafka消息订阅
└─vendor
```
### 系统对接的外部数据
1. 外部数据来源,接收企业平台发送过来的数据。目前接收的是公司和员工的数据
主要内容在文件夹
partnermg/pkg/application/unifiedUserCenter,
partnermg/pkg/port/beego/controller/sync_data_controller.go,
partnermg/pkg/port/beego/routers/routers.go,
具体对接需要的数据格式文档地址:
[yapi-企业平台-子系统对接](http://47.97.5.102:36666/project/187/interface/api)
2. 外部数据来源,接收香米小程序的订单,需要对接kafka消息。
主要内容在
partnermg/pkg/application/syncOrder,
partnermg/pkg/port/consumer,
具体对接需要的数据格式文档地址:
[yapi-合伙人-后端](http://47.97.5.102:36666/project/211/interface/api/9013)
3. 需要调用外部的api接口,调用企业平台,统一用户中心的接口
主要内容在
partnermg/pkg/infrastructure/serviceGateway
### 系统入口
- [测试环境--企业平台网站地址](https://enterprise-platform-dev.fjmaimaimai.com)
- [开发环境--企业平台网站地址](https://enterprise-platform-local.fjmaimaimai.com)
- 天联共创后台自身没有独立的登录入口,需要经过企业平台进行跳转登录
## 建议
1. vendor 目前作用是存放依赖,加快在容器中的构建速度。
2. 有"go.mod"文件存在,可以直接删除vendor文件夹。不过相应的dockerfile 也要进行一定的修改。
3. vendor 文件夹如果不是迫不得已,请不要手动修改其中的文件!可以使用命令 “go mod vendor”。
如果手动修改vendor中的文件,需自行进行版本管理。(慎重考虑!慎重考虑!慎重考虑!)。
... ...
... ... @@ -4,7 +4,6 @@ go 1.14
require (
github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.1
github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2
github.com/Shopify/sarama v1.23.1
github.com/ajg/form v1.5.1 // indirect
github.com/astaxie/beego v1.12.2
... ...
... ... @@ -17,7 +17,7 @@ type CreatePartnerInfoCommand struct {
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
// 合伙类别
PartnerCategory []int64 `json:"partnerCategory,omitempty"`
PartnerCategory []*domain.PartnerCategory `json:"partnerCategory,omitempty"`
//合作时间
CooperateTime time.Time `json:"cooperateTime"`
// 区域
... ... @@ -26,6 +26,8 @@ type CreatePartnerInfoCommand struct {
Salesman []domain.Salesman `json:"salesman,omitempty"`
//公司id
CompanyId int64 `json:"companyId"`
//备注
Remark string `json:"remark"`
}
func (command CreatePartnerInfoCommand) ValidateCommand() error {
... ...
/**
@author: stevechan
@date: 2020/12/29
@note:
**/
package command
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
// 移除合伙人
type RemovePartnerInfoCommand struct {
// 合伙人Id
Id int64 `json:"id" valid:"Required"`
}
func (command *RemovePartnerInfoCommand) ValidateCommand() error {
if command.Id == 0 {
return lib.ThrowError(lib.ARG_ERROR, "合伙人id错误")
}
return nil
}
... ...
... ... @@ -13,7 +13,7 @@ type UpdatePartnerInfoCommand struct {
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory []int64 `json:"partnerCategory,omitempty"`
PartnerCategory []*domain.PartnerCategory `json:"partnerCategory,omitempty"`
// 区域
RegionInfo *domain.RegionInfo `json:"regionInfo"`
//关联业务员
... ... @@ -22,6 +22,8 @@ type UpdatePartnerInfoCommand struct {
CooperateTime time.Time `json:"cooperateTime"`
//公司id
CompanyId int64 `json:"companyId"`
//备注
Remark string `json:"remark"`
}
func (command *UpdatePartnerInfoCommand) ValidateCommand() error {
... ...
... ... @@ -2,11 +2,12 @@ package query
type ListPartnerInfoQuery struct {
// 合伙人类别
Partnertype int `json:"partnerType"`
PartnerType int `json:"partnerType"`
//所属区域
RegionInfo string `json:"regionInfo"`
// 合伙人姓名
PartnerName string `json:"partnerName"`
// 公司id
CompanyId int64 `json:"companyId"`
// 查询偏离量
Offset int `json:"offset"`
... ... @@ -15,6 +16,5 @@ type ListPartnerInfoQuery struct {
}
func (q *ListPartnerInfoQuery) ValidateQuery() error {
return nil
}
... ...
... ... @@ -21,7 +21,13 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService {
return newPartnerInfoService
}
// CreatePartnerInfo 创建合伙人
/**
* @Author SteveChan
* @Description // 创建合伙人
* @Date 15:42 2020/12/29
* @Param
* @return
**/
func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.CreatePartnerInfoCommand) (data *domain.PartnerInfo, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ... @@ -35,16 +41,18 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
defer func() {
transactionContext.RollbackTransaction()
}()
//检查账号是否存在
var (
partnerinfoDao *dao.PartnerInfoDao
partnerInfoDao *dao.PartnerInfoDao
)
if partnerinfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
ok, err := partnerinfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId)
ok, err := partnerInfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId)
if err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
... ... @@ -52,10 +60,19 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在")
}
// 编号去重
for _, partnerCategory := range cmd.PartnerCategory {
if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, 0); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "合伙类型"+""+"编号"+partnerCategory.Code+"已存在")
}
}
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
categories []domain.PartnerCategory
)
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -67,13 +84,26 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: cmd.PartnerCategory,
var ids []int64
for _, partnerCategory := range cmd.PartnerCategory {
ids = append(ids, partnerCategory.Id)
}
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: ids,
})
if err != nil {
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
for i, category := range categories {
for _, partnerCategory := range cmd.PartnerCategory {
if category.Id == partnerCategory.Id {
categories[i].Code = partnerCategory.Code
}
}
}
newPartnerInfo := domain.PartnerInfo{
Partner: domain.Partner{
Account: cmd.Account,
... ... @@ -86,7 +116,8 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
Salesman: cmd.Salesman,
CooperateTime: cmd.CooperateTime,
CompanyId: cmd.CompanyId,
PartnerCategoryInfos: categorys,
PartnerCategoryInfos: categories,
Remark: cmd.Remark,
}
if err = partnerInfoRepository.Save(&newPartnerInfo); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -106,11 +137,18 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
return &newPartnerInfo, nil
}
// GetPartnerInfo 返回合伙人
/**
* @Author SteveChan
* @Description // 返回合伙人,增加合伙人编号字段
* @Date 15:43 2020/12/29
* @Param
* @return
**/
func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = q.ValidateQuery(); err != nil {
return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
}
... ... @@ -120,17 +158,21 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI
defer func() {
transactionContext.RollbackTransaction()
}()
var (
PartnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
categories []domain.PartnerCategory
partnerData *domain.PartnerInfo
)
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取合伙人数据
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
UserId: q.Id, CompanyId: q.CompanyId,
})
... ... @@ -140,33 +182,49 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI
if !partnerData.IsCompany(q.CompanyId) {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "企业信息异常操作")
}
// 获取合伙人类别
if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
categoryIds := []int64{}
var categoryIds []int64
for _, v := range partnerData.PartnerCategoryInfos {
categoryIds = append(categoryIds, v.Id)
}
if len(categoryIds) > 0 {
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: categoryIds,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
for i, category := range categories {
for _, partnerCategory := range partnerData.PartnerCategoryInfos {
if category.Id == partnerCategory.Id {
categories[i].Code = partnerCategory.Code
}
}
}
}
partnerData.PartnerCategoryInfos = categorys
partnerData.PartnerCategoryInfos = categories
err = transactionContext.CommitTransaction()
return partnerData, nil
}
//UpdatePartnerInfo 更新合伙人
/**
* @Author SteveChan
* @Description // 更新合伙人
* @Date 00:07 2020/12/30
* @Param
* @return
**/
func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.UpdatePartnerInfoCommand) (err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = cmd.ValidateCommand(); err != nil {
return application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -176,30 +234,65 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
defer func() {
transactionContext.RollbackTransaction()
}()
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
categories []domain.PartnerCategory
partnerInfoDao *dao.PartnerInfoDao
)
if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: cmd.PartnerCategory,
// 编号去重
for _, partnerCategory := range cmd.PartnerCategory {
if ok, err := partnerInfoDao.PartnerCodeExist(partnerCategory.Id, partnerCategory.Code, cmd.CompanyId, cmd.Id); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return lib.ThrowError(lib.BUSINESS_ERROR, "编号"+partnerCategory.Code+"已存在")
}
}
var ids []int64
for _, partnerCategory := range cmd.PartnerCategory {
ids = append(ids, partnerCategory.Id)
}
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: ids,
})
if err != nil {
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
for i, category := range categories {
for _, partnerCategory := range cmd.PartnerCategory {
if category.Id == partnerCategory.Id {
categories[i].Code = partnerCategory.Code
}
}
}
partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
UserId: cmd.Id, CompanyId: cmd.CompanyId,
UserId: cmd.Id,
CompanyId: cmd.CompanyId,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -207,11 +300,14 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
if !partnerInfo.IsCompany(cmd.CompanyId) {
return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作")
}
partnerInfo.Salesman = cmd.Salesman
partnerInfo.Status = cmd.Status
partnerInfo.RegionInfo = *cmd.RegionInfo
partnerInfo.CooperateTime = cmd.CooperateTime
partnerInfo.PartnerCategoryInfos = categorys
partnerInfo.PartnerCategoryInfos = categories
partnerInfo.Remark = cmd.Remark
if err = partnerInfoRepository.Save(partnerInfo); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -231,7 +327,13 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
return
}
// ListPartnerInfo 合伙人列表
/**
* @Author SteveChan
* @Description //合伙人列表,返回合伙人编号
* @Date 00:07 2020/12/30
* @Param
* @return
**/
func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (int, []domain.PartnerInfo, error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ... @@ -246,14 +348,13 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
categories []domain.PartnerCategory
)
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -271,8 +372,8 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
PartnerName: listPartnerInfoQuery.PartnerName,
CompanyId: listPartnerInfoQuery.CompanyId,
}
if listPartnerInfoQuery.Partnertype > 0 {
queryOption.PartnerCategory = []int{listPartnerInfoQuery.Partnertype}
if listPartnerInfoQuery.PartnerType > 0 {
queryOption.PartnerCategory = []int{listPartnerInfoQuery.PartnerType}
}
// RegionInfo
if len(listPartnerInfoQuery.RegionInfo) > 0 {
... ... @@ -284,18 +385,19 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
if count, err = partnerInfoRepository.CountAll(queryOption); err != nil {
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{})
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{})
if err != nil {
return count, partnerInfos, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
categorysMap := make(map[int64]domain.PartnerCategory)
for i := range categorys {
categorysMap[categorys[i].Id] = categorys[i]
categoriesMap := make(map[int64]domain.PartnerCategory)
for i := range categories {
categoriesMap[categories[i].Id] = categories[i]
}
for i := range partnerInfos {
categoryInPartner := []domain.PartnerCategory{}
var categoryInPartner []domain.PartnerCategory
for _, vv := range partnerInfos[i].PartnerCategoryInfos {
if categoryData, ok := categorysMap[vv.Id]; ok {
if categoryData, ok := categoriesMap[vv.Id]; ok {
categoryData.Code = vv.Code
categoryInPartner = append(categoryInPartner, categoryData)
}
}
... ... @@ -307,6 +409,47 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
return count, partnerInfos, nil
}
/**
* @Author SteveChan
* @Description //TODO 移除合伙人
* @Date 16:40 2020/12/29
* @Param
* @return
**/
func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.RemovePartnerInfoCommand) (err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = cmd.ValidateCommand(); err != nil {
return application.ThrowError(application.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
partnerInfoRepository domain.PartnerInfoRepository
)
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 判断合伙人是否有业务数据
if err = partnerInfoRepository.Remove(cmd.Id); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
transactionContext.CommitTransaction()
return nil
}
func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPartnerInfoCommand) (err error) {
if len(cmd.Ids) == 0 {
return nil
... ... @@ -324,14 +467,14 @@ func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPar
transactionContext.RollbackTransaction()
}()
var (
partnerinfoDao *dao.PartnerInfoDao
partnerInfoDao *dao.PartnerInfoDao
)
if partnerinfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
err = partnerinfoDao.UpdatePartnerStatus(cmd.Ids, cmd.CompanyId, cmd.Status)
err = partnerInfoDao.UpdatePartnerStatus(cmd.Ids, cmd.CompanyId, cmd.Status)
if err != nil {
e := fmt.Sprintf("更新合伙人(id=%v)的数据失败;%s", cmd.Ids, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
... ...
... ... @@ -8,14 +8,14 @@ var LOG_LEVEL = "debug"
var LOG_File = "./logs/partnermg.log"
var (
UCENTER_HOST = "https://suplus-ucenter-dev.fjmaimaimai.com" //统一用户中心地址
UCENTER_HOST = "https://suplus-ucenter-test.fjmaimaimai.com" //统一用户中心地址
UCENTER_SECRET = "cykbjnfqgctn"
UCENTER_APP_KEY = "39aefef9e22744a3b2d2d3791824ae7b"
UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735"
)
var (
BUSINESS_ADMIN_HOST = "http://suplus-business-admin-dev.fjmaimaimai.com" //企业平台的地址
BUSINESS_ADMIN_HOST = "http://suplus-business-admin-test.fjmaimaimai.com" //企业平台的地址
)
func init() {
... ... @@ -34,9 +34,7 @@ func init() {
if os.Getenv("UCENTER_CHECK_ALT") != "" {
UCENTER_CHECK_ALT = os.Getenv("UCENTER_CHECK_ALT")
}
if os.Getenv("BUSINESS_ADMIN_HOST") != "" {
BUSINESS_ADMIN_HOST = os.Getenv("BUSINESS_ADMIN_HOST")
}
}
... ...
... ... @@ -14,7 +14,7 @@ var KafkaCfg KafkaConfig
func init() {
KafkaCfg = KafkaConfig{
Servers: []string{""},
Servers: []string{"127.0.0.1:9092"},
ConsumerId: "partnermg_local",
}
if os.Getenv("KAFKA_HOST") != "" {
... ...
... ... @@ -2,11 +2,11 @@ package constant
import "os"
var POSTGRESQL_DB_NAME = "partner_dev"
var POSTGRESQL_DB_NAME = "partner_test"
var POSTGRESQL_USER = "postgres"
var POSTGRESQL_PASSWORD = "eagle1010"
var POSTGRESQL_HOST = "114.55.200.59"
var POSTGRESQL_PORT = "31543"
var POSTGRESQL_PASSWORD = "1993618jack" // eagle1010
var POSTGRESQL_HOST = "127.0.0.1" // 114.55.200.59
var POSTGRESQL_PORT = "5432" // 31543
var DISABLE_CREATE_TABLE = true
var DISABLE_SQL_GENERATE_PRINT = false
... ...
... ... @@ -114,7 +114,7 @@ type OrderBase struct {
DataFrom OrderDataFrom `json:"dataFrom"`
//备注
Remark OrderBaseRemark `json:"remark"`
//合伙人类型
PartnerCategory PartnerCategory `json:"partnerCategory"`
}
... ... @@ -182,16 +182,16 @@ func (order *OrderBase) AddGoods(goods []OrderGood) {
order.Compute()
}
func (order *OrderBase) ModifyGoodNumber(goodid int64, number int64) {
for i := range order.Goods {
if order.Goods[i].Id != goodid {
continue
}
// thisGood := order.Goods[i]
// func (order *OrderBase) ModifyGoodNumber(goodid int64, number int64) {
// for i := range order.Goods {
// if order.Goods[i].Id != goodid {
// continue
// }
// // thisGood := order.Goods[i]
}
order.Compute()
}
// }
// order.Compute()
// }
//Compute 数据汇总核算
func (order *OrderBase) Compute() error {
... ...
... ... @@ -6,6 +6,8 @@ type PartnerCategory struct {
Id int64 `json:"id"`
// 名称
Name string `json:"name,omitempty"`
// 合伙人编码
Code string `json:"code"`
}
type PartnerCategoryFindQuery struct {
... ...
... ... @@ -48,6 +48,8 @@ type PartnerInfo struct {
PartnerCategory int `json:"partnerCategory"`
//公司id
CompanyId int64 `json:"companyId"`
//备注
Remark string `json:"remark"`
}
func (p *PartnerInfo) IsUsable() bool {
... ... @@ -72,11 +74,13 @@ type PartnerFindQuery struct {
PartnerName string //合伙人姓名
CompanyId int64
Ids []int64
PartnerType []*PartnerCategory
}
type PartnerInfoRepository interface {
Save(dm *PartnerInfo) error
FindOne(queryOptions PartnerFindOneQuery) (*PartnerInfo, error)
Find(queryOptions PartnerFindQuery) ([]PartnerInfo, error)
Remove(Id int64) error
CountAll(queryOptions PartnerFindQuery) (int, error)
}
... ...
... ... @@ -2,7 +2,7 @@ package dao
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
... ... @@ -28,7 +28,6 @@ func (dao PartnerInfoDao) PartnerAccountExist(account string, companyId int64) (
Where("account=?", account).
Where("company_id=?", companyId).
Exists()
return ok, err
}
... ... @@ -42,3 +41,21 @@ func (dao PartnerInfoDao) UpdatePartnerStatus(ids []int64, companyId int64, stat
Update()
return err
}
/**
* @Author SteveChan
* @Description // 编号查重
* @Date 17:55 2020/12/28
* @Param
* @return
**/
func (dao PartnerInfoDao) PartnerCodeExist(categoryId int64, code string, companyId int64, id int64) (bool, error) {
tx := dao.transactionContext.PgDd
m := &models.PartnerInfo{}
ok, err := tx.Model(m).
Where(`partner_category_infos@> '[{"id":?,"code":?}]'`, categoryId, pg.Ident(code)).
Where("company_id=?", companyId).
Where("id <> ?", id).
Exists()
return ok, err
}
... ...
... ... @@ -35,4 +35,5 @@ type OrderBestshop struct {
//是否将数据同步到 order_base ,order_good
IsCopy bool `pg:",use_zero"`
CompanyId int64
OrderArea string
}
... ...
... ... @@ -7,4 +7,6 @@ type PartnerCategoryInfo struct {
Id int64
// 名称
Name string
// 合伙人编码
Code string
}
... ...
... ... @@ -36,6 +36,8 @@ type PartnerInfo struct {
PartnerCategoryInfos []domain.PartnerCategory
//公司id
CompanyId int64
//备注
Remark string
}
var _ pg.BeforeUpdateHook = (*PartnerInfo)(nil)
... ...
... ... @@ -43,6 +43,7 @@ func (respository OrderBestshopRepository) transformPgModelToDomainModel(orderMo
PartnerId: orderModel.PartnerId,
IsCopy: orderModel.IsCopy,
CompanyId: orderModel.CompanyId,
OrderArea: orderModel.OrderArea,
}, nil
}
... ... @@ -65,6 +66,7 @@ func (respository OrderBestshopRepository) Add(order *domain.OrderBestShop) erro
PartnerId: order.PartnerId,
IsCopy: order.IsCopy,
CompanyId: order.CompanyId,
OrderArea: order.OrderArea,
}
_, err := tx.Model(&m).Insert()
order.Id = m.Id
... ... @@ -91,6 +93,7 @@ func (respository OrderBestshopRepository) Edit(order *domain.OrderBestShop) err
PartnerId: order.PartnerId,
IsCopy: order.IsCopy,
CompanyId: order.CompanyId,
OrderArea: order.OrderArea,
}
_, err := tx.Model(&m).Where("id=?", order.Id).Update()
order.Id = m.Id
... ...
... ... @@ -12,21 +12,6 @@ type PartnerCategoryRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository PartnerCategoryRepository) transformPgModelToDomainModel(m *models.PartnerCategoryInfo) (domain.PartnerCategory, error) {
pc := domain.PartnerCategory{
Id: m.Id,
Name: m.Name,
}
return pc, nil
}
func NewPartnerCategoryRepository(transactionContext *transaction.TransactionContext) (*PartnerCategoryRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &PartnerCategoryRepository{transactionContext: transactionContext}, nil
}
func (repository PartnerCategoryRepository) Find(queryOptions domain.PartnerCategoryFindQuery) (int, []domain.PartnerCategory, error) {
tx := repository.transactionContext.PgTx
var (
... ... @@ -48,3 +33,19 @@ func (repository PartnerCategoryRepository) Find(queryOptions domain.PartnerCate
}
return cnt, partnerCategoryInfos, nil
}
func (repository PartnerCategoryRepository) transformPgModelToDomainModel(m *models.PartnerCategoryInfo) (domain.PartnerCategory, error) {
pc := domain.PartnerCategory{
Id: m.Id,
Name: m.Name,
Code: m.Code,
}
return pc, nil
}
func NewPartnerCategoryRepository(transactionContext *transaction.TransactionContext) (*PartnerCategoryRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &PartnerCategoryRepository{transactionContext: transactionContext}, nil
}
... ...
... ... @@ -18,50 +18,18 @@ var (
_ domain.PartnerInfoRepository = (*PartnerInfoRepository)(nil)
)
func (repository *PartnerInfoRepository) transformPgModelToDomainModel(partnerInfoModel *models.PartnerInfo) (domain.PartnerInfo, error) {
m := domain.PartnerInfo{
Partner: domain.Partner{
Id: partnerInfoModel.Id,
PartnerName: partnerInfoModel.PartnerName,
Account: partnerInfoModel.Account,
},
PartnerCategory: partnerInfoModel.PartnerCategory,
Password: partnerInfoModel.Password,
Status: partnerInfoModel.Status,
CreateAt: partnerInfoModel.CreateAt,
Salesman: partnerInfoModel.Salesman,
RegionInfo: partnerInfoModel.RegionInfo,
CooperateTime: partnerInfoModel.CooperateTime,
CompanyId: partnerInfoModel.CompanyId,
}
p := []domain.PartnerCategory{}
for _, v := range partnerInfoModel.PartnerCategoryInfos {
catagory := domain.PartnerCategory{
Id: v.Id,
}
p = append(p, catagory)
}
m.PartnerCategoryInfos = p
return m, nil
}
func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext) (*PartnerInfoRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &PartnerInfoRepository{transactionContext: transactionContext}, nil
}
func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error {
var (
err error
tx = repository.transactionContext.PgTx
)
categorys := []domain.PartnerCategory{}
var categories []domain.PartnerCategory
for _, v := range dm.PartnerCategoryInfos {
categorys = append(categorys, domain.PartnerCategory{
categories = append(categories, domain.PartnerCategory{
Id: v.Id,
Name: v.Name,
Code: v.Code,
})
}
m := &models.PartnerInfo{
... ... @@ -75,7 +43,8 @@ func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error {
RegionInfo: dm.RegionInfo,
CooperateTime: dm.CooperateTime,
CompanyId: dm.CompanyId,
PartnerCategoryInfos: categorys,
PartnerCategoryInfos: categories,
Remark: dm.Remark,
}
if m.Id == 0 {
err = tx.Insert(m)
... ... @@ -86,7 +55,7 @@ func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error {
} else {
_, err = tx.Model(m).WherePK().
Column("partner_name", "account", "password", "status", "partner_category", "salesman",
"region_info", "cooperate_time", "update_at", "partner_category_infos").
"region_info", "cooperate_time", "update_at", "partner_category_infos", "remark").
Update()
if err != nil {
return err
... ... @@ -124,7 +93,7 @@ func (repository *PartnerInfoRepository) FindOne(queryOptions domain.PartnerFind
func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuery) ([]domain.PartnerInfo, error) {
db := repository.transactionContext.PgTx
partnerModels := []models.PartnerInfo{}
var partnerModels []models.PartnerInfo
query := db.Model(&partnerModels)
if len(queryOption.PartnerName) > 0 {
query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%")
... ... @@ -174,7 +143,28 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer
return partnerReturn, nil
}
func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQuery) (int, error) {
/**
* @Author SteveChan
* @Description //TODO 移除合伙人
* @Date 15:33 2020/12/29
* @Param
* @return
**/
func (repository *PartnerInfoRepository) Remove(id int64) error {
var (
err error
tx = repository.transactionContext.PgTx
)
m := &models.PartnerInfo{
Id: id,
}
_, err = tx.Model(m).
Where("id=?", id).
Delete()
return err
}
func (repository *PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQuery) (int, error) {
db := repository.transactionContext.PgTx
partnerModels := models.PartnerInfo{}
query := db.Model(&partnerModels)
... ... @@ -202,3 +192,40 @@ func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQ
cnt, err := query.Count()
return cnt, err
}
func (repository *PartnerInfoRepository) transformPgModelToDomainModel(partnerInfoModel *models.PartnerInfo) (domain.PartnerInfo, error) {
m := domain.PartnerInfo{
Partner: domain.Partner{
Id: partnerInfoModel.Id,
PartnerName: partnerInfoModel.PartnerName,
Account: partnerInfoModel.Account,
},
PartnerCategory: partnerInfoModel.PartnerCategory,
Password: partnerInfoModel.Password,
Status: partnerInfoModel.Status,
CreateAt: partnerInfoModel.CreateAt,
Salesman: partnerInfoModel.Salesman,
RegionInfo: partnerInfoModel.RegionInfo,
CooperateTime: partnerInfoModel.CooperateTime,
CompanyId: partnerInfoModel.CompanyId,
Remark: partnerInfoModel.Remark,
}
var p []domain.PartnerCategory
for _, v := range partnerInfoModel.PartnerCategoryInfos {
category := domain.PartnerCategory{
Id: v.Id,
Name: v.Name,
Code: v.Code,
}
p = append(p, category)
}
m.PartnerCategoryInfos = p
return m, nil
}
func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext) (*PartnerInfoRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &PartnerInfoRepository{transactionContext: transactionContext}, nil
}
... ...
... ... @@ -64,6 +64,7 @@ func (gateway MmmBusinessAdminServiceGateway) httpDo(reqURL string, mathod strin
return body, nil
}
// GetUserAuth 请求企业平台确认用户是否可以使用天联共创后台
func (gateway MmmBusinessAdminServiceGateway) GetUserAuth(userId int64) (*ResponseGetUserAuth, error) {
param := map[string]interface{}{
"userId": fmt.Sprint(userId),
... ...
... ... @@ -36,13 +36,14 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
//用与适配前端定义的数据结构
type Parameter struct {
PartnerName string `json:"partnerName"`
PartnerType []int64 `json:"partnerType"`
PartnerType []*domain.PartnerCategory `json:"partnerType"`
Area string `json:"area"`
Account string `json:"account"`
State int `json:"state"`
CooperationTime string `json:"cooperationTime"`
SalesmanName string `json:"salesmanName"`
Phone string `json:"phone"`
Remark string `json:"remark"`
}
var (
param Parameter
... ... @@ -69,6 +70,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
PartnerCategory: param.PartnerType,
CooperateTime: cooperateTime,
CompanyId: companyId,
Remark: param.Remark,
}
if len(param.SalesmanName) > 0 || len(param.Phone) > 0 {
cmd.Salesman = []domain.Salesman{
... ... @@ -104,12 +106,13 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
//用与适配前端定义的数据结构
type Parameter struct {
ID int64 `json:"id"`
PartnerType []int64 `json:"partnerType"`
PartnerType []*domain.PartnerCategory `json:"partnerType"`
Area string `json:"area"`
State int `json:"state"`
CooperationTime string `json:"cooperationTime"`
SalesmanName string `json:"salesmanName"`
Phone string `json:"phone"`
Remark string `json:"remark"`
}
var (
param Parameter
... ... @@ -142,6 +145,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
},
},
CompanyId: companyId,
Remark: param.Remark,
}
serve := partnerInfoService.NewPartnerInfoService(nil)
err = serve.UpdatePartnerInfo(&cmd)
... ... @@ -190,16 +194,18 @@ func (c *PartnerInfoController) GetPartnerInfo() {
"cooperationTime": partnerInfo.CooperateTime.Local().Format("2006-01-02"),
"state": partnerInfo.Status,
"id": partnerInfo.Partner.Id,
"remark": partnerInfo.Remark,
}
if len(partnerInfo.Salesman) > 0 {
rspResult["salesmanName"] = partnerInfo.Salesman[0].Name
rspResult["phone"] = partnerInfo.Salesman[0].Telephone
}
partnerTypes := []map[string]interface{}{}
var partnerTypes []map[string]interface{}
for _, v := range partnerInfo.PartnerCategoryInfos {
m := map[string]interface{}{
"id": v.Id,
"name": v.Name,
"code": v.Code,
}
partnerTypes = append(partnerTypes, m)
}
... ... @@ -208,6 +214,40 @@ func (c *PartnerInfoController) GetPartnerInfo() {
return
}
/**
* @Author SteveChan
* @Description //TODO 移除合伙人
* @Date 15:31 2020/12/29
* @Param
* @return
**/
func (c *PartnerInfoController) RemovePartnerInfo() {
//用与适配前端定义的数据结构
type Parameter struct {
ID int64 `json:"id"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
cmd := partnerInfoCmd.RemovePartnerInfoCommand{
Id: param.ID,
}
serve := partnerInfoService.NewPartnerInfoService(nil)
err = serve.RemovePartnerInfo(cmd)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}
//PartnerInfoSetState 合伙人批量禁用.启用
func (c *PartnerInfoController) PartnerInfoSetState() {
//用与适配前端定义的数据结构
... ... @@ -224,19 +264,19 @@ func (c *PartnerInfoController) PartnerInfoSetState() {
c.ResponseError(errors.New("json数据解析失败"))
return
}
comanyId := c.GetUserCompany()
companyId := c.GetUserCompany()
var cmd partnerInfoCmd.StatusPartnerInfoCommand
switch param.Status {
case 0:
cmd = partnerInfoCmd.StatusPartnerInfoCommand{
Ids: param.Id,
CompanyId: comanyId,
CompanyId: companyId,
Status: domain.PARTNER_STATUS_NO,
}
case 1:
cmd = partnerInfoCmd.StatusPartnerInfoCommand{
Ids: param.Id,
CompanyId: comanyId,
CompanyId: companyId,
Status: domain.PARTNER_STATUS_YES,
}
default:
... ... @@ -256,7 +296,7 @@ func (c *PartnerInfoController) PartnerInfoSetState() {
//ListPartnerInfo 合伙人列表
func (c *PartnerInfoController) ListPartnerInfo() {
type Parameter struct {
Partnertype int `json:"partnerType"`
PartnerType int `json:"partnerType"`
Area string `json:"area"`
PartnerName string `json:"partnerName"`
PageSize int `json:"pageSize"`
... ... @@ -280,7 +320,7 @@ func (c *PartnerInfoController) ListPartnerInfo() {
}
companyId := c.GetUserCompany()
query := partnerQuery.ListPartnerInfoQuery{
Partnertype: param.Partnertype,
PartnerType: param.PartnerType,
PartnerName: param.PartnerName,
RegionInfo: param.Area,
Limit: param.PageSize,
... ... @@ -294,7 +334,7 @@ func (c *PartnerInfoController) ListPartnerInfo() {
c.ResponseError(err)
return
}
resp := []map[string]interface{}{}
var resp []map[string]interface{}
indexBegin := query.Offset
for i := range partners {
m := map[string]interface{}{
... ... @@ -309,6 +349,7 @@ func (c *PartnerInfoController) ListPartnerInfo() {
"partnerType": partners[i].PartnerCategoryInfos,
"salesmanName": "",
"phone": "",
"remark": partners[i].Remark,
}
if len(partners[i].Salesman) > 0 {
m["salesmanName"] = partners[i].Salesman[0].Name
... ...
... ... @@ -32,7 +32,7 @@ func (c *UserController) ListUser() {
//用与适配前端定义的数据结构
type Paramter struct {
SearchText string `json:"searchText"`
PageSize int `json::"pageSize"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
var (
... ...
... ... @@ -23,6 +23,7 @@ func init() {
beego.NSRouter("/edit", &controllers.PartnerInfoController{}, "POST:UpdatePartnerInfo"),
beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"),
beego.NSRouter("/batchDisabled", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"),
beego.NSRouter("/remove", &controllers.PartnerInfoController{}, "POST:RemovePartnerInfo"),
),
beego.NSNamespace("/dividends",
beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"),
... ...
... ... @@ -8,7 +8,9 @@ import (
//外部调用,企业平台,总后台调用
func init() {
nsPlatform := beego.NewNamespace("/platform",
//同步企业相关数据
beego.NSRouter("/action", &controllers.SyncDataController{}, "post:SyncData"),
//更换公司管理员
beego.NSRouter("/admins_change", &controllers.SyncDataController{}, "post:CompanyAdminChance"),
)
nsUcenter := beego.NewNamespace("/ucenter",
... ...
... ... @@ -51,6 +51,7 @@ func (c *MessageConsumer) ConsumeClaim(groupSession sarama.ConsumerGroupSession,
}
if err = topicHandle(message); err != nil {
logs.Error("Message claimed: kafka消息处理错误 topic =", message.Topic, message.Offset, err)
}
groupSession.MarkMessage(message, "")
}
... ...
... ... @@ -30,6 +30,9 @@ func init() {
if runEnv == "partnermg_prd" {
initHandleRoutersProd()
}
if runEnv == "partnermg_dev" {
initHandleRoutersDev()
}
}
func initHandleRoutersTest() {
... ... @@ -39,3 +42,7 @@ func initHandleRoutersTest() {
func initHandleRoutersProd() {
TopicHandleRouters["xiangmi_project"] = handles.DataFromXiangMi
}
func initHandleRoutersDev() {
TopicHandleRouters["xiangmi_project_dev"] = handles.DataFromXiangMi
}
\ No newline at end of file
... ...
package geetest
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"
)
type GeetestLib struct {
CaptchaID string
PrivateKey string
Client *http.Client
}
type FailbackRegisterRespnse struct {
Success int `json:"success"`
GT string `json:"gt"`
Challenge string `json:"challenge"`
NewCaptcha int `json:"new_captcha"`
}
const (
geetestHost = "http://api.geetest.com"
registerURL = geetestHost + "/register.php"
validateURL = geetestHost + "/validate.php"
)
func MD5Encode(input string) string {
md5Instant := md5.New()
md5Instant.Write([]byte(input))
return hex.EncodeToString(md5Instant.Sum(nil))
}
// 初始化 GeetestLib
func NewGeetestLib(capthcaID string, privateKey string, timeOut time.Duration) (geetest GeetestLib){
client := &http.Client{Timeout: timeOut}
geetest = GeetestLib{capthcaID, privateKey, client}
return
}
func (g *GeetestLib) getFailBackRegisterResponse(success int, challenge string) []byte {
if challenge == "" {
challenge = hex.EncodeToString(md5.New().Sum(nil))
}
response := FailbackRegisterRespnse{
success,
g.CaptchaID,
challenge,
1,
}
res, _ := json.Marshal(response)
return res
}
func (g *GeetestLib) do(req *http.Request) (body []byte, err error) {
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
var resp *http.Response
if resp, err = g.Client.Do(req); err != nil {
return
}
defer resp.Body.Close()
if resp.StatusCode >= http.StatusInternalServerError {
err = errors.New("http status code 5xx")
return
}
if body, err = ioutil.ReadAll(resp.Body); err != nil {
return
}
return
}
func (g *GeetestLib) PreProcess(userID string, userIP string) (int8, []byte) {
params := url.Values{}
params.Add("gt", g.CaptchaID)
params.Add("new_captcha", "1")
if userID != "" {
params.Add("user_id", userID)
}
if userIP != "" {
params.Add("ip_adress", userIP)
}
req, _ := http.NewRequest("GET", registerURL+"?"+params.Encode(), nil)
body, err := g.do(req)
if err != nil {
return 0, g.getFailBackRegisterResponse(0, "")
}
challenge := string(body)
if len(challenge) != 32 {
return 0, g.getFailBackRegisterResponse(0, "")
} else {
challenge = MD5Encode(challenge + g.PrivateKey)
return 1, g.getFailBackRegisterResponse(1, challenge)
}
}
func (g *GeetestLib) checkParas(challenge string, validate string, seccode string) bool {
if challenge == "" || validate == "" || seccode == "" {
return false
}
return true
}
func (g *GeetestLib) checkSuccessRes(challenge string, validate string) bool {
return MD5Encode(g.PrivateKey+"geetest"+challenge) == validate
}
func (g *GeetestLib) checkFailbackRes(challenge string, validate string) bool {
return MD5Encode(challenge) == validate
}
func (g *GeetestLib) SuccessValidate(challenge string, validate string, seccode string, userID string, userIP string) bool {
if !g.checkParas(challenge, validate, seccode) {
return false
}
if !g.checkSuccessRes(challenge, validate) {
return false
}
params := url.Values{}
params.Add("seccode", seccode)
params.Add("challenge", challenge)
params.Add("captchaid", g.CaptchaID)
params.Add("sdk", "golang_v1.0.0")
if userID != "" {
params.Add("user_id", userID)
}
if userIP != "" {
params.Add("ip_adress", userIP)
}
req, _ := http.NewRequest("POST", validateURL, strings.NewReader(params.Encode()))
body, err := g.do(req)
if err != nil {
return false
}
res := string(body)
return res == MD5Encode(seccode)
}
func (g *GeetestLib) FailbackValidate(challenge string, validate string, seccode string) bool {
if !g.checkParas(challenge, validate, seccode) {
return false
}
if !g.checkFailbackRes(challenge, validate) {
return false
}
return true
}
... ... @@ -3,9 +3,6 @@
github.com/360EntSecGroup-Skylar/excelize/v2
# github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798
github.com/DataDog/zstd
# github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2
## explicit
github.com/GeeTeam/gt3-golang-sdk/geetest
# github.com/Shopify/sarama v1.23.1
## explicit
github.com/Shopify/sarama
... ...