作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !2
@@ -411,7 +411,7 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue @@ -411,7 +411,7 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
411 411
412 /** 412 /**
413 * @Author SteveChan 413 * @Author SteveChan
414 - * @Description //TODO 移除合伙人 414 + * @Description // 移除合伙人
415 * @Date 16:40 2020/12/29 415 * @Date 16:40 2020/12/29
416 * @Param 416 * @Param
417 * @return 417 * @return
@@ -432,6 +432,8 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.Remo @@ -432,6 +432,8 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.Remo
432 432
433 var ( 433 var (
434 partnerInfoRepository domain.PartnerInfoRepository 434 partnerInfoRepository domain.PartnerInfoRepository
  435 + orderBaseRepository domain.OrderBaseRepository
  436 + orders []domain.OrderBase
435 ) 437 )
436 438
437 if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ 439 if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
@@ -440,7 +442,19 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.Remo @@ -440,7 +442,19 @@ func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.Remo
440 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 442 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
441 } 443 }
442 444
  445 + if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
  446 + "transactionContext": transactionContext,
  447 + }); err != nil {
  448 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  449 + }
  450 +
443 // 判断合伙人是否有业务数据 451 // 判断合伙人是否有业务数据
  452 + orders, _, err = orderBaseRepository.Find(domain.OrderBaseFindQuery{
  453 + PartnerId: cmd.Id,
  454 + })
  455 + if len(orders) > 0 {
  456 + return lib.ThrowError(lib.BUSINESS_ERROR, "该合伙人有业务数据,不可删除!")
  457 + }
444 458
445 if err = partnerInfoRepository.Remove(cmd.Id); err != nil { 459 if err = partnerInfoRepository.Remove(cmd.Id); err != nil {
446 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 460 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 const ( 9 const (
10 OrderReal = iota + 1 //实发订单 10 OrderReal = iota + 1 //实发订单
11 OrderIntention //意向订单 11 OrderIntention //意向订单
12 - OrderTypeBestShop //来自小程序海鲜干货的订单 12 + OrderTypeBestShop //来自小程序香米的订单
13 ) 13 )
14 14
15 func GetOrderBaseTypeName(orderType int) string { 15 func GetOrderBaseTypeName(orderType int) string {
@@ -70,7 +70,7 @@ type OrderGood struct { @@ -70,7 +70,7 @@ type OrderGood struct {
70 UseGoodNumber int `json:"useGoodNumber"` 70 UseGoodNumber int `json:"useGoodNumber"`
71 //货品单价 71 //货品单价
72 Price float64 `json:"price"` 72 Price float64 `json:"price"`
73 - //合伙人分红比例 73 + //合伙人分红比例 比如12.7等同于12.7%,使用负值表示分红比例未进行设置
74 PartnerBonusPercent float64 `json:"partnerBonusPercent"` 74 PartnerBonusPercent float64 `json:"partnerBonusPercent"`
75 //分红支付状态 75 //分红支付状态
76 BonusStatus int `json:"bonusStatus"` 76 BonusStatus int `json:"bonusStatus"`
@@ -87,6 +87,20 @@ type OrderGood struct { @@ -87,6 +87,20 @@ type OrderGood struct {
87 DataFrom OrderDataFrom `json:"data_from"` 87 DataFrom OrderDataFrom `json:"data_from"`
88 } 88 }
89 89
  90 +//NewOrderGood 初始值设定
  91 +func NewOrderGood() OrderGood {
  92 + return OrderGood{
  93 + UseGoodNumber: -1,
  94 + BonusStatus: OrderGoodWaitPay,
  95 + PartnerBonusPercent: -1,
  96 + GoodCompute: GoodCompute{
  97 + UsePartnerBonus: -1,
  98 + UseAmount: -1,
  99 + },
  100 + CurrentBonusStatus: OrderGoodBonusWaitPay{},
  101 + }
  102 +}
  103 +
90 //GetCurrentGoodNumber 获取当前的商品数量 104 //GetCurrentGoodNumber 获取当前的商品数量
91 func (good OrderGood) GetCurrentGoodNumber() int { 105 func (good OrderGood) GetCurrentGoodNumber() int {
92 if good.UseGoodNumber >= 0 { 106 if good.UseGoodNumber >= 0 {
@@ -111,7 +125,7 @@ func (good OrderGood) GetCurrentPartnerBonus() float64 { @@ -111,7 +125,7 @@ func (good OrderGood) GetCurrentPartnerBonus() float64 {
111 return good.GoodCompute.PlanPartnerBonus 125 return good.GoodCompute.PlanPartnerBonus
112 } 126 }
113 127
114 -//GetCurrentAmount 获取当前的商品合伙人分红 128 +//ModifyOrderGoodNumber 修改货品数量
115 func (good *OrderGood) ModifyOrderGoodNumber(number int, orderType int) error { 129 func (good *OrderGood) ModifyOrderGoodNumber(number int, orderType int) error {
116 if good.PlanGoodNumber < number { 130 if good.PlanGoodNumber < number {
117 return fmt.Errorf("修改数量不能大于初始值:%d", good.PlanGoodNumber) 131 return fmt.Errorf("修改数量不能大于初始值:%d", good.PlanGoodNumber)
@@ -120,6 +134,7 @@ func (good *OrderGood) ModifyOrderGoodNumber(number int, orderType int) error { @@ -120,6 +134,7 @@ func (good *OrderGood) ModifyOrderGoodNumber(number int, orderType int) error {
120 return err 134 return err
121 } 135 }
122 136
  137 +//ModifyPertnerBonusPercent 修改货品的分红比例
123 func (good *OrderGood) ModifyPertnerBonusPercent(percent float64, orderType int) error { 138 func (good *OrderGood) ModifyPertnerBonusPercent(percent float64, orderType int) error {
124 err := good.CurrentBonusStatus.ModifyPertnerBonusPercent(good, percent, orderType) 139 err := good.CurrentBonusStatus.ModifyPertnerBonusPercent(good, percent, orderType)
125 return err 140 return err
@@ -162,6 +177,7 @@ type OrderGoodBonusHasPay struct{} @@ -162,6 +177,7 @@ type OrderGoodBonusHasPay struct{}
162 177
163 var _ OrderGoodBonusStatus = (*OrderGoodBonusHasPay)(nil) 178 var _ OrderGoodBonusStatus = (*OrderGoodBonusHasPay)(nil)
164 179
  180 +//WartPayPartnerBonus 货品的支付状态从“待支付”状态变更为“待支付”
165 func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error { 181 func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error {
166 good.GoodCompute.PartnerBonusExpense = 0 182 good.GoodCompute.PartnerBonusExpense = 0
167 good.GoodCompute.PartnerBonusHas = 0 183 good.GoodCompute.PartnerBonusHas = 0
@@ -178,6 +194,7 @@ func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error @@ -178,6 +194,7 @@ func (waitPay OrderGoodBonusWaitPay) WartPayPartnerBonus(good *OrderGood) error
178 return nil 194 return nil
179 } 195 }
180 196
  197 +//PayPartnerBonus 货品的支付状态从“待支付”状态变更为“已支付”
181 func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error { 198 func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error {
182 //待支付状态转支付时 199 //待支付状态转支付时
183 //合伙人已收收分红等于合伙人应收分红(或者调整的) 200 //合伙人已收收分红等于合伙人应收分红(或者调整的)
@@ -196,6 +213,7 @@ func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error { @@ -196,6 +213,7 @@ func (waitPay OrderGoodBonusWaitPay) PayPartnerBonus(good *OrderGood) error {
196 return nil 213 return nil
197 } 214 }
198 215
  216 +//PayPartnerBonus 货品的支付状态从“已支付”状态变更为“已支付”
199 func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error { 217 func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error {
200 //已支付的值保持不变 218 //已支付的值保持不变
201 //未支付的值保持不变 219 //未支付的值保持不变
@@ -210,10 +228,12 @@ func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error { @@ -210,10 +228,12 @@ func (hasPay OrderGoodBonusHasPay) PayPartnerBonus(good *OrderGood) error {
210 return nil 228 return nil
211 } 229 }
212 230
  231 +//WartPayPartnerBonus 货品的支付状态从“已支付”状态变更为“待支付”
213 func (hasPay OrderGoodBonusHasPay) WartPayPartnerBonus(good *OrderGood) error { 232 func (hasPay OrderGoodBonusHasPay) WartPayPartnerBonus(good *OrderGood) error {
214 return errors.New("已支付的货单不能将状态回退为待支付") 233 return errors.New("已支付的货单不能将状态回退为待支付")
215 } 234 }
216 235
  236 +//ModifyOrderGoodNumber 货品的支付状态为“已支付”状态变时,修改货品数量
217 func (hasPay OrderGoodBonusHasPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error { 237 func (hasPay OrderGoodBonusHasPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error {
218 //规则描述: 238 //规则描述:
219 //实际自建订单(orderType==1),已支付分红状态下“可以”修改货品数量 239 //实际自建订单(orderType==1),已支付分红状态下“可以”修改货品数量
@@ -233,6 +253,7 @@ func (hasPay OrderGoodBonusHasPay) ModifyOrderGoodNumber(good *OrderGood, number @@ -233,6 +253,7 @@ func (hasPay OrderGoodBonusHasPay) ModifyOrderGoodNumber(good *OrderGood, number
233 return nil 253 return nil
234 } 254 }
235 255
  256 +//ModifyOrderGoodNumber 货品的支付状态为“待支付”状态变时,修改货品数量
236 func (waitPay OrderGoodBonusWaitPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error { 257 func (waitPay OrderGoodBonusWaitPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error {
237 //规则描述: 258 //规则描述:
238 //实际自建订单(orderType==1),未支付分红状态下“可以”修改货品数量 259 //实际自建订单(orderType==1),未支付分红状态下“可以”修改货品数量
@@ -247,6 +268,7 @@ func (waitPay OrderGoodBonusWaitPay) ModifyOrderGoodNumber(good *OrderGood, numb @@ -247,6 +268,7 @@ func (waitPay OrderGoodBonusWaitPay) ModifyOrderGoodNumber(good *OrderGood, numb
247 return nil 268 return nil
248 } 269 }
249 270
  271 +//ModifyPertnerBonusPercent 货品的支付状态为“待支付”状态变时,修改货品合伙人分红比例
250 func (waitPay OrderGoodBonusWaitPay) ModifyPertnerBonusPercent(good *OrderGood, percent float64, orderType int) error { 272 func (waitPay OrderGoodBonusWaitPay) ModifyPertnerBonusPercent(good *OrderGood, percent float64, orderType int) error {
251 //规则描述: 273 //规则描述:
252 //实际自建订单(orderType==1),未支付分红状态下“不可以”修改合伙人分红比例 274 //实际自建订单(orderType==1),未支付分红状态下“不可以”修改合伙人分红比例
@@ -276,20 +298,6 @@ func (hasPay OrderGoodBonusHasPay) ModifyPertnerBonusPercent(good *OrderGood, pe @@ -276,20 +298,6 @@ func (hasPay OrderGoodBonusHasPay) ModifyPertnerBonusPercent(good *OrderGood, pe
276 return errors.New("已支付分红的货品订单,不能修改合伙人分红比例") 298 return errors.New("已支付分红的货品订单,不能修改合伙人分红比例")
277 } 299 }
278 300
279 -//NewOrderGood 初始值设定  
280 -func NewOrderGood() OrderGood {  
281 - return OrderGood{  
282 - UseGoodNumber: -1,  
283 - BonusStatus: OrderGoodWaitPay,  
284 - PartnerBonusPercent: -1,  
285 - GoodCompute: GoodCompute{  
286 - UsePartnerBonus: -1,  
287 - UseAmount: -1,  
288 - },  
289 - CurrentBonusStatus: OrderGoodBonusWaitPay{},  
290 - }  
291 -}  
292 -  
293 //Compute 数据汇总核算 301 //Compute 数据汇总核算
294 func (good *OrderGood) Compute() error { 302 func (good *OrderGood) Compute() error {
295 //计算预计货品总值 303 //计算预计货品总值
@@ -299,15 +307,17 @@ func (good *OrderGood) Compute() error { @@ -299,15 +307,17 @@ func (good *OrderGood) Compute() error {
299 if good.PlanGoodNumber < 0 { 307 if good.PlanGoodNumber < 0 {
300 planGoodNumber = 0 308 planGoodNumber = 0
301 } 309 }
302 - planamount := price.Mul(decimal.NewFromInt(int64(planGoodNumber))) //price*planGoodNumber 310 + //计算预计货品总值(planamount), 货品单价*预计货品数量(price*planGoodNumber)
  311 + planamount := price.Mul(decimal.NewFromInt(int64(planGoodNumber)))
303 var partnerBonusPercent float64 312 var partnerBonusPercent float64
304 if good.PartnerBonusPercent < 0 { 313 if good.PartnerBonusPercent < 0 {
305 partnerBonusPercent = 0 314 partnerBonusPercent = 0
306 } else { 315 } else {
307 partnerBonusPercent = good.PartnerBonusPercent 316 partnerBonusPercent = good.PartnerBonusPercent
308 } 317 }
309 - //price*useGoodNumber 318 + //计算预计合伙人分红(planPartnerBonus), 预计货品总值*合伙人分成比例/100(planamount*partnerBonusPercent/100)
310 planPartnerBonus := planamount.Mul(decimal.NewFromFloat(partnerBonusPercent)).Div(decimal.NewFromInt(100)) //price*planGoodNumber*PartnerBonusPercent 319 planPartnerBonus := planamount.Mul(decimal.NewFromFloat(partnerBonusPercent)).Div(decimal.NewFromInt(100)) //price*planGoodNumber*PartnerBonusPercent
  320 + //货品预计总值
311 good.GoodCompute.PlanAmount, _ = planamount.Round(2).BigFloat().Float64() 321 good.GoodCompute.PlanAmount, _ = planamount.Round(2).BigFloat().Float64()
312 good.GoodCompute.PlanPartnerBonus, _ = planPartnerBonus.Round(2).BigFloat().Float64() 322 good.GoodCompute.PlanPartnerBonus, _ = planPartnerBonus.Round(2).BigFloat().Float64()
313 if good.UseGoodNumber < 0 { 323 if good.UseGoodNumber < 0 {
@@ -316,8 +326,8 @@ func (good *OrderGood) Compute() error { @@ -316,8 +326,8 @@ func (good *OrderGood) Compute() error {
316 good.GoodCompute.UseAmount = -1 326 good.GoodCompute.UseAmount = -1
317 } else { 327 } else {
318 //计算调整后的货品总值 328 //计算调整后的货品总值
319 - //计算调整后的合伙人分红  
320 - useamount := price.Mul(decimal.NewFromInt(int64(good.UseGoodNumber))) //price*useGoodNumber/price*useGoodNumber 329 + useamount := price.Mul(decimal.NewFromInt(int64(good.UseGoodNumber)))
  330 + //计算调整后的合伙人分红 //price*useGoodNumber/price*useGoodNumber
321 usePartnerBonus := useamount.Mul(decimal.NewFromFloat(partnerBonusPercent)).Div(decimal.NewFromInt(100)) //price*useGoodNumber*PartnerBonusPercent 331 usePartnerBonus := useamount.Mul(decimal.NewFromFloat(partnerBonusPercent)).Div(decimal.NewFromInt(100)) //price*useGoodNumber*PartnerBonusPercent
322 good.GoodCompute.UsePartnerBonus, _ = usePartnerBonus.Round(2).BigFloat().Float64() 332 good.GoodCompute.UsePartnerBonus, _ = usePartnerBonus.Round(2).BigFloat().Float64()
323 good.GoodCompute.UseAmount, _ = useamount.Round(2).BigFloat().Float64() 333 good.GoodCompute.UseAmount, _ = useamount.Round(2).BigFloat().Float64()
此 diff 太大无法显示。