作者 陈志颖

合并分支 'dev' 到 'master'

Dev



查看合并请求 !7
正在显示 45 个修改的文件 包含 636 行增加318 行删除
# 合伙人项目
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
}
... ...
... ... @@ -10,10 +10,12 @@ import (
type UpdatePartnerInfoCommand struct {
// 合伙人Id
Id int64 `json:"id"`
// 合伙人姓名
PartnerName string `json:"partnerName"`
// 状态(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 +24,8 @@ type UpdatePartnerInfoCommand struct {
CooperateTime time.Time `json:"cooperateTime"`
//公司id
CompanyId int64 `json:"companyId"`
//备注
Remark string `json:"remark"`
}
func (command *UpdatePartnerInfoCommand) ValidateCommand() error {
... ... @@ -31,7 +35,6 @@ func (command *UpdatePartnerInfoCommand) ValidateCommand() error {
if command.RegionInfo == nil {
return lib.ThrowError(lib.ARG_ERROR, "区域必填")
}
if command.Id == 0 {
return lib.ThrowError(lib.ARG_ERROR, "合伙人id错误")
}
... ...
... ... @@ -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,21 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
defer func() {
transactionContext.RollbackTransaction()
}()
//检查账号是否存在
var (
partnerinfoDao *dao.PartnerInfoDao
partnerInfoDao *dao.PartnerInfoDao
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categories []domain.PartnerCategory
)
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,11 +63,6 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在")
}
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
)
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
... ... @@ -67,13 +73,60 @@ 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 categoryMap = make(map[int64]string)
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: []int64{},
})
if err != nil {
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if len(categories) > 0 {
for _, category := range categories {
categoryMap[category.Id] = category.Name
}
}
// id去重
num := make(map[int64]bool)
for _, partnerCategory := range cmd.PartnerCategory {
if !num[partnerCategory.Id] {
num[partnerCategory.Id] = true
} else {
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, categoryMap[partnerCategory.Id]+"编号"+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 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 +139,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 +160,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 +181,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 +205,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 +257,90 @@ 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,
// 获取合伙人类型
var categoryMap = make(map[int64]string)
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: []int64{},
})
if err != nil {
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if len(categories) > 0 {
for _, category := range categories {
categoryMap[category.Id] = category.Name
}
}
// id去重
num := make(map[int64]bool)
for _, partnerCategory := range cmd.PartnerCategory {
if !num[partnerCategory.Id] {
num[partnerCategory.Id] = true
} else {
return lib.ThrowError(lib.BUSINESS_ERROR, "合伙类型不能重复")
}
}
// 编号去重
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, categoryMap[partnerCategory.Id]+"编号"+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 +348,15 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
if !partnerInfo.IsCompany(cmd.CompanyId) {
return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作")
}
partnerInfo.Partner.PartnerName = cmd.PartnerName
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 +376,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 +397,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 +421,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 +434,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 +458,61 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
return count, partnerInfos, nil
}
/**
* @Author SteveChan
* @Description // 移除合伙人
* @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
orderBaseRepository domain.OrderBaseRepository
orders []domain.OrderBase
)
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 判断合伙人是否有业务数据
orders, _, err = orderBaseRepository.Find(domain.OrderBaseFindQuery{
PartnerId: cmd.Id,
})
if len(orders) > 0 {
return lib.ThrowError(lib.BUSINESS_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 +530,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)
... ...
... ... @@ -16,7 +16,7 @@ import (
//从其他系统接收订单数据
const (
BEST_SHOP_UNIONID string = "gh_18eb644002fb" //海鲜干货小程序原始id
BEST_SHOP_UNIONID string = "gh_18eb644002fb" //香米小程序原始id
)
type SyncOrderService struct {
... ... @@ -79,6 +79,7 @@ func (s SyncOrderService) SyncOrderFromBestshop(cmd command.CreateOrderFromBests
//
logs.Warning("订单数据已存在:order_code=%s", cmd.OrderCode)
} else {
//复制数据到order_base表
err = s.CreateOrderFromBestshop(cmd)
}
return err
... ... @@ -225,6 +226,8 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
for _, v := range companyData.Applets {
//BEST_SHOP_UNIONID string = "gh_18eb644002fb" //香米小程序原始id
//接收香米小程序的订单数据
if len(v.Id) > 0 {
canCopyOrder = true
}
... ... @@ -237,7 +240,7 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord
orderbase domain.OrderBase
ordergoods []domain.OrderGood
)
//TODO 添加orderBase
//添加orderBase
orderBestshop.CopyToOrderBase(&orderbase)
orderbase.CompanyId = companyData.Id
for i := range orderBestshop.Goods {
... ... @@ -245,13 +248,15 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord
orderBestshop.Goods[i].CopyToOrderGood(&good)
good.CompanyId = partnerData.CompanyId
good.Compute()
//初始接收的订单按照待支付状态处理
good.CurrentBonusStatus.WartPayPartnerBonus(&good)
ordergoods = append(ordergoods, good)
}
orderbase.Goods = ordergoods
orderbase.PartnerId = partnerData.Partner.Id
orderbase.CompanyId = partnerData.CompanyId
orderbase.PartnerCategory = domain.PartnerCategory{Id: 1, Name: "事业合伙人"} // 默认设定为事业合伙人订单
// 默认设定为事业合伙人订单
orderbase.PartnerCategory = domain.PartnerCategory{Id: 1, Name: "事业合伙人"}
orderbase.Compute()
err = orderBaseRepository.Save(&orderbase)
if err != nil {
... ...
... ... @@ -6,8 +6,9 @@ import (
)
type SyncCallbackCommand struct {
//position:职位,department:部门,employee:员工,company:公司
//模块:position:职位,department:部门,employee:员工,company:公司
Module string `json:"module"`
//动作:
//add:添加,edit:编辑,delete删除,batchDelete:批量删除,
//setCompanyCharge:更改公司主管,batchForbid:批量禁用用户,
//batchRemove:批量更改用户部门,changeAdmin换管理员
... ...
... ... @@ -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
... ...
... ... @@ -9,7 +9,7 @@ import (
const (
OrderReal = iota + 1 //实发订单
OrderIntention //意向订单
OrderTypeBestShop //来自小程序海鲜干货的订单
OrderTypeBestShop //来自小程序香米的订单
)
func GetOrderBaseTypeName(orderType int) string {
... ... @@ -114,7 +114,7 @@ type OrderBase struct {
DataFrom OrderDataFrom `json:"dataFrom"`
//备注
Remark OrderBaseRemark `json:"remark"`
//合伙人类型
PartnerCategory PartnerCategory `json:"partnerCategory"`
}
... ... @@ -182,32 +182,41 @@ 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 {
planPartnerBonus := decimal.NewFromFloat(0)
planOrderAmount := decimal.NewFromFloat(0)
var (
//预计的货品总数,不包含调整后的值
planOrderCount int = 0
//调整后的货品总数,混合相加计算预计值和调整值中的一个,优先取调整值计算
useOrderCount int = 0
//订单的货品列表中是否存在调整货品数量
HasUseOrderCount bool = false
)
//调整后的合伙人分红,混合相加计算预计值和调整值中的一个,优先取调整值计算
usePartnerBonus := decimal.NewFromFloat(0)
//订单的货品列表中是否存在调整的合伙人分红
var hasUsePartnerBonus bool = false
//调整后的订单总额,混合相加计算预计值和调整值中的一个,优先取调整值计算
useOrderAmount := decimal.NewFromFloat(0)
var hasUseOrderAmount bool = false
//已支付分红
partnerBonusHas := decimal.NewFromFloat(0)
//未支付分红
partnerBonusNot := decimal.NewFromFloat(0)
//分红支出
partnerBonusExpense := decimal.NewFromFloat(0)
//初始订单的支付状态
order.BonusStatus = OrderGoodWaitPay
... ... @@ -215,14 +224,20 @@ func (order *OrderBase) Compute() error {
for i := range order.Goods {
if order.Goods[i].BonusStatus == OrderGoodHasPay {
//确定订单的支付状态
//订单的货品列表中“存在”支付状态的为已支付,则整体订单设定为已支付状态
order.BonusStatus = OrderGoodHasPay
}
//计算预计的合伙人分红,不含调整的值
planPartnerBonus = planPartnerBonus.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PlanPartnerBonus))
//计算预计的订单总金额,不含调整的值
planOrderAmount = planOrderAmount.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PlanAmount))
//计算预计的订单中货品总数,不含调整的值
planOrderCount += order.Goods[i].PlanGoodNumber
//获取调整货品调整后(数量)的总金额,
goodUseAmount := decimal.NewFromFloat(order.Goods[i].GoodCompute.UseAmount)
if goodUseAmount.GreaterThanOrEqual(decimal.NewFromFloat(0)) {
//调整值非负值得情况
//调整后货品总金额,非负值(大于等于0)的情况
hasUseOrderAmount = true
useOrderAmount = useOrderAmount.Add(goodUseAmount)
} else {
... ... @@ -230,12 +245,14 @@ func (order *OrderBase) Compute() error {
}
goodUsePartnerBonus := decimal.NewFromFloat(order.Goods[i].GoodCompute.UsePartnerBonus)
if goodUsePartnerBonus.GreaterThanOrEqual(decimal.NewFromFloat(0)) {
//货品中存在调整后的合伙人分红,即调整大于等于0
hasUsePartnerBonus = true
usePartnerBonus = usePartnerBonus.Add(goodUsePartnerBonus)
} else {
usePartnerBonus = usePartnerBonus.Add(decimal.NewFromFloat(order.Goods[i].GoodCompute.PlanPartnerBonus))
}
if order.Goods[i].UseGoodNumber >= 0 {
//货品中存在调整后的数量,调整值大于等于0
HasUseOrderCount = true
useOrderCount += order.Goods[i].UseGoodNumber
} else {
... ... @@ -256,6 +273,7 @@ func (order *OrderBase) Compute() error {
if hasUsePartnerBonus {
order.OrderCompute.UsePartnerBonus, _ = usePartnerBonus.Round(2).BigFloat().Float64()
} else {
//订单中的货品列表中合伙人分成没有调整值的情况下,对订单的调整值设置为负值用以标识
order.OrderCompute.UsePartnerBonus = -1
}
if hasUseOrderAmount {
... ... @@ -266,6 +284,7 @@ func (order *OrderBase) Compute() error {
Div(decimal.NewFromInt(100)).
Round(2).BigFloat().Float64()
} else {
//订单中的货品列表中货品总金额没有调整值的情况下,对订单的调整值设置为负值用以标识
order.OrderCompute.UseOrderAmount = -1
order.OrderCompute.SalesmanBonus, _ = planOrderAmount.
Mul(decimal.NewFromFloat(order.SalesmanBonusPercent)).
... ...
... ... @@ -70,7 +70,7 @@ type OrderGood struct {
UseGoodNumber int `json:"useGoodNumber"`
//货品单价
Price float64 `json:"price"`
//合伙人分红比例
//合伙人分红比例 比如12.7等同于12.7%,使用负值表示分红比例未进行设置
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//分红支付状态
BonusStatus int `json:"bonusStatus"`
... ... @@ -87,6 +87,20 @@ type OrderGood struct {
DataFrom OrderDataFrom `json:"data_from"`
}
//NewOrderGood 初始值设定
func NewOrderGood() OrderGood {
return OrderGood{
UseGoodNumber: -1,
BonusStatus: OrderGoodWaitPay,
PartnerBonusPercent: -1,
GoodCompute: GoodCompute{
UsePartnerBonus: -1,
UseAmount: -1,
},
CurrentBonusStatus: OrderGoodBonusWaitPay{},
}
}
//GetCurrentGoodNumber 获取当前的商品数量
func (good OrderGood) GetCurrentGoodNumber() int {
if good.UseGoodNumber >= 0 {
... ... @@ -111,7 +125,7 @@ func (good OrderGood) GetCurrentPartnerBonus() float64 {
return good.GoodCompute.PlanPartnerBonus
}
//GetCurrentAmount 获取当前的商品合伙人分红
//ModifyOrderGoodNumber 修改货品数量
func (good *OrderGood) ModifyOrderGoodNumber(number int, orderType int) error {
if good.PlanGoodNumber < number {
return fmt.Errorf("修改数量不能大于初始值:%d", good.PlanGoodNumber)
... ... @@ -120,6 +134,7 @@ func (good *OrderGood) ModifyOrderGoodNumber(number int, orderType int) error {
return err
}
//ModifyPertnerBonusPercent 修改货品的分红比例
func (good *OrderGood) ModifyPertnerBonusPercent(percent float64, orderType int) error {
err := good.CurrentBonusStatus.ModifyPertnerBonusPercent(good, percent, orderType)
return err
... ... @@ -162,6 +177,7 @@ type OrderGoodBonusHasPay struct{}
var _ OrderGoodBonusStatus = (*OrderGoodBonusHasPay)(nil)
//WartPayPartnerBonus 货品的支付状态从“待支付”状态变更为“待支付”
func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error {
good.GoodCompute.PartnerBonusExpense = 0
good.GoodCompute.PartnerBonusHas = 0
... ... @@ -178,6 +194,7 @@ func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error
return nil
}
//PayPartnerBonus 货品的支付状态从“待支付”状态变更为“已支付”
func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error {
//待支付状态转支付时
//合伙人已收收分红等于合伙人应收分红(或者调整的)
... ... @@ -196,6 +213,7 @@ func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error {
return nil
}
//PayPartnerBonus 货品的支付状态从“已支付”状态变更为“已支付”
func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error {
//已支付的值保持不变
//未支付的值保持不变
... ... @@ -210,10 +228,12 @@ func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error {
return nil
}
//WartPayPartnerBonus 货品的支付状态从“已支付”状态变更为“待支付”
func (hasPay OrderGoodBonusHasPay) WartPayPartnerBonus(good *OrderGood) error {
return errors.New("已支付的货单不能将状态回退为待支付")
}
//ModifyOrderGoodNumber 货品的支付状态为“已支付”状态变时,修改货品数量
func (hasPay OrderGoodBonusHasPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error {
//规则描述:
//实际自建订单(orderType==1),已支付分红状态下“可以”修改货品数量
... ... @@ -233,6 +253,7 @@ func (hasPay OrderGoodBonusHasPay) ModifyOrderGoodNumber(good *OrderGood, number
return nil
}
//ModifyOrderGoodNumber 货品的支付状态为“待支付”状态变时,修改货品数量
func (waitPay OrderGoodBonusWaitPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error {
//规则描述:
//实际自建订单(orderType==1),未支付分红状态下“可以”修改货品数量
... ... @@ -247,6 +268,7 @@ func (waitPay OrderGoodBonusWaitPay) ModifyOrderGoodNumber(good *OrderGood, numb
return nil
}
//ModifyPertnerBonusPercent 货品的支付状态为“待支付”状态变时,修改货品合伙人分红比例
func (waitPay OrderGoodBonusWaitPay) ModifyPertnerBonusPercent(good *OrderGood, percent float64, orderType int) error {
//规则描述:
//实际自建订单(orderType==1),未支付分红状态下“不可以”修改合伙人分红比例
... ... @@ -276,20 +298,6 @@ func (hasPay OrderGoodBonusHasPay) ModifyPertnerBonusPercent(good *OrderGood, pe
return errors.New("已支付分红的货品订单,不能修改合伙人分红比例")
}
//NewOrderGood 初始值设定
func NewOrderGood() OrderGood {
return OrderGood{
UseGoodNumber: -1,
BonusStatus: OrderGoodWaitPay,
PartnerBonusPercent: -1,
GoodCompute: GoodCompute{
UsePartnerBonus: -1,
UseAmount: -1,
},
CurrentBonusStatus: OrderGoodBonusWaitPay{},
}
}
//Compute 数据汇总核算
func (good *OrderGood) Compute() error {
//计算预计货品总值
... ... @@ -299,25 +307,28 @@ func (good *OrderGood) Compute() error {
if good.PlanGoodNumber < 0 {
planGoodNumber = 0
}
planamount := price.Mul(decimal.NewFromInt(int64(planGoodNumber))) //price*planGoodNumber
//计算预计货品总值(planamount), 货品单价*预计货品数量(price*planGoodNumber)
planamount := price.Mul(decimal.NewFromInt(int64(planGoodNumber)))
var partnerBonusPercent float64
if good.PartnerBonusPercent < 0 {
//判断合伙人分成比例是否设置,若未设置则按照 0 来计算分成
partnerBonusPercent = 0
} else {
partnerBonusPercent = good.PartnerBonusPercent
}
//price*useGoodNumber
//计算预计合伙人分红(planPartnerBonus), 预计货品总值*合伙人分成比例/100(planamount*partnerBonusPercent/100)
planPartnerBonus := planamount.Mul(decimal.NewFromFloat(partnerBonusPercent)).Div(decimal.NewFromInt(100)) //price*planGoodNumber*PartnerBonusPercent
//货品预计总值
good.GoodCompute.PlanAmount, _ = planamount.Round(2).BigFloat().Float64()
good.GoodCompute.PlanPartnerBonus, _ = planPartnerBonus.Round(2).BigFloat().Float64()
if good.UseGoodNumber < 0 {
//没有出现数量调整
//没有出现数量调整,使用负值进行标记
good.GoodCompute.UsePartnerBonus = -1
good.GoodCompute.UseAmount = -1
} else {
//计算调整后的货品总值
//计算调整后的合伙人分红
useamount := price.Mul(decimal.NewFromInt(int64(good.UseGoodNumber))) //price*useGoodNumber/price*useGoodNumber
useamount := price.Mul(decimal.NewFromInt(int64(good.UseGoodNumber)))
//计算调整后的合伙人分红 //price*useGoodNumber/price*useGoodNumber
usePartnerBonus := useamount.Mul(decimal.NewFromFloat(partnerBonusPercent)).Div(decimal.NewFromInt(100)) //price*useGoodNumber*PartnerBonusPercent
good.GoodCompute.UsePartnerBonus, _ = usePartnerBonus.Round(2).BigFloat().Float64()
good.GoodCompute.UseAmount, _ = useamount.Round(2).BigFloat().Float64()
... ...
... ... @@ -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+"%")
... ... @@ -159,7 +128,7 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer
err error
partnerReturn = make([]domain.PartnerInfo, 0)
)
query = query.Order("id DESC")
query = query.Order("create_at DESC")
err = query.Select()
if err != nil {
return partnerReturn, err
... ... @@ -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 // 移除合伙人
* @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,14 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
//用与适配前端定义的数据结构
type Parameter struct {
ID int64 `json:"id"`
PartnerType []int64 `json:"partnerType"`
PartnerName string `json:"partnerName"`
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
... ... @@ -129,6 +133,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
companyId := c.GetUserCompany()
cmd := partnerInfoCmd.UpdatePartnerInfoCommand{
Id: param.ID,
PartnerName: param.PartnerName,
Status: param.State,
PartnerCategory: param.PartnerType,
CooperateTime: cooperateTime,
... ... @@ -142,6 +147,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
},
},
CompanyId: companyId,
Remark: param.Remark,
}
serve := partnerInfoService.NewPartnerInfoService(nil)
err = serve.UpdatePartnerInfo(&cmd)
... ... @@ -190,16 +196,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 +216,40 @@ func (c *PartnerInfoController) GetPartnerInfo() {
return
}
/**
* @Author SteveChan
* @Description // 移除合伙人
* @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 +266,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 +298,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 +322,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 +336,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 +351,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
... ... @@ -316,6 +359,9 @@ func (c *PartnerInfoController) ListPartnerInfo() {
}
resp = append(resp, m)
}
if len(resp) == 0 {
resp = []map[string]interface{}{}
}
c.ResponsePageList(resp, count, param.PageNumber)
return
}
... ...
... ... @@ -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
... ...
此 diff 太大无法显示。
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
... ...