作者 唐旭辉

代码清理

@@ -182,7 +182,6 @@ func (subscriber *OrderLogSubscriber) SubscribedToEventTypes() []string { @@ -182,7 +182,6 @@ func (subscriber *OrderLogSubscriber) SubscribedToEventTypes() []string {
182 event.UPDATE_BONUS_BY_GOOD_NUMBER_EVENT, 182 event.UPDATE_BONUS_BY_GOOD_NUMBER_EVENT,
183 event.UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT, 183 event.UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT,
184 event.UPDATE_ORDER_REMARK, 184 event.UPDATE_ORDER_REMARK,
185 - event.PAY_ORDER_GOOD_BONUS_EVENT,  
186 event.BATCH_PAY_ORDER_GOOD_BONUS_EVENT, 185 event.BATCH_PAY_ORDER_GOOD_BONUS_EVENT,
187 } 186 }
188 } 187 }
@@ -2,7 +2,6 @@ package service @@ -2,7 +2,6 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "time"  
6 5
7 "github.com/astaxie/beego/logs" 6 "github.com/astaxie/beego/logs"
8 7
@@ -536,108 +535,108 @@ func (service OrderInfoService) deleteOldOrderGoods(newGoods []domain.OrderGood, @@ -536,108 +535,108 @@ func (service OrderInfoService) deleteOldOrderGoods(newGoods []domain.OrderGood,
536 } 535 }
537 536
538 //Delivery 发货 537 //Delivery 发货
539 -func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error {  
540 - var (  
541 - transactionContext, _ = factory.CreateTransactionContext(nil)  
542 - err error  
543 - )  
544 - if err = transactionContext.StartTransaction(); err != nil {  
545 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
546 - }  
547 - defer func() {  
548 - transactionContext.RollbackTransaction()  
549 - }()  
550 - var (  
551 - orderBaseRepository domain.OrderBaseRepository  
552 - orderGoodRepository domain.OrderGoodRepository  
553 - oldOrderData *domain.OrderBase  
554 - oldOrderGoods []domain.OrderGood  
555 - orderBaseDao *dao.OrderBaseDao  
556 - ) 538 +// func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error {
  539 +// var (
  540 +// transactionContext, _ = factory.CreateTransactionContext(nil)
  541 +// err error
  542 +// )
  543 +// if err = transactionContext.StartTransaction(); err != nil {
  544 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  545 +// }
  546 +// defer func() {
  547 +// transactionContext.RollbackTransaction()
  548 +// }()
  549 +// var (
  550 +// orderBaseRepository domain.OrderBaseRepository
  551 +// orderGoodRepository domain.OrderGoodRepository
  552 +// oldOrderData *domain.OrderBase
  553 +// oldOrderGoods []domain.OrderGood
  554 +// orderBaseDao *dao.OrderBaseDao
  555 +// )
557 556
558 - if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{  
559 - "transactionContext": transactionContext,  
560 - }); err != nil {  
561 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
562 - }  
563 - if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{  
564 - "transactionContext": transactionContext,  
565 - }); err != nil {  
566 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
567 - }  
568 - //获取旧的订单  
569 - oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{  
570 - CompanyId: cmd.CompanyId,  
571 - OrderId: cmd.OrderId,  
572 - })  
573 - if err != nil {  
574 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))  
575 - }  
576 - if oldOrderData.OrderType != domain.OrderIntention {  
577 - return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型已发生变更")  
578 - }  
579 - if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{  
580 - "transactionContext": transactionContext,  
581 - }); err != nil {  
582 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
583 - }  
584 - //检查delivery_code是否重复  
585 - if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.OrderId); err != nil {  
586 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
587 - } else if ok {  
588 - return lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")  
589 - }  
590 - //获取旧的订单中的商品  
591 - oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{  
592 - OrderId: cmd.OrderId,  
593 - CompanyId: cmd.CompanyId,  
594 - })  
595 - if err != nil {  
596 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))  
597 - }  
598 - for _, newGood := range cmd.Goods {  
599 - for i := range oldOrderGoods {  
600 - if newGood.Id != oldOrderGoods[i].Id {  
601 - continue  
602 - }  
603 - oldOrderGoods[i].GoodName = newGood.GoodName  
604 - oldOrderGoods[i].PlanGoodNumber = newGood.PlanGoodNumber  
605 - oldOrderGoods[i].Price = newGood.Price  
606 - oldOrderGoods[i].PartnerBonusPercent = newGood.PartnerBonusPercent  
607 - oldOrderGoods[i].Remark = newGood.Remark  
608 - err = oldOrderGoods[i].Compute()  
609 - if err != nil {  
610 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))  
611 - }  
612 - err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])  
613 - if err != nil {  
614 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))  
615 - }  
616 - }  
617 - }  
618 - oldOrderData.DeliveryCode = cmd.DeliveryCode  
619 - oldOrderData.DeliveryTime = time.Now()  
620 - oldOrderData.Goods = oldOrderGoods  
621 - //变更订单类型  
622 - oldOrderData.OrderType = domain.OrderReal  
623 - err = oldOrderData.Compute()  
624 - if err != nil {  
625 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))  
626 - }  
627 - err = orderBaseRepository.Save(oldOrderData)  
628 - if err != nil {  
629 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))  
630 - }  
631 - err = orderGoodRepository.Save(oldOrderGoods)  
632 - if err != nil {  
633 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))  
634 - }  
635 - err = transactionContext.CommitTransaction()  
636 - if err != nil {  
637 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
638 - }  
639 - return nil  
640 -} 557 +// if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
  558 +// "transactionContext": transactionContext,
  559 +// }); err != nil {
  560 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  561 +// }
  562 +// if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
  563 +// "transactionContext": transactionContext,
  564 +// }); err != nil {
  565 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  566 +// }
  567 +// //获取旧的订单
  568 +// oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
  569 +// CompanyId: cmd.CompanyId,
  570 +// OrderId: cmd.OrderId,
  571 +// })
  572 +// if err != nil {
  573 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
  574 +// }
  575 +// if oldOrderData.OrderType != domain.OrderIntention {
  576 +// return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型已发生变更")
  577 +// }
  578 +// if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
  579 +// "transactionContext": transactionContext,
  580 +// }); err != nil {
  581 +// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  582 +// }
  583 +// //检查delivery_code是否重复
  584 +// if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.OrderId); err != nil {
  585 +// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  586 +// } else if ok {
  587 +// return lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
  588 +// }
  589 +// //获取旧的订单中的商品
  590 +// oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
  591 +// OrderId: cmd.OrderId,
  592 +// CompanyId: cmd.CompanyId,
  593 +// })
  594 +// if err != nil {
  595 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
  596 +// }
  597 +// for _, newGood := range cmd.Goods {
  598 +// for i := range oldOrderGoods {
  599 +// if newGood.Id != oldOrderGoods[i].Id {
  600 +// continue
  601 +// }
  602 +// oldOrderGoods[i].GoodName = newGood.GoodName
  603 +// oldOrderGoods[i].PlanGoodNumber = newGood.PlanGoodNumber
  604 +// oldOrderGoods[i].Price = newGood.Price
  605 +// oldOrderGoods[i].PartnerBonusPercent = newGood.PartnerBonusPercent
  606 +// oldOrderGoods[i].Remark = newGood.Remark
  607 +// err = oldOrderGoods[i].Compute()
  608 +// if err != nil {
  609 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
  610 +// }
  611 +// err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
  612 +// if err != nil {
  613 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
  614 +// }
  615 +// }
  616 +// }
  617 +// oldOrderData.DeliveryCode = cmd.DeliveryCode
  618 +// oldOrderData.DeliveryTime = time.Now()
  619 +// oldOrderData.Goods = oldOrderGoods
  620 +// //变更订单类型
  621 +// oldOrderData.OrderType = domain.OrderReal
  622 +// err = oldOrderData.Compute()
  623 +// if err != nil {
  624 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
  625 +// }
  626 +// err = orderBaseRepository.Save(oldOrderData)
  627 +// if err != nil {
  628 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
  629 +// }
  630 +// err = orderGoodRepository.Save(oldOrderGoods)
  631 +// if err != nil {
  632 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
  633 +// }
  634 +// err = transactionContext.CommitTransaction()
  635 +// if err != nil {
  636 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  637 +// }
  638 +// return nil
  639 +// }
