Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/partnermg into dev
正在显示
8 个修改的文件
包含
70 行增加
和
23 行删除
@@ -28,3 +28,11 @@ func CreateOrderDao(options map[string]interface{}) (*dao.OrderDao, error) { | @@ -28,3 +28,11 @@ func CreateOrderDao(options map[string]interface{}) (*dao.OrderDao, error) { | ||
28 | } | 28 | } |
29 | return dao.NewOrderDao(transactionContext) | 29 | return dao.NewOrderDao(transactionContext) |
30 | } | 30 | } |
31 | + | ||
32 | +func CreateOrderPaymentDao(options map[string]interface{}) (*dao.OrderPayment, error) { | ||
33 | + var transactionContext *transaction.TransactionContext | ||
34 | + if value, ok := options["transactionContext"]; ok { | ||
35 | + transactionContext = value.(*transaction.TransactionContext) | ||
36 | + } | ||
37 | + return dao.NewOrderPayment(transactionContext) | ||
38 | +} |
@@ -14,6 +14,8 @@ type DivdendPyamentItem struct { | @@ -14,6 +14,8 @@ type DivdendPyamentItem struct { | ||
14 | StateOfPayment int `json:"stateOfPayment,omitempty"` | 14 | StateOfPayment int `json:"stateOfPayment,omitempty"` |
15 | //支付批次 | 15 | //支付批次 |
16 | PaymentSn int `json:"paymentSn,omitempty"` | 16 | PaymentSn int `json:"paymentSn,omitempty"` |
17 | + //支付编号 | ||
18 | + PaymentId int `json:"id,omitempty"` | ||
17 | } | 19 | } |
18 | 20 | ||
19 | func (command CreateOrderPaymentCommand) ValidateCommand() error { | 21 | func (command CreateOrderPaymentCommand) ValidateCommand() error { |
@@ -29,6 +29,7 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm | @@ -29,6 +29,7 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm | ||
29 | var ( | 29 | var ( |
30 | transactionContext, _ = factory.CreateTransactionContext(nil) | 30 | transactionContext, _ = factory.CreateTransactionContext(nil) |
31 | OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext}) | 31 | OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext}) |
32 | + OrderPaymentDao, _ = factory.CreateOrderPaymentDao(map[string]interface{}{"transactionContext": transactionContext}) | ||
32 | ) | 33 | ) |
33 | if err = command.ValidateCommand(); err != nil { | 34 | if err = command.ValidateCommand(); err != nil { |
34 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 35 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
@@ -57,43 +58,45 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm | @@ -57,43 +58,45 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm | ||
57 | err = e | 58 | err = e |
58 | return | 59 | return |
59 | } | 60 | } |
60 | - | 61 | + var excludeIdList []int |
62 | + excludeIdList = append(excludeIdList, 0) | ||
61 | for i := range command.DivdendPaymentItem { | 63 | for i := range command.DivdendPaymentItem { |
62 | paymentItem := command.DivdendPaymentItem[i] | 64 | paymentItem := command.DivdendPaymentItem[i] |
63 | dm := &domain.OrderPayment{ | 65 | dm := &domain.OrderPayment{ |
64 | OrderId: command.OrderId, | 66 | OrderId: command.OrderId, |
65 | - PartnerId: 0, | ||
66 | - PaymentAmount: 0, | ||
67 | - BonusAmount: 0, //计算分红金额 | ||
68 | - BonusStatus: 0, | ||
69 | CreateAt: time.Now(), | 67 | CreateAt: time.Now(), |
70 | - PaymentSn: paymentItem.PaymentSn, | ||
71 | UpdateAt: time.Now(), | 68 | UpdateAt: time.Now(), |
72 | } | 69 | } |
73 | - | 70 | + if paymentItem.PaymentId > 0 && paymentItem.StateOfPayment == domain.BonusPaid { |
71 | + continue | ||
72 | + } | ||
73 | + if paymentItem.PaymentId > 0 { | ||
74 | //检查货款 已存在 / 未存在 | 74 | //检查货款 已存在 / 未存在 |
75 | - if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentSn: paymentItem.PaymentSn}); e == nil { | 75 | + if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentId: paymentItem.PaymentId}); e == nil { |
76 | if findDm.BonusStatus == domain.BonusPaid { | 76 | if findDm.BonusStatus == domain.BonusPaid { |
77 | continue | 77 | continue |
78 | } | 78 | } |
79 | dm = findDm | 79 | dm = findDm |
80 | } | 80 | } |
81 | - | 81 | + } |
82 | dm.PartnerId = orderBase["PartnerId"].(int64) | 82 | dm.PartnerId = orderBase["PartnerId"].(int64) |
83 | - bonousPercent := orderBase["PartnerBonusPercent"].(float64) | ||
84 | - dm.BonusAmount = paymentItem.PaymentForGoods * (bonousPercent / 100.0) | 83 | + bonusPercent := orderBase["PartnerBonusPercent"].(float64) |
84 | + dm.BonusAmount = paymentItem.PaymentForGoods * (bonusPercent / 100.0) | ||
85 | dm.PaymentAmount = paymentItem.PaymentForGoods | 85 | dm.PaymentAmount = paymentItem.PaymentForGoods |
86 | dm.BonusStatus = paymentItem.StateOfPayment | 86 | dm.BonusStatus = paymentItem.StateOfPayment |
87 | - | 87 | + dm.UpdateAt = time.Now() |
88 | if data, err = OrderPaymentRepository.Save(dm); err != nil { | 88 | if data, err = OrderPaymentRepository.Save(dm); err != nil { |
89 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 89 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
90 | } | 90 | } |
91 | + excludeIdList = append(excludeIdList, int(dm.Id)) | ||
91 | } | 92 | } |
92 | var bonusStatus int = 1 | 93 | var bonusStatus int = 1 |
93 | if len(command.DivdendPaymentItem) > 0 { | 94 | if len(command.DivdendPaymentItem) > 0 { |
94 | bonusStatus = command.DivdendPaymentItem[len(command.DivdendPaymentItem)-1].StateOfPayment | 95 | bonusStatus = command.DivdendPaymentItem[len(command.DivdendPaymentItem)-1].StateOfPayment |
95 | } | 96 | } |
96 | - | 97 | + if err = OrderPaymentDao.Remove(command.OrderId, domain.BonusWaitPay, excludeIdList); err != nil { |
98 | + return | ||
99 | + } | ||
97 | if err = OrderDao.Update(map[string]interface{}{"id": command.OrderId, "orderPaymentAmount": command.TotalPaymentAmount, "bonusStatus": bonusStatus}); err != nil { | 100 | if err = OrderDao.Update(map[string]interface{}{"id": command.OrderId, "orderPaymentAmount": command.TotalPaymentAmount, "bonusStatus": bonusStatus}); err != nil { |
98 | return | 101 | return |
99 | } | 102 | } |
@@ -14,8 +14,6 @@ type OrderPayment struct { | @@ -14,8 +14,6 @@ type OrderPayment struct { | ||
14 | OrderId int64 `json:"orderId"` | 14 | OrderId int64 `json:"orderId"` |
15 | //合伙人编号 | 15 | //合伙人编号 |
16 | PartnerId int64 `json:"partnerId"` | 16 | PartnerId int64 `json:"partnerId"` |
17 | - //支付序号 | ||
18 | - PaymentSn int `json:"paymentSn"` | ||
19 | //支付货款 | 17 | //支付货款 |
20 | PaymentAmount float64 `json:"paymentAmount"` | 18 | PaymentAmount float64 `json:"paymentAmount"` |
21 | //分红金额 | 19 | //分红金额 |
@@ -58,7 +56,7 @@ func (m *OrderPayment) Update(data map[string]interface{}) error { | @@ -58,7 +56,7 @@ func (m *OrderPayment) Update(data map[string]interface{}) error { | ||
58 | type OrderPaymentFindOneQuery struct { | 56 | type OrderPaymentFindOneQuery struct { |
59 | Id int64 | 57 | Id int64 |
60 | OrderId int64 | 58 | OrderId int64 |
61 | - PaymentSn int | 59 | + PaymentId int |
62 | } | 60 | } |
63 | type OrderPaymentQuery struct { | 61 | type OrderPaymentQuery struct { |
64 | Offset int | 62 | Offset int |
1 | +package dao | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
6 | + | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
8 | +) | ||
9 | + | ||
10 | +type OrderPayment struct { | ||
11 | + transactionContext *transaction.TransactionContext | ||
12 | +} | ||
13 | + | ||
14 | +//删除数据 | ||
15 | +func (o *OrderPayment) Remove(orderId int64, status int, idList []int) error { | ||
16 | + if len(idList) == 0 { | ||
17 | + return nil | ||
18 | + } | ||
19 | + tx := o.transactionContext.PgTx | ||
20 | + m := new(models.OrderPayment) | ||
21 | + q := tx.Model(m).Where("order_id=?", orderId). | ||
22 | + Where("bonus_status=?", status). | ||
23 | + WhereIn("id not in(?)", idList) | ||
24 | + _, err := q.Delete() | ||
25 | + return err | ||
26 | +} | ||
27 | + | ||
28 | +func NewOrderPayment(transactionContext *transaction.TransactionContext) (*OrderPayment, error) { | ||
29 | + if transactionContext == nil { | ||
30 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
31 | + } else { | ||
32 | + return &OrderPayment{ | ||
33 | + transactionContext: transactionContext, | ||
34 | + }, nil | ||
35 | + } | ||
36 | +} |
@@ -10,8 +10,6 @@ type OrderPayment struct { | @@ -10,8 +10,6 @@ type OrderPayment struct { | ||
10 | OrderId int64 | 10 | OrderId int64 |
11 | //合伙人编号 | 11 | //合伙人编号 |
12 | PartnerId int64 | 12 | PartnerId int64 |
13 | - //支付序号 | ||
14 | - PaymentSn int | ||
15 | //支付货款 | 13 | //支付货款 |
16 | PaymentAmount float64 `pg:",notnull,default:0"` | 14 | PaymentAmount float64 `pg:",notnull,default:0"` |
17 | //分红金额 | 15 | //分红金额 |
@@ -24,7 +24,6 @@ func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain | @@ -24,7 +24,6 @@ func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain | ||
24 | BonusAmount: dm.BonusAmount, | 24 | BonusAmount: dm.BonusAmount, |
25 | BonusStatus: dm.BonusStatus, | 25 | BonusStatus: dm.BonusStatus, |
26 | CreateAt: dm.CreateAt, | 26 | CreateAt: dm.CreateAt, |
27 | - PaymentSn: dm.PaymentSn, | ||
28 | UpdateAt: dm.UpdateAt, | 27 | UpdateAt: dm.UpdateAt, |
29 | } | 28 | } |
30 | if m.Id == 0 { | 29 | if m.Id == 0 { |
@@ -61,8 +60,8 @@ func (repository *OrderPaymentRepository) FindOne(queryOptions domain.OrderPayme | @@ -61,8 +60,8 @@ func (repository *OrderPaymentRepository) FindOne(queryOptions domain.OrderPayme | ||
61 | if queryOptions.OrderId > 0 { | 60 | if queryOptions.OrderId > 0 { |
62 | query.Where("order_payment.order_id = ?", queryOptions.OrderId) | 61 | query.Where("order_payment.order_id = ?", queryOptions.OrderId) |
63 | } | 62 | } |
64 | - if queryOptions.PaymentSn > 0 { | ||
65 | - query.Where("order_payment.payment_sn = ?", queryOptions.PaymentSn) | 63 | + if queryOptions.PaymentId > 0 { |
64 | + query.Where("order_payment.id = ?", queryOptions.PaymentId) | ||
66 | } | 65 | } |
67 | if err := query.First(); err != nil { | 66 | if err := query.First(); err != nil { |
68 | return nil, err | 67 | return nil, err |
@@ -78,6 +77,7 @@ func (repository *OrderPaymentRepository) Find(queryOptions domain.OrderPaymentQ | @@ -78,6 +77,7 @@ func (repository *OrderPaymentRepository) Find(queryOptions domain.OrderPaymentQ | ||
78 | var OrderPaymentModels []*models.OrderPayment | 77 | var OrderPaymentModels []*models.OrderPayment |
79 | query := tx.Model(&OrderPaymentModels) | 78 | query := tx.Model(&OrderPaymentModels) |
80 | query.Where("order_payment.order_id = ?", queryOptions.OrderId) | 79 | query.Where("order_payment.order_id = ?", queryOptions.OrderId) |
80 | + query.Order("id ASC") | ||
81 | var ( | 81 | var ( |
82 | err error | 82 | err error |
83 | rsp = make([]*domain.OrderPayment, 0) | 83 | rsp = make([]*domain.OrderPayment, 0) |
@@ -121,7 +121,6 @@ func (repository *OrderPaymentRepository) transformPgModelToDomainModel(dm *mode | @@ -121,7 +121,6 @@ func (repository *OrderPaymentRepository) transformPgModelToDomainModel(dm *mode | ||
121 | PaymentAmount: dm.PaymentAmount, | 121 | PaymentAmount: dm.PaymentAmount, |
122 | BonusAmount: dm.BonusAmount, | 122 | BonusAmount: dm.BonusAmount, |
123 | BonusStatus: dm.BonusStatus, | 123 | BonusStatus: dm.BonusStatus, |
124 | - PaymentSn: dm.PaymentSn, | ||
125 | CreateAt: dm.CreateAt, | 124 | CreateAt: dm.CreateAt, |
126 | UpdateAt: dm.UpdateAt, | 125 | UpdateAt: dm.UpdateAt, |
127 | } | 126 | } |
@@ -39,6 +39,7 @@ func (c *DividendsController) Edit() { | @@ -39,6 +39,7 @@ func (c *DividendsController) Edit() { | ||
39 | type DividendPaymentItem struct { | 39 | type DividendPaymentItem struct { |
40 | PaymentForGoods float64 `json:"paymentForGoods"` | 40 | PaymentForGoods float64 `json:"paymentForGoods"` |
41 | StateOfPayment int `json:"stateOfPayment"` | 41 | StateOfPayment int `json:"stateOfPayment"` |
42 | + Id int `json:"id"` | ||
42 | } | 43 | } |
43 | type Parameter struct { | 44 | type Parameter struct { |
44 | Id string `json:"id"` //订单编号 | 45 | Id string `json:"id"` //订单编号 |
@@ -70,7 +71,7 @@ func (c *DividendsController) Edit() { | @@ -70,7 +71,7 @@ func (c *DividendsController) Edit() { | ||
70 | paymentItem.PaymentForGoods = item.PaymentForGoods | 71 | paymentItem.PaymentForGoods = item.PaymentForGoods |
71 | paymentItem.StateOfPayment = item.StateOfPayment | 72 | paymentItem.StateOfPayment = item.StateOfPayment |
72 | paymentItem.PaymentSn = i + 1 | 73 | paymentItem.PaymentSn = i + 1 |
73 | - | 74 | + paymentItem.PaymentId = item.Id |
74 | if paymentItem.StateOfPayment == domain.BonusPaid { | 75 | if paymentItem.StateOfPayment == domain.BonusPaid { |
75 | cmd.TotalPaymentAmount += paymentItem.PaymentForGoods | 76 | cmd.TotalPaymentAmount += paymentItem.PaymentForGoods |
76 | } | 77 | } |
@@ -132,6 +133,7 @@ func (c *DividendsController) Detail() { | @@ -132,6 +133,7 @@ func (c *DividendsController) Detail() { | ||
132 | StateOfPayment int `json:"stateOfPayment"` | 133 | StateOfPayment int `json:"stateOfPayment"` |
133 | Dividend float64 `json:"dividend"` | 134 | Dividend float64 `json:"dividend"` |
134 | DividendProportion float64 `json:"dividendProportion"` | 135 | DividendProportion float64 `json:"dividendProportion"` |
136 | + Id int64 `json:"id"` | ||
135 | } | 137 | } |
136 | type Order struct { | 138 | type Order struct { |
137 | OrderNumber string `json:"orderNumber"` //订单号 | 139 | OrderNumber string `json:"orderNumber"` //订单号 |
@@ -171,6 +173,7 @@ func (c *DividendsController) Detail() { | @@ -171,6 +173,7 @@ func (c *DividendsController) Detail() { | ||
171 | StateOfPayment: item.BonusStatus, | 173 | StateOfPayment: item.BonusStatus, |
172 | Dividend: item.BonusAmount, | 174 | Dividend: item.BonusAmount, |
173 | DividendProportion: order.PartnerBonusPercent, | 175 | DividendProportion: order.PartnerBonusPercent, |
176 | + Id: item.Id, | ||
174 | } | 177 | } |
175 | rsp.DividendPayment = append(rsp.DividendPayment, payment) | 178 | rsp.DividendPayment = append(rsp.DividendPayment, payment) |
176 | } | 179 | } |
-
请 注册 或 登录 后发表评论