作者 唐旭辉

新海鲜干货订单分红详情 完成

@@ -42,7 +42,7 @@ func CreateOrderGoodRepository(options map[string]interface{}) (domain.OrderGood @@ -42,7 +42,7 @@ func CreateOrderGoodRepository(options map[string]interface{}) (domain.OrderGood
42 return repository.NewOrderGoodRepository(transactionContext) 42 return repository.NewOrderGoodRepository(transactionContext)
43 } 43 }
44 44
45 -//CreateOrderGoodRepository 订单信息 45 +//CreateOrderGoodRepository 订单货品信息
46 func CreateUsersRepository(options map[string]interface{}) (domain.UsersRepository, error) { 46 func CreateUsersRepository(options map[string]interface{}) (domain.UsersRepository, error) {
47 var transactionContext *transaction.TransactionContext 47 var transactionContext *transaction.TransactionContext
48 if value, ok := options["transactionContext"]; ok { 48 if value, ok := options["transactionContext"]; ok {
@@ -77,3 +77,30 @@ func CreateBusinessBonusRepository(options map[string]interface{}) (domain.Busin @@ -77,3 +77,30 @@ func CreateBusinessBonusRepository(options map[string]interface{}) (domain.Busin
77 } 77 }
78 return repository.NewBusinessBonusRepository(transactionContext) 78 return repository.NewBusinessBonusRepository(transactionContext)
79 } 79 }
  80 +
  81 +//CreateOrderGoodBestshopRepository 海鲜干货订单商品信息
  82 +func CreateOrderGoodBestshopRepository(options map[string]interface{}) (domain.OrderGoodBestshopRepository, error) {
  83 + var transactionContext *transaction.TransactionContext
  84 + if value, ok := options["transactionContext"]; ok {
  85 + transactionContext = value.(*transaction.TransactionContext)
  86 + }
  87 + return repository.NewOrderGoodBestshopRepository(transactionContext)
  88 +}
  89 +
  90 +//CreateOrderGoodBestshopRepository 海鲜干货订单信息
  91 +func CreateOrderBestshopRepository(options map[string]interface{}) (domain.OrderBestshopRepository, error) {
  92 + var transactionContext *transaction.TransactionContext
  93 + if value, ok := options["transactionContext"]; ok {
  94 + transactionContext = value.(*transaction.TransactionContext)
  95 + }
  96 + return repository.NewOrderBestshopRepository(transactionContext)
  97 +}
  98 +
  99 +//CreateOrderGoodBestshopRepository 海鲜干货订单信息
  100 +func CreateOrderLogRepository(options map[string]interface{}) (domain.OrderLogRepository, error) {
  101 + var transactionContext *transaction.TransactionContext
  102 + if value, ok := options["transactionContext"]; ok {
  103 + transactionContext = value.(*transaction.TransactionContext)
  104 + }
  105 + return repository.NewOrderLogRepository(transactionContext)
  106 +}
@@ -789,6 +789,188 @@ func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrde @@ -789,6 +789,188 @@ func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrde
789 return orders, cnt, nil 789 return orders, cnt, nil
790 } 790 }
791 791
  792 +//GetOrderBestshopInfo 获取来源于海鲜干货订单的详情以及分红数据
  793 +func (service OrderInfoService) GetOrderBestshopInfoWithBonus(orderBaseId int64, companyId int64) (interface{}, error) {
  794 + var (
  795 + transactionContext, _ = factory.CreateTransactionContext(nil)
  796 + err error
  797 + )
  798 + if err = transactionContext.StartTransaction(); err != nil {
  799 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  800 + }
  801 + defer func() {
  802 + transactionContext.RollbackTransaction()
  803 + }()
  804 + var (
  805 + orderBaseRepository domain.OrderBaseRepository
  806 + orderGoodRepository domain.OrderGoodRepository
  807 + orderBestshopRepository domain.OrderBestshopRepository
  808 + orderGoodBestshopRepository domain.OrderGoodBestshopRepository
  809 + orderLogRepository domain.OrderLogRepository
  810 + partnerRepository domain.PartnerInfoRepository
  811 + )
  812 + if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
  813 + "transactionContext": transactionContext,
  814 + }); err != nil {
  815 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  816 + }
  817 + if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
  818 + "transactionContext": transactionContext,
  819 + }); err != nil {
  820 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  821 + }
  822 + if orderBestshopRepository, err = factory.CreateOrderBestshopRepository(map[string]interface{}{
  823 + "transactionContext": transactionContext,
  824 + }); err != nil {
  825 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  826 + }
  827 + if orderGoodBestshopRepository, err = factory.CreateOrderGoodBestshopRepository(map[string]interface{}{
  828 + "transactionContext": transactionContext,
  829 + }); err != nil {
  830 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  831 + }
  832 + if orderLogRepository, err = factory.CreateOrderLogRepository(map[string]interface{}{
  833 + "transactionContext": transactionContext,
  834 + }); err != nil {
  835 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  836 + }
  837 + if partnerRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
  838 + "transactionContext": transactionContext,
  839 + }); err != nil {
  840 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  841 + }
  842 + var (
  843 + orderData *domain.OrderBase
  844 + orderGoods []domain.OrderGood
  845 + orderBestshopData *domain.OrderBestShop
  846 + orderGoodBestshop []domain.OrderGoodBestShop
  847 + orderLogs []domain.OrderLog
  848 + partnerInfo *domain.PartnerInfo
  849 + )
  850 +
  851 + orderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
  852 + OrderId: orderBaseId,
  853 + CompanyId: companyId,
  854 + })
  855 + if err != nil {
  856 + e := fmt.Sprintf("获取订单(order_base)数据失败,id=%d,company_id=%d,err=%s", orderBaseId, companyId, err)
  857 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  858 + }
  859 + if orderData.OrderType != domain.OrderTypeBestShop {
  860 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "获取的订单数据失败,OrderType err")
  861 + }
  862 + orderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderData.Id})
  863 + if err != nil {
  864 + e := fmt.Sprintf("获取订单的商品(order_good)数据失败,order_id=%d,err=%s", orderData.Id, err)
  865 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  866 + }
  867 + orderData.Goods = orderGoods
  868 + partnerInfo, err = partnerRepository.FindOne(domain.PartnerFindOneQuery{UserId: orderData.PartnerId})
  869 + if err != nil {
  870 + e := fmt.Sprintf("获取订单中的合伙人(partner)数据失败,id=%d,order_id=%d,err=%s", orderData.PartnerId, orderData.Id, err)
  871 + logs.Error(e)
  872 + }
  873 + orderData.PartnerInfo = partnerInfo.Partner
  874 + orderBestshopData, err = orderBestshopRepository.FindOne(domain.OrderBestshopFindOneQuery{OrderId: orderData.DataFrom.DataId})
  875 + if err != nil {
  876 + e := fmt.Sprintf("获取海鲜干货订单(order_bestshop)数据失败,id=%d,err=%s", orderData.DataFrom.DataId, err)
  877 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  878 + }
  879 + orderGoodBestshop, err = orderGoodBestshopRepository.Find(domain.OrderGoodBestshopFindQuery{OrderId: orderBestshopData.Id})
  880 + if err != nil {
  881 + e := fmt.Sprintf("获取海鲜干货订单货品(order_good_bestshop)数据失败,order_id=%d,err=%s", orderBestshopData.Id, err)
  882 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  883 + }
  884 + orderBestshopData.Goods = orderGoodBestshop
  885 + orderLogs, err = orderLogRepository.Find(domain.OrderLogFindQuery{OrderId: orderData.Id})
  886 + if err != nil {
  887 + e := fmt.Sprintf("获取订单的修改记录(order_log)失败,err=%s", err)
  888 + logs.Error(e)
  889 + }
  890 + err = transactionContext.CommitTransaction()
  891 + if err != nil {
  892 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  893 + }
  894 + result := service.buildOrderBestshopInfoData(orderData, orderBestshopData, orderLogs)
  895 + return result, nil
  896 +}
  897 +
  898 +//BuildOrderBestshopInfoData 构建前端需要的数据结构
  899 +func (service OrderInfoService) buildOrderBestshopInfoData(orderBase *domain.OrderBase,
  900 + orderBestshop *domain.OrderBestShop, orderLogs []domain.OrderLog) interface{} {
  901 + orderGoodBestshopMap := map[int64]*domain.OrderGoodBestShop{}
  902 + for i := range orderBestshop.Goods {
  903 + goodid := orderBestshop.Goods[i].Id
  904 + orderGoodBestshopMap[goodid] = &orderBestshop.Goods[i]
  905 + }
  906 + //订单描述
  907 + order := map[string]interface{}{
  908 + "orderId": orderBase.Id,
  909 + "orderState": orderBestshop.OrderState,
  910 + "customers": orderBestshop.BuyerName,
  911 + "address": orderBestshop.BuyerAddress,
  912 + "remarks": orderBestshop.BuyerRemark,
  913 + "partner": orderBase.PartnerInfo.PartnerName,
  914 + "phone": orderBestshop.BuyerPhone,
  915 + "orderTime": orderBestshop.OrderTime,
  916 + "shippingStatus": orderBestshop.DeliveryState,
  917 + }
  918 + //订单中的商品
  919 + product := map[string]interface{}{
  920 + "orderNumCount": orderBase.GetCurrentOrderCount(),
  921 + "partnerDividendsCount": orderBase.GetCurrentPartnerBonus(),
  922 + "orderAmountAdjustmentCount": orderBase.GetCurrentOrderAmount(),
  923 + }
  924 + productDetail := []map[string]interface{}{}
  925 + for i := range orderBase.Goods {
  926 + detail := map[string]interface{}{
  927 + "commodityName": orderBase.Goods[i].GoodName,
  928 + "productCodes": "",
  929 + "commodityCode": "",
  930 + "univalence": orderBase.Goods[i].Price,
  931 + "orderNum": orderBase.Goods[i].GetCurrentGoodNumber(),
  932 + "commodityPrice": orderBase.Goods[i].GetCurrentAmount(),
  933 + "partnerDividends": orderBase.Goods[i].GetCurrentPartnerBonus(),
  934 + "productId": orderBase.Goods[i].Id,
  935 + "paymentStatus": orderBase.Goods[i].BonusStatus,
  936 + "partnerRatio": orderBase.Goods[i].PartnerBonusPercent,
  937 + }
  938 + goodBestshopId := orderBase.Goods[i].DataFrom.DataId
  939 + if v, ok := orderGoodBestshopMap[goodBestshopId]; ok {
  940 + detail["productCodes"] = v.Sn
  941 + detail["commodityCode"] = v.Bn
  942 + }
  943 + }
  944 + product["detail"] = productDetail
  945 + modifyLog := []map[string]interface{}{}
  946 + for i := range orderLogs {
  947 + m := map[string]interface{}{
  948 + "title": orderLogs[i].LogAction,
  949 + "time": orderLogs[i].AlterTime.Local().Format("2006-01-02 15:04:05"),
  950 + "userName": orderLogs[i].Operator,
  951 + "id": orderLogs[i].Id,
  952 + }
  953 + detail := []map[string]string{}
  954 + for ii, vv := range orderLogs[i].Descript {
  955 + d := map[string]string{
  956 + "updateTitle": vv.Title,
  957 + "id": fmt.Sprint(ii),
  958 + "content": fmt.Sprintf("%s:%s;%s", vv.Item, vv.Action, vv.Result),
  959 + }
  960 + detail = append(detail, d)
  961 + }
  962 + m["updateList"] = detail
  963 + modifyLog = append(modifyLog, m)
  964 + }
  965 +
  966 + result := map[string]interface{}{
  967 + "order": order,
  968 + "product": product,
  969 + "modify": modifyLog,
  970 + }
  971 + return result
  972 +}
  973 +