641 640
642 //DisableOrEnable 开启关闭订单 641 //DisableOrEnable 开启关闭订单
643 func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) error { 642 func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) error {
@@ -684,100 +683,100 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) @@ -684,100 +683,100 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand)
684 } 683 }
685 684
686 //UpdateGoodBouns 分红时,更新货品的分红相关的数值 685 //UpdateGoodBouns 分红时,更新货品的分红相关的数值
687 -func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) error {  
688 - var (  
689 - transactionContext, _ = factory.CreateTransactionContext(nil)  
690 - err error  
691 - )  
692 - if err = transactionContext.StartTransaction(); err != nil {  
693 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
694 - }  
695 - defer func() {  
696 - transactionContext.RollbackTransaction()  
697 - }()  
698 - var (  
699 - orderBaseRepository domain.OrderBaseRepository  
700 - orderGoodRepository domain.OrderGoodRepository  
701 - oldOrderData *domain.OrderBase  
702 - oldOrderGoods []domain.OrderGood  
703 - )  
704 - if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{  
705 - "transactionContext": transactionContext,  
706 - }); err != nil {  
707 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
708 - }  
709 - if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{  
710 - "transactionContext": transactionContext,  
711 - }); err != nil {  
712 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
713 - }  
714 - //获取旧的订单  
715 - oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{  
716 - OrderId: cmd.Id,  
717 - CompanyId: cmd.CompanyId,  
718 - })  
719 - if err != nil {  
720 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))  
721 - }  
722 - if oldOrderData.OrderType != domain.OrderReal {  
723 - return lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("指定的订单的订单类型发生变更"))  
724 - }  
725 - //获取旧的订单中的商品  
726 - oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{  
727 - OrderId: cmd.Id,  
728 - })  
729 - if err != nil {  
730 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))  
731 - }  
732 - for _, newGood := range cmd.GoodBouns {  
733 - for i := range oldOrderGoods {  
734 - if newGood.GoodId != oldOrderGoods[i].Id {  
735 - continue  
736 - }  
737 - oldOrderGoods[i].UseGoodNumber = newGood.UseGoodNumber  
738 - oldOrderGoods[i].Remark = newGood.Remark  
739 - oldOrderGoods[i].BonusStatus = newGood.BounsStatus  
740 - err = oldOrderGoods[i].Compute()  
741 - if err != nil {  
742 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))  
743 - }  
744 - switch newGood.BounsStatus {  
745 - case domain.OrderGoodWaitPay:  
746 - err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])  
747 - if err != nil {  
748 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))  
749 - }  
750 - case domain.OrderGoodHasPay:  
751 - err = oldOrderGoods[i].CurrentBonusStatus.PayPartnerBonus(&oldOrderGoods[i])  
752 - if err != nil {  
753 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))  
754 - }  
755 - default:  
756 - return lib.ThrowError(lib.ARG_ERROR, fmt.Sprintf("货品的支付状态错误"))  
757 - }  
758 - }  
759 - }  
760 - oldOrderData.Goods = oldOrderGoods 686 +// func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) error {
  687 +// var (
  688 +// transactionContext, _ = factory.CreateTransactionContext(nil)
  689 +// err error
  690 +// )
  691 +// if err = transactionContext.StartTransaction(); err != nil {
  692 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  693 +// }
  694 +// defer func() {
  695 +// transactionContext.RollbackTransaction()
  696 +// }()
  697 +// var (
  698 +// orderBaseRepository domain.OrderBaseRepository
  699 +// orderGoodRepository domain.OrderGoodRepository
  700 +// oldOrderData *domain.OrderBase
  701 +// oldOrderGoods []domain.OrderGood
  702 +// )
  703 +// if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
  704 +// "transactionContext": transactionContext,
  705 +// }); err != nil {
  706 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  707 +// }
  708 +// if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
  709 +// "transactionContext": transactionContext,
  710 +// }); err != nil {
  711 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  712 +// }
  713 +// //获取旧的订单
  714 +// oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
  715 +// OrderId: cmd.Id,
  716 +// CompanyId: cmd.CompanyId,
  717 +// })
  718 +// if err != nil {
  719 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
  720 +// }
  721 +// if oldOrderData.OrderType != domain.OrderReal {
  722 +// return lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("指定的订单的订单类型发生变更"))
  723 +// }
  724 +// //获取旧的订单中的商品
  725 +// oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
  726 +// OrderId: cmd.Id,
  727 +// })
  728 +// if err != nil {
  729 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
  730 +// }
  731 +// for _, newGood := range cmd.GoodBouns {
  732 +// for i := range oldOrderGoods {
  733 +// if newGood.GoodId != oldOrderGoods[i].Id {
  734 +// continue
  735 +// }
  736 +// oldOrderGoods[i].UseGoodNumber = newGood.UseGoodNumber
  737 +// oldOrderGoods[i].Remark = newGood.Remark
  738 +// oldOrderGoods[i].BonusStatus = newGood.BounsStatus
  739 +// err = oldOrderGoods[i].Compute()
  740 +// if err != nil {
  741 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
  742 +// }
  743 +// switch newGood.BounsStatus {
  744 +// case domain.OrderGoodWaitPay:
  745 +// err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
  746 +// if err != nil {
  747 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
  748 +// }
  749 +// case domain.OrderGoodHasPay:
  750 +// err = oldOrderGoods[i].CurrentBonusStatus.PayPartnerBonus(&oldOrderGoods[i])
  751 +// if err != nil {
  752 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
  753 +// }
  754 +// default:
  755 +// return lib.ThrowError(lib.ARG_ERROR, fmt.Sprintf("货品的支付状态错误"))
  756 +// }
  757 +// }
  758 +// }
  759 +// oldOrderData.Goods = oldOrderGoods
