Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/partnermg into dev
# Conflicts: # pkg/infrastructure/pg/models/order.go
正在显示
14 个修改的文件
包含
722 行增加
和
18 行删除
@@ -20,9 +20,9 @@ require ( | @@ -20,9 +20,9 @@ require ( | ||
20 | github.com/moul/http2curl v1.0.0 // indirect | 20 | github.com/moul/http2curl v1.0.0 // indirect |
21 | github.com/onsi/ginkgo v1.13.0 | 21 | github.com/onsi/ginkgo v1.13.0 |
22 | github.com/onsi/gomega v1.10.1 | 22 | github.com/onsi/gomega v1.10.1 |
23 | - github.com/prometheus/common v0.10.0 // indirect | ||
24 | github.com/sergi/go-diff v1.1.0 // indirect | 23 | github.com/sergi/go-diff v1.1.0 // indirect |
25 | github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect | 24 | github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect |
25 | + github.com/shopspring/decimal v1.2.0 | ||
26 | github.com/smartystreets/goconvey v1.6.4 // indirect | 26 | github.com/smartystreets/goconvey v1.6.4 // indirect |
27 | github.com/valyala/fasthttp v1.14.0 // indirect | 27 | github.com/valyala/fasthttp v1.14.0 // indirect |
28 | github.com/xeipuuv/gojsonschema v1.2.0 // indirect | 28 | github.com/xeipuuv/gojsonschema v1.2.0 // indirect |
@@ -20,3 +20,11 @@ func CreatePartnerInfoDao(options map[string]interface{}) (*dao.PartnerInfoDao, | @@ -20,3 +20,11 @@ func CreatePartnerInfoDao(options map[string]interface{}) (*dao.PartnerInfoDao, | ||
20 | } | 20 | } |
21 | return dao.NewPartnerInfoDao(transactionContext) | 21 | return dao.NewPartnerInfoDao(transactionContext) |
22 | } | 22 | } |
23 | + | ||
24 | +func CreateOrderDao(options map[string]interface{}) (*dao.OrderDao, error) { | ||
25 | + var transactionContext *transaction.TransactionContext | ||
26 | + if value, ok := options["transactionContext"]; ok { | ||
27 | + transactionContext = value.(*transaction.TransactionContext) | ||
28 | + } | ||
29 | + return dao.NewOrderDao(transactionContext) | ||
30 | +} |
@@ -32,3 +32,12 @@ func CreateAdminPermissionRepository(options map[string]interface{}) (domain.Adm | @@ -32,3 +32,12 @@ func CreateAdminPermissionRepository(options map[string]interface{}) (domain.Adm | ||
32 | } | 32 | } |
33 | return repository.NewAdminPermissionRepository(transactionContext) | 33 | return repository.NewAdminPermissionRepository(transactionContext) |
34 | } | 34 | } |
35 | + | ||
36 | +//CreatePartnerInfoRepository 合伙人信息 | ||
37 | +func CreateOrderPaymentRepository(options map[string]interface{}) (domain.OrderPaymentRepository, error) { | ||
38 | + var transactionContext *transaction.TransactionContext | ||
39 | + if value, ok := options["transactionContext"]; ok { | ||
40 | + transactionContext = value.(*transaction.TransactionContext) | ||
41 | + } | ||
42 | + return repository.NewOrderPaymentRepository(transactionContext) | ||
43 | +} |
1 | +package command | ||
2 | + | ||
3 | +type CreateOrderPaymentCommand struct { | ||
4 | + //订单编号 | ||
5 | + OrderId int64 `json:"orderId"` | ||
6 | + DivdendPaymentItem []DivdendPyamentItem `json:"dividendPayment"` | ||
7 | + TotalPaymentAmount float64 `json:"payment_amount"` | ||
8 | +} | ||
9 | + | ||
10 | +type DivdendPyamentItem struct { | ||
11 | + // 货款 | ||
12 | + PaymentForGoods float64 `json:"paymentForGoods,omitempty"` | ||
13 | + // 支付状态 | ||
14 | + StateOfPayment int `json:"stateOfPayment,omitempty"` | ||
15 | + //支付批次 | ||
16 | + PaymentSn int `json:"paymentSn,omitempty"` | ||
17 | +} | ||
18 | + | ||
19 | +func (command CreateOrderPaymentCommand) ValidateCommand() error { | ||
20 | + return nil | ||
21 | +} |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" | ||
8 | + "time" | ||
9 | + | ||
10 | + //"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
12 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
13 | +) | ||
14 | + | ||
15 | +// 客户价值服务 | ||
16 | +type OrderPaymentService struct { | ||
17 | +} | ||
18 | + | ||
19 | +func NewOrderPaymentService(options map[string]interface{}) *OrderPaymentService { | ||
20 | + newOrderPaymentService := &OrderPaymentService{} | ||
21 | + return newOrderPaymentService | ||
22 | +} | ||
23 | + | ||
24 | +// 创建订单支付数据 | ||
25 | +func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *command.CreateOrderPaymentCommand) (data interface{}, err error) { | ||
26 | + var ( | ||
27 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
28 | + OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext}) | ||
29 | + ) | ||
30 | + if err = command.ValidateCommand(); err != nil { | ||
31 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
32 | + } | ||
33 | + if err = transactionContext.StartTransaction(); err != nil { | ||
34 | + return nil, err | ||
35 | + } | ||
36 | + defer func() { | ||
37 | + if err == nil { | ||
38 | + err = transactionContext.CommitTransaction() | ||
39 | + } | ||
40 | + if err != nil { | ||
41 | + transactionContext.RollbackTransaction() | ||
42 | + } | ||
43 | + }() | ||
44 | + //检查订单是否存在 | ||
45 | + | ||
46 | + var OrderPaymentRepository domain.OrderPaymentRepository | ||
47 | + if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ | ||
48 | + "transactionContext": transactionContext, | ||
49 | + }); err != nil { | ||
50 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
51 | + } | ||
52 | + orderBase, e := OrderDao.GetOrderBaseInfo(command.OrderId) | ||
53 | + if e != nil { | ||
54 | + err = e | ||
55 | + return | ||
56 | + } | ||
57 | + | ||
58 | + for i := range command.DivdendPaymentItem { | ||
59 | + paymentItem := command.DivdendPaymentItem[i] | ||
60 | + dm := &domain.OrderPayment{ | ||
61 | + OrderId: command.OrderId, | ||
62 | + PartnerId: 0, | ||
63 | + PaymentAmount: 0, | ||
64 | + BonusAmount: 0, //计算分红金额 | ||
65 | + BonusStatus: 0, | ||
66 | + CreateAt: time.Now(), | ||
67 | + PaymentSn: paymentItem.PaymentSn, | ||
68 | + UpdateAt: time.Now(), | ||
69 | + } | ||
70 | + | ||
71 | + //检查货款 已存在 / 未存在 | ||
72 | + if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentSn: paymentItem.PaymentSn}); e == nil { | ||
73 | + if findDm.BonusStatus == domain.BonusPaid { | ||
74 | + continue | ||
75 | + } | ||
76 | + dm = findDm | ||
77 | + } | ||
78 | + | ||
79 | + dm.PartnerId = orderBase["PartnerId"].(int64) | ||
80 | + bonousPercent := orderBase["PartnerBonusPercent"].(float64) | ||
81 | + dm.BonusAmount = paymentItem.PaymentForGoods * (bonousPercent / 100.0) | ||
82 | + dm.PaymentAmount = paymentItem.PaymentForGoods | ||
83 | + dm.BonusStatus = paymentItem.StateOfPayment | ||
84 | + | ||
85 | + if data, err = OrderPaymentRepository.Save(dm); err != nil { | ||
86 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
87 | + } | ||
88 | + } | ||
89 | + | ||
90 | + if err = OrderDao.Update(map[string]interface{}{"id": command.OrderId, "orderPaymentAmount": command.TotalPaymentAmount}); err != nil { | ||
91 | + return | ||
92 | + } | ||
93 | + | ||
94 | + return | ||
95 | +} | ||
96 | + | ||
97 | +//// GetOrderPayment 返回合伙人 | ||
98 | +//func (OrderPaymentService *OrderPaymentService) GetOrderPayment(command query.GetOrderPaymentQuery) (data *domain.OrderPayment, err error) { | ||
99 | +// var ( | ||
100 | +// transactionContext, _ = factory.CreateTransactionContext(nil) | ||
101 | +// ) | ||
102 | +// if err = command.ValidateQuery(); err != nil { | ||
103 | +// return nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) | ||
104 | +// } | ||
105 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
106 | +// return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
107 | +// } | ||
108 | +// defer func() { | ||
109 | +// transactionContext.RollbackTransaction() | ||
110 | +// }() | ||
111 | +// var OrderPaymentRepository domain.OrderPaymentRepository | ||
112 | +// if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ | ||
113 | +// "transactionContext": transactionContext, | ||
114 | +// }); err != nil { | ||
115 | +// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
116 | +// } | ||
117 | +// data, err = OrderPaymentRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.Id}) | ||
118 | +// if err != nil { | ||
119 | +// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
120 | +// } | ||
121 | +// err = transactionContext.CommitTransaction() | ||
122 | +// return | ||
123 | +//} | ||
124 | +// | ||
125 | +//// 更新客户价值 | ||
126 | +//func (OrderPaymentService *OrderPaymentService) UpdateOrderPayment(updateOrderPaymentCommand *command.UpdateOrderPaymentCommand) (err error) { | ||
127 | +// var ( | ||
128 | +// transactionContext, _ = factory.CreateTransactionContext(nil) | ||
129 | +// ) | ||
130 | +// if err = updateOrderPaymentCommand.ValidateCommand(); err != nil { | ||
131 | +// return application.ThrowError(application.ARG_ERROR, err.Error()) | ||
132 | +// } | ||
133 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
134 | +// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
135 | +// } | ||
136 | +// defer func() { | ||
137 | +// transactionContext.RollbackTransaction() | ||
138 | +// }() | ||
139 | +// var OrderPaymentRepository domain.OrderPaymentRepository | ||
140 | +// if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ | ||
141 | +// "transactionContext": transactionContext, | ||
142 | +// }); err != nil { | ||
143 | +// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
144 | +// } | ||
145 | +// OrderPayment, err := OrderPaymentRepository.FindOne(domain.PartnerFindOneQuery{ | ||
146 | +// UserId: updateOrderPaymentCommand.Id, | ||
147 | +// }) | ||
148 | +// if err != nil { | ||
149 | +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
150 | +// } | ||
151 | +// OrderPayment.PartnerCategory = updateOrderPaymentCommand.PartnerCategory | ||
152 | +// OrderPayment.Salesman = updateOrderPaymentCommand.Salesman | ||
153 | +// OrderPayment.Status = updateOrderPaymentCommand.Status | ||
154 | +// OrderPayment.RegionInfo = updateOrderPaymentCommand.RegionInfo | ||
155 | +// if _, err = OrderPaymentRepository.Save(OrderPayment); err != nil { | ||
156 | +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
157 | +// } | ||
158 | +// transactionContext.CommitTransaction() | ||
159 | +// return | ||
160 | +//} | ||
161 | +// | ||
162 | +// 返回订单支付列表 | ||
163 | +func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.ListOrderPaymentQuery) (int, []*domain.OrderPayment, error) { | ||
164 | + var ( | ||
165 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
166 | + OrderPayments []*domain.OrderPayment | ||
167 | + count int | ||
168 | + err error | ||
169 | + ) | ||
170 | + if err = listOrderPaymentQuery.ValidateQuery(); err != nil { | ||
171 | + return 0, nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) | ||
172 | + } | ||
173 | + if err := transactionContext.StartTransaction(); err != nil { | ||
174 | + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
175 | + } | ||
176 | + defer func() { | ||
177 | + if err != nil { | ||
178 | + transactionContext.RollbackTransaction() | ||
179 | + } | ||
180 | + }() | ||
181 | + var OrderPaymentRepository domain.OrderPaymentRepository | ||
182 | + if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ | ||
183 | + "transactionContext": transactionContext, | ||
184 | + }); err != nil { | ||
185 | + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
186 | + } | ||
187 | + queryOption := domain.OrderPaymentQuery{ | ||
188 | + OrderId: listOrderPaymentQuery.OrderId, | ||
189 | + } | ||
190 | + if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil { | ||
191 | + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
192 | + } | ||
193 | + if count, err = OrderPaymentRepository.CountAll(queryOption); err != nil { | ||
194 | + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
195 | + } | ||
196 | + if err = transactionContext.CommitTransaction(); err != nil { | ||
197 | + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
198 | + } | ||
199 | + return count, OrderPayments, nil | ||
200 | +} |
pkg/domain/order_payment.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +const ( | ||
6 | + BonusWaitPay = iota + 1 //等待支付分红 | ||
7 | + BonusPaid //已经支付分红 | ||
8 | +) | ||
9 | + | ||
10 | +type OrderPayment struct { | ||
11 | + //编号 | ||
12 | + Id int64 `json:"id"` | ||
13 | + //订单编号 | ||
14 | + OrderId int64 `json:"orderId"` | ||
15 | + //合伙人编号 | ||
16 | + PartnerId int64 `json:"partnerId"` | ||
17 | + //支付序号 | ||
18 | + PaymentSn int `json:"paymentSn"` | ||
19 | + //支付货款 | ||
20 | + PaymentAmount float64 `json:"paymentAmount"` | ||
21 | + //分红金额 | ||
22 | + BonusAmount float64 `json:"bonusAmount"` | ||
23 | + //分红状态 1.等待支付分红 2.已支付分红 | ||
24 | + BonusStatus int `json:"bonusStatus"` | ||
25 | + //创建时间 | ||
26 | + CreateAt time.Time `json:"createAt"` | ||
27 | + //更新时间 | ||
28 | + UpdateAt time.Time `json:"updateAt"` | ||
29 | +} | ||
30 | + | ||
31 | +func (m *OrderPayment) Identify() interface{} { | ||
32 | + if m.Id == 0 { | ||
33 | + return nil | ||
34 | + } | ||
35 | + return m.Id | ||
36 | +} | ||
37 | + | ||
38 | +func (m *OrderPayment) Update(data map[string]interface{}) error { | ||
39 | + if m.BonusStatus != BonusWaitPay { | ||
40 | + return nil | ||
41 | + } | ||
42 | + if paymentAmount, ok := data["paymentAmount"]; ok && paymentAmount != 0 { | ||
43 | + m.PaymentAmount = paymentAmount.(float64) | ||
44 | + } | ||
45 | + if bonusAmount, ok := data["bonusAmount"]; ok && bonusAmount != 0 { | ||
46 | + m.BonusAmount = bonusAmount.(float64) | ||
47 | + } | ||
48 | + if bonusStatus, ok := data["bonusStatus"]; ok && bonusStatus != 0 { | ||
49 | + m.BonusStatus = bonusStatus.(int) | ||
50 | + } | ||
51 | + m.UpdateAt = time.Now() | ||
52 | + return nil | ||
53 | +} | ||
54 | + | ||
55 | +type OrderPaymentFindOneQuery struct { | ||
56 | + Id int64 | ||
57 | + OrderId int64 | ||
58 | + PaymentSn int | ||
59 | +} | ||
60 | +type OrderPaymentQuery struct { | ||
61 | + Offset int | ||
62 | + Limit int | ||
63 | + | ||
64 | + OrderId int64 | ||
65 | + //PartnerCategory []int //合伙人类型 | ||
66 | + //RegionInfo *RegionInfo //区域 | ||
67 | + //PartnerName string //合伙人姓名 | ||
68 | +} | ||
69 | + | ||
70 | +type OrderPaymentRepository interface { | ||
71 | + Save(dm *OrderPayment) (*OrderPayment, error) | ||
72 | + FindOne(queryOptions OrderPaymentFindOneQuery) (*OrderPayment, error) | ||
73 | + Find(queryOptions OrderPaymentQuery) ([]*OrderPayment, error) | ||
74 | + CountAll(queryOptions OrderPaymentQuery) (int, error) | ||
75 | +} |
pkg/infrastructure/dao/pg_order_dao.go
0 → 100644
1 | +package dao | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
7 | +) | ||
8 | + | ||
9 | +type OrderDao struct { | ||
10 | + transactionContext *transaction.TransactionContext | ||
11 | +} | ||
12 | + | ||
13 | +func (dao *OrderDao) Update(options map[string]interface{}) (err error) { | ||
14 | + tx := dao.transactionContext.PgTx | ||
15 | + order := new(models.Order) | ||
16 | + q := tx.Model(order) | ||
17 | + if v, ok := options["orderPaymentAmount"]; ok { | ||
18 | + q.Set("order_payment_amount = ?", v) | ||
19 | + } | ||
20 | + if v, ok := options["id"]; ok { | ||
21 | + q.Where("id = ?", v) | ||
22 | + } | ||
23 | + _, err = q.Update() | ||
24 | + return | ||
25 | +} | ||
26 | + | ||
27 | +func (dao *OrderDao) GetOrderBaseInfo(id int64) (data map[string]interface{}, err error) { | ||
28 | + tx := dao.transactionContext.PgTx | ||
29 | + order := new(models.Order) | ||
30 | + | ||
31 | + data = make(map[string]interface{}) | ||
32 | + q := tx.Model(order) | ||
33 | + q.Column("partner_id", "partner_bonus_percent", "order_payment_amount", "buyer") | ||
34 | + q.Where("id = ?", id) | ||
35 | + err = q.Select() | ||
36 | + if err == nil { | ||
37 | + data["PartnerId"] = order.PartnerId | ||
38 | + data["PartnerBonusPercent"] = order.PartnerBonusPercent | ||
39 | + data["OrderPaymentAmount"] = order.OrderPaymentAmount | ||
40 | + data["Buyer"] = order.Buyer | ||
41 | + } | ||
42 | + return | ||
43 | +} | ||
44 | + | ||
45 | +func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) { | ||
46 | + if transactionContext == nil { | ||
47 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
48 | + } else { | ||
49 | + return &OrderDao{ | ||
50 | + transactionContext: transactionContext, | ||
51 | + }, nil | ||
52 | + } | ||
53 | +} |
1 | package models | 1 | package models |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "time" | ||
5 | - | ||
6 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | 4 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" |
5 | + "time" | ||
7 | ) | 6 | ) |
8 | 7 | ||
9 | type Order struct { | 8 | type Order struct { |
10 | - tableName struct{} `pg:"order,alias:order"` | 9 | + tableName struct{} `pg:"order"` |
10 | + //id | ||
11 | Id int64 `pg:",pk"` | 11 | Id int64 `pg:",pk"` |
12 | - //订单类型 | ||
13 | - OrderType int | 12 | + //订单类型 1:实际订单 2:意向订单 |
13 | + OrderType int `pg:",notnull,default:1"` | ||
14 | //订单编号 | 14 | //订单编号 |
15 | - OrderCode string | 15 | + OrderCode string `pg:",notnull` |
16 | //订单名称 | 16 | //订单名称 |
17 | OrderName string | 17 | OrderName string |
18 | //订单状态 | 18 | //订单状态 |
19 | - OrderStatus int | ||
20 | - //数量 | 19 | + OrderStatus int `pg:",notnull,default:1"` |
20 | + //订单数量 | ||
21 | OrderCount int | 21 | OrderCount int |
22 | - //实际数量 | 22 | + //实际订单数量 |
23 | OrderActualCount int | 23 | OrderActualCount int |
24 | //订单金额 | 24 | //订单金额 |
25 | - OrderAmount int | ||
26 | - //实际订单金额 | ||
27 | - OrderActualAmount int | ||
28 | - //订单已支付分红金额(货款) | ||
29 | - OrderPaymentAmount int | 25 | + OrderAmount float64 |
26 | + //订单实际金额 | ||
27 | + OrderActualAmount float64 | ||
28 | + //订单已支付金额(货款) | ||
29 | + OrderPaymentAmount float64 | ||
30 | //订单区域信息 | 30 | //订单区域信息 |
31 | OrderRegionInfo *domain.RegionInfo | 31 | OrderRegionInfo *domain.RegionInfo |
32 | - //买家 | 32 | + |
33 | Buyer *domain.Buyer | 33 | Buyer *domain.Buyer |
34 | - //合伙人id | 34 | + //合伙人编号 |
35 | PartnerId int64 | 35 | PartnerId int64 |
36 | //合伙人分红百分比 | 36 | //合伙人分红百分比 |
37 | PartnerBonusPercent float64 | 37 | PartnerBonusPercent float64 |
38 | //业务员分红百分比 | 38 | //业务员分红百分比 |
39 | SalesmanBonusPercent float64 | 39 | SalesmanBonusPercent float64 |
40 | + | ||
40 | //创建时间 | 41 | //创建时间 |
41 | CreateAt time.Time | 42 | CreateAt time.Time |
42 | //更新时间 | 43 | //更新时间 |
43 | UpdateAt time.Time | 44 | UpdateAt time.Time |
44 | - //最后查看得时间 | 45 | + |
46 | + //上一次查看时间 已读情况 | ||
45 | LastViewTime time.Time | 47 | LastViewTime time.Time |
46 | } | 48 | } |
1 | +package models | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +type OrderPayment struct { | ||
6 | + tableName struct{} `pg:"order_payment"` | ||
7 | + //编号 | ||
8 | + Id int64 `pg:",pk"` | ||
9 | + //订单编号 | ||
10 | + OrderId int64 | ||
11 | + //合伙人编号 | ||
12 | + PartnerId int64 | ||
13 | + //支付序号 | ||
14 | + PaymentSn int | ||
15 | + //支付货款 | ||
16 | + PaymentAmount float64 `pg:",notnull,default:0"` | ||
17 | + //分红金额 | ||
18 | + BonusAmount float64 | ||
19 | + //分红状态 1.等待支付分红 2.已支付分红 | ||
20 | + BonusStatus int `pg:",notnull,default:1"` | ||
21 | + //创建时间 | ||
22 | + CreateAt time.Time | ||
23 | + //更新时间 | ||
24 | + UpdateAt time.Time | ||
25 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
8 | +) | ||
9 | + | ||
10 | +type OrderPaymentRepository struct { | ||
11 | + transactionContext *transaction.TransactionContext | ||
12 | +} | ||
13 | + | ||
14 | +func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain.OrderPayment, error) { | ||
15 | + var ( | ||
16 | + err error | ||
17 | + tx = repository.transactionContext.PgTx | ||
18 | + ) | ||
19 | + m := &models.OrderPayment{ | ||
20 | + Id: dm.Id, | ||
21 | + OrderId: dm.OrderId, | ||
22 | + PartnerId: dm.PartnerId, | ||
23 | + PaymentAmount: dm.PaymentAmount, | ||
24 | + BonusAmount: dm.BonusAmount, | ||
25 | + BonusStatus: dm.BonusStatus, | ||
26 | + CreateAt: dm.CreateAt, | ||
27 | + PaymentSn: dm.PaymentSn, | ||
28 | + UpdateAt: dm.UpdateAt, | ||
29 | + } | ||
30 | + if m.Id == 0 { | ||
31 | + err = tx.Insert(m) | ||
32 | + dm.Id = m.Id | ||
33 | + if err != nil { | ||
34 | + return nil, err | ||
35 | + } | ||
36 | + } else { | ||
37 | + err = tx.Update(m) | ||
38 | + if err != nil { | ||
39 | + return nil, err | ||
40 | + } | ||
41 | + } | ||
42 | + return dm, nil | ||
43 | +} | ||
44 | + | ||
45 | +func (repository *OrderPaymentRepository) Remove(OrderPayment *domain.OrderPayment) (*domain.OrderPayment, error) { | ||
46 | + var ( | ||
47 | + tx = repository.transactionContext.PgTx | ||
48 | + OrderPaymentModel = &models.OrderPayment{Id: OrderPayment.Identify().(int64)} | ||
49 | + ) | ||
50 | + if _, err := tx.Model(OrderPaymentModel).Where("id = ?", OrderPayment.Id).Delete(); err != nil { | ||
51 | + return OrderPayment, err | ||
52 | + } | ||
53 | + return OrderPayment, nil | ||
54 | +} | ||
55 | + | ||
56 | +func (repository *OrderPaymentRepository) FindOne(queryOptions domain.OrderPaymentFindOneQuery) (*domain.OrderPayment, error) { | ||
57 | + tx := repository.transactionContext.PgTx | ||
58 | + OrderPaymentModel := new(models.OrderPayment) | ||
59 | + query := tx.Model(OrderPaymentModel) | ||
60 | + | ||
61 | + if queryOptions.OrderId > 0 { | ||
62 | + query.Where("order_payment.order_id = ?", queryOptions.OrderId) | ||
63 | + } | ||
64 | + if queryOptions.PaymentSn > 0 { | ||
65 | + query.Where("order_payment.payment_sn = ?", queryOptions.PaymentSn) | ||
66 | + } | ||
67 | + if err := query.First(); err != nil { | ||
68 | + return nil, err | ||
69 | + } | ||
70 | + if OrderPaymentModel.Id == 0 { | ||
71 | + return nil, nil | ||
72 | + } | ||
73 | + return repository.transformPgModelToDomainModel(OrderPaymentModel) | ||
74 | +} | ||
75 | + | ||
76 | +func (repository *OrderPaymentRepository) Find(queryOptions domain.OrderPaymentQuery) ([]*domain.OrderPayment, error) { | ||
77 | + tx := repository.transactionContext.PgTx | ||
78 | + var OrderPaymentModels []*models.OrderPayment | ||
79 | + query := tx.Model(&OrderPaymentModels) | ||
80 | + query.Where("order_payment.order_id = ?", queryOptions.OrderId) | ||
81 | + var ( | ||
82 | + err error | ||
83 | + rsp = make([]*domain.OrderPayment, 0) | ||
84 | + ) | ||
85 | + err = query.Select() | ||
86 | + if err != nil { | ||
87 | + return rsp, err | ||
88 | + } | ||
89 | + for i := range OrderPaymentModels { | ||
90 | + dm, err := repository.transformPgModelToDomainModel(OrderPaymentModels[i]) | ||
91 | + if err != nil { | ||
92 | + return rsp, err | ||
93 | + } | ||
94 | + rsp = append(rsp, dm) | ||
95 | + } | ||
96 | + return rsp, nil | ||
97 | +} | ||
98 | + | ||
99 | +func (repository OrderPaymentRepository) CountAll(queryOption domain.OrderPaymentQuery) (int, error) { | ||
100 | + db := repository.transactionContext.PgDd | ||
101 | + partnerModels := models.PartnerInfo{} | ||
102 | + query := db.Model(&partnerModels) | ||
103 | + //if len(queryOption.PartnerName) > 0 { | ||
104 | + // query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%") | ||
105 | + //} | ||
106 | + //if queryOption.RegionInfo != nil { | ||
107 | + // query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%") | ||
108 | + //} | ||
109 | + //if len(queryOption.PartnerCategory) > 0 { | ||
110 | + // query = query.WhereIn("partner_category in(?)", queryOption.PartnerCategory) | ||
111 | + //} | ||
112 | + cnt, err := query.Count() | ||
113 | + return cnt, err | ||
114 | +} | ||
115 | + | ||
116 | +func (repository *OrderPaymentRepository) transformPgModelToDomainModel(dm *models.OrderPayment) (*domain.OrderPayment, error) { | ||
117 | + m := &domain.OrderPayment{ | ||
118 | + Id: dm.Id, | ||
119 | + OrderId: dm.OrderId, | ||
120 | + PartnerId: dm.PartnerId, | ||
121 | + PaymentAmount: dm.PaymentAmount, | ||
122 | + BonusAmount: dm.BonusAmount, | ||
123 | + BonusStatus: dm.BonusStatus, | ||
124 | + PaymentSn: dm.PaymentSn, | ||
125 | + CreateAt: dm.CreateAt, | ||
126 | + UpdateAt: dm.UpdateAt, | ||
127 | + } | ||
128 | + return m, nil | ||
129 | +} | ||
130 | + | ||
131 | +func NewOrderPaymentRepository(transactionContext *transaction.TransactionContext) (*OrderPaymentRepository, error) { | ||
132 | + if transactionContext == nil { | ||
133 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
134 | + } | ||
135 | + return &OrderPaymentRepository{transactionContext: transactionContext}, nil | ||
136 | +} |
pkg/infrastructure/utils/math.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/shopspring/decimal" | ||
5 | + "math" | ||
6 | + "math/rand" | ||
7 | + "time" | ||
8 | +) | ||
9 | + | ||
10 | +func decimal1(value float64) float64 { | ||
11 | + return math.Trunc(value*1e1+0.5) * 1e-1 | ||
12 | +} | ||
13 | + | ||
14 | +func Round(value float64, places int32) float64 { | ||
15 | + quantity := decimal.NewFromFloat(value) | ||
16 | + d := quantity.Round(places) | ||
17 | + rsp, _ := d.Float64() | ||
18 | + return rsp | ||
19 | +} | ||
20 | + | ||
21 | +func Decimal(value float64) float64 { | ||
22 | + return Round(value, 2) | ||
23 | +} | ||
24 | + | ||
25 | +func DecimalToNumber(value float64) float64 { | ||
26 | + return Round(value, 2) | ||
27 | +} | ||
28 | + | ||
29 | +func GenerateRangeNum(min, max int) int { | ||
30 | + rand.Seed(time.Now().Unix()) | ||
31 | + randNum := rand.Intn(max-min) + min | ||
32 | + return randNum | ||
33 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "github.com/astaxie/beego/logs" | ||
6 | + OrderPaymentCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command" | ||
7 | + OrderPaymentQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" | ||
8 | + OrderPaymentSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/service" | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
10 | + "strconv" | ||
11 | +) | ||
12 | + | ||
13 | +type DividendsController struct { | ||
14 | + BaseController | ||
15 | +} | ||
16 | + | ||
17 | +////Prepare 重写 BaseController 的Prepare方法 | ||
18 | +func (c *DividendsController) Prepare() { | ||
19 | + c.BaseController.Prepare() | ||
20 | + //if ok := c.ValidJWTToken(); !ok { | ||
21 | + // return | ||
22 | + //} | ||
23 | + //if ok := c.ValidAdminPermission(domain.PERMINSSION_PARTNER); !ok { | ||
24 | + // return | ||
25 | + //} | ||
26 | +} | ||
27 | + | ||
28 | +//Edit 编辑分红支付 | ||
29 | +func (c *DividendsController) Edit() { | ||
30 | + //用与适配前端定义的数据结构 | ||
31 | + type DividendPaymentItem struct { | ||
32 | + PaymentForGoods string `json:"paymentForGoods"` | ||
33 | + StateOfPayment string `json:"stateOfPayment"` | ||
34 | + } | ||
35 | + type Parameter struct { | ||
36 | + Id int64 `json:"id"` //订单编号 | ||
37 | + DividendPayment []DividendPaymentItem `json:"dividendPayment"` | ||
38 | + } | ||
39 | + var ( | ||
40 | + param Parameter | ||
41 | + err error | ||
42 | + ) | ||
43 | + if err = c.BindJsonData(¶m); err != nil { | ||
44 | + logs.Error(err) | ||
45 | + c.ResponseError(errors.New("json数据解析失败")) | ||
46 | + return | ||
47 | + } | ||
48 | + cmd := OrderPaymentCmd.CreateOrderPaymentCommand{ | ||
49 | + OrderId: param.Id, | ||
50 | + DivdendPaymentItem: make([]OrderPaymentCmd.DivdendPyamentItem, 0), | ||
51 | + } | ||
52 | + | ||
53 | + //编辑 | ||
54 | + for i := range param.DividendPayment { | ||
55 | + item := param.DividendPayment[i] | ||
56 | + paymentItem := OrderPaymentCmd.DivdendPyamentItem{} | ||
57 | + paymentItem.PaymentForGoods, _ = strconv.ParseFloat(item.PaymentForGoods, 64) | ||
58 | + paymentItem.StateOfPayment, _ = strconv.Atoi(item.StateOfPayment) | ||
59 | + paymentItem.PaymentSn = i + 1 | ||
60 | + | ||
61 | + if paymentItem.StateOfPayment == domain.BonusPaid { | ||
62 | + cmd.TotalPaymentAmount += paymentItem.PaymentForGoods | ||
63 | + } | ||
64 | + cmd.DivdendPaymentItem = append(cmd.DivdendPaymentItem, paymentItem) | ||
65 | + } | ||
66 | + serve := OrderPaymentSvr.NewOrderPaymentService(nil) | ||
67 | + _, err = serve.CreateOrderPayment(&cmd) | ||
68 | + if err != nil { | ||
69 | + c.ResponseError(err) | ||
70 | + return | ||
71 | + } | ||
72 | + c.ResponseData(nil) | ||
73 | + return | ||
74 | +} | ||
75 | + | ||
76 | +//Edit 分红支付详情 | ||
77 | +func (c *DividendsController) Detail() { | ||
78 | + type Parameter struct { | ||
79 | + Id int64 `json:"id"` //订单编号 | ||
80 | + } | ||
81 | + var ( | ||
82 | + param Parameter | ||
83 | + err error | ||
84 | + ) | ||
85 | + if err = c.BindJsonData(¶m); err != nil { | ||
86 | + logs.Error(err) | ||
87 | + c.ResponseError(errors.New("json数据解析失败")) | ||
88 | + return | ||
89 | + } | ||
90 | + | ||
91 | + cmd := OrderPaymentQuery.ListOrderPaymentQuery{ | ||
92 | + OrderId: param.Id, | ||
93 | + } | ||
94 | + serve := OrderPaymentSvr.NewOrderPaymentService(nil) | ||
95 | + var data []*domain.OrderPayment | ||
96 | + _, data, err = serve.ListOrderPayment(&cmd) | ||
97 | + if err != nil { | ||
98 | + c.ResponseError(err) | ||
99 | + return | ||
100 | + } | ||
101 | + | ||
102 | + type DividendPayment struct { | ||
103 | + PaymentForGoods float64 `json:"paymentForGoods"` | ||
104 | + UpdateTime string `json:"updateTime"` | ||
105 | + StateOfPayment int `json:"stateOfPayment"` | ||
106 | + Dividend float64 `json:"dividend"` | ||
107 | + DividendProportion float64 `json:"dividendProportion"` | ||
108 | + } | ||
109 | + type Response struct { | ||
110 | + DividendPayment []DividendPayment `json:"dividendPayment"` | ||
111 | + } | ||
112 | + rsp := Response{DividendPayment: make([]DividendPayment, 0)} | ||
113 | + for i := range data { | ||
114 | + item := data[i] | ||
115 | + payment := DividendPayment{ | ||
116 | + PaymentForGoods: item.PaymentAmount, | ||
117 | + UpdateTime: item.UpdateAt.Format("2006-01-02 15:04:05"), | ||
118 | + StateOfPayment: item.BonusStatus, | ||
119 | + Dividend: item.BonusAmount, | ||
120 | + DividendProportion: 2, | ||
121 | + } | ||
122 | + rsp.DividendPayment = append(rsp.DividendPayment, payment) | ||
123 | + } | ||
124 | + | ||
125 | + c.ResponseData(rsp) | ||
126 | + return | ||
127 | +} |
@@ -27,6 +27,10 @@ func init() { | @@ -27,6 +27,10 @@ func init() { | ||
27 | beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"), | 27 | beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"), |
28 | beego.NSRouter("/set-status", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"), | 28 | beego.NSRouter("/set-status", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"), |
29 | ), | 29 | ), |
30 | + beego.NSNamespace("/dividends", | ||
31 | + beego.NSRouter("/edit", &controllers.DividendsController{}, "POST:Edit"), | ||
32 | + beego.NSRouter("/detail", &controllers.DividendsController{}, "POST:Detail"), | ||
33 | + ), | ||
30 | ) | 34 | ) |
31 | beego.AddNamespace(adminRouter) | 35 | beego.AddNamespace(adminRouter) |
32 | } | 36 | } |
-
请 注册 或 登录 后发表评论