作者 Administrator

合并分支 'test' 到 'master'

Test



查看合并请求 !91
... ... @@ -387,6 +387,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
CooperationProjectId: cooperationProject.CooperationProjectId,
}
// 共创合约仓储初始化
... ...
... ... @@ -67,6 +67,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
res, err = statisticsService.PersonCooperationProjectSharedInfo(contractStatisticsQuery.QueryOptions)
case domain_service.PersonCooperationProjectSharedInfoAttachment:
res, err = statisticsService.PersonCooperationProjectSharedInfoAttachment(contractStatisticsQuery.QueryOptions)
case domain_service.PersonCooperationCompany:
res, err = statisticsService.PersonCooperationCompany(contractStatisticsQuery.QueryOptions)
case domain_service.CreditAccountStatistics:
res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.RelevantCooperationContractNumbers:
... ...
... ... @@ -12,13 +12,13 @@ type GetCreditAccountQuery struct {
// 账期结算单ID
CreditAccountId int64 `cname:"账期结算单ID" json:"creditAccountId" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId" valid:"Required"`
OrgId int64 `cname:"组织机构ID" json:"orgId"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID" json:"userId" valid:"Required"`
UserId int64 `cname:"用户ID" json:"userId"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId" valid:"Required"`
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId"`
}
func (getCreditAccountQuery *GetCreditAccountQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -77,6 +77,8 @@ type CooperationContract struct {
DeletedAt time.Time `json:"deletedAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 共创项目编号
CooperationProjectId int64 `json:"cooperationProjectId"`
}
type CooperationContractRepository interface {
... ... @@ -175,3 +177,20 @@ func (cooperationContract *CooperationContract) MoneyIncentivesRuleSliceEqualBCE
}
return true
}
func CooperationContractsToProjectIds(contracts []*CooperationContract) []int64 {
var projectIds = make([]int64, 0)
for i := range contracts {
var exist = false
for j := range projectIds {
if contracts[i].CooperationProjectId == projectIds[j] {
exist = true
break
}
}
if !exist {
projectIds = append(projectIds, contracts[i].CooperationProjectId)
}
}
return projectIds
}
... ...
... ... @@ -49,6 +49,8 @@ type ContractParticipant struct {
ContractContent string `json:"contractContent"`
// 支付凭证
PaymentDocument string `json:"paymentDocument"`
// 支付凭证
PaymentDocuments []*Attachment `json:"paymentDocuments"`
// 敏感标识
SensitiveFlag bool `json:"sensitiveFlag"`
// 共创合约编号
... ... @@ -76,9 +78,10 @@ func (ut *Salesman) ToUser() *User {
func NewContractParticipant(u *User, primaryKey string, attachments []*Attachment) *ContractParticipant {
p := &ContractParticipant{
User: u,
Participant: u.SimpleCopy(),
primaryKey: primaryKey,
User: u,
Participant: u.SimpleCopy(),
primaryKey: primaryKey,
PaymentDocuments: make([]*Attachment, 0),
}
if len(attachments) > 0 {
p.ContractContent = attachments[0].Name
... ...
... ... @@ -91,3 +91,28 @@ func (cooperationProject *CooperationProject) Update(data map[string]interface{}
cooperationProject.UpdatedAt = time.Now()
return nil
}
func CooperationProjectsToMap(queryOptions map[string]interface{}, find func(queryOptions map[string]interface{}) (int64, []*CooperationProject, error)) (map[int64]*CooperationProject, error) {
var result = make(map[int64]*CooperationProject)
_, projects, err := find(queryOptions)
if err != nil {
return nil, err
}
for i := range projects {
result[projects[i].CooperationProjectId] = projects[i]
}
return result, nil
}
func (cooperationProject *CooperationProject) CloneSimple() interface{} {
var mapResult = map[string]interface{}{
"cooperationProjectId": cooperationProject.CooperationProjectId,
"cooperationProjectName": cooperationProject.CooperationProjectName,
"cooperationProjectDescription": cooperationProject.CooperationProjectDescription,
"updatedAt": cooperationProject.UpdatedAt.Unix() * 1000,
}
if cooperationProject.UpdatedAt.Unix() < 0 {
mapResult["updatedAt"] = cooperationProject.CreatedAt.Unix() * 1000
}
return mapResult
}
... ...
... ... @@ -271,15 +271,6 @@ func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfo(quer
key := keyfun(u.CooperationContractNumber, u.Undertaker.UserBaseId)
userSorted = append(userSorted, key)
mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.ToUser(), key, u.Undertaker.ContractAttachment)
//if u.Undertaker.Referrer != nil {
// key = keyfun(u.CooperationContractNumber, u.Undertaker.Referrer.UserBaseId)
// userSorted = append(userSorted, key)
// mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.Referrer.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.Referrer.ToUser(), key, u.Undertaker.ContractAttachment)
//}
//if u.Undertaker.Salesman != nil {
// userSorted = append(userSorted, keyfun(u.CooperationContractNumber, u.Undertaker.Salesman.UserBaseId))
// mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.Salesman.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.Salesman.ToUser(), key, u.Undertaker.ContractAttachment)
//}
}
// 2.合约的订单金额
... ... @@ -325,10 +316,11 @@ func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfo(quer
detail := creditAccounts[i].AccountDetail[j]
key := keyfun(detail.CooperationContractNumber, creditAccounts[i].Participator.UserBaseId)
mapCreditAccount[key] = creditAccounts[i]
if v, ok := mapUser[key]; ok && len(v.PaymentDocument) == 0 {
if len(mapCreditAccount[key].PaymentDocumentAttachments) > 0 {
if v, ok := mapUser[key]; ok {
if len(v.PaymentDocument) == 0 && len(mapCreditAccount[key].PaymentDocumentAttachments) > 0 {
v.PaymentDocument = "查看"
}
v.PaymentDocuments = append(v.PaymentDocuments, creditAccounts[i].PaymentDocumentAttachments...)
}
}
}
... ... @@ -531,3 +523,42 @@ func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfoAttac
return response, nil
}
// 个人 - 共创企业
func (ptr *CooperationStatisticsService) PersonCooperationCompany(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
UserBaseId int64 `json:"userBaseId"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
var response = struct {
OrgIds []int64 `json:"orgIds"`
}{
OrgIds: make([]int64, 0),
}
undertakerDao, _ := dao.NewCooperationContractUndertakerDao(ptr.transactionContext)
_, undertakers, _ := undertakerDao.Find(map[string]interface{}{"userBaseId": request.UserBaseId, "offsetLimit": false})
contractIds := make([]int64, 0)
if len(undertakers) == 0 {
return response, nil
}
for i := range undertakers {
contractIds = append(contractIds, undertakers[i].CooperationContractId)
}
var mapOrg = make(map[int64]int64)
contractDao, _ := dao.NewCooperationContractDao(ptr.transactionContext)
_, contracts, err := contractDao.Find(map[string]interface{}{"cooperationContractIds": contractIds})
if err != nil {
return nil, err
}
for i := range contracts {
orgId := contracts[i].Org.OrgId
if _, ok := mapOrg[orgId]; !ok {
response.OrgIds = append(response.OrgIds, orgId)
mapOrg[orgId] = orgId
}
}
return response, nil
}
... ...
... ... @@ -47,6 +47,8 @@ const (
PersonCooperationProjectSharedInfo = "PersonCooperationProjectSharedInfo"
// 个人 - 共创项目共享信息数据 - 附件
PersonCooperationProjectSharedInfoAttachment = "PersonCooperationProjectSharedInfoAttachment"
// 个人 - 共创企业
PersonCooperationCompany = "PersonCooperationCompany"
// 账期结算单统计
CreditAccountStatistics = "CreditAccountStatistics"
... ... @@ -107,6 +109,18 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma
return nil, err
}
// 1.1 个人返回合约对应的项目
var mapProject = make(map[int64]*domain.CooperationProject)
var projectIds = domain.CooperationContractsToProjectIds(contracts)
if request.UserBaseId > 0 && len(projectIds) > 0 {
cooperationProjectRepository, _ := repository.NewCooperationProjectRepository(ptr.transactionContext)
mapProject, err = domain.CooperationProjectsToMap(map[string]interface{}{"cooperationProjectIds": projectIds}, cooperationProjectRepository.Find)
if err != nil {
return nil, err
}
}
// 2.根据合约查询分红预算
orderGoodDao, _ := dao.NewDividendsOrderDao(ptr.transactionContext)
dividendsEstimateDao, _ := dao.NewDividendsEstimateDao(ptr.transactionContext)
... ... @@ -123,20 +137,12 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma
}
resultItem.DividendsOrderAmount, _ = orderGoodDao.CalculateGoodOrderAmount(map[string]interface{}{"orgId": request.OrgId, "cooperationContractNumbers": []string{item.CooperationContractNumber}})
resultItem.DividendsAmount, _ = dividendsEstimateDao.CountDividendsEstimateDividendsAmount(map[string]interface{}{"orgId": request.OrgId, "userBaseId": request.UserBaseId, "cooperationContractNumbers": []string{item.CooperationContractNumber}})
if v, ok := mapProject[item.CooperationProjectId]; ok {
resultItem.Project = v.CloneSimple()
}
results = append(results, resultItem)
numbers = append(numbers, item.CooperationContractNumber)
}
//mapCreditAccount, err := ptr.getContractsCreditAccount(numbers)
//if err != nil {
// return nil, err
//}
//for i := range results {
// if v, ok := mapCreditAccount[results[i].CooperationContractNumber]; ok {
// results[i].DividendsAmount = v.SettlementAmount
// results[i].DividendsOrderAmount = v.GoodAmountCount
// }
//}
return results, nil
}
... ... @@ -273,6 +279,8 @@ type searchContractDividendsResult struct {
DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
// 创建时间
CreatedAt int64 `json:"createdAt"`
// 共创项目数据
Project interface{} `json:"project"`
}
/*1.2 分红合约详情*/
... ... @@ -306,7 +314,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
if err != nil {
return nil, err
}
res["cooperationContract"] = map[string]interface{}{
mapContract := map[string]interface{}{
"cooperationContractDescription": contract.CooperationContractDescription,
"cooperationContractId": contract.CooperationContractId,
"cooperationContractName": contract.CooperationContractName,
... ... @@ -314,21 +322,36 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
"createdAt": contract.CreatedAt.Unix() * 1000,
"status": contract.Status,
}
if request.UserBaseId > 0 {
// 1.1.合约第一条合同的附件
undertakerRepository, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
_, undertakers, err := undertakerRepository.Find(map[string]interface{}{"cooperationContractId": contract.CooperationContractId, "userBaseId": request.UserBaseId, "companyId": contract.Company.CompanyId, "orgId": contract.Org.OrgId, "offsetLimit": false})
if err != nil {
return nil, err
}
for i := range undertakers {
if len(undertakers[i].Undertaker.ContractAttachment) > 0 && len(undertakers[i].Undertaker.ContractAttachment[0].Url) > 0 {
mapContract["contractAttachment"] = undertakers[i].Undertaker.ContractAttachment[0]
}
}
}
res["cooperationContract"] = mapContract
// 2.合约分红列表
creditAccountRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
queryOptions["cooperationContractNumber"] = contract.CooperationContractNumber
queryOptions["orgId"] = contract.Org.OrgId
queryOptions["isCanceled"] = false
_, creditAccounts, err := creditAccountRepository.Find(queryOptions)
_, dividendsEstimates, err := dividendsEstimateRepository.Find(queryOptions)
if err != nil {
return res, err
}
// 3.取订单商品列表
var orderGoodIds []int64
for i := range creditAccounts {
a := creditAccounts[i]
for i := range dividendsEstimates {
a := dividendsEstimates[i]
orderGoodIds = append(orderGoodIds, a.OrderGoodId)
}
var mapOrderGoods = make(map[int64]*domain.OrderGood)
... ... @@ -344,18 +367,18 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
}
var dividends = make([]interface{}, 0)
for i := range creditAccounts {
a := creditAccounts[i]
for i := range dividendsEstimates {
a := dividendsEstimates[i]
// 个人查看的时候只查看自己的分红明细
//if request.UserBaseId!=0 && a.DividendsUser.UserBaseId!=request.UserBaseId{
// continue
//}
item := map[string]interface{}{
"creditAccountId": a.DividendsEstimateId,
"orderGoodName": "",
"dividendsType": a.DividendsType,
"dividendsRatio": 0,
"dividendsAmount": a.DividendsAmount,
"dividendsEstimateId": a.DividendsEstimateId,
"orderGoodName": "",
"dividendsType": a.DividendsType,
"dividendsRatio": 0,
"dividendsAmount": a.DividendsAmount,
"dividendsUser": map[string]interface{}{
"userInfo": a.DividendsUser.UserInfo,
"userId": a.DividendsUser.UserId,
... ... @@ -364,6 +387,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
"dividendsAccountStatus": a.DividendsAccountStatus,
"dividendsEstimateTime": a.CreatedAt.Unix() * 1000,
"orderOrReturnedOrderNum": a.DividendsEstimateOrderNumber,
"creditAccountId": a.CreditAccountId,
}
if a.PaymentStatus == 2 {
item["dividendsAccountStatus"] = 3
... ...
... ... @@ -43,4 +43,6 @@ type CooperationContract struct {
DeletedAt time.Time `comment:"删除时间" pg:",soft_delete"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 共创项目编号
CooperationProjectId int64 `comment:"共创项目编号"`
}
... ...
... ... @@ -134,5 +134,6 @@ func TransformToCooperationContractDomainModelFromPgModels(
CreatedAt: cooperationContractModel.CreatedAt,
DeletedAt: cooperationContractModel.DeletedAt,
UpdatedAt: cooperationContractModel.UpdatedAt,
CooperationProjectId: cooperationContractModel.CooperationProjectId,
}, nil
}
... ...
... ... @@ -44,6 +44,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
"created_at",
"deleted_at",
"updated_at",
"cooperation_project_id",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
... ... @@ -78,6 +79,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
&cooperationContract.CreatedAt,
&cooperationContract.DeletedAt,
&cooperationContract.UpdatedAt,
&cooperationContract.CooperationProjectId,
),
fmt.Sprintf("INSERT INTO cooperation_contracts (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
cooperationContract.CooperationContractId,
... ... @@ -98,6 +100,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.CreatedAt,
nil,
cooperationContract.UpdatedAt,
cooperationContract.CooperationProjectId,
); err != nil {
return cooperationContract, err
}
... ... @@ -277,6 +280,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
&cooperationContract.CreatedAt,
&cooperationContract.DeletedAt,
&cooperationContract.UpdatedAt,
&cooperationContract.CooperationProjectId,
),
fmt.Sprintf("UPDATE cooperation_contracts SET %s WHERE cooperation_contract_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
cooperationContract.CooperationContractId,
... ... @@ -297,6 +301,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.CreatedAt,
nil,
cooperationContract.UpdatedAt,
cooperationContract.CooperationProjectId,
cooperationContract.Identify(),
); err != nil {
return cooperationContract, err
... ...
... ... @@ -183,6 +183,9 @@ func (repository *CooperationContractUndertakerRepository) Find(queryOptions map
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions)
if cooperationContractId, ok := queryOptions["cooperationContractId"]; ok && cooperationContractId.(int64) != 0 {
query.Where("cooperation_contract_id = ? ", cooperationContractId)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
... ...