761 760
762 - err = oldOrderData.Compute()  
763 - if err != nil {  
764 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))  
765 - }  
766 - err = orderBaseRepository.Save(oldOrderData)  
767 - if err != nil {  
768 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))  
769 - }  
770 - err = orderGoodRepository.Save(oldOrderGoods)  
771 - if err != nil {  
772 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))  
773 - }  
774 - err = transactionContext.CommitTransaction()  
775 - if err != nil {  
776 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
777 - }  
778 - return nil 761 +// err = oldOrderData.Compute()
  762 +// if err != nil {
  763 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
  764 +// }
  765 +// err = orderBaseRepository.Save(oldOrderData)
  766 +// if err != nil {
  767 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
  768 +// }
  769 +// err = orderGoodRepository.Save(oldOrderGoods)
  770 +// if err != nil {
  771 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
  772 +// }
  773 +// err = transactionContext.CommitTransaction()
  774 +// if err != nil {
  775 +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  776 +// }
  777 +// return nil
779 778
780 -} 779 +// }
781 780
782 //PageListOrderBouns 获取订单的分红列表 781 //PageListOrderBouns 获取订单的分红列表
783 func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrderBonusQuery) ([]map[string]interface{}, int, error) { 782 func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrderBonusQuery) ([]map[string]interface{}, int, error) {
@@ -4,7 +4,7 @@ import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" @@ -4,7 +4,7 @@ import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
4 4
5 const ( 5 const (
6 //支付订单中货品的分红 6 //支付订单中货品的分红
7 - PAY_ORDER_GOOD_BONUS_EVENT string = "PayOrderGoodBonus" 7 + //PAY_ORDER_GOOD_BONUS_EVENT string = "PayOrderGoodBonus"
8 BATCH_PAY_ORDER_GOOD_BONUS_EVENT string = "BatchPayOrderGoodBonus" 8 BATCH_PAY_ORDER_GOOD_BONUS_EVENT string = "BatchPayOrderGoodBonus"
9 ) 9 )
10 10
1 -package domain  
2 -  
3 -//类型为(orderType=OrderTypeBestShop) 海鲜干货的订单分红  
4 -//因页面上的对于该类型的订单分红状态处理方式 有别于原有的其他类型(OrderReal),所以单独提取出来  
5 -  
6 -// OrderGoodWithBestshopBonusStatus 支付状态  
7 -// type OrderGoodWithBestshopBonusStatus interface {  
8 -// OrderGoodBonusStatus  
9 -// UpdateOrderGoodNumber(good *OrderGood, number int) error  
10 -// UpdatePertnerBonusPercent(good *OrderGood, percent float64) error  
11 -// }  
12 -  
13 -// //OrderGoodWithBestshop 处理订单中商品的分红相关数据  
14 -// type OrderGoodWithBestshop struct {  
15 -// currentBonusStatus OrderGoodWithBestshopBonusStatus  
16 -// }  
17 -  
18 -// func (o *OrderGoodWithBestshop) UpdateBonusByGoodNumber(good *OrderGood, number int) error {  
19 -// o.reset(good)  
20 -// if good.PlanGoodNumber < number {  
21 -// return fmt.Errorf("修改商品数量的值不能大于初始值%d", good.PlanGoodNumber)  
22 -// }  
23 -// err := o.currentBonusStatus.UpdateOrderGoodNumber(good, number)  
24 -// return err  
25 -// }  
26 -  
27 -// func (o *OrderGoodWithBestshop) UpdateBonusByPertnerBonusPercent(good *OrderGood, percent float64) error {  
28 -// o.reset(good)  
29 -// err := o.currentBonusStatus.UpdatePertnerBonusPercent(good, percent)  
30 -// return err  
31 -// }  
32 -  
33 -// func (o *OrderGoodWithBestshop) PayPartnerBonus(good *OrderGood) error {  
34 -// o.currentBonusStatus = OrderGoodBonusBestshopHasPay{}  
35 -// err := good.Compute()  
36 -// if err != nil {  
37 -// return errors.New("核算商品数据失败" + err.Error())  
38 -// }  
39 -// err = good.CurrentBonusStatus.PayPartnerBonus(good)  
40 -// return err  
41 -// }  
42 -  
43 -// func (o *OrderGoodWithBestshop) reset(good *OrderGood) {  
44 -// switch good.BonusStatus {  
45 -// case OrderGoodWaitPay:  
46 -// o.currentBonusStatus = OrderGoodBonusBestshopWaitPay{}  
47 -// case OrderGoodHasPay:  
48 -// o.currentBonusStatus = OrderGoodBonusBestshopHasPay{}  
49 -// }  
50 -// return  
51 -// }  
52 -  
53 -// //OrderGoodBonusBestshopWaitPay 货品支付状态:待支付  
54 -// type OrderGoodBonusBestshopWaitPay struct {  
55 -// OrderGoodBonusWaitPay  
56 -// }  
57 -  
58 -// var _ OrderGoodWithBestshopBonusStatus = (*OrderGoodBonusBestshopWaitPay)(nil)  
59 -  
60 -// func (waitPay OrderGoodBonusBestshopWaitPay) UpdateOrderGoodNumber(good *OrderGood, number int) error {  
61 -// good.UseGoodNumber = number  
62 -// //待支付状态计算  
63 -// err := good.Compute()  
64 -// if err != nil {  
65 -// return errors.New("核算商品数据失败" + err.Error())  
66 -// }  
67 -// err = good.CurrentBonusStatus.WartPayPartnerBonus(good)  
68 -// return err  
69 -// }  
70 -  
71 -// func (waitPay OrderGoodBonusBestshopWaitPay) UpdatePertnerBonusPercent(good *OrderGood, percent float64) error {  
72 -// good.PartnerBonusPercent = percent  
73 -// //待支付状态计算  
74 -// err := good.Compute()  
75 -// if err != nil {  
76 -// return errors.New("核算商品数据失败" + err.Error())  
77 -// }  
78 -// err = good.CurrentBonusStatus.WartPayPartnerBonus(good)  
79 -// return err  
80 -// }  
81 -  
82 -// //OrderGoodBonusBestshopHasPay 货品支付状态:已支付  
83 -// type OrderGoodBonusBestshopHasPay struct {  
84 -// OrderGoodBonusHasPay  
85 -// }  
86 -  
87 -// var _ OrderGoodWithBestshopBonusStatus = (*OrderGoodBonusBestshopHasPay)(nil)  
88 -  
89 -// func (hasPay OrderGoodBonusBestshopHasPay) UpdateOrderGoodNumber(good *OrderGood, number int) error {  
90 -// return errors.New("已支付分红的货品订单,不能修改货品数量")  
91 -// }  
92 -  
93 -// func (hasPay OrderGoodBonusBestshopHasPay) UpdatePertnerBonusPercent(good *OrderGood, percent float64) error {  
94 -// return errors.New("已支付分红的货品订单,不能修改合伙人分红比例")  
95 -// }  
@@ -2,11 +2,7 @@ package dao @@ -2,11 +2,7 @@ package dao
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 - "strings"  
6 - "time"  
7 5
8 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"  
9 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"  
10 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" 6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
11 ) 7 )
12 8
@@ -24,81 +20,81 @@ func NewBusinessBonusDao(transactionContext *transaction.TransactionContext) (*B @@ -24,81 +20,81 @@ func NewBusinessBonusDao(transactionContext *transaction.TransactionContext) (*B
24 } 20 }
25 } 21 }
26 22
27 -type CustomBusinessBonus struct {  
28 - Id int64  
29 - Bonus string  
30 - BonusNot string  
31 - BonusExpense string  
32 - BonusHas string  
33 - BonusStatus int8  
34 - PartnerName string  
35 - UpdateAt time.Time  
36 -} 23 +// type CustomBusinessBonus struct {
  24 +// Id int64
  25 +// Bonus string
  26 +// BonusNot string
  27 +// BonusExpense string
  28 +// BonusHas string
  29 +// BonusStatus int8
  30 +// PartnerName string
  31 +// UpdateAt time.Time
  32 +// }
