正在显示
12 个修改的文件
包含
516 行增加
和
5 行删除
| 1 | package command | 1 | package command |
| 2 | 2 | ||
| 3 | type UpdateBusinessBonusCommand struct { | 3 | type UpdateBusinessBonusCommand struct { |
| 4 | + Id int64 `json:"id"` | ||
| 5 | + Bonus float64 `json:"bonus"` | ||
| 6 | + BonusStatus int8 `json:"bonusStatus"` | ||
| 7 | + CompanyId int64 `json:"companyId"` | ||
| 4 | } | 8 | } |
| 5 | 9 | ||
| 6 | func (cmd UpdateBusinessBonusCommand) ValidateCommand() error { | 10 | func (cmd UpdateBusinessBonusCommand) ValidateCommand() error { |
| 1 | +package query | ||
| 2 | + | ||
| 3 | +type ListBusinessBonusQuery struct { | ||
| 4 | + | ||
| 5 | + //用户名称匹配 | ||
| 6 | + PartnerNameMatch string `json:"userNameMatch" ` | ||
| 7 | + // 查询偏离量 | ||
| 8 | + Offset int `json:"offset" ` | ||
| 9 | + // 查询限制 | ||
| 10 | + Limit int `json:"limit"` | ||
| 11 | + PartnerId int64 `json:"partnerId"` | ||
| 12 | + CompanyId int64 `json:"companyId"` | ||
| 13 | +} |
| 1 | package service | 1 | package service |
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/command" | ||
| 7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/query" | ||
| 8 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" | ||
| 9 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
| 10 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao" | ||
| 11 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type BusinessBonusService struct { | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +func NewBusinessBonusService(option map[string]interface{}) *BusinessBonusService { | ||
| 18 | + newService := new(BusinessBonusService) | ||
| 19 | + return newService | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func (srv BusinessBonusService) ListBusinessBonus(queryOption query.ListBusinessBonusQuery) (int, interface{}, error) { | ||
| 23 | + var ( | ||
| 24 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 25 | + err error | ||
| 26 | + ) | ||
| 27 | + if err = transactionContext.StartTransaction(); err != nil { | ||
| 28 | + return 0, nil, err | ||
| 29 | + } | ||
| 30 | + defer func() { | ||
| 31 | + transactionContext.RollbackTransaction() | ||
| 32 | + }() | ||
| 33 | + | ||
| 34 | + var ( | ||
| 35 | + bonusDaoao *dao.BusinessBonusDao | ||
| 36 | + ) | ||
| 37 | + if bonusDaoao, err = factory.CreateBusinessBonusDao(map[string]interface{}{ | ||
| 38 | + "transactionContext": transactionContext, | ||
| 39 | + }); err != nil { | ||
| 40 | + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
| 41 | + } | ||
| 42 | + result, err := bonusDaoao.SearchBusinessBonus(queryOption.PartnerId, queryOption.PartnerNameMatch, | ||
| 43 | + queryOption.CompanyId, queryOption.Limit, queryOption.Offset) | ||
| 44 | + if err != nil { | ||
| 45 | + return 0, nil, err | ||
| 46 | + } | ||
| 47 | + err = transactionContext.CommitTransaction() | ||
| 48 | + | ||
| 49 | + returnData := []map[string]interface{}{} | ||
| 50 | + for _, v := range result { | ||
| 51 | + m := map[string]interface{}{ | ||
| 52 | + "id": v.Id, | ||
| 53 | + "uncollectedDividends": v.BonusNot, | ||
| 54 | + "receiveDividends": v.BonusHas, | ||
| 55 | + "dividendsReceivable": v.Bonus, | ||
| 56 | + "stateOfPayment": v.BonusStatus, | ||
| 57 | + "stateOfPaymentName": domain.DescribeBusinessBonusStatus(v.BonusStatus), | ||
| 58 | + "partner": v.PartnerName, | ||
| 59 | + "updateTime": v.UpdateAt.Format("2006-01-02 15:04:05"), | ||
| 60 | + } | ||
| 61 | + returnData = append(returnData, m) | ||
| 62 | + } | ||
| 63 | + return 0, returnData, nil | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +func (srv BusinessBonusService) UpdateBusinessBonus(cmd command.UpdateBusinessBonusCommand) error { | ||
| 67 | + var ( | ||
| 68 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 69 | + err error | ||
| 70 | + ) | ||
| 71 | + if err = transactionContext.StartTransaction(); err != nil { | ||
| 72 | + return err | ||
| 73 | + } | ||
| 74 | + defer func() { | ||
| 75 | + transactionContext.RollbackTransaction() | ||
| 76 | + }() | ||
| 77 | + var ( | ||
| 78 | + bonusRespository domain.BusinessBonusRepository | ||
| 79 | + bonusData *domain.BusinessBonus | ||
| 80 | + ) | ||
| 81 | + if bonusRespository, err = factory.CreateBusinessBonusRepository(map[string]interface{}{ | ||
| 82 | + "transactionContext": transactionContext, | ||
| 83 | + }); err != nil { | ||
| 84 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 85 | + } | ||
| 86 | + bonusData, err = bonusRespository.FindOne(domain.BusinessBonusFindOneQuery{ | ||
| 87 | + Id: cmd.Id, CompanyId: cmd.CompanyId, | ||
| 88 | + }) | ||
| 89 | + if err != nil { | ||
| 90 | + e := fmt.Sprintf("获取业务分红(id=%d;company_id=%d)数据失败:%s", cmd.Id, cmd.CompanyId, err) | ||
| 91 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) | ||
| 92 | + } | ||
| 93 | + bonusData.Bonus = cmd.Bonus | ||
| 94 | + switch cmd.BonusStatus { | ||
| 95 | + case domain.BUSINESS_BONUS_HAS_PAY: | ||
| 96 | + bonusData.BusinessBonusPayStatus.PayPartnerBonus(bonusData) | ||
| 97 | + case domain.BUSINESS_BONUS_WAIT_PAY: | ||
| 98 | + bonusData.BusinessBonusPayStatus.WartPayPartnerBonus(bonusData) | ||
| 99 | + default: | ||
| 100 | + return lib.ThrowError(lib.BUSINESS_ERROR, "支付状态错误") | ||
| 101 | + } | ||
| 102 | + err = bonusRespository.Edit(bonusData) | ||
| 103 | + if err != nil { | ||
| 104 | + e := fmt.Sprintf("更新业务分行(id=%d)数据失败:%s", bonusData.Id, err) | ||
| 105 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) | ||
| 106 | + } | ||
| 107 | + err = transactionContext.CommitTransaction() | ||
| 108 | + return nil | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +func (srv BusinessBonusService) GetBusinessBonus(queryOption query.GetBusinessBonusQuery) (map[string]interface{}, error) { | ||
| 112 | + | ||
| 113 | + var ( | ||
| 114 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 115 | + err error | ||
| 116 | + ) | ||
| 117 | + if err = transactionContext.StartTransaction(); err != nil { | ||
| 118 | + return nil, err | ||
| 119 | + } | ||
| 120 | + defer func() { | ||
| 121 | + transactionContext.RollbackTransaction() | ||
| 122 | + }() | ||
| 123 | + var ( | ||
| 124 | + bonusRespository domain.BusinessBonusRepository | ||
| 125 | + partnerInfoRepository domain.PartnerInfoRepository | ||
| 126 | + bonusData *domain.BusinessBonus | ||
| 127 | + partnerData *domain.PartnerInfo | ||
| 128 | + ) | ||
| 129 | + if bonusRespository, err = factory.CreateBusinessBonusRepository(map[string]interface{}{ | ||
| 130 | + "transactionContext": transactionContext, | ||
| 131 | + }); err != nil { | ||
| 132 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 133 | + } | ||
| 134 | + bonusData, err = bonusRespository.FindOne(domain.BusinessBonusFindOneQuery{ | ||
| 135 | + Id: queryOption.Id, CompanyId: queryOption.CompanyId, | ||
| 136 | + }) | ||
| 137 | + if err != nil { | ||
| 138 | + e := fmt.Sprintf("获取业务分红(id=%d;company_id=%d)数据失败:%s", queryOption.Id, queryOption.CompanyId, err) | ||
| 139 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) | ||
| 140 | + } | ||
| 141 | + if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ | ||
| 142 | + "transactionContext": transactionContext, | ||
| 143 | + }); err != nil { | ||
| 144 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 145 | + } | ||
| 146 | + partnerData, err = partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: bonusData.PartnerInfoId}) | ||
| 147 | + if err != nil { | ||
| 148 | + e := fmt.Sprintf("获取合伙人(id=%d)数据失败:%s", bonusData.PartnerInfoId, err) | ||
| 149 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) | ||
| 150 | + } | ||
| 151 | + err = transactionContext.CommitTransaction() | ||
| 152 | + returnData := map[string]interface{}{ | ||
| 153 | + "partner": partnerData.Partner.PartnerName, | ||
| 154 | + "dividendsReceivable": bonusData.Bonus, | ||
| 155 | + "receiveDividends": bonusData.BonusHas, | ||
| 156 | + "uncollectedDividends": bonusData.BonusNot, | ||
| 157 | + "updateTime": bonusData.UpdateAt.Format("2006-01-02 15:04:05"), | ||
| 158 | + "stateOfPayment": bonusData.BonusStatus, | ||
| 159 | + "stateOfPaymentName": domain.DescribeBusinessBonusStatus(bonusData.BonusStatus), | ||
| 160 | + "id": bonusData.Id, | ||
| 161 | + } | ||
| 162 | + return returnData, nil | ||
| 163 | +} |
| @@ -36,3 +36,11 @@ func CreateUsersDao(options map[string]interface{}) (*dao.UsersDao, error) { | @@ -36,3 +36,11 @@ func CreateUsersDao(options map[string]interface{}) (*dao.UsersDao, error) { | ||
| 36 | } | 36 | } |
| 37 | return dao.NewUsersDao(transactionContext) | 37 | return dao.NewUsersDao(transactionContext) |
| 38 | } | 38 | } |
| 39 | + | ||
| 40 | +func CreateBusinessBonusDao(options map[string]interface{}) (*dao.BusinessBonusDao, error) { | ||
| 41 | + var transactionContext *transaction.TransactionContext | ||
| 42 | + if value, ok := options["transactionContext"]; ok { | ||
| 43 | + transactionContext = value.(*transaction.TransactionContext) | ||
| 44 | + } | ||
| 45 | + return dao.NewBusinessBonusDao(transactionContext) | ||
| 46 | +} |
| @@ -77,3 +77,12 @@ func CreatePartnerCategoryRepository(options map[string]interface{}) (domain.Par | @@ -77,3 +77,12 @@ func CreatePartnerCategoryRepository(options map[string]interface{}) (domain.Par | ||
| 77 | } | 77 | } |
| 78 | return repository.NewPartnerCategoryRepository(transactionContext) | 78 | return repository.NewPartnerCategoryRepository(transactionContext) |
| 79 | } | 79 | } |
| 80 | + | ||
| 81 | +// CreateBusinessBonusRepository 业务分红 | ||
| 82 | +func CreateBusinessBonusRepository(options map[string]interface{}) (domain.BusinessBonusRepository, error) { | ||
| 83 | + var transactionContext *transaction.TransactionContext | ||
| 84 | + if value, ok := options["transactionContext"]; ok { | ||
| 85 | + transactionContext = value.(*transaction.TransactionContext) | ||
| 86 | + } | ||
| 87 | + return repository.NewBusinessBonusRepository(transactionContext) | ||
| 88 | +} |
| @@ -11,11 +11,32 @@ const ( | @@ -11,11 +11,32 @@ const ( | ||
| 11 | // 分红状态 1:待支付分红 2:已支付分红 | 11 | // 分红状态 1:待支付分红 2:已支付分红 |
| 12 | const ( | 12 | const ( |
| 13 | //待支付 | 13 | //待支付 |
| 14 | - BUSINESS_BONUS_WAIT_PAY int = 1 | 14 | + BUSINESS_BONUS_WAIT_PAY int8 = 1 |
| 15 | //已支付 | 15 | //已支付 |
| 16 | - BUSINESS_BONUS_HAS_PAY int = 2 | 16 | + BUSINESS_BONUS_HAS_PAY int8 = 2 |
| 17 | ) | 17 | ) |
| 18 | 18 | ||
| 19 | +func DescribeBusinessBonusStatus(i int8) string { | ||
| 20 | + m := map[int8]string{ | ||
| 21 | + BUSINESS_BONUS_WAIT_PAY: "待支付分红", | ||
| 22 | + BUSINESS_BONUS_HAS_PAY: "已支付分红", | ||
| 23 | + } | ||
| 24 | + if v, ok := m[i]; ok { | ||
| 25 | + return v | ||
| 26 | + } | ||
| 27 | + return "" | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +//分红状态 | ||
| 31 | +type BusinessBonusBonusStatus interface { | ||
| 32 | + //状态变更为空 | ||
| 33 | + NullPayPartnerBonus(*BusinessBonus) error | ||
| 34 | + //状态变更为待支付 | ||
| 35 | + WartPayPartnerBonus(*BusinessBonus) error | ||
| 36 | + //状态变更为已支付 | ||
| 37 | + PayPartnerBonus(*BusinessBonus) error | ||
| 38 | +} | ||
| 39 | + | ||
| 19 | // 业务分红信息 | 40 | // 业务分红信息 |
| 20 | type BusinessBonus struct { | 41 | type BusinessBonus struct { |
| 21 | // 唯一标识 | 42 | // 唯一标识 |
| @@ -28,6 +49,8 @@ type BusinessBonus struct { | @@ -28,6 +49,8 @@ type BusinessBonus struct { | ||
| 28 | Bonus float64 `json:"bonus"` | 49 | Bonus float64 `json:"bonus"` |
| 29 | // 未收分红 | 50 | // 未收分红 |
| 30 | BonusNot float64 `json:"bonusNot"` | 51 | BonusNot float64 `json:"bonusNot"` |
| 52 | + //已收分红 | ||
| 53 | + BonusHas float64 `json:"bonusHas"` | ||
| 31 | // 分红支出 | 54 | // 分红支出 |
| 32 | BonusExpense float64 `json:"bonusExpense"` | 55 | BonusExpense float64 `json:"bonusExpense"` |
| 33 | // 是否关闭【0;否】【1:是】 | 56 | // 是否关闭【0;否】【1:是】 |
| @@ -40,11 +63,93 @@ type BusinessBonus struct { | @@ -40,11 +63,93 @@ type BusinessBonus struct { | ||
| 40 | UpdateAt time.Time `json:"updateAt"` | 63 | UpdateAt time.Time `json:"updateAt"` |
| 41 | // 删除时间 | 64 | // 删除时间 |
| 42 | DeleteAt time.Time `json:"deleteAt"` | 65 | DeleteAt time.Time `json:"deleteAt"` |
| 66 | + | ||
| 67 | + BusinessBonusPayStatus BusinessBonusBonusStatus | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +type BusinessBonusNullPay struct{} | ||
| 71 | + | ||
| 72 | +var _ BusinessBonusBonusStatus = (*BusinessBonusNullPay)(nil) | ||
| 73 | + | ||
| 74 | +type BusinessBonusWaitPay struct{} | ||
| 75 | + | ||
| 76 | +var _ BusinessBonusBonusStatus = (*BusinessBonusWaitPay)(nil) | ||
| 77 | + | ||
| 78 | +//OrderGoodBonusHasPay 货品分红已支付 | ||
| 79 | +type BusinessBonusHasPay struct{} | ||
| 80 | + | ||
| 81 | +var _ BusinessBonusBonusStatus = (*BusinessBonusHasPay)(nil) | ||
| 82 | + | ||
| 83 | +// -----默认空状态----- | ||
| 84 | +//状态变更为空 | ||
| 85 | +func (pay BusinessBonusNullPay) NullPayPartnerBonus(bonus *BusinessBonus) error { | ||
| 86 | + bonus.BonusStatus = 0 | ||
| 87 | + return nil | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +//状态变更为待支付 | ||
| 91 | +func (pay BusinessBonusNullPay) WartPayPartnerBonus(bonus *BusinessBonus) error { | ||
| 92 | + bonus.BonusNot = bonus.Bonus | ||
| 93 | + bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY | ||
| 94 | + return nil | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +//状态变更为已支付 | ||
| 98 | +func (pay BusinessBonusNullPay) PayPartnerBonus(bonus *BusinessBonus) error { | ||
| 99 | + bonus.BonusNot = 0 | ||
| 100 | + bonus.BonusHas = bonus.Bonus | ||
| 101 | + bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY | ||
| 102 | + return nil | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +// -----待支付状态----- | ||
| 106 | +//状态变更为空 | ||
| 107 | +func (pay BusinessBonusWaitPay) NullPayPartnerBonus(bonus *BusinessBonus) error { | ||
| 108 | + bonus.BonusStatus = 0 | ||
| 109 | + return nil | ||
| 110 | +} | ||
| 111 | + | ||
| 112 | +//状态变更为待支付 | ||
| 113 | +func (pay BusinessBonusWaitPay) WartPayPartnerBonus(bonus *BusinessBonus) error { | ||
| 114 | + bonus.BonusNot = bonus.Bonus | ||
| 115 | + bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY | ||
| 116 | + return nil | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +//状态变更为已支付 | ||
| 120 | +func (pay BusinessBonusWaitPay) PayPartnerBonus(bonus *BusinessBonus) error { | ||
| 121 | + bonus.BonusNot = 0 | ||
| 122 | + bonus.BonusHas = bonus.Bonus | ||
| 123 | + bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY | ||
| 124 | + return nil | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +// -----已经支付状态----- | ||
| 128 | +//状态变更为空 | ||
| 129 | +func (pay BusinessBonusHasPay) NullPayPartnerBonus(bonus *BusinessBonus) error { | ||
| 130 | + bonus.BonusStatus = 0 | ||
| 131 | + return nil | ||
| 132 | +} | ||
| 133 | + | ||
| 134 | +//状态变更为待支付 | ||
| 135 | +func (pay BusinessBonusHasPay) WartPayPartnerBonus(bonus *BusinessBonus) error { | ||
| 136 | + bonus.BonusNot = bonus.Bonus | ||
| 137 | + bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY | ||
| 138 | + return nil | ||
| 139 | +} | ||
| 140 | + | ||
| 141 | +//状态变更为已支付 | ||
| 142 | +func (pay BusinessBonusHasPay) PayPartnerBonus(bonus *BusinessBonus) error { | ||
| 143 | + bonus.BonusNot = 0 | ||
| 144 | + bonus.BonusHas = bonus.Bonus | ||
| 145 | + bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY | ||
| 146 | + return nil | ||
| 43 | } | 147 | } |
| 44 | 148 | ||
| 45 | type BusinessBonusFindOneQuery struct { | 149 | type BusinessBonusFindOneQuery struct { |
| 46 | Id int64 | 150 | Id int64 |
| 47 | PartnerId int64 | 151 | PartnerId int64 |
| 152 | + CompanyId int64 | ||
| 48 | } | 153 | } |
| 49 | type BusinessBonusFindQuery struct { | 154 | type BusinessBonusFindQuery struct { |
| 50 | Offset int | 155 | Offset int |
pkg/infrastructure/dao/pg_business_bonus.go
0 → 100644
| 1 | +package dao | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "strings" | ||
| 6 | + "time" | ||
| 7 | + | ||
| 8 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type BusinessBonusDao struct { | ||
| 12 | + transactionContext *transaction.TransactionContext | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +func NewBusinessBonusDao(transactionContext *transaction.TransactionContext) (*BusinessBonusDao, error) { | ||
| 16 | + if transactionContext == nil { | ||
| 17 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 18 | + } else { | ||
| 19 | + return &BusinessBonusDao{ | ||
| 20 | + transactionContext: transactionContext, | ||
| 21 | + }, nil | ||
| 22 | + } | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +type CustomBusinessBonus struct { | ||
| 26 | + Id int64 | ||
| 27 | + Bonus string | ||
| 28 | + BonusNot string | ||
| 29 | + BonusExpense string | ||
| 30 | + BonusHas string | ||
| 31 | + BonusStatus int8 | ||
| 32 | + PartnerName string | ||
| 33 | + UpdateAt time.Time | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +func (dao BusinessBonusDao) SearchBusinessBonus(partnerId int64, partnerNameMatch string, | ||
| 37 | + companyId int64, limit int, offset int) ([]CustomBusinessBonus, error) { | ||
| 38 | + sql := `SELECT business_bonus.id, business_bonus.bonus,business_bonus.bonus_not | ||
| 39 | + ,business_bonus.bonus_expense,business_bonus.bonus_status,business_bonus.update_at | ||
| 40 | + ,partner_info.partner_name,business_bonus.bonus_has | ||
| 41 | + FROM business_bonus | ||
| 42 | + JOIN partner_info ON business_bonus.partner_info_id=partner_info.id | ||
| 43 | + WHERE business_bonus.company_id = ? ` | ||
| 44 | + partnerCondition := []string{} | ||
| 45 | + allParam := []interface{}{companyId} | ||
| 46 | + if partnerId > 0 { | ||
| 47 | + partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `) | ||
| 48 | + allParam = append(allParam, partnerId) | ||
| 49 | + } | ||
| 50 | + if len(partnerNameMatch) > 0 { | ||
| 51 | + allParam = append(allParam, "%"+partnerNameMatch+"%") | ||
| 52 | + partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `) | ||
| 53 | + } | ||
| 54 | + if len(partnerCondition) > 0 { | ||
| 55 | + sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR ")) | ||
| 56 | + } | ||
| 57 | + sql += ` limit ? OFFSET ? ` | ||
| 58 | + allParam = append(allParam, limit, offset) | ||
| 59 | + tx := dao.transactionContext.PgTx | ||
| 60 | + var ( | ||
| 61 | + result []CustomBusinessBonus | ||
| 62 | + err error | ||
| 63 | + ) | ||
| 64 | + _, err = tx.Query(&result, sql, allParam...) | ||
| 65 | + return result, err | ||
| 66 | +} |
| @@ -22,6 +22,8 @@ type BusinessBonus struct { | @@ -22,6 +22,8 @@ type BusinessBonus struct { | ||
| 22 | BonusNot float64 | 22 | BonusNot float64 |
| 23 | // 分红支出 | 23 | // 分红支出 |
| 24 | BonusExpense float64 | 24 | BonusExpense float64 |
| 25 | + //已收分红 | ||
| 26 | + BonusHas float64 | ||
| 25 | // 是否关闭【0;否】【1:是】 | 27 | // 是否关闭【0;否】【1:是】 |
| 26 | IsDisable int8 | 28 | IsDisable int8 |
| 27 | // 分红状态 1:待支付分红 2:已支付分红 | 29 | // 分红状态 1:待支付分红 2:已支付分红 |
| @@ -13,9 +13,29 @@ type BusinessBonusRepository struct { | @@ -13,9 +13,29 @@ type BusinessBonusRepository struct { | ||
| 13 | transactionContext *transaction.TransactionContext | 13 | transactionContext *transaction.TransactionContext |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | -func (repository *BusinessBonusRepository) transformPgModelToDomainModel(BusinessBonusModel *models.BusinessBonus) (domain.BusinessBonus, error) { | ||
| 17 | - m := domain.BusinessBonus{} | ||
| 18 | - return m, nil | 16 | +func (repository *BusinessBonusRepository) transformPgModelToDomainModel(m *models.BusinessBonus) (domain.BusinessBonus, error) { |
| 17 | + dm := domain.BusinessBonus{ | ||
| 18 | + Id: m.Id, | ||
| 19 | + CompanyId: m.CompanyId, | ||
| 20 | + PartnerInfoId: m.PartnerInfoId, | ||
| 21 | + Bonus: m.Bonus, | ||
| 22 | + BonusNot: m.BonusNot, | ||
| 23 | + BonusHas: m.BonusHas, | ||
| 24 | + BonusExpense: m.BonusExpense, | ||
| 25 | + IsDisable: m.IsDisable, | ||
| 26 | + BonusStatus: m.BonusStatus, | ||
| 27 | + CreateAt: m.CreateAt, | ||
| 28 | + UpdateAt: m.UpdateAt, | ||
| 29 | + } | ||
| 30 | + switch m.BonusStatus { | ||
| 31 | + case domain.BUSINESS_BONUS_WAIT_PAY: | ||
| 32 | + dm.BusinessBonusPayStatus = domain.BusinessBonusWaitPay{} | ||
| 33 | + case domain.BUSINESS_BONUS_HAS_PAY: | ||
| 34 | + dm.BusinessBonusPayStatus = domain.BusinessBonusHasPay{} | ||
| 35 | + default: | ||
| 36 | + dm.BusinessBonusPayStatus = domain.BusinessBonusNullPay{} | ||
| 37 | + } | ||
| 38 | + return dm, nil | ||
| 19 | } | 39 | } |
| 20 | 40 | ||
| 21 | func NewBusinessBonusRepository(transactionContext *transaction.TransactionContext) (*BusinessBonusRepository, error) { | 41 | func NewBusinessBonusRepository(transactionContext *transaction.TransactionContext) (*BusinessBonusRepository, error) { |
| @@ -33,6 +53,7 @@ func (repository *BusinessBonusRepository) Add(dm *domain.BusinessBonus) error { | @@ -33,6 +53,7 @@ func (repository *BusinessBonusRepository) Add(dm *domain.BusinessBonus) error { | ||
| 33 | PartnerInfoId: dm.PartnerInfoId, | 53 | PartnerInfoId: dm.PartnerInfoId, |
| 34 | Bonus: dm.Bonus, | 54 | Bonus: dm.Bonus, |
| 35 | BonusNot: dm.Bonus, | 55 | BonusNot: dm.Bonus, |
| 56 | + BonusHas: dm.BonusHas, | ||
| 36 | BonusExpense: dm.BonusExpense, | 57 | BonusExpense: dm.BonusExpense, |
| 37 | IsDisable: dm.IsDisable, | 58 | IsDisable: dm.IsDisable, |
| 38 | BonusStatus: dm.BonusStatus, | 59 | BonusStatus: dm.BonusStatus, |
| @@ -54,6 +75,7 @@ func (repository *BusinessBonusRepository) Edit(dm *domain.BusinessBonus) error | @@ -54,6 +75,7 @@ func (repository *BusinessBonusRepository) Edit(dm *domain.BusinessBonus) error | ||
| 54 | Bonus: dm.Bonus, | 75 | Bonus: dm.Bonus, |
| 55 | BonusNot: dm.Bonus, | 76 | BonusNot: dm.Bonus, |
| 56 | BonusExpense: dm.BonusExpense, | 77 | BonusExpense: dm.BonusExpense, |
| 78 | + BonusHas: dm.BonusHas, | ||
| 57 | IsDisable: dm.IsDisable, | 79 | IsDisable: dm.IsDisable, |
| 58 | BonusStatus: dm.BonusStatus, | 80 | BonusStatus: dm.BonusStatus, |
| 59 | CreateAt: dm.CreateAt, | 81 | CreateAt: dm.CreateAt, |
| @@ -77,6 +99,10 @@ func (repository *BusinessBonusRepository) FindOne(queryOptions domain.BusinessB | @@ -77,6 +99,10 @@ func (repository *BusinessBonusRepository) FindOne(queryOptions domain.BusinessB | ||
| 77 | hasCondition = true | 99 | hasCondition = true |
| 78 | query = query.Where("partner_info_id=?", queryOptions.PartnerId) | 100 | query = query.Where("partner_info_id=?", queryOptions.PartnerId) |
| 79 | } | 101 | } |
| 102 | + if queryOptions.CompanyId > 0 { | ||
| 103 | + hasCondition = true | ||
| 104 | + query = query.Where("company_id=?", queryOptions.CompanyId) | ||
| 105 | + } | ||
| 80 | if !hasCondition { | 106 | if !hasCondition { |
| 81 | return nil, errors.New("没有查询条件") | 107 | return nil, errors.New("没有查询条件") |
| 82 | } | 108 | } |
| 1 | +package controllers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "errors" | ||
| 5 | + | ||
| 6 | + "github.com/astaxie/beego/logs" | ||
| 7 | + businessCommand "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/command" | ||
| 8 | + businessQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/query" | ||
| 9 | + businessService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/service" | ||
| 10 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +type BusinessBonusController struct { | ||
| 14 | + BaseController | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +func (c *BusinessBonusController) Prepare() { | ||
| 18 | + c.BaseController.Prepare() | ||
| 19 | + if ok := c.ValidJWTToken(); !ok { | ||
| 20 | + return | ||
| 21 | + } | ||
| 22 | + if ok := c.ValidAdminPermission(domain.PERMISSION_DIVIDEND); !ok { | ||
| 23 | + return | ||
| 24 | + } | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +func (c *BusinessBonusController) ListBusinessBonus() { | ||
| 28 | + type Parameter struct { | ||
| 29 | + PageNumber int `json:"pageNumber"` | ||
| 30 | + Partner int64 `json:"partner"` | ||
| 31 | + PageSize int `json:"pageSize"` | ||
| 32 | + SearchText string `json:"searchText"` | ||
| 33 | + } | ||
| 34 | + var ( | ||
| 35 | + param Parameter | ||
| 36 | + err error | ||
| 37 | + ) | ||
| 38 | + if err = c.BindJsonData(¶m); err != nil { | ||
| 39 | + logs.Error(err) | ||
| 40 | + c.ResponseError(errors.New("json数据解析失败")) | ||
| 41 | + return | ||
| 42 | + } | ||
| 43 | + companyId := c.GetUserCompany() | ||
| 44 | + srv := businessService.NewBusinessBonusService(nil) | ||
| 45 | + _, result, err := srv.ListBusinessBonus(businessQuery.ListBusinessBonusQuery{ | ||
| 46 | + CompanyId: companyId, | ||
| 47 | + }) | ||
| 48 | + if err != nil { | ||
| 49 | + c.ResponseError(err) | ||
| 50 | + return | ||
| 51 | + } | ||
| 52 | + c.ResponsePageList(result, 0, param.PageNumber) | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +func (c *BusinessBonusController) UpdateBusinessBonus() { | ||
| 56 | + type Parameter struct { | ||
| 57 | + Id int64 `json:"id"` | ||
| 58 | + DividendsReceivable string `json:"dividendsReceivable"` | ||
| 59 | + StateOfPayment string `json:"stateOfPayment"` | ||
| 60 | + } | ||
| 61 | + var ( | ||
| 62 | + param Parameter | ||
| 63 | + err error | ||
| 64 | + ) | ||
| 65 | + if err = c.BindJsonData(¶m); err != nil { | ||
| 66 | + logs.Error(err) | ||
| 67 | + c.ResponseError(errors.New("json数据解析失败")) | ||
| 68 | + return | ||
| 69 | + } | ||
| 70 | + companyId := c.GetUserCompany() | ||
| 71 | + srv := businessService.NewBusinessBonusService(nil) | ||
| 72 | + err = srv.UpdateBusinessBonus(businessCommand.UpdateBusinessBonusCommand{ | ||
| 73 | + CompanyId: companyId, | ||
| 74 | + }) | ||
| 75 | + if err != nil { | ||
| 76 | + c.ResponseError(err) | ||
| 77 | + return | ||
| 78 | + } | ||
| 79 | + c.ResponseData(nil) | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +func (c *BusinessBonusController) GetBusinessBonus() { | ||
| 83 | + type Parameter struct { | ||
| 84 | + Id int64 `json:"id"` | ||
| 85 | + } | ||
| 86 | + var ( | ||
| 87 | + param Parameter | ||
| 88 | + err error | ||
| 89 | + ) | ||
| 90 | + if err = c.BindJsonData(¶m); err != nil { | ||
| 91 | + logs.Error(err) | ||
| 92 | + c.ResponseError(errors.New("json数据解析失败")) | ||
| 93 | + return | ||
| 94 | + } | ||
| 95 | + companyId := c.GetUserCompany() | ||
| 96 | + srv := businessService.NewBusinessBonusService(nil) | ||
| 97 | + data, err := srv.GetBusinessBonus(businessQuery.GetBusinessBonusQuery{ | ||
| 98 | + Id: param.Id, | ||
| 99 | + CompanyId: companyId, | ||
| 100 | + }) | ||
| 101 | + if err != nil { | ||
| 102 | + c.ResponseError(err) | ||
| 103 | + return | ||
| 104 | + } | ||
| 105 | + c.ResponseData(data) | ||
| 106 | +} |
| @@ -32,6 +32,10 @@ func init() { | @@ -32,6 +32,10 @@ func init() { | ||
| 32 | beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"), | 32 | beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"), |
| 33 | beego.NSRouter("/edit", &controllers.OrderDividendController{}, "POST:EditOrderDividend"), | 33 | beego.NSRouter("/edit", &controllers.OrderDividendController{}, "POST:EditOrderDividend"), |
| 34 | beego.NSRouter("/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetail"), | 34 | beego.NSRouter("/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetail"), |
| 35 | + | ||
| 36 | + beego.NSRouter("business/detail", &controllers.BusinessBonusController{}, "POST:GetBusinessBonus"), | ||
| 37 | + beego.NSRouter("business/edit", &controllers.BusinessBonusController{}, "POST:UpdateBusinessBonus"), | ||
| 38 | + beego.NSRouter("business/list", &controllers.BusinessBonusController{}, "POST:ListBusinessBonus"), | ||
| 35 | ), | 39 | ), |
| 36 | beego.NSNamespace("/order", | 40 | beego.NSNamespace("/order", |
| 37 | beego.NSRouter("/purpose/list", &controllers.OrderInfoController{}, "POST:PageListOrderPurpose"), | 41 | beego.NSRouter("/purpose/list", &controllers.OrderInfoController{}, "POST:PageListOrderPurpose"), |
-
请 注册 或 登录 后发表评论