792 //UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动 974 //UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
793 func (service OrderInfoService) UpdateBonusByGoodNumber() error { 975 func (service OrderInfoService) UpdateBonusByGoodNumber() error {
794 var ( 976 var (
@@ -7,9 +7,9 @@ import ( @@ -7,9 +7,9 @@ import (
7 ) 7 )
8 8
9 const ( 9 const (
10 - OrderReal = iota + 1 //实发订单  
11 - OrderIntention //意向订单  
12 - OrderHaiXian //来自小程序海鲜干货的订单 10 + OrderReal = iota + 1 //实发订单
  11 + OrderIntention //意向订单
  12 + OrderTypeBestShop //来自小程序海鲜干货的订单
13 ) 13 )
14 14
15 func GetOrderBaseTypeName(orderType int) string { 15 func GetOrderBaseTypeName(orderType int) string {
@@ -17,7 +17,7 @@ func GetOrderBaseTypeName(orderType int) string { @@ -17,7 +17,7 @@ func GetOrderBaseTypeName(orderType int) string {
17 switch orderType { 17 switch orderType {
18 case OrderReal: 18 case OrderReal:
19 name = "自建订单" 19 name = "自建订单"
20 - case OrderHaiXian: 20 + case OrderTypeBestShop:
21 name = "小程序订单" 21 name = "小程序订单"
22 case OrderIntention: 22 case OrderIntention:
23 name = "意向订单" 23 name = "意向订单"
@@ -42,13 +42,6 @@ type Buyer struct { @@ -42,13 +42,6 @@ type Buyer struct {
42 Remark string `json:"remark"` 42 Remark string `json:"remark"`
43 } 43 }
44 44
45 -//OrderDataFrom 订单数据来源  
46 -type OrderDataFrom struct {  
47 - Platform string `json:"platform"` //订单数据来源平台  
48 - PlatformId string `json:"platformId"` //平台唯一标识  
49 - DataId int64 `json:"dataId"` //订单数据id标识  
50 -}  
51 -  
52 type OrderCompute struct { 45 type OrderCompute struct {
53 //合伙人应收分红 46 //合伙人应收分红
54 PlanPartnerBonus float64 `json:"planPartnerBonus"` 47 PlanPartnerBonus float64 `json:"planPartnerBonus"`
@@ -123,6 +116,30 @@ type OrderBase struct { @@ -123,6 +116,30 @@ type OrderBase struct {
123 Remark OrderBaseRemark `json:"remark"` 116 Remark OrderBaseRemark `json:"remark"`
124 } 117 }
125 118
  119 +//GetCurrentPartnerBonus 获取当前合伙人应收分红
  120 +func (order *OrderBase) GetCurrentPartnerBonus() float64 {
  121 + if order.OrderCompute.UsePartnerBonus >= 0 {
  122 + return order.OrderCompute.UsePartnerBonus
  123 + }
  124 + return order.OrderCompute.PlanPartnerBonus
  125 +}
  126 +
  127 +//GetCurrentOrderCount 获取当前订单商品总数
  128 +func (order *OrderBase) GetCurrentOrderCount() int {
  129 + if order.OrderCompute.UseOrderCount >= 0 {
  130 + return order.OrderCompute.UseOrderCount
  131 + }
  132 + return order.OrderCompute.PlanOrderCount
  133 +}
  134 +
  135 +// GetCurrentOrderAmount 获取当前订单的总额
  136 +func (order *OrderBase) GetCurrentOrderAmount() float64 {
  137 + if order.OrderCompute.UseOrderAmount >= 0 {
  138 + return order.OrderCompute.UseOrderAmount
  139 + }
  140 + return order.OrderCompute.PlanOrderAmount
  141 +}
  142 +
126 //Update 更新订单数据 143 //Update 更新订单数据
127 //orderData 订单数据 144 //orderData 订单数据
128 //goodsMap 货品的数据,以货品的id做键,map[id]map[string]interface{} 145 //goodsMap 货品的数据,以货品的id做键,map[id]map[string]interface{}
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +//OrderBestShop 来源海鲜干货的订单
  6 +type OrderBestShop struct {
  7 + Id int64 `json:"id"`
  8 + //订单编号
  9 + OrderCode string `json:"orderCode"`
  10 + //下单时间
  11 + OrderTime string `json:"orderTime"`
  12 + //订单状态
  13 + OrderState int8 `json:"order_state"`
  14 + //发货状态
  15 + DeliveryState int8 `json:"delivery_state"`
  16 + //买家名称
  17 + BuyerName string `json:"buyerName"`
  18 + //买家电话
  19 + BuyerPhone string `json:"buyerPhone"`
  20 + //买家地址
  21 + BuyerAddress string `json:"buyerAddress"`
  22 + //买家备注
  23 + BuyerRemark string `json:"buyerRemark"`
  24 + //商品总数
  25 + OrderCount int `json:"orderCount"`
  26 + //d订单总额
  27 + OrderAmount float64 `json:"orderAmount"`
  28 + //发货时间
  29 + DeliveryTime time.Time `json:"deliveryTime"`
  30 + //创建时间
  31 + CreateTime time.Time `json:"createTime"`
  32 + Goods []OrderGoodBestShop `json:"goods"`
  33 +}
  34 +
  35 +func (order OrderBestShop) CopyToOrderBase(o *OrderBase) {
  36 + o.Buyer = Buyer{
  37 + BuyerName: order.BuyerName,
  38 + ContactInfo: order.BuyerPhone,
  39 + ShippingAddress: order.BuyerAddress,
  40 + Remark: order.BuyerRemark,
  41 + }
  42 + o.DataFrom = OrderDataFrom{
  43 + Platform: OrderDataFromBestShop,
  44 + DataId: order.Id,
  45 + }
  46 + o.OrderCode = order.OrderCode
  47 + o.OrderCompute.PlanOrderAmount = order.OrderAmount
  48 + o.OrderCompute.PlanOrderCount = order.OrderCount
  49 + o.DeliveryTime = order.DeliveryTime
  50 + return
  51 +}
  52 +
  53 +type OrderBestshopFindOneQuery struct {
  54 + OrderId int64
  55 +}
  56 +
  57 +type OrderBestshopRepository interface {
  58 + Add(order *OrderBestShop) error
  59 + FindOne(qureyOptions OrderBestshopFindOneQuery) (*OrderBestShop, error)
  60 +}
  61 +
  62 +//OrderGoodBestShop 订单明细
  63 +type OrderGoodBestShop struct {
  64 + Id int64 `json:"id"`
  65 + //订单id
  66 + OrdeId int64 `json:"orderId"`
  67 + //货品编号
  68 + Sn string `json:"sn"`
  69 + //商品编号
  70 + Bn string `json:"bn"`
  71 + //货品名称
  72 + Name string `json:"name"`
  73 + //单价
  74 + Price float64 `json:"price"`
  75 + //货品数量
  76 + Nums int `json:"nums"`
  77 + //订单总价
  78 + Amount float64 `json:"amount"`
  79 +}
  80 +
  81 +func (good OrderGoodBestShop) CopyToOrderGood(g *OrderGood) {
  82 + g.DataFrom = OrderDataFrom{
  83 + Platform: OrderDataFromBestShop,
  84 + DataId: good.Id,
  85 + }
  86 + g.GoodName = good.Name
  87 + g.Price = good.Price
  88 + g.PlanGoodNumber = good.Nums
  89 + g.GoodCompute.PlanAmount = good.Amount
  90 + return
  91 +}
  92 +
  93 +type OrderGoodBestshopFindQuery struct {
  94 + OrderId int64
  95 +}
  96 +
  97 +type OrderGoodBestshopRepository interface {
  98 + Add(order *OrderGoodBestShop) error
  99 + Find(qureyOptions OrderGoodBestshopFindQuery) ([]OrderGoodBestShop, error)
  100 +}
  1 +package domain
  2 +
  3 +const (
  4 + OrderDataFromBestShop string = "bestshop"
  5 +)
  6 +
  7 +//OrderDataFrom 订单数据来源
  8 +type OrderDataFrom struct {
  9 + Platform string `json:"platform"` //订单数据来源平台
  10 + DataId int64 `json:"dataId"` //订单数据id标识
  11 +}
@@ -78,6 +78,31 @@ type OrderGood struct { @@ -78,6 +78,31 @@ type OrderGood struct {
78 CompanyId int64 `json:"companyId"` 78 CompanyId int64 `json:"companyId"`
79 //原因备注 79 //原因备注
80 RemarkReason OrderGoodRemarkReason `json:"remarkReason"` 80 RemarkReason OrderGoodRemarkReason `json:"remarkReason"`
  81 + DataFrom OrderDataFrom `json:"data_from"`
  82 +}
  83 +
  84 +//GetCurrentGoodNumber 获取当前的商品数量
  85 +func (good OrderGood) GetCurrentGoodNumber() int {
  86 + if good.UseGoodNumber >= 0 {
  87 + return good.UseGoodNumber
  88 + }
  89 + return good.PlanGoodNumber
  90 +}
  91 +
  92 +//GetCurrentAmount 获取当前的商品总额
  93 +func (good OrderGood) GetCurrentAmount() float64 {
  94 + if good.GoodCompute.UseAmount >= 0 {
  95 + return good.GoodCompute.UseAmount
  96 + }
  97 + return good.GoodCompute.PlanAmount
  98 +}
  99 +
  100 +//GetCurrentAmount 获取当前的商品合伙人分红
  101 +func (good OrderGood) GetCurrentPartnerBonus() float64 {
  102 + if good.GoodCompute.UsePartnerBonus >= 0 {
  103 + return good.GoodCompute.UsePartnerBonus
  104 + }
  105 + return good.GoodCompute.PlanPartnerBonus
81 } 106 }
82 107
83 //Update 更新商品相关的数据 108 //Update 更新商品相关的数据
@@ -34,6 +34,7 @@ type OrderLogContent struct { @@ -34,6 +34,7 @@ type OrderLogContent struct {
34 34
35 //OrderLog 订单修改记录 35 //OrderLog 订单修改记录
36 type OrderLog struct { 36 type OrderLog struct {
  37 + Id int64
37 OrderId int64 `json:"order_id"` //订单id 38 OrderId int64 `json:"order_id"` //订单id
38 AlterTime time.Time `json:"alter_time"` //时间 39 AlterTime time.Time `json:"alter_time"` //时间
39 Operator string `json:"operator"` //操作人员 40 Operator string `json:"operator"` //操作人员
  1 +package models
  2 +
  3 +import "time"
  4 +
  5 +type OrderBestshop struct {
  6 + tableName struct{} `pg:"order_bestshop"`
  7 + Id int64
  8 + //订单编号
  9 + OrderCode string
  10 + //下单时间
  11 + OrderTime string
  12 + //订单状态
  13 + OrderState int8
  14 + //发货状态
  15 + DeliveryState int8
  16 + //买家名称
  17 + BuyerName string
  18 + //买家电话
  19 + BuyerPhone string
  20 + //买家地址
  21 + BuyerAddress string
  22 + //买家备注
  23 + BuyerRemark string
  24 + //订单总数
  25 + OrderCount int
  26 + //d订单总额
  27 + OrderAmount float64
  28 + //发货时间
  29 + DeliveryTime time.Time
  30 + //创建时间
  31 + CreateTime time.Time
  32 +}
  1 +package models
  2 +
  3 +type OrderGoodBestshop struct {
  4 + tableName struct{} `pg:"order_good_bestshop"`
  5 + Id int64
  6 + //订单id
  7 + OrdeId int64
  8 + //货品编号
  9 + Sn string
  10 + //商品编号
  11 + Bn string
  12 + //货品名称
  13 + Name string
  14 + //单价
  15 + Price float64
  16 + //货品数量
  17 + Nums int
  18 + //订单总价
  19 + Amount float64
  20 +}
@@ -10,7 +10,8 @@ import ( @@ -10,7 +10,8 @@ import (
10 10
11 //OrderLog 订单修改记录 11 //OrderLog 订单修改记录
12 type OrderLog struct { 12 type OrderLog struct {
13 - tableName struct{} `pg:"order_log"` 13 + tableName struct{} `pg:"order_log"`
  14 + Id int64
14 OrderId int64 `` //订单id 15 OrderId int64 `` //订单id
15 AlterTime time.Time `` //时间 16 AlterTime time.Time `` //时间
16 Operator string `` //操作人员 17 Operator string `` //操作人员
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
  9 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
  10 +)
  11 +
  12 +type OrderBestshopRepository struct {
  13 + transactionContext *transaction.TransactionContext
  14 +}
  15 +
  16 +var (
  17 + _ domain.OrderBestshopRepository = (*OrderBestshopRepository)(nil)
  18 +)
  19 +
  20 +func NewOrderBestshopRepository(transactionContext *transaction.TransactionContext) (*OrderBestshopRepository, error) {
  21 + if transactionContext == nil {
  22 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  23 + }
  24 + return &OrderBestshopRepository{transactionContext: transactionContext}, nil
  25 +}
  26 +
  27 +func (respository OrderBestshopRepository) transformPgModelToDomainModel(orderModel *models.OrderBestshop) (order domain.OrderBestShop, err error) {
  28 + return domain.OrderBestShop{
  29 + Id: orderModel.Id,
  30 + OrderCode: orderModel.OrderCode,
  31 + OrderTime: orderModel.OrderTime,
  32 + OrderState: orderModel.OrderState,
  33 + DeliveryState: orderModel.DeliveryState,
  34 + BuyerName: orderModel.BuyerName,
  35 + BuyerPhone: orderModel.BuyerPhone,
  36 + BuyerAddress: orderModel.BuyerAddress,
  37 + BuyerRemark: orderModel.BuyerRemark,
  38 + OrderCount: orderModel.OrderCount,
  39 + OrderAmount: orderModel.OrderAmount,
  40 + DeliveryTime: orderModel.DeliveryTime,
  41 + CreateTime: orderModel.CreateTime,
  42 + }, nil
  43 +}
  44 +
  45 +func (respository OrderBestshopRepository) Add(order *domain.OrderBestShop) error {
  46 + tx := respository.transactionContext.GetDB()
  47 + m := models.OrderBestshop{
  48 + OrderCode: order.OrderCode,
  49 + OrderTime: order.OrderTime,
  50 + OrderState: order.OrderState,
  51 + DeliveryState: order.DeliveryState,
  52 + BuyerName: order.BuyerName,
  53 + BuyerPhone: order.BuyerPhone,
  54 + BuyerAddress: order.BuyerAddress,
  55 + BuyerRemark: order.BuyerRemark,
  56 + OrderCount: order.OrderCount,
  57 + OrderAmount: order.OrderAmount,
  58 + DeliveryTime: order.DeliveryTime,
  59 + CreateTime: time.Now(),
  60 + }
  61 + _, err := tx.Model(&m).Insert()
  62 + order.Id = m.Id
  63 + return err
  64 +}
  65 +
  66 +func (respository OrderBestshopRepository) FindOne(queryOption domain.OrderBestshopFindOneQuery) (*domain.OrderBestShop, error) {
  67 + tx := respository.transactionContext.GetDB()
  68 + m := models.OrderBestshop{}
  69 + err := tx.Model(&m).
  70 + Where("id=?", queryOption.OrderId).
  71 + First()
  72 + if err != nil {
  73 + return nil, err
  74 + }
  75 + var order domain.OrderBestShop
  76 + order, err = respository.transformPgModelToDomainModel(&m)
  77 + if err != nil {
  78 + return nil, fmt.Errorf("OrderBestshop domain 数据结构转换失败:%s", err)
  79 + }
  80 + return &order, nil
  81 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
  9 +)
  10 +
  11 +type OrderGoodBestshopRepository struct {
  12 + transactionContext *transaction.TransactionContext
  13 +}
  14 +
  15 +var (
  16 + _ domain.OrderGoodBestshopRepository = (*OrderGoodBestshopRepository)(nil)
  17 +)
  18 +
  19 +func NewOrderGoodBestshopRepository(transactionContext *transaction.TransactionContext) (*OrderGoodBestshopRepository, error) {
  20 + if transactionContext == nil {
  21 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  22 + }
  23 + return &OrderGoodBestshopRepository{transactionContext: transactionContext}, nil
  24 +}
  25 +
  26 +func (respository OrderGoodBestshopRepository) transformPgModelToDomainModel(orderGoodModel *models.OrderGoodBestshop) (orderGood domain.OrderGoodBestShop, err error) {
  27 + return domain.OrderGoodBestShop{
  28 + Id: orderGoodModel.Id,
  29 + OrdeId: orderGoodModel.OrdeId,
  30 + Sn: orderGoodModel.Sn,
  31 + Bn: orderGoodModel.Bn,
  32 + Name: orderGoodModel.Name,
  33 + Price: orderGoodModel.Price,
  34 + Nums: orderGoodModel.Nums,
  35 + Amount: orderGoodModel.Amount,
  36 + }, nil
  37 +}
  38 +
  39 +func (respository OrderGoodBestshopRepository) Add(good *domain.OrderGoodBestShop) error {
  40 + tx := respository.transactionContext.GetDB()
  41 + m := models.OrderGoodBestshop{
  42 + Id: good.Id,
  43 + OrdeId: good.OrdeId,
  44 + Sn: good.Sn,
  45 + Bn: good.Bn,
  46 + Name: good.Name,
  47 + Price: good.Price,
  48 + Nums: good.Nums,
  49 + Amount: good.Amount,
  50 + }
  51 + _, err := tx.Model(&m).Insert()
  52 + good.Id = m.Id
  53 + return err
  54 +}
  55 +
  56 +func (respository OrderGoodBestshopRepository) Find(queryOption domain.OrderGoodBestshopFindQuery) ([]domain.OrderGoodBestShop, error) {
  57 + tx := respository.transactionContext.GetDB()
  58 + goodModels := []models.OrderGoodBestshop{}
  59 + query := tx.Model(&goodModels)
  60 + if queryOption.OrderId > 0 {
  61 + query = query.Where("order_id=?", queryOption.OrderId)
  62 + }
  63 + query = query.Limit(1000)
  64 + err := query.Select()
  65 + if err != nil {
  66 + return nil, err
  67 + }
  68 + goods := []domain.OrderGoodBestShop{}
  69 + for i := range goodModels {
  70 + g, _ := respository.transformPgModelToDomainModel(&goodModels[i])
  71 + goods = append(goods, g)
  72 + }
  73 + return goods, nil
  74 +}
@@ -15,7 +15,7 @@ type OrderLogRepository struct { @@ -15,7 +15,7 @@ type OrderLogRepository struct {
15 15
16 var _ domain.OrderLogRepository = (*OrderLogRepository)(nil) 16 var _ domain.OrderLogRepository = (*OrderLogRepository)(nil)
17 17
18 -func NewOrderInfoRepository(transactionContext *transaction.TransactionContext) (*OrderLogRepository, error) { 18 +func NewOrderLogRepository(transactionContext *transaction.TransactionContext) (*OrderLogRepository, error) {
19 if transactionContext == nil { 19 if transactionContext == nil {
20 return nil, fmt.Errorf("transactionContext参数不能为nil") 20 return nil, fmt.Errorf("transactionContext参数不能为nil")
21 } 21 }
@@ -24,6 +24,7 @@ func NewOrderInfoRepository(transactionContext *transaction.TransactionContext) @@ -24,6 +24,7 @@ func NewOrderInfoRepository(transactionContext *transaction.TransactionContext)
24 24
25 func (repository OrderLogRepository) transformPgModelToDomainModel(m *models.OrderLog) (data domain.OrderLog, err error) { 25 func (repository OrderLogRepository) transformPgModelToDomainModel(m *models.OrderLog) (data domain.OrderLog, err error) {
26 return domain.OrderLog{ 26 return domain.OrderLog{
  27 + Id: m.Id,
27 OrderId: m.OrderId, 28 OrderId: m.OrderId,
28 Operator: m.Operator, 29 Operator: m.Operator,
29 OperatorId: m.OperatorId, 30 OperatorId: m.OperatorId,
@@ -74,8 +74,8 @@ func (c *CommonController) GetOrderType() { @@ -74,8 +74,8 @@ func (c *CommonController) GetOrderType() {
74 "name": domain.GetOrderBaseTypeName(domain.OrderReal), 74 "name": domain.GetOrderBaseTypeName(domain.OrderReal),
75 }, 75 },
76 map[string]interface{}{ 76 map[string]interface{}{
77 - "id": domain.OrderHaiXian,  
78 - "name": domain.GetOrderBaseTypeName(domain.OrderHaiXian), 77 + "id": domain.OrderTypeBestShop,
  78 + "name": domain.GetOrderBaseTypeName(domain.OrderTypeBestShop),
79 }, 79 },
80 } 80 }
81 c.ResponseData(resp) 81 c.ResponseData(resp)
@@ -47,7 +47,7 @@ func (c *OrderDividendController) PageListOrderDividend() { @@ -47,7 +47,7 @@ func (c *OrderDividendController) PageListOrderDividend() {
47 } 47 }
48 if !(param.OrderType == 0 || 48 if !(param.OrderType == 0 ||
49 param.OrderType == domain.OrderReal || 49 param.OrderType == domain.OrderReal ||
50 - param.OrderType == domain.OrderHaiXian) { 50 + param.OrderType == domain.OrderTypeBestShop) {
51 c.ResponseError(errors.New("参数异常")) 51 c.ResponseError(errors.New("参数异常"))
52 return 52 return
53 } 53 }