37 33
38 -func (dao BusinessBonusDao) SearchBusinessBonus(partnerId int64, partnerNameMatch string,  
39 - companyId int64, limit int, offset int) ([]CustomBusinessBonus, error) {  
40 - sql := `SELECT business_bonus.id, business_bonus.bonus,business_bonus.bonus_not  
41 - ,business_bonus.bonus_expense,business_bonus.bonus_status,business_bonus.update_at  
42 - ,partner_info.partner_name,business_bonus.bonus_has  
43 - FROM business_bonus  
44 - JOIN partner_info ON business_bonus.partner_info_id=partner_info.id  
45 - WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `  
46 - partnerCondition := []string{}  
47 - allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}  
48 - if partnerId > 0 {  
49 - partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)  
50 - allParam = append(allParam, partnerId)  
51 - }  
52 - if len(partnerNameMatch) > 0 {  
53 - allParam = append(allParam, "%"+partnerNameMatch+"%")  
54 - partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)  
55 - }  
56 - if len(partnerCondition) > 0 {  
57 - sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))  
58 - }  
59 - sql += `ORDER BY business_bonus.id DESC limit ? OFFSET ? `  
60 - allParam = append(allParam, limit, offset)  
61 - tx := dao.transactionContext.PgTx  
62 - var (  
63 - result []CustomBusinessBonus  
64 - err error  
65 - )  
66 - _, err = tx.Query(&result, sql, allParam...)  
67 - return result, err  
68 -} 34 +// func (dao BusinessBonusDao) SearchBusinessBonus(partnerId int64, partnerNameMatch string,
  35 +// companyId int64, limit int, offset int) ([]CustomBusinessBonus, error) {
  36 +// sql := `SELECT business_bonus.id, business_bonus.bonus,business_bonus.bonus_not
  37 +// ,business_bonus.bonus_expense,business_bonus.bonus_status,business_bonus.update_at
  38 +// ,partner_info.partner_name,business_bonus.bonus_has
  39 +// FROM business_bonus
  40 +// JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
  41 +// WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
  42 +// partnerCondition := []string{}
  43 +// allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
  44 +// if partnerId > 0 {
  45 +// partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
  46 +// allParam = append(allParam, partnerId)
  47 +// }
  48 +// if len(partnerNameMatch) > 0 {
  49 +// allParam = append(allParam, "%"+partnerNameMatch+"%")
  50 +// partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
  51 +// }
  52 +// if len(partnerCondition) > 0 {
  53 +// sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
  54 +// }
  55 +// sql += `ORDER BY business_bonus.id DESC limit ? OFFSET ? `
  56 +// allParam = append(allParam, limit, offset)
  57 +// tx := dao.transactionContext.PgTx
  58 +// var (
  59 +// result []CustomBusinessBonus
  60 +// err error
  61 +// )
  62 +// _, err = tx.Query(&result, sql, allParam...)
  63 +// return result, err
  64 +// }
