|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/command"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/query"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
|
|
)
|
|
|
|
|
|
type BusinessBonusService struct {
|
|
|
}
|
|
|
|
...
|
...
|
@@ -20,160 +9,160 @@ func NewBusinessBonusService(option map[string]interface{}) *BusinessBonusServic |
|
|
}
|
|
|
|
|
|
// ListBusinessBonus 列表
|
|
|
func (srv BusinessBonusService) ListBusinessBonus(queryOption query.ListBusinessBonusQuery) (int, interface{}, error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return 0, nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
// func (srv BusinessBonusService) ListBusinessBonus(queryOption query.ListBusinessBonusQuery) (int, interface{}, error) {
|
|
|
// var (
|
|
|
// transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
// err error
|
|
|
// )
|
|
|
// if err = transactionContext.StartTransaction(); err != nil {
|
|
|
// return 0, nil, err
|
|
|
// }
|
|
|
// defer func() {
|
|
|
// transactionContext.RollbackTransaction()
|
|
|
// }()
|
|
|
|
|
|
var (
|
|
|
bonusDaoao *dao.BusinessBonusDao
|
|
|
)
|
|
|
if bonusDaoao, err = factory.CreateBusinessBonusDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
result, err := bonusDaoao.SearchBusinessBonus(queryOption.PartnerId, queryOption.PartnerNameMatch,
|
|
|
queryOption.CompanyId, queryOption.Limit, queryOption.Offset)
|
|
|
if err != nil {
|
|
|
return 0, nil, err
|
|
|
}
|
|
|
cnt, err := bonusDaoao.CountBusinessBonus(queryOption.PartnerId, queryOption.PartnerNameMatch,
|
|
|
queryOption.CompanyId, queryOption.Limit, queryOption.Offset)
|
|
|
if err != nil {
|
|
|
return 0, nil, err
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
// var (
|
|
|
// bonusDaoao *dao.BusinessBonusDao
|
|
|
// )
|
|
|
// if bonusDaoao, err = factory.CreateBusinessBonusDao(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
// }); err != nil {
|
|
|
// return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
// }
|
|
|
// result, err := bonusDaoao.SearchBusinessBonus(queryOption.PartnerId, queryOption.PartnerNameMatch,
|
|
|
// queryOption.CompanyId, queryOption.Limit, queryOption.Offset)
|
|
|
// if err != nil {
|
|
|
// return 0, nil, err
|
|
|
// }
|
|
|
// cnt, err := bonusDaoao.CountBusinessBonus(queryOption.PartnerId, queryOption.PartnerNameMatch,
|
|
|
// queryOption.CompanyId, queryOption.Limit, queryOption.Offset)
|
|
|
// if err != nil {
|
|
|
// return 0, nil, err
|
|
|
// }
|
|
|
// err = transactionContext.CommitTransaction()
|
|
|
|
|
|
returnData := []map[string]interface{}{}
|
|
|
for _, v := range result {
|
|
|
m := map[string]interface{}{
|
|
|
"id": v.Id,
|
|
|
"uncollectedDividends": v.BonusNot,
|
|
|
"receiveDividends": v.BonusHas,
|
|
|
"dividendsReceivable": v.Bonus,
|
|
|
"stateOfPayment": v.BonusStatus,
|
|
|
"stateOfPaymentName": domain.DescribeBusinessBonusStatus(v.BonusStatus),
|
|
|
"partner": v.PartnerName,
|
|
|
"updateTime": "",
|
|
|
}
|
|
|
if !v.UpdateAt.IsZero() {
|
|
|
m["updateTime"] = v.UpdateAt.Local().Format("2006-01-02 15:04:05")
|
|
|
}
|
|
|
returnData = append(returnData, m)
|
|
|
}
|
|
|
return cnt, returnData, nil
|
|
|
}
|
|
|
// returnData := []map[string]interface{}{}
|
|
|
// for _, v := range result {
|
|
|
// m := map[string]interface{}{
|
|
|
// "id": v.Id,
|
|
|
// "uncollectedDividends": v.BonusNot,
|
|
|
// "receiveDividends": v.BonusHas,
|
|
|
// "dividendsReceivable": v.Bonus,
|
|
|
// "stateOfPayment": v.BonusStatus,
|
|
|
// "stateOfPaymentName": domain.DescribeBusinessBonusStatus(v.BonusStatus),
|
|
|
// "partner": v.PartnerName,
|
|
|
// "updateTime": "",
|
|
|
// }
|
|
|
// if !v.UpdateAt.IsZero() {
|
|
|
// m["updateTime"] = v.UpdateAt.Local().Format("2006-01-02 15:04:05")
|
|
|
// }
|
|
|
// returnData = append(returnData, m)
|
|
|
// }
|
|
|
// return cnt, returnData, nil
|
|
|
// }
|
|
|
|
|
|
func (srv BusinessBonusService) UpdateBusinessBonus(cmd command.UpdateBusinessBonusCommand) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
bonusRespository domain.BusinessBonusRepository
|
|
|
bonusData *domain.BusinessBonus
|
|
|
)
|
|
|
if bonusRespository, err = factory.CreateBusinessBonusRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
bonusData, err = bonusRespository.FindOne(domain.BusinessBonusFindOneQuery{
|
|
|
Id: cmd.Id, CompanyId: cmd.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取业务分红(id=%d;company_id=%d)数据失败:%s", cmd.Id, cmd.CompanyId, err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
bonusData.Bonus = cmd.Bonus
|
|
|
switch cmd.BonusStatus {
|
|
|
case domain.BUSINESS_BONUS_HAS_PAY:
|
|
|
bonusData.BusinessBonusPayStatus.PayPartnerBonus(bonusData)
|
|
|
case domain.BUSINESS_BONUS_WAIT_PAY:
|
|
|
bonusData.BusinessBonusPayStatus.WartPayPartnerBonus(bonusData)
|
|
|
case domain.BUSINESS_BONUS_NULL_PAY:
|
|
|
bonusData.BusinessBonusPayStatus.NullPayPartnerBonus(bonusData)
|
|
|
default:
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "支付状态错误")
|
|
|
}
|
|
|
err = bonusRespository.Edit(bonusData)
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("更新业务分红(id=%d)数据失败:%s", bonusData.Id, err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return nil
|
|
|
}
|
|
|
// func (srv BusinessBonusService) UpdateBusinessBonus(cmd command.UpdateBusinessBonusCommand) error {
|
|
|
// var (
|
|
|
// transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
// err error
|
|
|
// )
|
|
|
// if err = transactionContext.StartTransaction(); err != nil {
|
|
|
// return err
|
|
|
// }
|
|
|
// defer func() {
|
|
|
// transactionContext.RollbackTransaction()
|
|
|
// }()
|
|
|
// var (
|
|
|
// bonusRespository domain.BusinessBonusRepository
|
|
|
// bonusData *domain.BusinessBonus
|
|
|
// )
|
|
|
// if bonusRespository, err = factory.CreateBusinessBonusRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
// }); err != nil {
|
|
|
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// }
|
|
|
// bonusData, err = bonusRespository.FindOne(domain.BusinessBonusFindOneQuery{
|
|
|
// Id: cmd.Id, CompanyId: cmd.CompanyId,
|
|
|
// })
|
|
|
// if err != nil {
|
|
|
// e := fmt.Sprintf("获取业务分红(id=%d;company_id=%d)数据失败:%s", cmd.Id, cmd.CompanyId, err)
|
|
|
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
// }
|
|
|
// bonusData.Bonus = cmd.Bonus
|
|
|
// switch cmd.BonusStatus {
|
|
|
// case domain.BUSINESS_BONUS_HAS_PAY:
|
|
|
// bonusData.BusinessBonusPayStatus.PayPartnerBonus(bonusData)
|
|
|
// case domain.BUSINESS_BONUS_WAIT_PAY:
|
|
|
// bonusData.BusinessBonusPayStatus.WartPayPartnerBonus(bonusData)
|
|
|
// case domain.BUSINESS_BONUS_NULL_PAY:
|
|
|
// bonusData.BusinessBonusPayStatus.NullPayPartnerBonus(bonusData)
|
|
|
// default:
|
|
|
// return lib.ThrowError(lib.BUSINESS_ERROR, "支付状态错误")
|
|
|
// }
|
|
|
// err = bonusRespository.Edit(bonusData)
|
|
|
// if err != nil {
|
|
|
// e := fmt.Sprintf("更新业务分红(id=%d)数据失败:%s", bonusData.Id, err)
|
|
|
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
// }
|
|
|
// err = transactionContext.CommitTransaction()
|
|
|
// return nil
|
|
|
// }
|
|
|
|
|
|
//GetBusinessBonus 获取详情
|
|
|
func (srv BusinessBonusService) GetBusinessBonus(queryOption query.GetBusinessBonusQuery) (map[string]interface{}, error) {
|
|
|
// func (srv BusinessBonusService) GetBusinessBonus(queryOption query.GetBusinessBonusQuery) (map[string]interface{}, error) {
|
|
|
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
bonusRespository domain.BusinessBonusRepository
|
|
|
partnerInfoRepository domain.PartnerInfoRepository
|
|
|
bonusData *domain.BusinessBonus
|
|
|
partnerData *domain.PartnerInfo
|
|
|
)
|
|
|
if bonusRespository, err = factory.CreateBusinessBonusRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
bonusData, err = bonusRespository.FindOne(domain.BusinessBonusFindOneQuery{
|
|
|
Id: queryOption.Id, CompanyId: queryOption.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取业务分红(id=%d;company_id=%d)数据失败:%s", queryOption.Id, queryOption.CompanyId, err)
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
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: bonusData.PartnerInfoId})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取合伙人(id=%d)数据失败:%s", bonusData.PartnerInfoId, err)
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
returnData := map[string]interface{}{
|
|
|
"partner": partnerData.Partner.PartnerName,
|
|
|
"dividendsReceivable": bonusData.Bonus,
|
|
|
"receiveDividends": bonusData.BonusHas,
|
|
|
"uncollectedDividends": bonusData.BonusNot,
|
|
|
"updateTime": "",
|
|
|
"stateOfPayment": bonusData.BonusStatus,
|
|
|
"stateOfPaymentName": domain.DescribeBusinessBonusStatus(bonusData.BonusStatus),
|
|
|
"id": bonusData.Id,
|
|
|
}
|
|
|
if !bonusData.UpdateAt.IsZero() {
|
|
|
returnData["updateTime"] = bonusData.UpdateAt.Local().Format("2006-01-02 15:04:05")
|
|
|
}
|
|
|
// var (
|
|
|
// transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
// err error
|
|
|
// )
|
|
|
// if err = transactionContext.StartTransaction(); err != nil {
|
|
|
// return nil, err
|
|
|
// }
|
|
|
// defer func() {
|
|
|
// transactionContext.RollbackTransaction()
|
|
|
// }()
|
|
|
// var (
|
|
|
// bonusRespository domain.BusinessBonusRepository
|
|
|
// partnerInfoRepository domain.PartnerInfoRepository
|
|
|
// bonusData *domain.BusinessBonus
|
|
|
// partnerData *domain.PartnerInfo
|
|
|
// )
|
|
|
// if bonusRespository, err = factory.CreateBusinessBonusRepository(map[string]interface{}{
|
|
|
// "transactionContext": transactionContext,
|
|
|
// }); err != nil {
|
|
|
// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// }
|
|
|
// bonusData, err = bonusRespository.FindOne(domain.BusinessBonusFindOneQuery{
|
|
|
// Id: queryOption.Id, CompanyId: queryOption.CompanyId,
|
|
|
// })
|
|
|
// if err != nil {
|
|
|
// e := fmt.Sprintf("获取业务分红(id=%d;company_id=%d)数据失败:%s", queryOption.Id, queryOption.CompanyId, err)
|
|
|
// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
// }
|
|
|
// 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: bonusData.PartnerInfoId})
|
|
|
// if err != nil {
|
|
|
// e := fmt.Sprintf("获取合伙人(id=%d)数据失败:%s", bonusData.PartnerInfoId, err)
|
|
|
// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
// }
|
|
|
// err = transactionContext.CommitTransaction()
|
|
|
// returnData := map[string]interface{}{
|
|
|
// "partner": partnerData.Partner.PartnerName,
|
|
|
// "dividendsReceivable": bonusData.Bonus,
|
|
|
// "receiveDividends": bonusData.BonusHas,
|
|
|
// "uncollectedDividends": bonusData.BonusNot,
|
|
|
// "updateTime": "",
|
|
|
// "stateOfPayment": bonusData.BonusStatus,
|
|
|
// "stateOfPaymentName": domain.DescribeBusinessBonusStatus(bonusData.BonusStatus),
|
|
|
// "id": bonusData.Id,
|
|
|
// }
|
|
|
// if !bonusData.UpdateAt.IsZero() {
|
|
|
// returnData["updateTime"] = bonusData.UpdateAt.Local().Format("2006-01-02 15:04:05")
|
|
|
// }
|
|
|
|
|
|
return returnData, nil
|
|
|
} |
|
|
// return returnData, nil
|
|
|
// } |
...
|
...
|
|