69 65
70 -func (dao BusinessBonusDao) CountBusinessBonus(partnerId int64, partnerNameMatch string,  
71 - companyId int64, limit int, offset int) (int, error) {  
72 - sql := `SELECT count(*)  
73 - FROM business_bonus  
74 - JOIN partner_info ON business_bonus.partner_info_id=partner_info.id  
75 - WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `  
76 - partnerCondition := []string{}  
77 - allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}  
78 - if partnerId > 0 {  
79 - partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)  
80 - allParam = append(allParam, partnerId)  
81 - }  
82 - if len(partnerNameMatch) > 0 {  
83 - allParam = append(allParam, "%"+partnerNameMatch+"%")  
84 - partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)  
85 - }  
86 - if len(partnerCondition) > 0 {  
87 - sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))  
88 - }  
89 - tx := dao.transactionContext.PgTx  
90 - var (  
91 - result int  
92 - err error  
93 - )  
94 - _, err = tx.Query(&result, sql, allParam...)  
95 - return result, err  
96 -} 66 +// func (dao BusinessBonusDao) CountBusinessBonus(partnerId int64, partnerNameMatch string,
  67 +// companyId int64, limit int, offset int) (int, error) {
  68 +// sql := `SELECT count(*)
  69 +// FROM business_bonus
  70 +// JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
  71 +// WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
  72 +// partnerCondition := []string{}
  73 +// allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
  74 +// if partnerId > 0 {
  75 +// partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
  76 +// allParam = append(allParam, partnerId)
  77 +// }
  78 +// if len(partnerNameMatch) > 0 {
  79 +// allParam = append(allParam, "%"+partnerNameMatch+"%")
  80 +// partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
  81 +// }
  82 +// if len(partnerCondition) > 0 {
  83 +// sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
  84 +// }
  85 +// tx := dao.transactionContext.PgTx
  86 +// var (
  87 +// result int
  88 +// err error
  89 +// )
  90 +// _, err = tx.Query(&result, sql, allParam...)
  91 +// return result, err
  92 +// }
97 93
98 -func (dao BusinessBonusDao) ExistBusinessBonus(userId int64) (bool, error) {  
99 - tx := dao.transactionContext.PgTx  
100 - ok, err := tx.Model(&models.BusinessBonus{}).  
101 - Where("partner_info_id=?", userId).  
102 - Exists()  
103 - return ok, err  
104 -} 94 +// func (dao BusinessBonusDao) ExistBusinessBonus(userId int64) (bool, error) {
  95 +// tx := dao.transactionContext.PgTx
  96 +// ok, err := tx.Model(&models.BusinessBonus{}).
  97 +// Where("partner_info_id=?", userId).
  98 +// Exists()
  99 +// return ok, err
  100 +// }