正在显示
48 个修改的文件
包含
2069 行增加
和
656 行删除
| @@ -9,5 +9,5 @@ require ( | @@ -9,5 +9,5 @@ require ( | ||
| 9 | github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 | 9 | github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 |
| 10 | github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect | 10 | github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect |
| 11 | github.com/shopspring/decimal v1.2.0 | 11 | github.com/shopspring/decimal v1.2.0 |
| 12 | - github.com/tiptok/gocomm v0.0.0-20190919092013-c230743f8095 | 12 | + github.com/tiptok/gocomm v1.0.0 |
| 13 | ) | 13 | ) |
| @@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
| 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" |
| 6 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" | 6 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" |
| 7 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg" | 7 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg" |
| 8 | + _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/redis" | ||
| 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
| 9 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr" | 10 | _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr" |
| 10 | ) | 11 | ) |
| @@ -3,10 +3,7 @@ package auth | @@ -3,10 +3,7 @@ package auth | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" |
| 6 | - //"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" | ||
| 7 | - //"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" | ||
| 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
| 9 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr" | ||
| 10 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
| 11 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
| 12 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
| @@ -70,13 +67,18 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | @@ -70,13 +67,18 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | ||
| 70 | break | 67 | break |
| 71 | } | 68 | } |
| 72 | rsp.AuthCode, _ = utils.GenerateToken(partnerInfo.Id, protocol.AuthCodeExpire*time.Second) | 69 | rsp.AuthCode, _ = utils.GenerateToken(partnerInfo.Id, protocol.AuthCodeExpire*time.Second) |
| 70 | + | ||
| 71 | + if err = InitOrUpdateUserIMInfo(partnerInfo, transactionContext); err != nil { | ||
| 72 | + log.Error(err) | ||
| 73 | + return | ||
| 74 | + } | ||
| 73 | err = transactionContext.CommitTransaction() | 75 | err = transactionContext.CommitTransaction() |
| 74 | return | 76 | return |
| 75 | } | 77 | } |
| 76 | 78 | ||
| 77 | func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, err error) { | 79 | func SmsCode(request *protocol.SmsCodeRequest) (rsp *protocol.SmsCodeResponse, err error) { |
| 78 | var data map[string]interface{} | 80 | var data map[string]interface{} |
| 79 | - sms := svr.NewHttplibMmmSmsApiServiceGateway() | 81 | + sms, _ := factory.CreateSmsCodeService() |
| 80 | data, err = sms.SendSms(request.Phone) | 82 | data, err = sms.SendSms(request.Phone) |
| 81 | rsp = &protocol.SmsCodeResponse{} | 83 | rsp = &protocol.SmsCodeResponse{} |
| 82 | if err != nil { | 84 | if err != nil { |
| @@ -106,6 +108,14 @@ func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessToke | @@ -106,6 +108,14 @@ func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessToke | ||
| 106 | rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, protocol.TokenExpire*time.Second) | 108 | rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, protocol.TokenExpire*time.Second) |
| 107 | rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, protocol.RefreshTokenExipre*time.Second) | 109 | rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, protocol.RefreshTokenExipre*time.Second) |
| 108 | rsp.ExpiresIn = protocol.TokenExpire | 110 | rsp.ExpiresIn = protocol.TokenExpire |
| 111 | + | ||
| 112 | + //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId), | ||
| 113 | + // userAuth.WithAccessToken(rsp.AccessToken), | ||
| 114 | + // userAuth.WithRefreshToken(rsp.RefreshToken)) | ||
| 115 | + //if err = auth.AddAuth(); err != nil { | ||
| 116 | + // log.Error(err) | ||
| 117 | + // return | ||
| 118 | + //} | ||
| 109 | return | 119 | return |
| 110 | } | 120 | } |
| 111 | 121 | ||
| @@ -122,16 +132,29 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT | @@ -122,16 +132,29 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT | ||
| 122 | err = protocol.NewErrWithMessage(1, fmt.Errorf("jwt refrshToken (%v) valid", request.RefreshToken)) | 132 | err = protocol.NewErrWithMessage(1, fmt.Errorf("jwt refrshToken (%v) valid", request.RefreshToken)) |
| 123 | return | 133 | return |
| 124 | } | 134 | } |
| 135 | + //oldAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId)) | ||
| 136 | + //if err = oldAuth.Check(userAuth.NewOptions(userAuth.WithRefreshToken(request.RefreshToken))); err != nil { | ||
| 137 | + // log.Error(err) | ||
| 138 | + // err = protocol.NewErrWithMessage(4140, err) | ||
| 139 | + // return | ||
| 140 | + //} | ||
| 125 | rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, protocol.TokenExpire*time.Second) | 141 | rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, protocol.TokenExpire*time.Second) |
| 126 | rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, protocol.RefreshTokenExipre*time.Second) | 142 | rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, protocol.RefreshTokenExipre*time.Second) |
| 127 | rsp.ExpiresIn = protocol.TokenExpire | 143 | rsp.ExpiresIn = protocol.TokenExpire |
| 128 | - return | 144 | + |
| 145 | + //newAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId), | ||
| 146 | + // userAuth.WithAccessToken(rsp.AccessToken), | ||
| 147 | + // userAuth.WithRefreshToken(rsp.RefreshToken)) | ||
| 148 | + //if err = newAuth.AddAuth(); err != nil { | ||
| 149 | + // log.Error(err) | ||
| 150 | + // return | ||
| 151 | + //} | ||
| 129 | return | 152 | return |
| 130 | } | 153 | } |
| 131 | 154 | ||
| 132 | //验证短信验证码 T | 155 | //验证短信验证码 T |
| 133 | func CheckSmsCode(phone, code string) (result bool, err error) { | 156 | func CheckSmsCode(phone, code string) (result bool, err error) { |
| 134 | - sms := svr.NewHttplibMmmSmsApiServiceGateway() | 157 | + sms, _ := factory.CreateSmsCodeService() |
| 135 | var data map[string]interface{} | 158 | var data map[string]interface{} |
| 136 | data, err = sms.CheckSmsCode(phone, code) | 159 | data, err = sms.CheckSmsCode(phone, code) |
| 137 | if err != nil { | 160 | if err != nil { |
| @@ -154,3 +177,18 @@ func AuthCheckSmsCode(header *protocol.RequestHeader, request *protocol.AuthChec | @@ -154,3 +177,18 @@ func AuthCheckSmsCode(header *protocol.RequestHeader, request *protocol.AuthChec | ||
| 154 | } | 177 | } |
| 155 | return | 178 | return |
| 156 | } | 179 | } |
| 180 | + | ||
| 181 | +//注销登录 | ||
| 182 | +func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rsp *protocol.RevokeResponse, err error) { | ||
| 183 | + //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId)) | ||
| 184 | + //rsp = &protocol.RevokeResponse{} | ||
| 185 | + //if !auth.Exist() { | ||
| 186 | + // return | ||
| 187 | + //} | ||
| 188 | + //if err = auth.RemoveAuth(); err != nil { | ||
| 189 | + // log.Error(err) | ||
| 190 | + // err = protocol.NewErrWithMessage(4140, err) | ||
| 191 | + // return | ||
| 192 | + //} | ||
| 193 | + return | ||
| 194 | +} |
pkg/application/auth/im.go
0 → 100644
| 1 | +package auth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | ||
| 6 | + "strconv" | ||
| 7 | + "time" | ||
| 8 | + | ||
| 9 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | ||
| 10 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
| 11 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/im" | ||
| 12 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
| 13 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 14 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
| 15 | +) | ||
| 16 | + | ||
| 17 | +// 更新用户 IM INFO | ||
| 18 | +func InitOrUpdateUserIMInfo(partnerInfo *domain.PartnerInfo, ctx *transaction.TransactionContext) (err error) { | ||
| 19 | + var ( | ||
| 20 | + ImInfoRepository, _ = factory.CreateImInfoRepository(ctx) | ||
| 21 | + checkImRequest *protocol.CheckImRequest = &protocol.CheckImRequest{} | ||
| 22 | + IsCreated = false | ||
| 23 | + checkImResponse *protocol.CheckImResponse | ||
| 24 | + ) | ||
| 25 | + imInfo, e := ImInfoRepository.FindOne(map[string]interface{}{"user_id": partnerInfo.Id}) | ||
| 26 | + // 异常 | ||
| 27 | + if e != nil && e != domain.QueryNoRow { | ||
| 28 | + err = e | ||
| 29 | + return | ||
| 30 | + } | ||
| 31 | + // 不存在 | ||
| 32 | + if e == domain.QueryNoRow { | ||
| 33 | + imInfo = &domain.ImInfo{ | ||
| 34 | + UserId: partnerInfo.Id, | ||
| 35 | + CreateTime: time.Now(), | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + // 已存在 | ||
| 39 | + if e == nil && imInfo != nil { | ||
| 40 | + IsCreated = true | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + if len(imInfo.ImId) == 0 { | ||
| 44 | + id, _ := utils.NewSnowflakeId() | ||
| 45 | + imInfo.ImId = fmt.Sprintf("%v", id) | ||
| 46 | + } | ||
| 47 | + checkImRequest = &protocol.CheckImRequest{ | ||
| 48 | + UserId: imInfo.UserId, | ||
| 49 | + ImId: imInfo.ImId, | ||
| 50 | + Uname: partnerInfo.PartnerName, | ||
| 51 | + CustomerImId: fmt.Sprintf("%v", imInfo.CustomerImId), | ||
| 52 | + IsCreated: IsCreated, | ||
| 53 | + } | ||
| 54 | + if checkImResponse, err = CheckIm(checkImRequest); err != nil { | ||
| 55 | + return | ||
| 56 | + } | ||
| 57 | + if imInfo.CustomerImId == 0 { | ||
| 58 | + imInfo.CustomerImId = getRandomCustomerAccount(partnerInfo.Id, ctx) | ||
| 59 | + } | ||
| 60 | + imInfo.ImToken = checkImResponse.ImToken | ||
| 61 | + imInfo.UpdateTime = time.Now() | ||
| 62 | + if _, err = ImInfoRepository.Save(imInfo); err != nil { | ||
| 63 | + return | ||
| 64 | + } | ||
| 65 | + return | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +// 检查ImToken | ||
| 69 | +func CheckIm(request *protocol.CheckImRequest) (rsp *protocol.CheckImResponse, err error) { | ||
| 70 | + var () | ||
| 71 | + rsp = &protocol.CheckImResponse{} | ||
| 72 | + if !request.IsCreated { | ||
| 73 | + if err = imCreate(request, rsp); err != nil { | ||
| 74 | + return | ||
| 75 | + } | ||
| 76 | + } else { | ||
| 77 | + if err = imUpdate(request, rsp); err != nil { | ||
| 78 | + return | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + if err = imRefreshToken(request, rsp); err != nil { | ||
| 82 | + return | ||
| 83 | + } | ||
| 84 | + return | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +//create | ||
| 88 | +func imCreate(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) { | ||
| 89 | + var ( | ||
| 90 | + param im.UserCreate = im.UserCreate{ | ||
| 91 | + Accid: request.ImId, | ||
| 92 | + Name: request.Uname, | ||
| 93 | + Icon: request.Icon, | ||
| 94 | + } | ||
| 95 | + out *im.UserTokenResult | ||
| 96 | + ) | ||
| 97 | + if out, err = im.CallCreate(param); err != nil { | ||
| 98 | + return | ||
| 99 | + } | ||
| 100 | + if out.Code != 200 || (out.Info.Accid != request.ImId) { | ||
| 101 | + return im.ErrorFailCall | ||
| 102 | + } | ||
| 103 | + rsp.ImToken = out.Info.Token | ||
| 104 | + return | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +//update user info | ||
| 108 | +func imUpdate(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) { | ||
| 109 | + var ( | ||
| 110 | + param im.UserUpdate = im.UserUpdate{ | ||
| 111 | + Accid: request.ImId, | ||
| 112 | + Name: request.Uname, | ||
| 113 | + Icon: request.Icon, | ||
| 114 | + } | ||
| 115 | + out *im.BaseResp | ||
| 116 | + ) | ||
| 117 | + if out, err = im.CallUpdate(param); err != nil { | ||
| 118 | + return | ||
| 119 | + } | ||
| 120 | + if out.Code != 200 { | ||
| 121 | + return im.ErrorFailCall | ||
| 122 | + } | ||
| 123 | + return | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +//refresh token | ||
| 127 | +func imRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImResponse) (err error) { | ||
| 128 | + var ( | ||
| 129 | + param im.UserRefreshToken = im.UserRefreshToken{ | ||
| 130 | + Accid: request.ImId, | ||
| 131 | + } | ||
| 132 | + out *im.UserTokenResult | ||
| 133 | + ) | ||
| 134 | + if out, err = im.CallRefreshToken(param); err != nil { | ||
| 135 | + return | ||
| 136 | + } | ||
| 137 | + if out.Code != 200 || (out.Info.Accid != request.ImId) { | ||
| 138 | + return im.ErrorFailCall | ||
| 139 | + } | ||
| 140 | + rsp.ImToken = out.Info.Token | ||
| 141 | + return | ||
| 142 | +} | ||
| 143 | + | ||
| 144 | +// 获取客服id | ||
| 145 | +func getRandomCustomerAccount(userId int64, ctx *transaction.TransactionContext) (acid int64) { | ||
| 146 | + ImCustomerServiceRepository, _ := factory.CreateImCustomerServiceRepository(ctx) | ||
| 147 | + total, customers, err := ImCustomerServiceRepository.Find(map[string]interface{}{"sortById": domain.ASC}) | ||
| 148 | + if err != nil { | ||
| 149 | + log.Error(err) | ||
| 150 | + return 0 | ||
| 151 | + } | ||
| 152 | + if total == 0 { | ||
| 153 | + return 0 | ||
| 154 | + } | ||
| 155 | + index := userId % total | ||
| 156 | + if int(index) < len(customers) { | ||
| 157 | + acid, _ = strconv.ParseInt(customers[index].ImId, 10, 64) | ||
| 158 | + return | ||
| 159 | + } | ||
| 160 | + acid, _ = strconv.ParseInt(customers[0].ImId, 10, 64) | ||
| 161 | + return | ||
| 162 | +} |
| @@ -3,18 +3,17 @@ package dividend | @@ -3,18 +3,17 @@ package dividend | ||
| 3 | import ( | 3 | import ( |
| 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" |
| 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
| 6 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | ||
| 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
| 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
| 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
| 10 | "time" | 9 | "time" |
| 11 | ) | 10 | ) |
| 12 | 11 | ||
| 13 | -//分红统计 | ||
| 14 | -func DividendStatistics(header *protocol.RequestHeader, request *protocol.DividendStatisticsRequest) (rsp *protocol.DividendStatisticsResponse, err error) { | 12 | +// 分红统计 |
| 13 | +func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatisticsRequest) (rsp *protocol.DividendStatisticsResponse, err error) { | ||
| 15 | var ( | 14 | var ( |
| 16 | transactionContext, _ = factory.CreateTransactionContext(nil) | 15 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| 17 | - OrderResponsitory, _ = factory.CreateOrderRepository(transactionContext) | 16 | + OrderBaseResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext) |
| 18 | //beginTime = time.Unix(request.StartTime/1000, 0) | 17 | //beginTime = time.Unix(request.StartTime/1000, 0) |
| 19 | //endTime = time.Unix(request.EndTime/1000, 0) | 18 | //endTime = time.Unix(request.EndTime/1000, 0) |
| 20 | ) | 19 | ) |
| @@ -24,13 +23,13 @@ func DividendStatistics(header *protocol.RequestHeader, request *protocol.Divide | @@ -24,13 +23,13 @@ func DividendStatistics(header *protocol.RequestHeader, request *protocol.Divide | ||
| 24 | defer func() { | 23 | defer func() { |
| 25 | transactionContext.RollbackTransaction() | 24 | transactionContext.RollbackTransaction() |
| 26 | }() | 25 | }() |
| 27 | - _, orderAll, e := OrderResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: header.UserId, EndTime: time.Now(), SortByCreateTime: domain.DESC, OrderType: domain.OrderReal})) | 26 | + _, orderAll, e := OrderBaseResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: header.UserId, EndTime: time.Now(), SortByCreateTime: domain.DESC, OrderType: domain.OrderReal})) |
| 28 | if e != nil { | 27 | if e != nil { |
| 29 | log.Error(e) | 28 | log.Error(e) |
| 30 | } | 29 | } |
| 31 | - var orderBetween []*domain.Order | 30 | + var orderBetween []*domain.OrderBase |
| 32 | for i := range orderAll { | 31 | for i := range orderAll { |
| 33 | - if orderAll[i].CreateAt.Unix() >= (request.StartTime/1000) && orderAll[i].CreateAt.Unix() < (request.EndTime/1000) { | 32 | + if orderAll[i].CreateTime.Unix() >= (request.StartTime/1000) && orderAll[i].CreateTime.Unix() < (request.EndTime/1000) { |
| 34 | orderBetween = append(orderBetween, orderAll[i]) | 33 | orderBetween = append(orderBetween, orderAll[i]) |
| 35 | } | 34 | } |
| 36 | } | 35 | } |
| @@ -40,42 +39,62 @@ func DividendStatistics(header *protocol.RequestHeader, request *protocol.Divide | @@ -40,42 +39,62 @@ func DividendStatistics(header *protocol.RequestHeader, request *protocol.Divide | ||
| 40 | rsp.Statistics = protocol.DividendStatistics{ | 39 | rsp.Statistics = protocol.DividendStatistics{ |
| 41 | Received: bonusAll.Received, | 40 | Received: bonusAll.Received, |
| 42 | Outstanding: bonusAll.Outstanding, | 41 | Outstanding: bonusAll.Outstanding, |
| 42 | + Receivable: bonusAll.Receivable, | ||
| 43 | Quarters: bonusQuarters, | 43 | Quarters: bonusQuarters, |
| 44 | } | 44 | } |
| 45 | err = transactionContext.CommitTransaction() | 45 | err = transactionContext.CommitTransaction() |
| 46 | return | 46 | return |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | -//累计分红 | ||
| 50 | -func AllBonusStatics(orders []*domain.Order, action int) (bonus protocol.Bonus) { | 49 | +// 累计分红 |
| 50 | +func AllBonusStatics(orders []*domain.OrderBase, action int) (bonus protocol.Bonus) { | ||
| 51 | bonus = protocol.Bonus{} | 51 | bonus = protocol.Bonus{} |
| 52 | for i := range orders { | 52 | for i := range orders { |
| 53 | o := orders[i] | 53 | o := orders[i] |
| 54 | - bonus.Received = utils.Decimal(bonus.Received + o.OrderBonusReceive()) | ||
| 55 | - bonus.Outstanding = utils.Decimal(bonus.Outstanding + o.OrderBonusWait()) | 54 | + static := o.OrderBonusStatic() |
| 55 | + bonus.Received = utils.Decimal(bonus.Received + static.OrderBonusReceive()) | ||
| 56 | + bonus.Outstanding = utils.Decimal(bonus.Outstanding + static.OrderBonusWait()) | ||
| 57 | + bonus.Receivable = utils.Decimal(bonus.Receivable + static.OrderTotalReceivable()) | ||
| 56 | } | 58 | } |
| 57 | return | 59 | return |
| 58 | } | 60 | } |
| 59 | 61 | ||
| 60 | -//订单-季度分红统计 | ||
| 61 | -func QuartersBonusStatics(orders []*domain.Order, action int) (bonus []protocol.Bonus) { | 62 | +// 订单-季度分红统计 |
| 63 | +func QuartersBonusStatics(orders []*domain.OrderBase, action int) (bonus []protocol.Bonus) { | ||
| 62 | bonus = make([]protocol.Bonus, 4) | 64 | bonus = make([]protocol.Bonus, 4) |
| 63 | for i := range orders { | 65 | for i := range orders { |
| 64 | o := orders[i] | 66 | o := orders[i] |
| 65 | - quarter := (o.CreateAt.Month() - 1) / 3 | ||
| 66 | - bonus[quarter].Received = utils.Decimal(bonus[quarter].Received + o.OrderBonusReceive()) | ||
| 67 | - bonus[quarter].Outstanding = utils.Decimal(bonus[quarter].Outstanding + o.OrderBonusWait()) | ||
| 68 | - bonus[quarter].Expend = utils.Decimal(bonus[quarter].Expend + o.OrderBonusOutstanding()) | 67 | + quarter := quarter(o.CreateTime) |
| 68 | + static := o.OrderBonusStatic() | ||
| 69 | + bonus[quarter].Receivable = utils.Decimal(bonus[quarter].Receivable + static.OrderTotalReceivable()) | ||
| 70 | + bonus[quarter].Received = utils.Decimal(bonus[quarter].Received + static.OrderBonusReceive()) | ||
| 71 | + bonus[quarter].Outstanding = utils.Decimal(bonus[quarter].Outstanding + static.OrderBonusWait()) | ||
| 69 | } | 72 | } |
| 70 | return | 73 | return |
| 71 | } | 74 | } |
| 72 | 75 | ||
| 73 | -//分红订单 | ||
| 74 | -func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOrdersRequest) (rsp *protocol.DividendOrdersResponse, err error) { | 76 | +// 季度 |
| 77 | +func quarter(t time.Time) int { | ||
| 78 | + q := t.Month() | ||
| 79 | + switch q { | ||
| 80 | + case 4, 5, 6: | ||
| 81 | + return 0 | ||
| 82 | + case 7, 8, 9: | ||
| 83 | + return 1 | ||
| 84 | + case 10, 11, 12: | ||
| 85 | + return 2 | ||
| 86 | + case 1, 2, 3: | ||
| 87 | + return 3 | ||
| 88 | + } | ||
| 89 | + return 0 | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +// 分红订单 | ||
| 93 | +func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersRequest) (rsp *protocol.DividendOrdersResponse, err error) { | ||
| 75 | var ( | 94 | var ( |
| 76 | transactionContext, _ = factory.CreateTransactionContext(nil) | 95 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| 77 | - OrderDao, _ = factory.CreateOrderDao(transactionContext) | ||
| 78 | - orders []*models.Order | 96 | + OrderDao, _ = factory.CreateOrderBaseDao(transactionContext) |
| 97 | + orders []*domain.OrderBase | ||
| 79 | count int | 98 | count int |
| 80 | ) | 99 | ) |
| 81 | if err = transactionContext.StartTransaction(); err != nil { | 100 | if err = transactionContext.StartTransaction(); err != nil { |
| @@ -91,6 +110,7 @@ func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOr | @@ -91,6 +110,7 @@ func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOr | ||
| 91 | PartnerId: header.UserId, | 110 | PartnerId: header.UserId, |
| 92 | DetailAction: request.DetailAction, | 111 | DetailAction: request.DetailAction, |
| 93 | DividendAction: request.DividendAction, | 112 | DividendAction: request.DividendAction, |
| 113 | + //IsDisable: "0", | ||
| 94 | StartTime: request.StartTime, | 114 | StartTime: request.StartTime, |
| 95 | EndTime: request.EndTime, | 115 | EndTime: request.EndTime, |
| 96 | Offset: request.PageIndex * request.PageSize, | 116 | Offset: request.PageIndex * request.PageSize, |
| @@ -103,11 +123,12 @@ func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOr | @@ -103,11 +123,12 @@ func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOr | ||
| 103 | 123 | ||
| 104 | for i := range orders { | 124 | for i := range orders { |
| 105 | o := orders[i] | 125 | o := orders[i] |
| 126 | + s := o.OrderBonusStatic() | ||
| 106 | item := &protocol.DividendOrderListItem{ | 127 | item := &protocol.DividendOrderListItem{ |
| 107 | Id: o.Id, | 128 | Id: o.Id, |
| 108 | - OrderNo: o.OrderCode, | ||
| 109 | - OrderAmount: o.OrderActualAmount, | ||
| 110 | - MyDividend: utils.Decimal(o.OrderActualAmount * (o.PartnerBonusPercent / 100.0)), | 129 | + DeliveryNo: o.DeliveryCode, |
| 130 | + OrderAmount: s.PlanOrderAmount, //s.OrderAmount(), | ||
| 131 | + DividendReceivable: utils.Decimal(s.OrderTotalReceivable()), | ||
| 111 | } | 132 | } |
| 112 | rsp.List = append(rsp.List, item) | 133 | rsp.List = append(rsp.List, item) |
| 113 | } | 134 | } |
| @@ -5,18 +5,10 @@ import ( | @@ -5,18 +5,10 @@ import ( | ||
| 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" |
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | -//func CreateTaskDao(options map[string]interface{}) (*dao.TaskDao, error) { | ||
| 9 | -// var transactionContext *pg.TransactionContext | ||
| 10 | -// if value, ok := options["transactionContext"]; ok { | ||
| 11 | -// transactionContext = value.(*pg.TransactionContext) | ||
| 12 | -// } | ||
| 13 | -// return dao.NewTaskDao(transactionContext) | ||
| 14 | -//} | ||
| 15 | - | ||
| 16 | -func CreateOrderDao(ctx *transaction.TransactionContext) (*dao.OrderDao, error) { | ||
| 17 | - return dao.NewOrderDao(ctx) | ||
| 18 | -} | ||
| 19 | - | ||
| 20 | func CreatePartnerInfoDao(ctx *transaction.TransactionContext) (*dao.PartnerInfoDao, error) { | 8 | func CreatePartnerInfoDao(ctx *transaction.TransactionContext) (*dao.PartnerInfoDao, error) { |
| 21 | return dao.NewPartnerInfoDao(ctx) | 9 | return dao.NewPartnerInfoDao(ctx) |
| 22 | } | 10 | } |
| 11 | + | ||
| 12 | +func CreateOrderBaseDao(ctx *transaction.TransactionContext) (*dao.OrderBaseDao, error) { | ||
| 13 | + return dao.NewOrderBaseDao(ctx) | ||
| 14 | +} |
| 1 | package factory | 1 | package factory |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | -//pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
| 5 | -//"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service" | ||
| 6 | -//domainService "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/domain_service" | 4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/service" |
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr" | ||
| 7 | ) | 6 | ) |
| 8 | 7 | ||
| 9 | -//func CreateReadSentNotificationService(options map[string]interface{}) (service.ReadSentNotificationService, error) { | ||
| 10 | -// var transactionContext *pgTransaction.TransactionContext | ||
| 11 | -// if value, ok := options["transactionContext"]; ok { | ||
| 12 | -// transactionContext = value.(*pgTransaction.TransactionContext) | ||
| 13 | -// } | ||
| 14 | -// return domainService.NewReadSentNotificationService(transactionContext) | ||
| 15 | -//} | 8 | +func CreateSmsCodeService() (service.SmsCodeService, error) { |
| 9 | + return svr.NewHttplibMmmSmsApiServiceGateway(), nil | ||
| 10 | +} |
| @@ -24,16 +24,6 @@ func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUser | @@ -24,16 +24,6 @@ func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUser | ||
| 24 | return repository.NewAdminUserRepository(transactionContext) | 24 | return repository.NewAdminUserRepository(transactionContext) |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | -//CreateOrderRepository 订单 | ||
| 28 | -func CreateOrderRepository(transactionContext *transaction.TransactionContext) (domain.OrderRepository, error) { | ||
| 29 | - return repository.NewOrderRepository(transactionContext) | ||
| 30 | -} | ||
| 31 | - | ||
| 32 | -//CreateOrderRepository 订单 | ||
| 33 | -func CreateOrderPaymentRepository(transactionContext *transaction.TransactionContext) (domain.OrderPaymentRepository, error) { | ||
| 34 | - return repository.NewOrderPaymentRepository(transactionContext) | ||
| 35 | -} | ||
| 36 | - | ||
| 37 | func CreatePartnerInfoRepositoryIn(transactionContext *transaction.TransactionContext) (domain.PartnerInfoRepository, error) { | 27 | func CreatePartnerInfoRepositoryIn(transactionContext *transaction.TransactionContext) (domain.PartnerInfoRepository, error) { |
| 38 | return repository.NewPartnerInfoRepository(transactionContext) | 28 | return repository.NewPartnerInfoRepository(transactionContext) |
| 39 | } | 29 | } |
| @@ -46,3 +36,23 @@ func CreatePartnerSubAccountRepository(transactionContext *transaction.Transacti | @@ -46,3 +36,23 @@ func CreatePartnerSubAccountRepository(transactionContext *transaction.Transacti | ||
| 46 | func CreateCompanyRepository(transactionContext *transaction.TransactionContext) (domain.CompanyRepository, error) { | 36 | func CreateCompanyRepository(transactionContext *transaction.TransactionContext) (domain.CompanyRepository, error) { |
| 47 | return repository.NewCompanyRepository(transactionContext) | 37 | return repository.NewCompanyRepository(transactionContext) |
| 48 | } | 38 | } |
| 39 | + | ||
| 40 | +//CreateOrderBaseRepository 订单基础 | ||
| 41 | +func CreateOrderBaseRepository(transactionContext *transaction.TransactionContext) (domain.OrderBaseRepository, error) { | ||
| 42 | + return repository.NewOrderBaseRepository(transactionContext) | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +//CreateOrderGoodRepository 订单基础 | ||
| 46 | +func CreateOrderGoodRepository(transactionContext *transaction.TransactionContext) (domain.OrderGoodRepository, error) { | ||
| 47 | + return repository.NewOrderGoodRepository(transactionContext) | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +//CreateImInfoRepository Im信息 | ||
| 51 | +func CreateImInfoRepository(transactionContext *transaction.TransactionContext) (domain.ImInfoRepository, error) { | ||
| 52 | + return repository.NewImInfoRepository(transactionContext) | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +//CreateImInfoRepository Im信息 | ||
| 56 | +func CreateImCustomerServiceRepository(transactionContext *transaction.TransactionContext) (domain.ImCustomerServiceRepository, error) { | ||
| 57 | + return repository.NewImCustomerServiceRepository(transactionContext) | ||
| 58 | +} |
| @@ -2,10 +2,7 @@ package order | @@ -2,10 +2,7 @@ package order | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" |
| 5 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
| 6 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
| 8 | - "time" | ||
| 9 | ) | 6 | ) |
| 10 | 7 | ||
| 11 | func Template(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) { | 8 | func Template(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) { |
| @@ -23,195 +20,3 @@ func Template(header *protocol.RequestHeader, request *protocol.OrderDetailReque | @@ -23,195 +20,3 @@ func Template(header *protocol.RequestHeader, request *protocol.OrderDetailReque | ||
| 23 | err = transactionContext.CommitTransaction() | 20 | err = transactionContext.CommitTransaction() |
| 24 | return | 21 | return |
| 25 | } | 22 | } |
| 26 | - | ||
| 27 | -//订单详情 | ||
| 28 | -func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) { | ||
| 29 | - var ( | ||
| 30 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 31 | - OrderResponsitory, _ = factory.CreateOrderRepository(transactionContext) | ||
| 32 | - OrderDao, _ = factory.CreateOrderDao(transactionContext) | ||
| 33 | - order *domain.Order | ||
| 34 | - ) | ||
| 35 | - if err = transactionContext.StartTransaction(); err != nil { | ||
| 36 | - return nil, err | ||
| 37 | - } | ||
| 38 | - defer func() { | ||
| 39 | - transactionContext.RollbackTransaction() | ||
| 40 | - }() | ||
| 41 | - | ||
| 42 | - rsp = &protocol.OrderDetailResponse{} | ||
| 43 | - if order, err = OrderResponsitory.FindOne(utils.ObjectJsonToMap(request)); err != nil { | ||
| 44 | - return | ||
| 45 | - } | ||
| 46 | - rsp.Order = protocol.OrderDetail{ | ||
| 47 | - Id: order.Id, | ||
| 48 | - OrderNo: order.OrderCode, | ||
| 49 | - OrderName: order.OrderName, | ||
| 50 | - OrderStatus: order.OrderStatus, | ||
| 51 | - CreateTime: order.CreateAt.Unix() * 1000, | ||
| 52 | - UpdateTime: order.UpdateAt.Unix() * 1000, | ||
| 53 | - OrderQuantity: order.OrderActualCount, | ||
| 54 | - OrderAmount: order.OrderActualAmount, | ||
| 55 | - OrderAmountCancel: order.OrderAmountCancel(), | ||
| 56 | - OrderUpdateReason: order.Reason, | ||
| 57 | - OrderDistrict: map[string]interface{}{"id": order.OrderRegionInfo.RegionId, "name": order.OrderRegionInfo.RegionName}, | ||
| 58 | - Customer: protocol.Customer{Uname: order.Buyer.BuyerName, Phone: order.Buyer.ContactInfo}, | ||
| 59 | - MyDividend: order.OrderTotalBonus(), | ||
| 60 | - MyDividendPercent: order.PartnerBonusPercent, | ||
| 61 | - } | ||
| 62 | - if header.UserId == order.PartnerId && order.UpdateAt.After(order.LastViewTime) { | ||
| 63 | - if err = OrderDao.UpdateLastViewTime(order.Id, time.Now()); err != nil { | ||
| 64 | - return | ||
| 65 | - } | ||
| 66 | - } | ||
| 67 | - err = transactionContext.CommitTransaction() | ||
| 68 | - return | ||
| 69 | -} | ||
| 70 | - | ||
| 71 | -//订单统计 | ||
| 72 | -func OrderStatistics(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) { | ||
| 73 | - var ( | ||
| 74 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 75 | - OrderDao, _ = factory.CreateOrderDao(transactionContext) | ||
| 76 | - ) | ||
| 77 | - if err = transactionContext.StartTransaction(); err != nil { | ||
| 78 | - return nil, err | ||
| 79 | - } | ||
| 80 | - defer func() { | ||
| 81 | - transactionContext.RollbackTransaction() | ||
| 82 | - }() | ||
| 83 | - rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}} | ||
| 84 | - if rsp.Statistics.TodayIntentionQuantity, rsp.Statistics.TodayIntentionMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 85 | - BeginTime: utils.GetDayBegin().Unix() * 1000, | ||
| 86 | - EndTime: utils.GetDayEnd().Unix() * 1000, | ||
| 87 | - OrderType: domain.OrderIntention, | ||
| 88 | - PartnerId: header.UserId, | ||
| 89 | - }); err != nil { | ||
| 90 | - return | ||
| 91 | - } | ||
| 92 | - if rsp.Statistics.TodayRealQuantity, rsp.Statistics.TodayRealMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 93 | - BeginTime: utils.GetDayBegin().Unix() * 1000, | ||
| 94 | - EndTime: utils.GetDayEnd().Unix() * 1000, | ||
| 95 | - OrderType: domain.OrderReal, | ||
| 96 | - PartnerId: header.UserId, | ||
| 97 | - }); err != nil { | ||
| 98 | - return | ||
| 99 | - } | ||
| 100 | - if rsp.Statistics.CumulativeQuantity, rsp.Statistics.CumulativeMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 101 | - EndTime: time.Now().Unix() * 1000, | ||
| 102 | - OrderType: domain.OrderReal, | ||
| 103 | - PartnerId: header.UserId, | ||
| 104 | - }); err != nil { | ||
| 105 | - return | ||
| 106 | - } | ||
| 107 | - err = transactionContext.CommitTransaction() | ||
| 108 | - return | ||
| 109 | -} | ||
| 110 | - | ||
| 111 | -//订单列表 | ||
| 112 | -func OrderList(header *protocol.RequestHeader, request *protocol.OrderListRequest) (rsp *protocol.OrderListResponse, err error) { | ||
| 113 | - var ( | ||
| 114 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 115 | - OrderResponsitory, _ = factory.CreateOrderRepository(transactionContext) | ||
| 116 | - OrderDao, _ = factory.CreateOrderDao(transactionContext) | ||
| 117 | - orders []*domain.Order | ||
| 118 | - ) | ||
| 119 | - | ||
| 120 | - rsp = &protocol.OrderListResponse{ | ||
| 121 | - List: make([]*protocol.OrderListItem, 0), | ||
| 122 | - Statistics: make(map[string]interface{}), | ||
| 123 | - } | ||
| 124 | - if err = transactionContext.StartTransaction(); err != nil { | ||
| 125 | - return nil, err | ||
| 126 | - } | ||
| 127 | - defer func() { | ||
| 128 | - transactionContext.RollbackTransaction() | ||
| 129 | - }() | ||
| 130 | - queryOption := &domain.OrderQueryOption{ | ||
| 131 | - PartnerId: header.UserId, | ||
| 132 | - Limit: request.PageSize, | ||
| 133 | - Offset: request.PageSize * request.PageIndex, | ||
| 134 | - SortByUpdateTime: domain.DESC, | ||
| 135 | - } | ||
| 136 | - if request.OrderAction == 1 { | ||
| 137 | - queryOption.OrderStatus = domain.OrderStatusDeliverSome | ||
| 138 | - } else if request.OrderAction == 2 { | ||
| 139 | - queryOption.OrderStatus = domain.OrderStatusDeliverAll | ||
| 140 | - } | ||
| 141 | - if request.StartTime > 0 { | ||
| 142 | - queryOption.BeginTime = time.Unix(request.StartTime/1000, 0) | ||
| 143 | - } | ||
| 144 | - if request.EndTime > 0 { | ||
| 145 | - queryOption.EndTime = time.Unix(request.EndTime/1000, 0) | ||
| 146 | - } | ||
| 147 | - queryOption.OrderType = request.OrderType | ||
| 148 | - _, orders, _ = OrderResponsitory.Find(utils.ObjectJsonToMap(queryOption)) | ||
| 149 | - //统计数据 | ||
| 150 | - if request.PageIndex == 0 { | ||
| 151 | - var ( | ||
| 152 | - partShipmentQuantity, allShipmentQuantity int | ||
| 153 | - cumulativeQuantity, intentionQuantity int | ||
| 154 | - ) | ||
| 155 | - //部分发货的订单数量 | ||
| 156 | - partShipmentQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 157 | - EndTime: request.EndTime, | ||
| 158 | - BeginTime: request.StartTime, | ||
| 159 | - OrderType: domain.OrderReal, | ||
| 160 | - PartnerId: header.UserId, | ||
| 161 | - OrderStatus: domain.OrderStatusDeliverSome, | ||
| 162 | - }) | ||
| 163 | - //全部发货的订单数量 | ||
| 164 | - allShipmentQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 165 | - EndTime: request.EndTime, | ||
| 166 | - BeginTime: request.StartTime, | ||
| 167 | - OrderType: domain.OrderReal, | ||
| 168 | - PartnerId: header.UserId, | ||
| 169 | - OrderStatus: domain.OrderStatusDeliverAll, | ||
| 170 | - }) | ||
| 171 | - //累计实发订单 | ||
| 172 | - cumulativeQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 173 | - EndTime: time.Now().Unix() * 1000, | ||
| 174 | - //BeginTime: request.StartTime, | ||
| 175 | - OrderType: domain.OrderReal, | ||
| 176 | - PartnerId: header.UserId, | ||
| 177 | - }) | ||
| 178 | - //累计意向订单 | ||
| 179 | - intentionQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 180 | - EndTime: time.Now().Unix() * 1000, | ||
| 181 | - //BeginTime: request.StartTime, | ||
| 182 | - OrderType: domain.OrderIntention, | ||
| 183 | - PartnerId: header.UserId, | ||
| 184 | - }) | ||
| 185 | - //订单数量 | ||
| 186 | - rsp.Statistics["partShipmentQuantity"] = partShipmentQuantity | ||
| 187 | - rsp.Statistics["allShipmentQuantity"] = allShipmentQuantity | ||
| 188 | - rsp.Statistics["orderQuantity"] = partShipmentQuantity + allShipmentQuantity //所有订单 = 部分发货 + 已经发货 | ||
| 189 | - rsp.Statistics["cumulativeQuantity"] = cumulativeQuantity //实发订单 = 部分发货 + 全部发货 | ||
| 190 | - rsp.Statistics["intentionQuantity"] = intentionQuantity | ||
| 191 | - | ||
| 192 | - } | ||
| 193 | - | ||
| 194 | - if len(orders) == 0 { | ||
| 195 | - return | ||
| 196 | - } | ||
| 197 | - for i := range orders { | ||
| 198 | - rsp.List = append(rsp.List, DomainOrderToOrderListItem(orders[i])) | ||
| 199 | - } | ||
| 200 | - | ||
| 201 | - err = transactionContext.CommitTransaction() | ||
| 202 | - return | ||
| 203 | -} | ||
| 204 | -func DomainOrderToOrderListItem(order *domain.Order) *protocol.OrderListItem { | ||
| 205 | - return &protocol.OrderListItem{ | ||
| 206 | - Id: order.Id, | ||
| 207 | - OrderType: order.OrderType, | ||
| 208 | - OrderNo: order.OrderCode, | ||
| 209 | - OrderName: order.OrderName, | ||
| 210 | - OrderAmount: order.OrderActualAmount, | ||
| 211 | - OrderActualCount: order.OrderActualCount, | ||
| 212 | - OrderStatus: order.OrderStatus, | ||
| 213 | - UpdateTime: order.UpdateAt.Unix() * 1000, | ||
| 214 | - MyDividend: order.OrderTotalBonus(), | ||
| 215 | - IsRead: order.IsRead(), | ||
| 216 | - } | ||
| 217 | -} |
pkg/application/order/order_v2.go
0 → 100644
| 1 | +package order | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | ||
| 8 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
| 9 | + "time" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +// 订单详情 | ||
| 13 | +func Detail(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) { | ||
| 14 | + var ( | ||
| 15 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 16 | + OrderResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext) | ||
| 17 | + OrderDao, _ = factory.CreateOrderBaseDao(transactionContext) | ||
| 18 | + order *domain.OrderBase | ||
| 19 | + ) | ||
| 20 | + if err = transactionContext.StartTransaction(); err != nil { | ||
| 21 | + return nil, err | ||
| 22 | + } | ||
| 23 | + defer func() { | ||
| 24 | + transactionContext.RollbackTransaction() | ||
| 25 | + }() | ||
| 26 | + | ||
| 27 | + rsp = &protocol.OrderDetailResponse{} | ||
| 28 | + if order, err = OrderResponsitory.FindOne(utils.ObjectJsonToMap(request)); err != nil { | ||
| 29 | + log.Error(err) | ||
| 30 | + return | ||
| 31 | + } | ||
| 32 | + rsp.Order = protocol.OrderDetail{ | ||
| 33 | + Id: order.Id, | ||
| 34 | + OrderNo: order.OrderCode, | ||
| 35 | + DeliveryNo: order.DeliveryCode, | ||
| 36 | + OrderStatus: orderStatus(order), | ||
| 37 | + CreateTime: order.CreateTime.Unix() * 1000, | ||
| 38 | + UpdateTime: order.UpdateTime.Unix() * 1000, | ||
| 39 | + OrderDistrict: map[string]interface{}{"id": order.RegionInfo.RegionId, "name": order.RegionInfo.RegionName}, | ||
| 40 | + Customer: protocol.Customer{Uname: order.Buyer.BuyerName, Phone: order.Buyer.ContactInfo}, | ||
| 41 | + Products: orderProducts(order), | ||
| 42 | + Total: orderTotalStatic(order), | ||
| 43 | + } | ||
| 44 | + if header.UserId == order.PartnerId && order.UpdateTime.After(order.LastViewTime) { | ||
| 45 | + if err = OrderDao.UpdateLastViewTime(order.Id, time.Now()); err != nil { | ||
| 46 | + return | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + err = transactionContext.CommitTransaction() | ||
| 50 | + return | ||
| 51 | +} | ||
| 52 | +func orderStatus(order *domain.OrderBase) int { | ||
| 53 | + var hasBonus = false | ||
| 54 | + for i := range order.OrderGood { | ||
| 55 | + good := order.OrderGood[i] | ||
| 56 | + if good.BonusStatus == domain.BonusPaid { | ||
| 57 | + hasBonus = true | ||
| 58 | + break | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + if hasBonus { | ||
| 62 | + if order.UseOrderCount >= 0 && order.UseOrderCount < order.PlanOrderCount { | ||
| 63 | + return 3 // 已支付退货 | ||
| 64 | + } | ||
| 65 | + return 2 // 已支付分红 | ||
| 66 | + } | ||
| 67 | + if !hasBonus { | ||
| 68 | + if order.UseOrderCount >= 0 && order.UseOrderCount < order.PlanOrderCount { | ||
| 69 | + return 4 // 待支付退货 | ||
| 70 | + } | ||
| 71 | + return 1 | ||
| 72 | + } | ||
| 73 | + return 1 | ||
| 74 | +} | ||
| 75 | +func orderProducts(order *domain.OrderBase) interface{} { | ||
| 76 | + var products []map[string]interface{} | ||
| 77 | + for i := range order.OrderGood { | ||
| 78 | + good := order.OrderGood[i] | ||
| 79 | + static := good.OrderBonusStatic() | ||
| 80 | + item := make(map[string]interface{}) | ||
| 81 | + item["productName"] = good.GoodName | ||
| 82 | + item["orderCount"] = good.PlanGoodNumber | ||
| 83 | + item["orderAmount"] = good.PlanAmount | ||
| 84 | + item["dividendPercent"] = good.PartnerBonusPercent | ||
| 85 | + item["dividendReceivable"] = static.OrderTotalReceivable() //应收分红 | ||
| 86 | + item["dividendReceived"] = static.OrderBonusReceive() //已收分红 | ||
| 87 | + item["dividendUnReceive"] = static.OrderBonusWait() // 未收分红 | ||
| 88 | + item["dividendExpend"] = static.OrderBonusOutstanding() //分红支出 | ||
| 89 | + if len(good.Remark) > 0 { | ||
| 90 | + item["orderUpdateReason"] = good.Remark | ||
| 91 | + } | ||
| 92 | + item["dividendStatus"] = good.Status() | ||
| 93 | + if good.Status() > 2 { | ||
| 94 | + item["countAdjust"] = good.UseGoodNumber | ||
| 95 | + item["amountAdjust"] = good.UseAmount | ||
| 96 | + } | ||
| 97 | + products = append(products, item) | ||
| 98 | + } | ||
| 99 | + return products | ||
| 100 | +} | ||
| 101 | +func orderTotalStatic(order *domain.OrderBase) interface{} { | ||
| 102 | + item := make(map[string]interface{}) | ||
| 103 | + static := order.OrderBonusStatic() | ||
| 104 | + item["totalCount"] = order.PlanOrderCount | ||
| 105 | + item["totalAmount"] = order.PlanOrderAmount | ||
| 106 | + item["totalDividendReceivable"] = static.OrderTotalReceivable() | ||
| 107 | + item["totalReceived"] = static.OrderBonusReceive() | ||
| 108 | + item["totalUnReceive"] = static.OrderBonusWait() | ||
| 109 | + item["totalExpend"] = static.OrderBonusOutstanding() | ||
| 110 | + if order.UseOrderCount > 0 { | ||
| 111 | + item["totalCountAdjust"] = order.UseOrderCount | ||
| 112 | + item["totalAmountAdjust"] = order.UseOrderAmount | ||
| 113 | + } | ||
| 114 | + return item | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +// 订单统计 | ||
| 118 | +func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) { | ||
| 119 | + var ( | ||
| 120 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 121 | + OrderDao, _ = factory.CreateOrderBaseDao(transactionContext) | ||
| 122 | + ) | ||
| 123 | + if err = transactionContext.StartTransaction(); err != nil { | ||
| 124 | + return nil, err | ||
| 125 | + } | ||
| 126 | + defer func() { | ||
| 127 | + transactionContext.RollbackTransaction() | ||
| 128 | + }() | ||
| 129 | + rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}} | ||
| 130 | + //if rsp.Statistics.TodayIntentionQuantity, rsp.Statistics.TodayIntentionMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 131 | + // BeginTime: utils.GetDayBegin().Unix() * 1000, | ||
| 132 | + // EndTime: utils.GetDayEnd().Unix() * 1000, | ||
| 133 | + // OrderType: domain.OrderIntention, | ||
| 134 | + // PartnerId: header.UserId, | ||
| 135 | + //}); err != nil { | ||
| 136 | + // return | ||
| 137 | + //} | ||
| 138 | + if rsp.Statistics.TodayRealQuantity, rsp.Statistics.TodayRealMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 139 | + BeginTime: utils.GetDayBegin().Unix() * 1000, | ||
| 140 | + EndTime: utils.GetDayEnd().Unix() * 1000, | ||
| 141 | + OrderType: domain.OrderReal, | ||
| 142 | + PartnerId: header.UserId, | ||
| 143 | + }); err != nil { | ||
| 144 | + return | ||
| 145 | + } | ||
| 146 | + if rsp.Statistics.CumulativeQuantity, rsp.Statistics.CumulativeMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 147 | + EndTime: time.Now().Unix() * 1000, | ||
| 148 | + OrderType: domain.OrderReal, | ||
| 149 | + PartnerId: header.UserId, | ||
| 150 | + }); err != nil { | ||
| 151 | + return | ||
| 152 | + } | ||
| 153 | + rsp.Statistics.TodayRealMoney = utils.Decimal(rsp.Statistics.TodayRealMoney) | ||
| 154 | + rsp.Statistics.CumulativeMoney = utils.Decimal(rsp.Statistics.CumulativeMoney) | ||
| 155 | + err = transactionContext.CommitTransaction() | ||
| 156 | + return | ||
| 157 | +} | ||
| 158 | + | ||
| 159 | +// 订单列表 | ||
| 160 | +func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (rsp *protocol.OrderListResponse, err error) { | ||
| 161 | + var ( | ||
| 162 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 163 | + OrderResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext) | ||
| 164 | + OrderDao, _ = factory.CreateOrderBaseDao(transactionContext) | ||
| 165 | + orders []*domain.OrderBase | ||
| 166 | + ) | ||
| 167 | + | ||
| 168 | + rsp = &protocol.OrderListResponse{ | ||
| 169 | + List: make([]*protocol.OrderListItem, 0), | ||
| 170 | + Statistics: make(map[string]interface{}), | ||
| 171 | + } | ||
| 172 | + if err = transactionContext.StartTransaction(); err != nil { | ||
| 173 | + return nil, err | ||
| 174 | + } | ||
| 175 | + defer func() { | ||
| 176 | + transactionContext.RollbackTransaction() | ||
| 177 | + }() | ||
| 178 | + queryOption := &domain.OrderQueryOption{ | ||
| 179 | + PartnerId: header.UserId, | ||
| 180 | + Limit: request.PageSize, | ||
| 181 | + Offset: request.PageSize * request.PageIndex, | ||
| 182 | + SortByUpdateTime: domain.DESC, | ||
| 183 | + } | ||
| 184 | + if request.StartTime > 0 { | ||
| 185 | + queryOption.BeginTime = time.Unix(request.StartTime/1000, 0) | ||
| 186 | + } | ||
| 187 | + if request.EndTime > 0 { | ||
| 188 | + queryOption.EndTime = time.Unix(request.EndTime/1000, 0) | ||
| 189 | + } | ||
| 190 | + queryOption.OrderType = request.OrderType | ||
| 191 | + _, orders, _ = OrderResponsitory.Find(utils.ObjectJsonToMap(queryOption)) | ||
| 192 | + //统计数据 | ||
| 193 | + if request.PageIndex == 0 { | ||
| 194 | + var ( | ||
| 195 | + cumulativeQuantity int | ||
| 196 | + ) | ||
| 197 | + //累计实发订单 | ||
| 198 | + cumulativeQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 199 | + EndTime: time.Now().Unix() * 1000, | ||
| 200 | + OrderType: domain.OrderReal, | ||
| 201 | + PartnerId: header.UserId, | ||
| 202 | + }) | ||
| 203 | + rsp.Total = cumulativeQuantity | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + if len(orders) == 0 { | ||
| 207 | + return | ||
| 208 | + } | ||
| 209 | + for i := range orders { | ||
| 210 | + rsp.List = append(rsp.List, DomainOrderToOrderListItem(orders[i])) | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + err = transactionContext.CommitTransaction() | ||
| 214 | + return | ||
| 215 | +} | ||
| 216 | +func DomainOrderToOrderListItem(order *domain.OrderBase) *protocol.OrderListItem { | ||
| 217 | + bonusStatic := order.OrderBonusStatic() | ||
| 218 | + return &protocol.OrderListItem{ | ||
| 219 | + Id: order.Id, | ||
| 220 | + OrderType: order.OrderType, | ||
| 221 | + OrderNo: order.OrderCode, | ||
| 222 | + DeliveryNo: order.DeliveryCode, | ||
| 223 | + OrderAmount: order.PlanOrderAmount, | ||
| 224 | + UpdateTime: order.UpdateTime.Unix() * 1000, | ||
| 225 | + MyDividend: bonusStatic.OrderTotalReceivable(), | ||
| 226 | + IsRead: order.IsRead(), | ||
| 227 | + } | ||
| 228 | +} |
| 1 | package user | 1 | package user |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "fmt" | ||
| 4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth" |
| 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" |
| 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" |
| @@ -8,6 +9,7 @@ import ( | @@ -8,6 +9,7 @@ import ( | ||
| 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
| 9 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | 10 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" |
| 10 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | 11 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
| 12 | + "strconv" | ||
| 11 | "strings" | 13 | "strings" |
| 12 | ) | 14 | ) |
| 13 | 15 | ||
| @@ -18,6 +20,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) | @@ -18,6 +20,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) | ||
| 18 | transactionContext, _ = factory.CreateTransactionContext(nil) | 20 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| 19 | CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext) | 21 | CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext) |
| 20 | PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | 22 | PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) |
| 23 | + ImInfoRepository, _ = factory.CreateImInfoRepository(transactionContext) | ||
| 21 | company *domain.Company | 24 | company *domain.Company |
| 22 | ) | 25 | ) |
| 23 | if err = transactionContext.StartTransaction(); err != nil { | 26 | if err = transactionContext.StartTransaction(); err != nil { |
| @@ -53,6 +56,11 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) | @@ -53,6 +56,11 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) | ||
| 53 | } else { | 56 | } else { |
| 54 | rsp.User.Salesman = map[string]interface{}{} | 57 | rsp.User.Salesman = map[string]interface{}{} |
| 55 | } | 58 | } |
| 59 | + if imInfo, e := ImInfoRepository.FindOne(map[string]interface{}{"user_id": partnerInfo.Id}); e == nil && imInfo != nil { | ||
| 60 | + rsp.User.ImToken = imInfo.ImToken | ||
| 61 | + rsp.User.AccountID, _ = strconv.ParseInt(imInfo.ImId, 10, 64) | ||
| 62 | + rsp.User.CsAccountID = fmt.Sprintf("%v", imInfo.CustomerImId) | ||
| 63 | + } | ||
| 56 | err = transactionContext.CommitTransaction() | 64 | err = transactionContext.CommitTransaction() |
| 57 | return | 65 | return |
| 58 | } | 66 | } |
| @@ -144,6 +152,16 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | @@ -144,6 +152,16 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo | ||
| 144 | }); err != nil { | 152 | }); err != nil { |
| 145 | return | 153 | return |
| 146 | } | 154 | } |
| 155 | + //清除auth token | ||
| 156 | + //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId)) | ||
| 157 | + //if !auth.Exist() { | ||
| 158 | + // return | ||
| 159 | + //} | ||
| 160 | + //if err = auth.RemoveAuth(); err != nil { | ||
| 161 | + // log.Error(err) | ||
| 162 | + // err = protocol.NewErrWithMessage(4140, err) | ||
| 163 | + // return | ||
| 164 | + //} | ||
| 147 | err = transactionContext.CommitTransaction() | 165 | err = transactionContext.CommitTransaction() |
| 148 | return | 166 | return |
| 149 | } | 167 | } |
| @@ -190,6 +208,16 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass | @@ -190,6 +208,16 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass | ||
| 190 | }); err != nil { | 208 | }); err != nil { |
| 191 | return | 209 | return |
| 192 | } | 210 | } |
| 211 | + //清除auth token | ||
| 212 | + //auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId)) | ||
| 213 | + //if !auth.Exist() { | ||
| 214 | + // return | ||
| 215 | + //} | ||
| 216 | + //if err = auth.RemoveAuth(); err != nil { | ||
| 217 | + // log.Error(err) | ||
| 218 | + // err = protocol.NewErrWithMessage(4140, err) | ||
| 219 | + // return | ||
| 220 | + //} | ||
| 193 | err = transactionContext.CommitTransaction() | 221 | err = transactionContext.CommitTransaction() |
| 194 | return | 222 | return |
| 195 | } | 223 | } |
pkg/application/userAuth/user_auth.go
0 → 100644
| 1 | +package userAuth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + "fmt" | ||
| 6 | + "github.com/tiptok/gocomm/pkg/redis" | ||
| 7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 8 | + "strconv" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +var ( | ||
| 12 | + errDataType = fmt.Errorf("auth:data type assert error") | ||
| 13 | + errNoMatch = fmt.Errorf("auth:user auth no match") | ||
| 14 | + errNotFound = func(field string) error { return fmt.Errorf("auth:hset field (%v) not found", field) } | ||
| 15 | + errTokenNotEqual = func(target, compare string) error { | ||
| 16 | + return fmt.Errorf("auth:token not equal (%v != %v)", target, compare) | ||
| 17 | + } | ||
| 18 | +) | ||
| 19 | + | ||
| 20 | +type UserAuthManager interface { | ||
| 21 | + //添加用户权限 | ||
| 22 | + AddAuth() error | ||
| 23 | + //获取用户权限 | ||
| 24 | + GetAuth() (interface{}, error) | ||
| 25 | + //移除用户权限 | ||
| 26 | + RemoveAuth() error | ||
| 27 | + //检验权限 | ||
| 28 | + //检查 refreshToken assessToken 是否一致 | ||
| 29 | + Check(*Options) error | ||
| 30 | + //用户权限是否存在 | ||
| 31 | + //true:存在 false:不存在 | ||
| 32 | + Exist() bool | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +var _ UserAuthManager = (*RedisUserAuth)(nil) | ||
| 36 | + | ||
| 37 | +type Options struct { | ||
| 38 | + UserId int64 | ||
| 39 | + RefreshToken string | ||
| 40 | + AccessToken string | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +func NewOptions(options ...Option) *Options { | ||
| 44 | + Options := &Options{} | ||
| 45 | + for i := range options { | ||
| 46 | + options[i](Options) | ||
| 47 | + } | ||
| 48 | + return Options | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +type Option func(options *Options) | ||
| 52 | + | ||
| 53 | +//option 参数 | ||
| 54 | +func WithRefreshToken(token string) Option { | ||
| 55 | + return func(options *Options) { | ||
| 56 | + options.RefreshToken = token | ||
| 57 | + } | ||
| 58 | +} | ||
| 59 | +func WithAccessToken(token string) Option { | ||
| 60 | + return func(options *Options) { | ||
| 61 | + options.AccessToken = token | ||
| 62 | + } | ||
| 63 | +} | ||
| 64 | +func WithUserId(uid int64) Option { | ||
| 65 | + return func(options *Options) { | ||
| 66 | + options.UserId = uid | ||
| 67 | + } | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +//Redis用户权限 | ||
| 71 | +type RedisUserAuth struct { | ||
| 72 | + Options *Options | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +func NewRedisUserAuth(options ...Option) *RedisUserAuth { | ||
| 76 | + rua := &RedisUserAuth{ | ||
| 77 | + Options: NewOptions(options...), | ||
| 78 | + } | ||
| 79 | + return rua | ||
| 80 | +} | ||
| 81 | +func (auth RedisUserAuth) AddAuth() error { | ||
| 82 | + err := redis.Hset( | ||
| 83 | + auth.redisKey(), | ||
| 84 | + auth.field(), | ||
| 85 | + utils.JsonAssertString(NewRedisUserAuthData(auth.Options)), 0, | ||
| 86 | + ) | ||
| 87 | + return err | ||
| 88 | +} | ||
| 89 | +func (auth RedisUserAuth) RemoveAuth() error { | ||
| 90 | + if !auth.Exist() { | ||
| 91 | + return nil | ||
| 92 | + } | ||
| 93 | + return redis.Hdel(auth.redisKey(), auth.field()) | ||
| 94 | +} | ||
| 95 | +func (auth RedisUserAuth) GetAuth() (interface{}, error) { | ||
| 96 | + if !auth.Exist() { | ||
| 97 | + return nil, errNotFound(auth.field()) | ||
| 98 | + } | ||
| 99 | + data, err := redis.Hget(auth.redisKey(), auth.field()) | ||
| 100 | + if err != nil { | ||
| 101 | + return nil, err | ||
| 102 | + } | ||
| 103 | + var authData *RedisUserAuthData | ||
| 104 | + if err = json.Unmarshal([]byte(data), &authData); err != nil { | ||
| 105 | + return nil, err | ||
| 106 | + } | ||
| 107 | + return authData, nil | ||
| 108 | +} | ||
| 109 | +func (auth RedisUserAuth) Check(options *Options) error { | ||
| 110 | + data, err := auth.GetAuth() | ||
| 111 | + if err != nil { | ||
| 112 | + return err | ||
| 113 | + } | ||
| 114 | + authData, ok := data.(*RedisUserAuthData) | ||
| 115 | + if !ok { | ||
| 116 | + return errDataType | ||
| 117 | + } | ||
| 118 | + if options.AccessToken != "" { | ||
| 119 | + if authData.AccessToken != options.AccessToken { | ||
| 120 | + return errTokenNotEqual(authData.AccessToken, options.AccessToken) | ||
| 121 | + } | ||
| 122 | + return nil | ||
| 123 | + } | ||
| 124 | + if options.RefreshToken != "" { | ||
| 125 | + if authData.RefreshToken != options.RefreshToken { | ||
| 126 | + return errTokenNotEqual(authData.RefreshToken, options.RefreshToken) | ||
| 127 | + } | ||
| 128 | + return nil | ||
| 129 | + } | ||
| 130 | + return errNoMatch | ||
| 131 | +} | ||
| 132 | +func (auth RedisUserAuth) Exist() bool { | ||
| 133 | + return redis.Hexists(auth.redisKey(), auth.field()) | ||
| 134 | +} | ||
| 135 | +func (auth RedisUserAuth) redisKey() string { | ||
| 136 | + if auth.Options.UserId == 0 { | ||
| 137 | + return "" | ||
| 138 | + } | ||
| 139 | + return utils.RedisKey("user_auth") | ||
| 140 | +} | ||
| 141 | +func (auth RedisUserAuth) field() string { | ||
| 142 | + return strconv.Itoa(int(auth.Options.UserId)) | ||
| 143 | +} | ||
| 144 | + | ||
| 145 | +//存储到redis的数据结构 | ||
| 146 | +type RedisUserAuthData struct { | ||
| 147 | + UserId int64 `json:"userId"` | ||
| 148 | + RefreshToken string `json:"refreshToken"` | ||
| 149 | + AccessToken string `json:"accessToken"` | ||
| 150 | +} | ||
| 151 | + | ||
| 152 | +func NewRedisUserAuthData(options *Options) RedisUserAuthData { | ||
| 153 | + return RedisUserAuthData{ | ||
| 154 | + UserId: options.UserId, | ||
| 155 | + RefreshToken: options.RefreshToken, | ||
| 156 | + AccessToken: options.AccessToken, | ||
| 157 | + } | ||
| 158 | +} |
pkg/application/userAuth/user_auth_test.go
0 → 100644
| 1 | +package userAuth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/tiptok/gocomm/pkg/redis" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" | ||
| 7 | + "testing" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +func initRedis() { | ||
| 11 | + redisSource := fmt.Sprintf("%v:%v", constant.REDIS_HOST, constant.REDIS_PORT) | ||
| 12 | + err := redis.InitWithDb(100, redisSource, constant.REDIS_AUTH, "0") | ||
| 13 | + if err != nil { | ||
| 14 | + panic(err) | ||
| 15 | + } | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func TestRedisUserAuth(t *testing.T) { | ||
| 19 | + initRedis() | ||
| 20 | + | ||
| 21 | + userAuth := NewRedisUserAuth(WithUserId(1), | ||
| 22 | + WithAccessToken("abc"), | ||
| 23 | + WithRefreshToken("cdf"), | ||
| 24 | + ) | ||
| 25 | + err := userAuth.AddAuth() | ||
| 26 | + if err != nil { | ||
| 27 | + t.Fatal(err) | ||
| 28 | + } | ||
| 29 | + _, err = userAuth.GetAuth() | ||
| 30 | + if err != nil { | ||
| 31 | + t.Fatal("get auth", err) | ||
| 32 | + } | ||
| 33 | + if !userAuth.Exist() { | ||
| 34 | + t.Fatal("except:true") | ||
| 35 | + } | ||
| 36 | + if err = userAuth.Check(NewOptions(WithAccessToken("abc"))); err != nil { | ||
| 37 | + t.Fatal("check accessToken:", err) | ||
| 38 | + } | ||
| 39 | + if err = userAuth.Check(NewOptions(WithRefreshToken("cdf"))); err != nil { | ||
| 40 | + t.Fatal("check refreshToken:", err) | ||
| 41 | + } | ||
| 42 | + if err = userAuth.RemoveAuth(); err != nil { | ||
| 43 | + t.Fatal("remove:", err) | ||
| 44 | + } | ||
| 45 | + if userAuth.field() != "1" { | ||
| 46 | + t.Fatal("except:1") | ||
| 47 | + } | ||
| 48 | + if userAuth.Exist() { | ||
| 49 | + t.Fatal("except:false") | ||
| 50 | + } | ||
| 51 | +} |
pkg/constant/im.go
0 → 100644
| 1 | +package constant | ||
| 2 | + | ||
| 3 | +import "os" | ||
| 4 | + | ||
| 5 | +var ( | ||
| 6 | + IM_SERVICE_ADDRESS = "https://api.netease.im/nimserver" | ||
| 7 | + IM_APP_KEY = "be7c0639c10e6a69f86ce3b4fa8dc8ec" //"ebf3ae278ee1b346773b99be5080f6a9" | ||
| 8 | + IM_APP_SECRET = "9c5b60346613" //"67ea92e1ea45" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +func init() { | ||
| 12 | + if os.Getenv("IM_APP_KEY") != "" { | ||
| 13 | + IM_APP_KEY = os.Getenv("IM_APP_KEY") | ||
| 14 | + } | ||
| 15 | + if os.Getenv("IM_APP_SECRET") != "" { | ||
| 16 | + IM_APP_SECRET = os.Getenv("IM_APP_SECRET") | ||
| 17 | + } | ||
| 18 | +} |
pkg/domain/customer_service.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +type ImCustomerService struct { | ||
| 6 | + // id | ||
| 7 | + Id int64 | ||
| 8 | + // 用户id(合伙人Id) | ||
| 9 | + UserId int64 | ||
| 10 | + // IM唯一id | ||
| 11 | + ImId string | ||
| 12 | + // IM颁发的token | ||
| 13 | + ImToken string | ||
| 14 | + // 创建时间 | ||
| 15 | + CreateTime time.Time | ||
| 16 | + // 更新时间 | ||
| 17 | + UpdateTime time.Time | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +type ImCustomerServiceRepository interface { | ||
| 21 | + Save(dm *ImCustomerService) (*ImCustomerService, error) | ||
| 22 | + Remove(dm *ImCustomerService) (*ImCustomerService, error) | ||
| 23 | + FindOne(queryOptions map[string]interface{}) (*ImCustomerService, error) | ||
| 24 | + Find(queryOptions map[string]interface{}) (int64, []*ImCustomerService, error) | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +func (m *ImCustomerService) Identify() interface{} { | ||
| 28 | + if m.Id == 0 { | ||
| 29 | + return nil | ||
| 30 | + } | ||
| 31 | + return m.Id | ||
| 32 | +} |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | +import "fmt" | ||
| 4 | + | ||
| 3 | //查询参数 | 5 | //查询参数 |
| 4 | const ( | 6 | const ( |
| 5 | ASC = "ASC" | 7 | ASC = "ASC" |
| 6 | DESC = "DESC" | 8 | DESC = "DESC" |
| 7 | ) | 9 | ) |
| 10 | + | ||
| 11 | +const ( | ||
| 12 | + OrderReal = iota + 1 //实发订单 | ||
| 13 | + OrderIntention //意向订单 | ||
| 14 | +) | ||
| 15 | + | ||
| 16 | +const ( | ||
| 17 | + BonusWaitPay = iota + 1 //等待支付分红 | ||
| 18 | + BonusPaid //已经支付分红 | ||
| 19 | +) | ||
| 20 | + | ||
| 21 | +var ( | ||
| 22 | + QueryNoRow = fmt.Errorf("not row found") | ||
| 23 | +) |
pkg/domain/im_info.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +type ImInfo struct { | ||
| 6 | + tableName struct{} `pg:"im_info"` | ||
| 7 | + // id | ||
| 8 | + Id int64 | ||
| 9 | + // 合伙人Id | ||
| 10 | + UserId int64 | ||
| 11 | + // IM唯一id | ||
| 12 | + ImId string | ||
| 13 | + // IM颁发的token | ||
| 14 | + ImToken string | ||
| 15 | + // 客服IM编号 | ||
| 16 | + CustomerImId int64 | ||
| 17 | + // 是否是客服 true:是 false:否 | ||
| 18 | + //IsCustomer bool | ||
| 19 | + // 创建时间 | ||
| 20 | + CreateTime time.Time | ||
| 21 | + // 更新时间 | ||
| 22 | + UpdateTime time.Time | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +type ImInfoRepository interface { | ||
| 26 | + Save(dm *ImInfo) (*ImInfo, error) | ||
| 27 | + Remove(dm *ImInfo) (*ImInfo, error) | ||
| 28 | + FindOne(queryOptions map[string]interface{}) (*ImInfo, error) | ||
| 29 | + Find(queryOptions map[string]interface{}) (int64, []*ImInfo, error) | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +func (m *ImInfo) Identify() interface{} { | ||
| 33 | + if m.Id == 0 { | ||
| 34 | + return nil | ||
| 35 | + } | ||
| 36 | + return m.Id | ||
| 37 | +} |
pkg/domain/order.go
已删除
100644 → 0
| 1 | -package domain | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 5 | - "time" | ||
| 6 | -) | ||
| 7 | - | ||
| 8 | -const ( | ||
| 9 | - OrderStatusReserve = iota + 1 //预定中 | ||
| 10 | - OrderStatusDeliverSome //部分发货 | ||
| 11 | - OrderStatusDeliverAll //全部发货 | ||
| 12 | -) | ||
| 13 | - | ||
| 14 | -const ( | ||
| 15 | - OrderReal = iota + 1 //实发订单 | ||
| 16 | - OrderIntention //意向订单 | ||
| 17 | -) | ||
| 18 | - | ||
| 19 | -type OrderRepository interface { | ||
| 20 | - Save(dm *Order) (*Order, error) | ||
| 21 | - Remove(dm *Order) (*Order, error) | ||
| 22 | - FindOne(queryOptions map[string]interface{}) (*Order, error) | ||
| 23 | - Find(queryOptions map[string]interface{}) (int64, []*Order, error) | ||
| 24 | -} | ||
| 25 | - | ||
| 26 | -//Order 订单信息 | ||
| 27 | -type Order struct { | ||
| 28 | - //id | ||
| 29 | - Id int64 `json:"Id,omitempty"` | ||
| 30 | - //订单类型 | ||
| 31 | - OrderType int `json:"orderType,omitempty"` | ||
| 32 | - //订单编号 | ||
| 33 | - OrderCode string `json:"orderCode,omitempty"` | ||
| 34 | - //订单名称 | ||
| 35 | - OrderName string `json:"orderName,omitempty"` | ||
| 36 | - //订单状态 | ||
| 37 | - OrderStatus int `json:"orderStatus,omitempty"` | ||
| 38 | - //订单数量 | ||
| 39 | - OrderCount int `json:"orderCount,omitempty"` | ||
| 40 | - //实际订单数量 | ||
| 41 | - OrderActualCount int `json:"orderActualCount,omitempty"` | ||
| 42 | - //订单金额 | ||
| 43 | - OrderAmount float64 `json:"admin_name,omitempty"` | ||
| 44 | - //订单实际金额 | ||
| 45 | - OrderActualAmount float64 `json:"orderActualAmount,omitempty"` | ||
| 46 | - //订单已支付金额(货款) | ||
| 47 | - OrderPaymentAmount float64 `json:"orderPaymentAmount,omitempty"` | ||
| 48 | - //订单区域信息 | ||
| 49 | - OrderRegionInfo *RegionInfo `json:"orderRegionInfo,omitempty"` | ||
| 50 | - | ||
| 51 | - Buyer *Buyer `json:"buyer,omitempty"` | ||
| 52 | - //合伙人编号 | ||
| 53 | - PartnerId int64 `json:"partnerId,omitempty"` | ||
| 54 | - //合伙人分红百分比 | ||
| 55 | - PartnerBonusPercent float64 `json:"partnerBonusPercent,omitempty"` | ||
| 56 | - //业务员分红百分比 | ||
| 57 | - SalesmanBonusPercent float64 `json:"salesmanBonusPercent,omitempty"` | ||
| 58 | - | ||
| 59 | - //创建时间 | ||
| 60 | - CreateAt time.Time `json:"createAt,omitempty"` | ||
| 61 | - //更新时间 | ||
| 62 | - UpdateAt time.Time `json:"updateAt,omitempty"` | ||
| 63 | - | ||
| 64 | - //上一次查看时间 已读情况 | ||
| 65 | - LastViewTime time.Time `json:"lastViewTime,omitempty"` | ||
| 66 | - //订单更新理由 | ||
| 67 | - Reason string `json:"reason,omitempty"` | ||
| 68 | -} | ||
| 69 | - | ||
| 70 | -func (m *Order) Identify() interface{} { | ||
| 71 | - if m.Id == 0 { | ||
| 72 | - return nil | ||
| 73 | - } | ||
| 74 | - return m.Id | ||
| 75 | -} | ||
| 76 | - | ||
| 77 | -func (m *Order) Update(data map[string]interface{}) error { | ||
| 78 | - if orderType, ok := data["orderType"]; ok && orderType != 0 { | ||
| 79 | - m.OrderType = orderType.(int) | ||
| 80 | - } | ||
| 81 | - if orderCode, ok := data["orderCode"]; ok && orderCode != "" { | ||
| 82 | - m.OrderCode = orderCode.(string) | ||
| 83 | - } | ||
| 84 | - if orderName, ok := data["orderName"]; ok && orderName != "" { | ||
| 85 | - m.OrderName = orderName.(string) | ||
| 86 | - } | ||
| 87 | - if orderStatus, ok := data["orderStatus"]; ok && orderStatus != 0 { | ||
| 88 | - m.OrderStatus = orderStatus.(int) | ||
| 89 | - } | ||
| 90 | - if lastViewTime, ok := data["lastViewTime"]; ok && lastViewTime != 0 { | ||
| 91 | - m.LastViewTime = lastViewTime.(time.Time) | ||
| 92 | - } | ||
| 93 | - m.UpdateAt = time.Now() | ||
| 94 | - return nil | ||
| 95 | -} | ||
| 96 | - | ||
| 97 | -//合伙人 | ||
| 98 | -//订单累计分红 | ||
| 99 | -func (m *Order) OrderTotalBonus() float64 { | ||
| 100 | - return utils.Decimal(m.OrderActualAmount * (m.PartnerBonusPercent / 100.0)) | ||
| 101 | -} | ||
| 102 | - | ||
| 103 | -//订单已收分红 | ||
| 104 | -func (m *Order) OrderBonusReceive() float64 { | ||
| 105 | - return utils.Decimal(m.OrderPaymentAmount * (m.PartnerBonusPercent / 100.0)) | ||
| 106 | -} | ||
| 107 | - | ||
| 108 | -//订单未收分红 | ||
| 109 | -func (m *Order) OrderBonusWait() float64 { | ||
| 110 | - bonusWait := m.OrderTotalBonus() - m.OrderBonusReceive() | ||
| 111 | - if bonusWait < 0 { | ||
| 112 | - return 0 | ||
| 113 | - } | ||
| 114 | - return bonusWait | ||
| 115 | -} | ||
| 116 | - | ||
| 117 | -//分红支出 | ||
| 118 | -func (m *Order) OrderBonusOutstanding() float64 { | ||
| 119 | - if m.OrderAmount <= m.OrderActualAmount { | ||
| 120 | - return 0 | ||
| 121 | - } | ||
| 122 | - return utils.Decimal((m.OrderAmount - m.OrderActualAmount) * (m.PartnerBonusPercent / 100.0)) | ||
| 123 | -} | ||
| 124 | - | ||
| 125 | -//订单被取消金额 | ||
| 126 | -func (m *Order) OrderAmountCancel() float64 { | ||
| 127 | - if m.OrderAmount <= m.OrderActualAmount { | ||
| 128 | - return 0 | ||
| 129 | - } | ||
| 130 | - return utils.Decimal(m.OrderAmount - m.OrderActualAmount) | ||
| 131 | -} | ||
| 132 | - | ||
| 133 | -//订单是否已读 | ||
| 134 | -func (m *Order) IsRead() int { | ||
| 135 | - if m.UpdateAt.After(m.LastViewTime) { | ||
| 136 | - return 0 | ||
| 137 | - } | ||
| 138 | - return 1 | ||
| 139 | -} | ||
| 140 | - | ||
| 141 | -type OrderQueryOption struct { | ||
| 142 | - PartnerId int64 `json:"partnerId,omitempty"` | ||
| 143 | - OrderType int `json:"orderType,omitempty"` | ||
| 144 | - OrderStatus int `json:"orderStatus,omitempty"` | ||
| 145 | - BeginTime time.Time `json:"beginTime,omitempty"` | ||
| 146 | - EndTime time.Time `json:"endTime,omitempty"` | ||
| 147 | - SortByCreateTime string `json:"sortByCreateTime,omitempty"` | ||
| 148 | - SortByUpdateTime string `json:"sortByUpdateTime,omitempty"` | ||
| 149 | - Offset int `json:"offset,omitempty"` | ||
| 150 | - Limit int `json:"limit,omitempty"` | ||
| 151 | -} | ||
| 152 | - | ||
| 153 | -type DividendOrdersQueryOption struct { | ||
| 154 | - PartnerId int64 `json:"partnerId"` | ||
| 155 | - OrderType int `json:"orderType"` //订单类型 | ||
| 156 | - DetailAction int `json:"detailAction"` //明细类型(0已收明细、1未收明细) | ||
| 157 | - DividendAction int `json:"dividendAction"` //分红类型(0累计分红、1分红支出) | ||
| 158 | - StartTime int64 `json:"startTime" ` | ||
| 159 | - EndTime int64 `json:"endTime"` | ||
| 160 | - Offset int `json:"offset,omitempty"` | ||
| 161 | - Limit int `json:"limit,omitempty"` | ||
| 162 | - SortByUpdateTime string `json:"sortByUpdateTime,omitempty"` | ||
| 163 | -} | ||
| 164 | - | ||
| 165 | -//买家 | ||
| 166 | -type Buyer struct { | ||
| 167 | - //买家姓名 | ||
| 168 | - BuyerName string `json:"buyerName"` | ||
| 169 | - //联系方式 | ||
| 170 | - ContactInfo string `json:"contactInfo"` | ||
| 171 | - //收获地址 | ||
| 172 | - ShippingAddress string `json:"shippingAddress"` | ||
| 173 | -} |
pkg/domain/order_base.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +//OrderBase 订单基础 | ||
| 9 | +type OrderBase struct { | ||
| 10 | + //表id | ||
| 11 | + Id int64 | ||
| 12 | + //订单类型 1:实际订单 2:意向订单 | ||
| 13 | + OrderType int `pg:",notnull,default:1"` | ||
| 14 | + //订单编号 | ||
| 15 | + OrderCode string | ||
| 16 | + //交货编号 | ||
| 17 | + DeliveryCode string | ||
| 18 | + //买家 | ||
| 19 | + Buyer *Buyer | ||
| 20 | + //订单区域信息 | ||
| 21 | + RegionInfo *RegionInfo | ||
| 22 | + //订单对应的合伙人 | ||
| 23 | + PartnerId int64 | ||
| 24 | + //业务员抽成比例 | ||
| 25 | + SalesmanBonusPercent float64 | ||
| 26 | + //业务员抽成 | ||
| 27 | + SalesmanBonus float64 | ||
| 28 | + //预计的订单内货品总数 | ||
| 29 | + PlanOrderCount int | ||
| 30 | + //预计的订单的总金额 | ||
| 31 | + PlanOrderAmount float64 | ||
| 32 | + //按需使用的订单内货品总数 (初始值=-1) | ||
| 33 | + UseOrderCount int | ||
| 34 | + //按需使用的订单内货品总数 (初始值=-1) | ||
| 35 | + UseOrderAmount float64 | ||
| 36 | + //订单的创建时间 | ||
| 37 | + CreateTime time.Time | ||
| 38 | + //发货时间 | ||
| 39 | + DeliveryTime time.Time | ||
| 40 | + //更新时间 | ||
| 41 | + UpdateTime time.Time | ||
| 42 | + //上一次查看时间 已读情况 | ||
| 43 | + LastViewTime time.Time | ||
| 44 | + //合伙人应收分红 | ||
| 45 | + PlanPartnerBonus float64 | ||
| 46 | + //调整后的合伙人应收分红 (初始值=-1) | ||
| 47 | + UsePartnerBonus float64 | ||
| 48 | + //合伙人已收分红 | ||
| 49 | + PartnerBonusHas float64 | ||
| 50 | + //合伙人未收分红 | ||
| 51 | + PartnerBonusNot float64 | ||
| 52 | + //合伙人分红支出 | ||
| 53 | + PartnerBonusExpense float64 | ||
| 54 | + //是否关闭【0;否】【1:是】 | ||
| 55 | + IsDisable int8 | ||
| 56 | + //1:待支付分红 2:已支付分红 | ||
| 57 | + BonusStatus int8 | ||
| 58 | + //货物列表 | ||
| 59 | + OrderGood []*OrderGood | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +func (m *OrderBase) Identify() interface{} { | ||
| 63 | + if m.Id == 0 { | ||
| 64 | + return nil | ||
| 65 | + } | ||
| 66 | + return m.Id | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +//合伙人 | ||
| 70 | +//订单累计分红 | ||
| 71 | +func (m *OrderBase) OrderTotalBonus() float64 { | ||
| 72 | + if m.UseOrderCount >= 0 { | ||
| 73 | + return utils.Decimal(m.UsePartnerBonus + m.PartnerBonusExpense) | ||
| 74 | + } | ||
| 75 | + return utils.Decimal(m.PlanPartnerBonus) | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +//订单已收分红 | ||
| 79 | +func (m *OrderBase) OrderBonusReceive() float64 { | ||
| 80 | + return utils.Decimal(m.PartnerBonusHas) | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +//订单未收分红 | ||
| 84 | +func (m *OrderBase) OrderBonusWait() float64 { | ||
| 85 | + bonusWait := m.OrderTotalBonus() - m.OrderBonusReceive() | ||
| 86 | + if bonusWait < 0 { | ||
| 87 | + return 0 | ||
| 88 | + } | ||
| 89 | + return bonusWait | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +//分红支出 | ||
| 93 | +func (m *OrderBase) OrderBonusOutstanding() float64 { | ||
| 94 | + return utils.Decimal(m.PartnerBonusExpense) | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +//订单被取消金额 | ||
| 98 | +func (m *OrderBase) OrderAmountCancel() float64 { | ||
| 99 | + if m.UseOrderAmount < 0 { | ||
| 100 | + return 0 | ||
| 101 | + } | ||
| 102 | + if m.PlanOrderAmount > m.UseOrderAmount { | ||
| 103 | + return 0 | ||
| 104 | + } | ||
| 105 | + return utils.Decimal(m.UseOrderAmount - m.PlanOrderAmount) | ||
| 106 | +} | ||
| 107 | + | ||
| 108 | +//订单金额 | ||
| 109 | +func (m *OrderBase) OrderAmount() float64 { | ||
| 110 | + if m.UseOrderAmount < 0 { | ||
| 111 | + return m.PlanOrderAmount | ||
| 112 | + } | ||
| 113 | + return m.UseOrderAmount | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +//订单是否已读 | ||
| 117 | +func (m *OrderBase) IsRead() int { | ||
| 118 | + if m.UpdateTime.After(m.LastViewTime) { | ||
| 119 | + return 0 | ||
| 120 | + } | ||
| 121 | + return 1 | ||
| 122 | +} | ||
| 123 | + | ||
| 124 | +func (m *OrderBase) OrderBonusStatic() *OrderStatics { | ||
| 125 | + return &OrderStatics{ | ||
| 126 | + BonusStatus: m.BonusStatus, | ||
| 127 | + PlanOrderCount: m.PlanOrderCount, | ||
| 128 | + PlanOrderAmount: m.PlanOrderAmount, | ||
| 129 | + UseOrderCount: m.UseOrderCount, | ||
| 130 | + UseOrderAmount: m.UseOrderAmount, | ||
| 131 | + PlanPartnerBonus: m.PlanPartnerBonus, | ||
| 132 | + UsePartnerBonus: m.UsePartnerBonus, | ||
| 133 | + PartnerBonusHas: m.PartnerBonusHas, | ||
| 134 | + PartnerBonusNot: m.PartnerBonusNot, | ||
| 135 | + PartnerBonusExpense: m.PartnerBonusExpense, | ||
| 136 | + } | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +type OrderQueryOption struct { | ||
| 140 | + PartnerId int64 `json:"partnerId,omitempty"` | ||
| 141 | + OrderType int `json:"orderType,omitempty"` | ||
| 142 | + OrderStatus int `json:"orderStatus,omitempty"` | ||
| 143 | + BeginTime time.Time `json:"beginTime,omitempty"` | ||
| 144 | + EndTime time.Time `json:"endTime,omitempty"` | ||
| 145 | + //IsDisable string `json:"isDisable,omitempty"` | ||
| 146 | + SortByCreateTime string `json:"sortByCreateTime,omitempty"` | ||
| 147 | + SortByUpdateTime string `json:"sortByUpdateTime,omitempty"` | ||
| 148 | + Offset int `json:"offset,omitempty"` | ||
| 149 | + Limit int `json:"limit,omitempty"` | ||
| 150 | +} | ||
| 151 | + | ||
| 152 | +type DividendOrdersQueryOption struct { | ||
| 153 | + PartnerId int64 `json:"partnerId"` | ||
| 154 | + OrderType int `json:"orderType"` //订单类型 | ||
| 155 | + DetailAction int `json:"detailAction"` //明细类型(0已收明细、1未收明细) | ||
| 156 | + DividendAction int `json:"dividendAction"` //分红类型(0累计分红、1分红支出) | ||
| 157 | + IsDisable string `json:"isDisable,omitempty"` | ||
| 158 | + StartTime int64 `json:"startTime" ` | ||
| 159 | + EndTime int64 `json:"endTime"` | ||
| 160 | + Offset int `json:"offset,omitempty"` | ||
| 161 | + Limit int `json:"limit,omitempty"` | ||
| 162 | + SortByUpdateTime string `json:"sortByUpdateTime,omitempty"` | ||
| 163 | +} | ||
| 164 | + | ||
| 165 | +//买家 | ||
| 166 | +type Buyer struct { | ||
| 167 | + //买家姓名 | ||
| 168 | + BuyerName string `json:"buyerName"` | ||
| 169 | + //联系方式 | ||
| 170 | + ContactInfo string `json:"contactInfo"` | ||
| 171 | + //收获地址 | ||
| 172 | + ShippingAddress string `json:"shippingAddress"` | ||
| 173 | +} | ||
| 174 | + | ||
| 175 | +type OrderBaseRepository interface { | ||
| 176 | + Save(dm *OrderBase) (*OrderBase, error) | ||
| 177 | + Remove(dm *OrderBase) (*OrderBase, error) | ||
| 178 | + FindOne(queryOptions map[string]interface{}) (*OrderBase, error) | ||
| 179 | + Find(queryOptions map[string]interface{}) (int64, []*OrderBase, error) | ||
| 180 | +} |
pkg/domain/order_good.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +//OrderGood 订单中的货品 | ||
| 4 | +type OrderGood struct { | ||
| 5 | + //货品id | ||
| 6 | + Id int64 | ||
| 7 | + //所属订单id | ||
| 8 | + OrderId int64 | ||
| 9 | + //货品名称 长度可能较长 | ||
| 10 | + GoodName string | ||
| 11 | + //预计的货品数量 | ||
| 12 | + PlanGoodNumber int | ||
| 13 | + //货品单价 | ||
| 14 | + Price float64 | ||
| 15 | + //预计的货品总额 | ||
| 16 | + PlanAmount float64 | ||
| 17 | + //调整后的货品数量 | ||
| 18 | + UseGoodNumber int | ||
| 19 | + //调整后的货品总额 | ||
| 20 | + UseAmount float64 | ||
| 21 | + //合伙人分红比例 | ||
| 22 | + PartnerBonusPercent float64 | ||
| 23 | + //预计的合伙人分红 | ||
| 24 | + PlanPartnerBonus float64 | ||
| 25 | + //合伙人应收分红调整 (初始值=-1) | ||
| 26 | + UsePartnerBonus float64 | ||
| 27 | + //合伙人已收分红 | ||
| 28 | + PartnerBonusHas float64 | ||
| 29 | + //合伙人未收分红 | ||
| 30 | + PartnerBonusNot float64 | ||
| 31 | + //合伙人分红支出 | ||
| 32 | + PartnerBonusExpense float64 | ||
| 33 | + //分红状态 | ||
| 34 | + BonusStatus int | ||
| 35 | + //备注信息 | ||
| 36 | + Remark string | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +func (g *OrderGood) Status() GoodStatus { | ||
| 40 | + if g.BonusStatus == BonusWaitPay && g.UseGoodNumber >= 0 && g.UseGoodNumber < g.PlanGoodNumber { | ||
| 41 | + return goodStatusWithGoodsReturn | ||
| 42 | + } | ||
| 43 | + if g.BonusStatus == BonusWaitPay { | ||
| 44 | + return goodStatusWait | ||
| 45 | + } | ||
| 46 | + if g.BonusStatus == BonusPaid && g.UseGoodNumber >= 0 && g.UseGoodNumber < g.PlanGoodNumber { | ||
| 47 | + return goodStatusPayWithGoodsReturn | ||
| 48 | + } | ||
| 49 | + if g.BonusStatus == BonusPaid { | ||
| 50 | + return goodStatusPay | ||
| 51 | + } | ||
| 52 | + return goodStatusWait | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +type GoodStatus int | ||
| 56 | + | ||
| 57 | +const ( | ||
| 58 | + // 待支付 | ||
| 59 | + goodStatusWait GoodStatus = GoodStatus(iota + 1) | ||
| 60 | + // 已支付 | ||
| 61 | + goodStatusPay | ||
| 62 | + // 已支付退货 | ||
| 63 | + goodStatusPayWithGoodsReturn | ||
| 64 | + // 待支付退货 | ||
| 65 | + goodStatusWithGoodsReturn | ||
| 66 | +) | ||
| 67 | + | ||
| 68 | +func (m *OrderGood) Identify() interface{} { | ||
| 69 | + if m.Id == 0 { | ||
| 70 | + return nil | ||
| 71 | + } | ||
| 72 | + return m.Id | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +func (m *OrderGood) OrderBonusStatic() *OrderStatics { | ||
| 76 | + return &OrderStatics{ | ||
| 77 | + BonusStatus: int8(m.BonusStatus), | ||
| 78 | + PlanOrderCount: m.PlanGoodNumber, | ||
| 79 | + PlanOrderAmount: m.PlanAmount, | ||
| 80 | + UseOrderCount: m.UseGoodNumber, | ||
| 81 | + UseOrderAmount: m.UseAmount, | ||
| 82 | + PlanPartnerBonus: m.PlanPartnerBonus, | ||
| 83 | + UsePartnerBonus: m.UsePartnerBonus, | ||
| 84 | + PartnerBonusHas: m.PartnerBonusHas, | ||
| 85 | + PartnerBonusNot: m.PartnerBonusNot, | ||
| 86 | + PartnerBonusExpense: m.PartnerBonusExpense, | ||
| 87 | + } | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +type OrderGoodRepository interface { | ||
| 91 | + Save(dm *OrderGood) (*OrderGood, error) | ||
| 92 | + Remove(dm *OrderGood) (*OrderGood, error) | ||
| 93 | + FindOne(queryOptions map[string]interface{}) (*OrderGood, error) | ||
| 94 | + Find(queryOptions map[string]interface{}) (int64, []*OrderGood, error) | ||
| 95 | +} |
pkg/domain/order_payment.go
已删除
100644 → 0
| 1 | -package domain | ||
| 2 | - | ||
| 3 | -import "time" | ||
| 4 | - | ||
| 5 | -const ( | ||
| 6 | - BonusWaitPay = iota + 1 //等待支付分红 | ||
| 7 | - BonusPaid //已经支付分红 | ||
| 8 | -) | ||
| 9 | - | ||
| 10 | -type OrderPaymentRepository interface { | ||
| 11 | - Save(dm *OrderPayment) (*OrderPayment, error) | ||
| 12 | - Remove(dm *OrderPayment) (*OrderPayment, error) | ||
| 13 | - FindOne(queryOptions map[string]interface{}) (*OrderPayment, error) | ||
| 14 | - Find(queryOptions map[string]interface{}) (int64, []*OrderPayment, error) | ||
| 15 | -} | ||
| 16 | - | ||
| 17 | -type OrderPayment struct { | ||
| 18 | - //编号 | ||
| 19 | - Id int64 `json:"id"` | ||
| 20 | - //订单编号 | ||
| 21 | - OrderId int64 `json:"orderId"` | ||
| 22 | - //合伙人编号 | ||
| 23 | - PartnerId int64 `json:"partnerId"` | ||
| 24 | - //支付货款 | ||
| 25 | - PaymentAmount float64 `json:"paymentAmount"` | ||
| 26 | - //分红金额 | ||
| 27 | - BonusAmount float64 `json:"bonusAmount"` | ||
| 28 | - //分红状态 1.等待支付分红 2.已支付分红 | ||
| 29 | - BonusStatus int `json:"bonusStatus"` | ||
| 30 | - //创建时间 | ||
| 31 | - CreateAt time.Time `json:"createAt"` | ||
| 32 | - //更新时间 | ||
| 33 | - UpdateAt time.Time `json:"updateAt"` | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -func (m *OrderPayment) Identify() interface{} { | ||
| 37 | - if m.Id == 0 { | ||
| 38 | - return nil | ||
| 39 | - } | ||
| 40 | - return m.Id | ||
| 41 | -} | ||
| 42 | - | ||
| 43 | -func (m *OrderPayment) Update(data map[string]interface{}) error { | ||
| 44 | - if m.BonusStatus != BonusWaitPay { | ||
| 45 | - return nil | ||
| 46 | - } | ||
| 47 | - if paymentAmount, ok := data["paymentAmount"]; ok && paymentAmount != 0 { | ||
| 48 | - m.PaymentAmount = paymentAmount.(float64) | ||
| 49 | - } | ||
| 50 | - if bonusAmount, ok := data["bonusAmount"]; ok && bonusAmount != 0 { | ||
| 51 | - m.BonusAmount = bonusAmount.(float64) | ||
| 52 | - } | ||
| 53 | - if bonusStatus, ok := data["bonusStatus"]; ok && bonusStatus != 0 { | ||
| 54 | - m.BonusStatus = bonusStatus.(int) | ||
| 55 | - } | ||
| 56 | - m.UpdateAt = time.Now() | ||
| 57 | - return nil | ||
| 58 | -} |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | -//type OrderTodayStatic struct { | ||
| 4 | -// TodayIntentionQuantity int `json:"todayIntentionQuantity"` //今日新增意向订单 | ||
| 5 | -// TodayIntentionMoney int `json:"todayIntentionMoney"` //今日新增意向订单金额 | ||
| 6 | -// TodayRealQuantity int `json:"todayRealQuantity"` //今日新增实发订单 | ||
| 7 | -// TodayRealMoney int `json:"todayRealMoney"` //今日新增实发订单金额 | ||
| 8 | -// //CumulativeQuantity int `json:"cumulativeQuantity"` //累计实发订单 | ||
| 9 | -// //CumulativeMoney int `json:"cumulativeMoney"` //累计实发订单金额 | ||
| 10 | -//} | ||
| 11 | -////实发订单统计 | ||
| 12 | -//type OrderRealStatic struct { | ||
| 13 | -// CumulativeQuantity int `json:"cumulativeQuantity"` //累计实发订单 | ||
| 14 | -// CumulativeMoney int `json:"cumulativeMoney"` //累计实发订单金额 | ||
| 15 | -//} | ||
| 16 | -////意向订单统计 | ||
| 17 | -//type OrderIntentionStatic struct { | ||
| 18 | -// CumulativeQuantity int `json:"cumulativeQuantity"` //累计意向订单 | ||
| 19 | -// CumulativeMoney int `json:"cumulativeMoney"` //累计意向订单金额 | ||
| 20 | -//} | ||
| 21 | - | ||
| 22 | type OrderStatic struct { | 3 | type OrderStatic struct { |
| 23 | CumulativeQuantity int `json:"cumulativeQuantity"` //累计数量 | 4 | CumulativeQuantity int `json:"cumulativeQuantity"` //累计数量 |
| 24 | CumulativeMoney int `json:"cumulativeMoney"` //累计金额 | 5 | CumulativeMoney int `json:"cumulativeMoney"` //累计金额 |
| @@ -30,6 +11,7 @@ type OrderStaticQuery struct { | @@ -30,6 +11,7 @@ type OrderStaticQuery struct { | ||
| 30 | EndTime int64 `json:"endTime,omitempty"` | 11 | EndTime int64 `json:"endTime,omitempty"` |
| 31 | OrderStatus int `json:"orderStatus,omitempty"` | 12 | OrderStatus int `json:"orderStatus,omitempty"` |
| 32 | OrderType int `json:"orderType,omitempty"` | 13 | OrderType int `json:"orderType,omitempty"` |
| 14 | + //IsDisable int `json:"isDisable,omitempty"` | ||
| 33 | } | 15 | } |
| 34 | 16 | ||
| 35 | type DividendOrdersQuery struct { | 17 | type DividendOrdersQuery struct { |
pkg/domain/order_statics.go
0 → 100644
| 1 | +package domain | ||
| 2 | + | ||
| 3 | +import "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 4 | + | ||
| 5 | +//分洪统计 | ||
| 6 | +type OrderStatics struct { | ||
| 7 | + //1:待支付分红 2:已支付分红 | ||
| 8 | + BonusStatus int8 | ||
| 9 | + //预计的订单内货品总数 | ||
| 10 | + PlanOrderCount int | ||
| 11 | + //预计的订单的总金额 | ||
| 12 | + PlanOrderAmount float64 | ||
| 13 | + //按需使用的订单内货品总数 (初始值=-1) | ||
| 14 | + UseOrderCount int | ||
| 15 | + //按需使用的订单内货品总数 (初始值=-1) | ||
| 16 | + UseOrderAmount float64 | ||
| 17 | + //合伙人应收分红 | ||
| 18 | + PlanPartnerBonus float64 | ||
| 19 | + //调整后的合伙人应收分红 (初始值=-1) | ||
| 20 | + UsePartnerBonus float64 | ||
| 21 | + //合伙人已收分红 | ||
| 22 | + PartnerBonusHas float64 | ||
| 23 | + //合伙人未收分红 | ||
| 24 | + PartnerBonusNot float64 | ||
| 25 | + //合伙人分红支出 | ||
| 26 | + PartnerBonusExpense float64 | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +//订单应收分红 = 初始分红 / 有调整 取调整后分红 | ||
| 30 | +func (m *OrderStatics) OrderTotalReceivable() float64 { | ||
| 31 | + if m.UseOrderCount >= 0 { | ||
| 32 | + return utils.Decimal(m.UsePartnerBonus) | ||
| 33 | + } | ||
| 34 | + return utils.Decimal(m.PlanPartnerBonus) | ||
| 35 | + //return utils.Decimal(m.PartnerBonusHas + m.PartnerBonusNot) | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +//订单已收分红 = 已收分红 | ||
| 39 | +func (m *OrderStatics) OrderBonusReceive() float64 { | ||
| 40 | + return utils.Decimal(m.PartnerBonusHas) | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +//订单未收分红 = 未收分红 | ||
| 44 | +func (m *OrderStatics) OrderBonusWait() float64 { | ||
| 45 | + //bonusWait := m.OrderTotalBonus() - m.OrderBonusReceive() | ||
| 46 | + //if bonusWait < 0 { | ||
| 47 | + // return 0 | ||
| 48 | + //} | ||
| 49 | + //return bonusWait | ||
| 50 | + return m.PartnerBonusNot | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +//分红支出 = 分红支出 | ||
| 54 | +func (m *OrderStatics) OrderBonusOutstanding() float64 { | ||
| 55 | + return utils.Decimal(m.PartnerBonusExpense) | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +//订单被取消金额 | ||
| 59 | +func (m *OrderStatics) OrderAmountCancel() float64 { | ||
| 60 | + if m.UseOrderAmount < 0 { | ||
| 61 | + return 0 | ||
| 62 | + } | ||
| 63 | + if m.PlanOrderAmount < m.UseOrderAmount { | ||
| 64 | + return 0 | ||
| 65 | + } | ||
| 66 | + return utils.Decimal(m.PlanOrderAmount - m.UseOrderAmount) | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +//订单金额 | ||
| 70 | +func (m *OrderStatics) OrderAmount() float64 { | ||
| 71 | + if m.UseOrderAmount < 0 { | ||
| 72 | + return m.PlanOrderAmount | ||
| 73 | + } | ||
| 74 | + return m.UseOrderAmount | ||
| 75 | +} |
pkg/domain/service/sms_code_service.go
0 → 100644
| @@ -5,37 +5,37 @@ import ( | @@ -5,37 +5,37 @@ import ( | ||
| 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
| 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" |
| 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" |
| 8 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 8 | "time" | 9 | "time" |
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | -type OrderDao struct { | 12 | +type OrderBaseDao struct { |
| 12 | transactionContext *transaction.TransactionContext | 13 | transactionContext *transaction.TransactionContext |
| 13 | } | 14 | } |
| 14 | 15 | ||
| 15 | //订单统计 | 16 | //订单统计 |
| 16 | -func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, amount float64, err error) { | 17 | +func (dao *OrderBaseDao) OrderStatics(option *domain.OrderStaticQuery) (count int, amount float64, err error) { |
| 17 | tx := dao.transactionContext.PgTx | 18 | tx := dao.transactionContext.PgTx |
| 18 | - order := new(models.Order) | 19 | + order := new(models.OrderBase) |
| 19 | var orderAmount float64 | 20 | var orderAmount float64 |
| 20 | q := tx.Model(order) | 21 | q := tx.Model(order) |
| 21 | q.ColumnExpr("count(*) count") | 22 | q.ColumnExpr("count(*) count") |
| 22 | - q.ColumnExpr("sum(order_actual_amount) total_order_actual_amount") | ||
| 23 | - q.ColumnExpr("sum(order_amount) total_order_amount") | 23 | + //q.ColumnExpr("sum(case when use_order_amount >0 THEN use_order_amount else plan_order_amount END) total_order_actual_amount") |
| 24 | + q.ColumnExpr("sum(plan_order_amount) total_order_actual_amount") | ||
| 25 | + q.ColumnExpr("sum(use_order_amount) total_order_amount") | ||
| 24 | if option.PartnerId > 0 { | 26 | if option.PartnerId > 0 { |
| 25 | - q.Where(`"order".partner_id =?`, option.PartnerId) | 27 | + q.Where(`"order_base".partner_id =?`, option.PartnerId) |
| 26 | } | 28 | } |
| 27 | if option.OrderType > 0 { | 29 | if option.OrderType > 0 { |
| 28 | - q.Where(`"order".order_type =?`, option.OrderType) | ||
| 29 | - } | ||
| 30 | - if option.OrderStatus > 0 { | ||
| 31 | - q.Where(`"order".order_status =?`, option.OrderStatus) | 30 | + q.Where(`"order_base".order_type =?`, option.OrderType) |
| 32 | } | 31 | } |
| 33 | if option.BeginTime > 0 { | 32 | if option.BeginTime > 0 { |
| 34 | - q.Where(`"order".create_at >=?`, time.Unix(option.BeginTime/1000, 0)) | 33 | + q.Where(`"order_base".create_time >=?`, time.Unix(option.BeginTime/1000, 0)) |
| 35 | } | 34 | } |
| 36 | if option.EndTime > 0 { | 35 | if option.EndTime > 0 { |
| 37 | - q.Where(`"order".create_at <?`, time.Unix(option.EndTime/1000, 0)) | 36 | + q.Where(`"order_base".create_time <?`, time.Unix(option.EndTime/1000, 0)) |
| 38 | } | 37 | } |
| 38 | + //q.Where(`"order_base".is_disable =?`, 0) | ||
| 39 | err = q.Select(&count, &amount, &orderAmount) | 39 | err = q.Select(&count, &amount, &orderAmount) |
| 40 | if option.OrderType == domain.OrderIntention { //意向订单值只有 order_amount order_actual_amount还未赋值 | 40 | if option.OrderType == domain.OrderIntention { //意向订单值只有 order_amount order_actual_amount还未赋值 |
| 41 | amount = orderAmount | 41 | amount = orderAmount |
| @@ -44,32 +44,35 @@ func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, a | @@ -44,32 +44,35 @@ func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, a | ||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | //分红订单 | 46 | //分红订单 |
| 47 | -func (dao *OrderDao) DividendOrders(option *domain.DividendOrdersQueryOption) (count int, orders []*models.Order, err error) { | 47 | +func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption) (count int, domainOrders []*domain.OrderBase, err error) { |
| 48 | tx := dao.transactionContext.PgTx | 48 | tx := dao.transactionContext.PgTx |
| 49 | + var orders []*models.OrderBase | ||
| 49 | q := tx.Model(&orders) | 50 | q := tx.Model(&orders) |
| 50 | - q.Column(`order.id`, `order.order_code`, `order.order_actual_amount`, `order.partner_bonus_percent`) | ||
| 51 | - //q.Where(`"order".order_status >=?`, domain.OrderStatusDeliverSome) //已经发货 | 51 | + //q.Column(`order_base.id`, `order_base.order_code`, `order_base.order_actual_amount`, `order_base.partner_bonus_percent`) |
| 52 | if option.OrderType > 0 { | 52 | if option.OrderType > 0 { |
| 53 | - q.Where(`"order".order_type=?`, option.OrderType) | 53 | + q.Where(`"order_base".order_type=?`, option.OrderType) |
| 54 | } | 54 | } |
| 55 | if option.PartnerId > 0 { | 55 | if option.PartnerId > 0 { |
| 56 | - q.Where(`"order".partner_id=?`, option.PartnerId) | 56 | + q.Where(`"order_base".partner_id=?`, option.PartnerId) |
| 57 | } | 57 | } |
| 58 | if option.StartTime > 0 { | 58 | if option.StartTime > 0 { |
| 59 | - q.Where(`"order".create_at >=?`, time.Unix(option.StartTime/1000, 0)) | 59 | + q.Where(`"order_base".create_time >=?`, time.Unix(option.StartTime/1000, 0)) |
| 60 | } | 60 | } |
| 61 | if option.EndTime > 0 { | 61 | if option.EndTime > 0 { |
| 62 | - q.Where(`"order".create_at <?`, time.Unix(option.EndTime/1000, 0)) | 62 | + q.Where(`"order_base".create_time <?`, time.Unix(option.EndTime/1000, 0)) |
| 63 | } | 63 | } |
| 64 | + //if len(option.IsDisable) > 0 { | ||
| 65 | + // value, _ := strconv.Atoi(option.IsDisable) | ||
| 66 | + // q.Where(`"order_base".is_disable =?`, value) | ||
| 67 | + //} | ||
| 64 | if option.DividendAction == 0 { //累计分红 | 68 | if option.DividendAction == 0 { //累计分红 |
| 65 | if option.DetailAction == 0 { //已收明细 | 69 | if option.DetailAction == 0 { //已收明细 |
| 66 | - q.Join(`JOIN order_payment as a ON a.order_id="order".id`) | ||
| 67 | - q.Where(`"a".bonus_status=?`, domain.BonusPaid) | 70 | + q.Where(`"order_base".partner_bonus_has>0`) |
| 68 | } else if option.DetailAction == 1 { //未收明细 //实际金额>已支付金额 | 71 | } else if option.DetailAction == 1 { //未收明细 //实际金额>已支付金额 |
| 69 | - q.Where(`"order".order_actual_amount>"order".order_payment_amount`) | 72 | + q.Where(`"order_base".partner_bonus_not>0`) |
| 70 | } | 73 | } |
| 71 | } else if option.DividendAction == 1 { //分红支出 | 74 | } else if option.DividendAction == 1 { //分红支出 |
| 72 | - q.Where(`"order".order_amount>"order".order_actual_amount`) | 75 | + q.Where(`"order_base".partner_bonus_expense>0`) |
| 73 | } | 76 | } |
| 74 | if option.Limit > 0 { | 77 | if option.Limit > 0 { |
| 75 | q.Limit(option.Limit) | 78 | q.Limit(option.Limit) |
| @@ -78,26 +81,34 @@ func (dao *OrderDao) DividendOrders(option *domain.DividendOrdersQueryOption) (c | @@ -78,26 +81,34 @@ func (dao *OrderDao) DividendOrders(option *domain.DividendOrdersQueryOption) (c | ||
| 78 | q.Offset(option.Offset) | 81 | q.Offset(option.Offset) |
| 79 | } | 82 | } |
| 80 | if len(option.SortByUpdateTime) > 0 { | 83 | if len(option.SortByUpdateTime) > 0 { |
| 81 | - q.Order(fmt.Sprintf("order.id %v", option.SortByUpdateTime)) | 84 | + q.Order(fmt.Sprintf("order_base.id %v", option.SortByUpdateTime)) |
| 82 | } | 85 | } |
| 83 | count, err = q.Distinct().SelectAndCount() | 86 | count, err = q.Distinct().SelectAndCount() |
| 87 | + for i := range orders { | ||
| 88 | + var domainOrder *domain.OrderBase | ||
| 89 | + err = utils.GobModelTransform(&domainOrder, &orders[i]) | ||
| 90 | + if err != nil { | ||
| 91 | + return | ||
| 92 | + } | ||
| 93 | + domainOrders = append(domainOrders, domainOrder) | ||
| 94 | + } | ||
| 84 | return | 95 | return |
| 85 | } | 96 | } |
| 86 | 97 | ||
| 87 | -func (dao *OrderDao) UpdateLastViewTime(id int64, lastViewTime time.Time) (err error) { | 98 | +func (dao *OrderBaseDao) UpdateLastViewTime(id int64, lastViewTime time.Time) (err error) { |
| 88 | tx := dao.transactionContext.PgTx | 99 | tx := dao.transactionContext.PgTx |
| 89 | - order := new(models.Order) | 100 | + order := new(models.OrderBase) |
| 90 | q := tx.Model(order).Set("last_view_time = ?", lastViewTime) | 101 | q := tx.Model(order).Set("last_view_time = ?", lastViewTime) |
| 91 | q.Where("id=?", id) | 102 | q.Where("id=?", id) |
| 92 | _, err = q.Update() | 103 | _, err = q.Update() |
| 93 | return | 104 | return |
| 94 | } | 105 | } |
| 95 | 106 | ||
| 96 | -func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) { | 107 | +func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*OrderBaseDao, error) { |
| 97 | if transactionContext == nil { | 108 | if transactionContext == nil { |
| 98 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 109 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
| 99 | } else { | 110 | } else { |
| 100 | - return &OrderDao{ | 111 | + return &OrderBaseDao{ |
| 101 | transactionContext: transactionContext, | 112 | transactionContext: transactionContext, |
| 102 | }, nil | 113 | }, nil |
| 103 | } | 114 | } |
pkg/infrastructure/im/im.go
0 → 100644
| 1 | +package im | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func init() { | ||
| 9 | + InitImClient(constant.IM_SERVICE_ADDRESS, constant.IM_APP_KEY, constant.IM_APP_SECRET) | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +type RequestParam interface { | ||
| 13 | + Format() map[string]string | ||
| 14 | + GetPath() string | ||
| 15 | + Valid() error | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +//接口 | ||
| 19 | +func CallCreate(v UserCreate) (*UserTokenResult, error) { | ||
| 20 | + var result UserTokenResult | ||
| 21 | + btData, err := DefaultImClient.Call(v) | ||
| 22 | + if err != nil { | ||
| 23 | + return nil, err | ||
| 24 | + } | ||
| 25 | + err = json.Unmarshal(btData, &result) | ||
| 26 | + if err != nil { | ||
| 27 | + return nil, err | ||
| 28 | + } | ||
| 29 | + return &result, nil | ||
| 30 | +} | ||
| 31 | +func CallRefreshToken(v UserRefreshToken) (*UserTokenResult, error) { | ||
| 32 | + var result UserTokenResult | ||
| 33 | + btData, err := DefaultImClient.Call(v) | ||
| 34 | + if err != nil { | ||
| 35 | + return nil, err | ||
| 36 | + } | ||
| 37 | + err = json.Unmarshal(btData, &result) | ||
| 38 | + if err != nil { | ||
| 39 | + return nil, err | ||
| 40 | + } | ||
| 41 | + return &result, nil | ||
| 42 | +} | ||
| 43 | +func CallUpdate(v UserUpdate) (*BaseResp, error) { | ||
| 44 | + var result BaseResp | ||
| 45 | + btData, err := DefaultImClient.Call(v) | ||
| 46 | + if err != nil { | ||
| 47 | + return nil, err | ||
| 48 | + } | ||
| 49 | + err = json.Unmarshal(btData, &result) | ||
| 50 | + if err != nil { | ||
| 51 | + return nil, err | ||
| 52 | + } | ||
| 53 | + return &result, nil | ||
| 54 | +} |
pkg/infrastructure/im/im_test.go
0 → 100644
| 1 | +package im | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" | ||
| 5 | + "testing" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func TestCallCreate(t *testing.T) { | ||
| 9 | + InitImClient(constant.IM_SERVICE_ADDRESS, constant.IM_APP_KEY, constant.IM_APP_SECRET) | ||
| 10 | + token, err := CallCreate(UserCreate{Accid: "1"}) | ||
| 11 | + if err != nil { | ||
| 12 | + t.Fatal(err) | ||
| 13 | + } | ||
| 14 | + if token == nil { | ||
| 15 | + t.Fatal("token is nil") | ||
| 16 | + } | ||
| 17 | + t.Log(token.Code, token.Info) | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func TestCallRefreshToken(t *testing.T) { | ||
| 21 | + InitImClient(constant.IM_SERVICE_ADDRESS, constant.IM_APP_KEY, constant.IM_APP_SECRET) | ||
| 22 | + token, err := CallRefreshToken(UserRefreshToken{Accid: "1"}) | ||
| 23 | + if err != nil { | ||
| 24 | + t.Fatal(err) | ||
| 25 | + } | ||
| 26 | + if token == nil { | ||
| 27 | + t.Fatal("token is nil") | ||
| 28 | + } | ||
| 29 | + t.Log(token.Code, token.Info) | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +func TestCallUpdate(t *testing.T) { | ||
| 33 | + InitImClient(constant.IM_SERVICE_ADDRESS, constant.IM_APP_KEY, constant.IM_APP_SECRET) | ||
| 34 | + token, err := CallUpdate(UserUpdate{Accid: "1", Name: "tip tok"}) | ||
| 35 | + if err != nil { | ||
| 36 | + t.Fatal(err) | ||
| 37 | + } | ||
| 38 | + if token == nil { | ||
| 39 | + t.Fatal("token is nil") | ||
| 40 | + } | ||
| 41 | + t.Log(token.Code) | ||
| 42 | +} |
pkg/infrastructure/im/netease.go
0 → 100644
| 1 | +package im | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "crypto/sha1" | ||
| 5 | + "encoding/hex" | ||
| 6 | + "fmt" | ||
| 7 | + "io/ioutil" | ||
| 8 | + "math/rand" | ||
| 9 | + "net/http" | ||
| 10 | + "net/url" | ||
| 11 | + "strconv" | ||
| 12 | + "strings" | ||
| 13 | + "time" | ||
| 14 | +) | ||
| 15 | + | ||
| 16 | +var DefaultImClient Client | ||
| 17 | + | ||
| 18 | +var ErrorFailCall = fmt.Errorf(" imclient call failed") | ||
| 19 | + | ||
| 20 | +func InitImClient(baseUrl, appKey, appSecret string) { | ||
| 21 | + DefaultImClient = Client{ | ||
| 22 | + baseUrl: baseUrl, | ||
| 23 | + appKey: appKey, | ||
| 24 | + appSecret: appSecret, | ||
| 25 | + } | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +type Client struct { | ||
| 29 | + baseUrl string | ||
| 30 | + appKey string | ||
| 31 | + appSecret string | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +func (i Client) Call(param RequestParam) ([]byte, error) { | ||
| 35 | + return i.httpDo(param.GetPath(), param.Format()) | ||
| 36 | +} | ||
| 37 | +func (i Client) buildHeader() http.Header { | ||
| 38 | + var h = http.Header{} | ||
| 39 | + curTime := strconv.FormatInt(time.Now().Unix(), 10) | ||
| 40 | + nonce := strconv.FormatInt(time.Now().Unix()+rand.Int63n(5000), 10) | ||
| 41 | + checkSum := buildCheckSum(i.appSecret, nonce, curTime) | ||
| 42 | + h.Set("Content-Type", "application/x-www-form-urlencoded") | ||
| 43 | + h.Set("AppKey", i.appKey) | ||
| 44 | + h.Set("Nonce", nonce) | ||
| 45 | + h.Set("CurTime", curTime) | ||
| 46 | + h.Set("CheckSum", checkSum) | ||
| 47 | + return h | ||
| 48 | +} | ||
| 49 | +func (i Client) httpDo(path string, posts map[string]string) ([]byte, error) { | ||
| 50 | + client := http.Client{ | ||
| 51 | + Timeout: 5 * time.Second, //请求超时时间5秒 | ||
| 52 | + } | ||
| 53 | + reqURL := i.baseUrl + path | ||
| 54 | + params := url.Values{} | ||
| 55 | + for k, v := range posts { | ||
| 56 | + params.Add(k, v) | ||
| 57 | + } | ||
| 58 | + req, err := http.NewRequest("POST", reqURL, strings.NewReader(params.Encode())) | ||
| 59 | + if err != nil { | ||
| 60 | + return nil, err | ||
| 61 | + } | ||
| 62 | + req.Header = i.buildHeader() | ||
| 63 | + resp, err := client.Do(req) | ||
| 64 | + if err != nil { | ||
| 65 | + return nil, err | ||
| 66 | + } | ||
| 67 | + defer resp.Body.Close() | ||
| 68 | + | ||
| 69 | + body, err := ioutil.ReadAll(resp.Body) | ||
| 70 | + if err != nil { | ||
| 71 | + return nil, err | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + return body, nil | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +func buildCheckSum(appSecret string, nonce string, curTime string) string { | ||
| 78 | + str := []byte(appSecret + nonce + curTime) | ||
| 79 | + sh := sha1.New() | ||
| 80 | + sh.Write(str) | ||
| 81 | + result := hex.EncodeToString(sh.Sum(nil)) | ||
| 82 | + return strings.ToLower(result) | ||
| 83 | +} |
pkg/infrastructure/im/netease_request.go
0 → 100644
| 1 | +package im | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | +) | ||
| 6 | + | ||
| 7 | +var ( | ||
| 8 | + _ RequestParam = UserCreate{} | ||
| 9 | + _ RequestParam = UserUpdate{} | ||
| 10 | + _ RequestParam = UserRefreshToken{} | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +type BaseResp struct { | ||
| 14 | + Code int `json:"code"` | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +// TokenInfo 云通信Token | ||
| 18 | +type TokenInfo struct { | ||
| 19 | + Token string `json:"token"` | ||
| 20 | + Accid string `json:"accid"` | ||
| 21 | + Name string `json:"name"` | ||
| 22 | +} | ||
| 23 | +type UserTokenResult struct { | ||
| 24 | + BaseResp | ||
| 25 | + Info TokenInfo `json:"info"` | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +// 创建网易云通信ID | ||
| 29 | +type UserCreate struct { | ||
| 30 | + Accid string //网易云通信ID,最大长度32字符 | ||
| 31 | + Name string //ID昵称,最大长度64字符。 | ||
| 32 | + Props string //json属性,开发者可选填,最大长度1024字符 | ||
| 33 | + Icon string //ID头像URL,开发者可选填,最大长度1024字符 | ||
| 34 | + /** | ||
| 35 | + 云通信ID可以指定登录token值,最大长度128字符, | ||
| 36 | + 并更新,如果未指定,会自动生成token,并在 | ||
| 37 | + 创建成功后返回 | ||
| 38 | + **/ | ||
| 39 | + Token string | ||
| 40 | + Sign string //签名 | ||
| 41 | + Email string | ||
| 42 | + Birth string | ||
| 43 | + Mobile string | ||
| 44 | + Gender int //0未知,1男,2女 | ||
| 45 | + Ex string //扩展字段 | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +func (p UserCreate) Format() map[string]string { | ||
| 49 | + return map[string]string{ | ||
| 50 | + "accid": p.Accid, | ||
| 51 | + "name": p.Name, | ||
| 52 | + "props": p.Props, | ||
| 53 | + "icon": p.Icon, | ||
| 54 | + "token": p.Token, | ||
| 55 | + "sign": p.Sign, | ||
| 56 | + "email": p.Email, | ||
| 57 | + "birth": p.Birth, | ||
| 58 | + "mobile": p.Mobile, | ||
| 59 | + "gender": fmt.Sprintf("%d", p.Gender), | ||
| 60 | + "ex": p.Ex, | ||
| 61 | + } | ||
| 62 | +} | ||
| 63 | +func (p UserCreate) GetPath() string { | ||
| 64 | + return "/user/create.action" | ||
| 65 | +} | ||
| 66 | +func (p UserCreate) Valid() error { | ||
| 67 | + return nil | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +// 重置网易云通信token | ||
| 71 | +type UserRefreshToken struct { | ||
| 72 | + Accid string //网易云通信ID,最大长度32字符,必须保证一个 APP内唯一 | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +func (p UserRefreshToken) Format() map[string]string { | ||
| 76 | + return map[string]string{ | ||
| 77 | + "accid": p.Accid, | ||
| 78 | + } | ||
| 79 | +} | ||
| 80 | +func (p UserRefreshToken) GetPath() string { | ||
| 81 | + return "/user/refreshToken.action" | ||
| 82 | +} | ||
| 83 | +func (p UserRefreshToken) Valid() error { | ||
| 84 | + return nil | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +// 更新网易云通信token | ||
| 88 | +type UserUpdate struct { | ||
| 89 | + Accid string | ||
| 90 | + Name string //这边网易云要有昵称以手机号码为昵称 | ||
| 91 | + Icon string //icon默认头像 | ||
| 92 | + Sign string //签名 | ||
| 93 | + Email string | ||
| 94 | + Birth string | ||
| 95 | + Mobile string | ||
| 96 | + Gender int //0未知,1男,2女 | ||
| 97 | + Ex string //扩展字段 | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +func (u UserUpdate) Format() map[string]string { | ||
| 101 | + return map[string]string{ | ||
| 102 | + "accid": u.Accid, | ||
| 103 | + "name": u.Name, | ||
| 104 | + "icon": u.Icon, | ||
| 105 | + "sign": u.Sign, | ||
| 106 | + "email": u.Email, | ||
| 107 | + "birth": u.Birth, | ||
| 108 | + "mobile": u.Mobile, | ||
| 109 | + "gender": fmt.Sprintf("%d", u.Gender), | ||
| 110 | + "ex": u.Ex, | ||
| 111 | + } | ||
| 112 | +} | ||
| 113 | +func (u UserUpdate) GetPath() string { | ||
| 114 | + return "/user/refreshToken.action" | ||
| 115 | +} | ||
| 116 | +func (u UserUpdate) Valid() error { | ||
| 117 | + return nil | ||
| 118 | +} |
| @@ -22,6 +22,7 @@ func init() { | @@ -22,6 +22,7 @@ func init() { | ||
| 22 | if !constant.DISABLE_SQL_GENERATE_PRINT { | 22 | if !constant.DISABLE_SQL_GENERATE_PRINT { |
| 23 | DB.AddQueryHook(SqlGeneratePrintHook{}) | 23 | DB.AddQueryHook(SqlGeneratePrintHook{}) |
| 24 | } | 24 | } |
| 25 | + //orm.RegisterTable((*models.OrderGood)(nil)) | ||
| 25 | if !constant.DISABLE_CREATE_TABLE { | 26 | if !constant.DISABLE_CREATE_TABLE { |
| 26 | for _, model := range []interface{}{ | 27 | for _, model := range []interface{}{ |
| 27 | //(*models.Employee)(nil), | 28 | //(*models.Employee)(nil), |
| @@ -30,6 +31,10 @@ func init() { | @@ -30,6 +31,10 @@ func init() { | ||
| 30 | (*models.OrderPayment)(nil), | 31 | (*models.OrderPayment)(nil), |
| 31 | (*models.PartnerSubAccount)(nil), | 32 | (*models.PartnerSubAccount)(nil), |
| 32 | (*models.Company)(nil), | 33 | (*models.Company)(nil), |
| 34 | + (*models.OrderBase)(nil), | ||
| 35 | + (*models.OrderGood)(nil), | ||
| 36 | + (*models.ImInfo)(nil), | ||
| 37 | + (*models.ImCustomerService)(nil), | ||
| 33 | } { | 38 | } { |
| 34 | err := DB.CreateTable(model, &orm.CreateTableOptions{ | 39 | err := DB.CreateTable(model, &orm.CreateTableOptions{ |
| 35 | Temp: false, | 40 | Temp: false, |
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +type ImCustomerService struct { | ||
| 6 | + tableName struct{} `pg:"im_customer_service"` | ||
| 7 | + // id | ||
| 8 | + Id int64 | ||
| 9 | + // 用户id(合伙人Id) | ||
| 10 | + UserId int64 | ||
| 11 | + // IM唯一id | ||
| 12 | + ImId string | ||
| 13 | + // IM颁发的token | ||
| 14 | + ImToken string | ||
| 15 | + // 创建时间 | ||
| 16 | + CreateTime time.Time | ||
| 17 | + // 更新时间 | ||
| 18 | + UpdateTime time.Time | ||
| 19 | +} |
pkg/infrastructure/pg/models/im_info.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +type ImInfo struct { | ||
| 6 | + tableName struct{} `pg:"im_info"` | ||
| 7 | + // id | ||
| 8 | + Id int64 | ||
| 9 | + // 合伙人Id | ||
| 10 | + UserId int64 | ||
| 11 | + // IM唯一id | ||
| 12 | + ImId string | ||
| 13 | + // IM颁发的token | ||
| 14 | + ImToken string | ||
| 15 | + // 客服IM编号 | ||
| 16 | + CustomerImId int64 | ||
| 17 | + // 是否是客服 true:是 false:否 | ||
| 18 | + //IsCustomer bool | ||
| 19 | + // 创建时间 | ||
| 20 | + CreateTime time.Time | ||
| 21 | + // 更新时间 | ||
| 22 | + UpdateTime time.Time | ||
| 23 | +} |
pkg/infrastructure/pg/models/order_base.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
| 5 | + "time" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +//OrderBase 订单基础 | ||
| 9 | +type OrderBase struct { | ||
| 10 | + tableName struct{} `pg:"order_base"` | ||
| 11 | + //表id | ||
| 12 | + Id int64 `pg:",pk"` | ||
| 13 | + //订单类型 1:实际订单 2:意向订单 | ||
| 14 | + OrderType int `pg:",notnull,default:1"` | ||
| 15 | + //订单编号 | ||
| 16 | + OrderCode string | ||
| 17 | + //交货编号 | ||
| 18 | + DeliveryCode string | ||
| 19 | + //买家 | ||
| 20 | + Buyer *domain.Buyer | ||
| 21 | + //订单区域信息 | ||
| 22 | + RegionInfo *domain.RegionInfo | ||
| 23 | + //订单对应的合伙人 | ||
| 24 | + PartnerId int64 | ||
| 25 | + //业务员抽成比例 | ||
| 26 | + SalesmanBonusPercent float64 | ||
| 27 | + //业务员抽成 | ||
| 28 | + SalesmanBonus float64 | ||
| 29 | + //预计的订单内货品总数 | ||
| 30 | + PlanOrderCount int | ||
| 31 | + //预计的订单的总金额 | ||
| 32 | + PlanOrderAmount float64 | ||
| 33 | + //按需使用的订单内货品总数 (初始值=-1) | ||
| 34 | + UseOrderCount int | ||
| 35 | + //按需使用的订单内货总金额 (初始值=-1) | ||
| 36 | + UseOrderAmount float64 | ||
| 37 | + //订单的创建时间 | ||
| 38 | + CreateTime time.Time | ||
| 39 | + //发货时间 | ||
| 40 | + DeliveryTime time.Time | ||
| 41 | + //更新时间 | ||
| 42 | + UpdateTime time.Time | ||
| 43 | + //上一次查看时间 已读情况 | ||
| 44 | + LastViewTime time.Time | ||
| 45 | + //合伙人应收分红 | ||
| 46 | + PlanPartnerBonus float64 | ||
| 47 | + //调整后的合伙人应收分红 (初始值=-1) | ||
| 48 | + UsePartnerBonus float64 | ||
| 49 | + //合伙人已收分红 | ||
| 50 | + PartnerBonusHas float64 | ||
| 51 | + //合伙人未收分红 | ||
| 52 | + PartnerBonusNot float64 | ||
| 53 | + //合伙人分红支出 | ||
| 54 | + PartnerBonusExpense float64 | ||
| 55 | + //是否关闭【0;否】【1:是】 | ||
| 56 | + IsDisable int8 | ||
| 57 | + //1:待支付分红 2:已支付分红 | ||
| 58 | + BonusStatus int8 | ||
| 59 | + //货物列表 | ||
| 60 | + OrderGood []*OrderGood `pg:"fk:order_id"` | ||
| 61 | +} |
pkg/infrastructure/pg/models/order_good.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +//OrderGood 订单中的货品 | ||
| 4 | +type OrderGood struct { | ||
| 5 | + tableName struct{} `pg:"order_good"` | ||
| 6 | + //货品id | ||
| 7 | + Id int64 `pg:",pk"` | ||
| 8 | + //所属订单id | ||
| 9 | + OrderId int64 | ||
| 10 | + //货品名称 长度可能较长 | ||
| 11 | + GoodName string | ||
| 12 | + //预计的货品数量 | ||
| 13 | + PlanGoodNumber int | ||
| 14 | + //货品单价 | ||
| 15 | + Price float64 | ||
| 16 | + //预计的货品总额 | ||
| 17 | + PlanAmount float64 | ||
| 18 | + //调整后的货品数量 | ||
| 19 | + UseGoodNumber int | ||
| 20 | + //调整后的货品总额 | ||
| 21 | + UseAmount float64 | ||
| 22 | + //合伙人分红比例 | ||
| 23 | + PartnerBonusPercent float64 | ||
| 24 | + //预计的合伙人分红 | ||
| 25 | + PlanPartnerBonus float64 | ||
| 26 | + //合伙人应收分红调整 (初始值=-1) | ||
| 27 | + UsePartnerBonus float64 | ||
| 28 | + //合伙人已收分红 | ||
| 29 | + PartnerBonusHas float64 | ||
| 30 | + //合伙人未收分红 | ||
| 31 | + PartnerBonusNot float64 | ||
| 32 | + //合伙人分红支出 | ||
| 33 | + PartnerBonusExpense float64 | ||
| 34 | + //分红状态 | ||
| 35 | + BonusStatus int | ||
| 36 | + //备注信息 | ||
| 37 | + Remark string | ||
| 38 | +} |
| @@ -4,12 +4,13 @@ import ( | @@ -4,12 +4,13 @@ import ( | ||
| 4 | "fmt" | 4 | "fmt" |
| 5 | "github.com/tiptok/gocomm/pkg/redis" | 5 | "github.com/tiptok/gocomm/pkg/redis" |
| 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" |
| 7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" | ||
| 7 | ) | 8 | ) |
| 8 | 9 | ||
| 9 | func init() { | 10 | func init() { |
| 10 | redisSource := fmt.Sprintf("%v:%v", constant.REDIS_HOST, constant.REDIS_PORT) | 11 | redisSource := fmt.Sprintf("%v:%v", constant.REDIS_HOST, constant.REDIS_PORT) |
| 11 | err := redis.InitWithDb(100, redisSource, constant.REDIS_AUTH, "0") | 12 | err := redis.InitWithDb(100, redisSource, constant.REDIS_AUTH, "0") |
| 12 | if err != nil { | 13 | if err != nil { |
| 13 | - panic(err) | 14 | + log.Error(err) |
| 14 | } | 15 | } |
| 15 | } | 16 | } |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
| 7 | + . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +type ImCustomerServiceRepository struct { | ||
| 11 | + transactionContext *transaction.TransactionContext | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +func (repository *ImCustomerServiceRepository) Save(dm *domain.ImCustomerService) (*domain.ImCustomerService, error) { | ||
| 15 | + var ( | ||
| 16 | + err error | ||
| 17 | + m = &models.ImCustomerService{} | ||
| 18 | + tx = repository.transactionContext.PgTx | ||
| 19 | + ) | ||
| 20 | + if err = GobModelTransform(m, dm); err != nil { | ||
| 21 | + return nil, err | ||
| 22 | + } | ||
| 23 | + if dm.Identify() == nil { | ||
| 24 | + if err = tx.Insert(m); err != nil { | ||
| 25 | + return nil, err | ||
| 26 | + } | ||
| 27 | + return dm, nil | ||
| 28 | + } | ||
| 29 | + if err = tx.Update(m); err != nil { | ||
| 30 | + return nil, err | ||
| 31 | + } | ||
| 32 | + return dm, nil | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +func (repository *ImCustomerServiceRepository) Remove(ImCustomerService *domain.ImCustomerService) (*domain.ImCustomerService, error) { | ||
| 36 | + var ( | ||
| 37 | + tx = repository.transactionContext.PgTx | ||
| 38 | + ImCustomerServiceModel = &models.ImCustomerService{Id: ImCustomerService.Identify().(int64)} | ||
| 39 | + ) | ||
| 40 | + if _, err := tx.Model(ImCustomerServiceModel).Where("id = ?", ImCustomerService.Id).Delete(); err != nil { | ||
| 41 | + return ImCustomerService, err | ||
| 42 | + } | ||
| 43 | + return ImCustomerService, nil | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +func (repository *ImCustomerServiceRepository) FindOne(queryOptions map[string]interface{}) (*domain.ImCustomerService, error) { | ||
| 47 | + tx := repository.transactionContext.PgTx | ||
| 48 | + ImCustomerServiceModel := new(models.ImCustomerService) | ||
| 49 | + query := NewQuery(tx.Model(ImCustomerServiceModel), queryOptions) | ||
| 50 | + query.SetWhere("id = ?", "id") | ||
| 51 | + query.SetWhere("user_id = ?", "user_id") | ||
| 52 | + if err := query.First(); err != nil { | ||
| 53 | + return nil, domain.QueryNoRow | ||
| 54 | + } | ||
| 55 | + if ImCustomerServiceModel.Id == 0 { | ||
| 56 | + return nil, domain.QueryNoRow | ||
| 57 | + } | ||
| 58 | + return repository.transformPgModelToDomainModel(ImCustomerServiceModel) | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | +func (repository *ImCustomerServiceRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ImCustomerService, error) { | ||
| 62 | + tx := repository.transactionContext.PgTx | ||
| 63 | + var ImCustomerServiceModels []*models.ImCustomerService | ||
| 64 | + ImCustomerServices := make([]*domain.ImCustomerService, 0) | ||
| 65 | + query := NewQuery(tx.Model(&ImCustomerServiceModels), queryOptions). | ||
| 66 | + SetOrder("create_time", "sortByCreateTime"). | ||
| 67 | + SetOrder("update_time", "sortByUpdateTime"). | ||
| 68 | + SetOrder("id", "sortById") | ||
| 69 | + var err error | ||
| 70 | + if query.AffectRow, err = query.SelectAndCount(); err != nil { | ||
| 71 | + return 0, ImCustomerServices, err | ||
| 72 | + } | ||
| 73 | + for _, ImCustomerServiceModel := range ImCustomerServiceModels { | ||
| 74 | + if ImCustomerService, err := repository.transformPgModelToDomainModel(ImCustomerServiceModel); err != nil { | ||
| 75 | + return 0, ImCustomerServices, err | ||
| 76 | + } else { | ||
| 77 | + ImCustomerServices = append(ImCustomerServices, ImCustomerService) | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + return int64(query.AffectRow), ImCustomerServices, nil | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +func (repository *ImCustomerServiceRepository) transformPgModelToDomainModel(ImCustomerServiceModel *models.ImCustomerService) (*domain.ImCustomerService, error) { | ||
| 84 | + m := &domain.ImCustomerService{} | ||
| 85 | + err := GobModelTransform(m, ImCustomerServiceModel) | ||
| 86 | + return m, err | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +func NewImCustomerServiceRepository(transactionContext *transaction.TransactionContext) (*ImCustomerServiceRepository, error) { | ||
| 90 | + if transactionContext == nil { | ||
| 91 | + return nil, ERR_EMPTY_TC | ||
| 92 | + } | ||
| 93 | + return &ImCustomerServiceRepository{transactionContext: transactionContext}, nil | ||
| 94 | +} |
| @@ -7,24 +7,20 @@ import ( | @@ -7,24 +7,20 @@ import ( | ||
| 7 | . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | 7 | . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
| 8 | ) | 8 | ) |
| 9 | 9 | ||
| 10 | -type OrderPaymentRepository struct { | 10 | +type ImInfoRepository struct { |
| 11 | transactionContext *transaction.TransactionContext | 11 | transactionContext *transaction.TransactionContext |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | -func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain.OrderPayment, error) { | 14 | +func (repository *ImInfoRepository) Save(dm *domain.ImInfo) (*domain.ImInfo, error) { |
| 15 | var ( | 15 | var ( |
| 16 | err error | 16 | err error |
| 17 | - m = &models.OrderPayment{} | 17 | + m = &models.ImInfo{} |
| 18 | tx = repository.transactionContext.PgTx | 18 | tx = repository.transactionContext.PgTx |
| 19 | ) | 19 | ) |
| 20 | if err = GobModelTransform(m, dm); err != nil { | 20 | if err = GobModelTransform(m, dm); err != nil { |
| 21 | return nil, err | 21 | return nil, err |
| 22 | } | 22 | } |
| 23 | if dm.Identify() == nil { | 23 | if dm.Identify() == nil { |
| 24 | - if dm.Id, err = NewSnowflakeId(); err != nil { | ||
| 25 | - return dm, err | ||
| 26 | - } | ||
| 27 | - m.Id = dm.Id | ||
| 28 | if err = tx.Insert(m); err != nil { | 24 | if err = tx.Insert(m); err != nil { |
| 29 | return nil, err | 25 | return nil, err |
| 30 | } | 26 | } |
| @@ -36,68 +32,62 @@ func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain | @@ -36,68 +32,62 @@ func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain | ||
| 36 | return dm, nil | 32 | return dm, nil |
| 37 | } | 33 | } |
| 38 | 34 | ||
| 39 | -func (repository *OrderPaymentRepository) Remove(OrderPayment *domain.OrderPayment) (*domain.OrderPayment, error) { | 35 | +func (repository *ImInfoRepository) Remove(ImInfo *domain.ImInfo) (*domain.ImInfo, error) { |
| 40 | var ( | 36 | var ( |
| 41 | tx = repository.transactionContext.PgTx | 37 | tx = repository.transactionContext.PgTx |
| 42 | - OrderPaymentModel = &models.OrderPayment{Id: OrderPayment.Identify().(int64)} | 38 | + ImInfoModel = &models.ImInfo{Id: ImInfo.Identify().(int64)} |
| 43 | ) | 39 | ) |
| 44 | - if _, err := tx.Model(OrderPaymentModel).Where("id = ?", OrderPayment.Id).Delete(); err != nil { | ||
| 45 | - return OrderPayment, err | 40 | + if _, err := tx.Model(ImInfoModel).Where("id = ?", ImInfo.Id).Delete(); err != nil { |
| 41 | + return ImInfo, err | ||
| 46 | } | 42 | } |
| 47 | - return OrderPayment, nil | 43 | + return ImInfo, nil |
| 48 | } | 44 | } |
| 49 | 45 | ||
| 50 | -func (repository *OrderPaymentRepository) FindOne(queryOptions map[string]interface{}) (*domain.OrderPayment, error) { | 46 | +func (repository *ImInfoRepository) FindOne(queryOptions map[string]interface{}) (*domain.ImInfo, error) { |
| 51 | tx := repository.transactionContext.PgTx | 47 | tx := repository.transactionContext.PgTx |
| 52 | - OrderPaymentModel := new(models.OrderPayment) | ||
| 53 | - query := NewQuery(tx.Model(OrderPaymentModel), queryOptions) | ||
| 54 | - query.SetWhere("order_payment.id = ?", "id") | ||
| 55 | - query.SetWhere("order_payment.order_id = ?", "orderId") | 48 | + ImInfoModel := new(models.ImInfo) |
| 49 | + query := NewQuery(tx.Model(ImInfoModel), queryOptions) | ||
| 50 | + query.SetWhere("id = ?", "id") | ||
| 51 | + query.SetWhere("user_id = ?", "user_id") | ||
| 56 | if err := query.First(); err != nil { | 52 | if err := query.First(); err != nil { |
| 57 | - return nil, query.HandleError(err, "没有此订单") | 53 | + return nil, domain.QueryNoRow |
| 58 | } | 54 | } |
| 59 | - if OrderPaymentModel.Id == 0 { | ||
| 60 | - return nil, nil | 55 | + if ImInfoModel.Id == 0 { |
| 56 | + return nil, domain.QueryNoRow | ||
| 61 | } | 57 | } |
| 62 | - return repository.transformPgModelToDomainModel(OrderPaymentModel) | 58 | + return repository.transformPgModelToDomainModel(ImInfoModel) |
| 63 | } | 59 | } |
| 64 | 60 | ||
| 65 | -func (repository *OrderPaymentRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.OrderPayment, error) { | 61 | +func (repository *ImInfoRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ImInfo, error) { |
| 66 | tx := repository.transactionContext.PgTx | 62 | tx := repository.transactionContext.PgTx |
| 67 | - var OrderPaymentModels []*models.OrderPayment | ||
| 68 | - OrderPayments := make([]*domain.OrderPayment, 0) | ||
| 69 | - query := NewQuery(tx.Model(&OrderPaymentModels), queryOptions) | ||
| 70 | - query. | ||
| 71 | - SetWhere("order_payment.partner_id = ?", "partnerId"). | ||
| 72 | - SetWhere("order_payment.order_id = ?", "orderId"). | ||
| 73 | - SetWhere(`order_payment.create_at >= ?`, "beginTime"). | ||
| 74 | - SetWhere(`order_payment.create_at < ?`, "endTime"). | ||
| 75 | - SetLimit(). | ||
| 76 | - SetOrder("order_payment.create_at", "sortByCreateTime"). | ||
| 77 | - SetOrder("order_payment.update_at", "sortByUpdateTime") | 63 | + var ImInfoModels []*models.ImInfo |
| 64 | + ImInfos := make([]*domain.ImInfo, 0) | ||
| 65 | + query := NewQuery(tx.Model(&ImInfoModels), queryOptions). | ||
| 66 | + SetOrder("im_info.create_time", "sortByCreateTime"). | ||
| 67 | + SetOrder("im_info.update_time", "sortByUpdateTime") | ||
| 78 | var err error | 68 | var err error |
| 79 | if query.AffectRow, err = query.SelectAndCount(); err != nil { | 69 | if query.AffectRow, err = query.SelectAndCount(); err != nil { |
| 80 | - return 0, OrderPayments, err | 70 | + return 0, ImInfos, err |
| 81 | } | 71 | } |
| 82 | - for _, OrderPaymentModel := range OrderPaymentModels { | ||
| 83 | - if OrderPayment, err := repository.transformPgModelToDomainModel(OrderPaymentModel); err != nil { | ||
| 84 | - return 0, OrderPayments, err | 72 | + for _, ImInfoModel := range ImInfoModels { |
| 73 | + if ImInfo, err := repository.transformPgModelToDomainModel(ImInfoModel); err != nil { | ||
| 74 | + return 0, ImInfos, err | ||
| 85 | } else { | 75 | } else { |
| 86 | - OrderPayments = append(OrderPayments, OrderPayment) | 76 | + ImInfos = append(ImInfos, ImInfo) |
| 87 | } | 77 | } |
| 88 | } | 78 | } |
| 89 | - return int64(query.AffectRow), OrderPayments, nil | 79 | + return int64(query.AffectRow), ImInfos, nil |
| 90 | } | 80 | } |
| 91 | 81 | ||
| 92 | -func (repository *OrderPaymentRepository) transformPgModelToDomainModel(OrderPaymentModel *models.OrderPayment) (*domain.OrderPayment, error) { | ||
| 93 | - m := &domain.OrderPayment{} | ||
| 94 | - err := GobModelTransform(m, OrderPaymentModel) | 82 | +func (repository *ImInfoRepository) transformPgModelToDomainModel(ImInfoModel *models.ImInfo) (*domain.ImInfo, error) { |
| 83 | + m := &domain.ImInfo{} | ||
| 84 | + err := GobModelTransform(m, ImInfoModel) | ||
| 95 | return m, err | 85 | return m, err |
| 96 | } | 86 | } |
| 97 | 87 | ||
| 98 | -func NewOrderPaymentRepository(transactionContext *transaction.TransactionContext) (*OrderPaymentRepository, error) { | 88 | +func NewImInfoRepository(transactionContext *transaction.TransactionContext) (*ImInfoRepository, error) { |
| 99 | if transactionContext == nil { | 89 | if transactionContext == nil { |
| 100 | return nil, ERR_EMPTY_TC | 90 | return nil, ERR_EMPTY_TC |
| 101 | } | 91 | } |
| 102 | - return &OrderPaymentRepository{transactionContext: transactionContext}, nil | 92 | + return &ImInfoRepository{transactionContext: transactionContext}, nil |
| 103 | } | 93 | } |
| 1 | +package repository | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10/orm" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | ||
| 7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
| 8 | + . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type OrderBaseRepository struct { | ||
| 12 | + transactionContext *transaction.TransactionContext | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +func (repository *OrderBaseRepository) Save(dm *domain.OrderBase) (*domain.OrderBase, error) { | ||
| 16 | + var ( | ||
| 17 | + err error | ||
| 18 | + m = &models.OrderBase{} | ||
| 19 | + tx = repository.transactionContext.PgTx | ||
| 20 | + ) | ||
| 21 | + if err = GobModelTransform(m, dm); err != nil { | ||
| 22 | + return nil, err | ||
| 23 | + } | ||
| 24 | + if dm.Identify() == nil { | ||
| 25 | + //if dm.Id, err = NewSnowflakeId(); err != nil { | ||
| 26 | + // return dm, err | ||
| 27 | + //} | ||
| 28 | + //m.Id = dm.Id | ||
| 29 | + if err = tx.Insert(m); err != nil { | ||
| 30 | + return nil, err | ||
| 31 | + } | ||
| 32 | + return dm, nil | ||
| 33 | + } | ||
| 34 | + if err = tx.Update(m); err != nil { | ||
| 35 | + return nil, err | ||
| 36 | + } | ||
| 37 | + return dm, nil | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +func (repository *OrderBaseRepository) Remove(OrderBase *domain.OrderBase) (*domain.OrderBase, error) { | ||
| 41 | + var ( | ||
| 42 | + tx = repository.transactionContext.PgTx | ||
| 43 | + OrderBaseModel = &models.OrderBase{Id: OrderBase.Identify().(int64)} | ||
| 44 | + ) | ||
| 45 | + if _, err := tx.Model(OrderBaseModel).Where("id = ?", OrderBase.Id).Delete(); err != nil { | ||
| 46 | + return OrderBase, err | ||
| 47 | + } | ||
| 48 | + return OrderBase, nil | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +func (repository *OrderBaseRepository) FindOne(queryOptions map[string]interface{}) (*domain.OrderBase, error) { | ||
| 52 | + tx := repository.transactionContext.PgTx | ||
| 53 | + OrderBaseModel := new(models.OrderBase) | ||
| 54 | + query := NewQuery(tx.Model(OrderBaseModel), queryOptions) | ||
| 55 | + query.ColumnExpr("order_base.*") | ||
| 56 | + query.Relation("OrderGood", func(q *orm.Query) (*orm.Query, error) { | ||
| 57 | + q.ColumnExpr("order_good.*") | ||
| 58 | + q.Order("id") | ||
| 59 | + return q, nil | ||
| 60 | + }) | ||
| 61 | + query.SetWhere(`"order_base".id = ?`, "id") | ||
| 62 | + query.SetWhere(`"order_base".order_code = ?`, "order_code") | ||
| 63 | + | ||
| 64 | + if err := query.First(); err != nil { | ||
| 65 | + return nil, query.HandleError(err, "没有此订单") | ||
| 66 | + } | ||
| 67 | + if OrderBaseModel.Id == 0 { | ||
| 68 | + return nil, nil | ||
| 69 | + } | ||
| 70 | + return repository.transformPgModelToDomainModel(OrderBaseModel) | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +func (repository *OrderBaseRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.OrderBase, error) { | ||
| 74 | + tx := repository.transactionContext.PgTx | ||
| 75 | + var OrderBaseModels []*models.OrderBase | ||
| 76 | + OrderBases := make([]*domain.OrderBase, 0) | ||
| 77 | + query := NewQuery(tx.Model(&OrderBaseModels), queryOptions) | ||
| 78 | + query. | ||
| 79 | + SetWhere(`"order_base".partner_id= ?`, "partnerId"). | ||
| 80 | + SetWhere(`"order_base".order_type= ?`, "orderType"). | ||
| 81 | + SetWhere(`"order_base".create_time >= ?`, "beginTime"). | ||
| 82 | + SetWhere(`"order_base".create_time < ?`, "endTime"). | ||
| 83 | + //SetWhere(`"order_base".is_disable = ?`, "isDisable"). | ||
| 84 | + SetLimit(). | ||
| 85 | + SetOrder(`order_base.create_time`, "sortByCreateTime"). | ||
| 86 | + SetOrder(`order_base.update_time`, "sortByUpdateTime") | ||
| 87 | + var err error | ||
| 88 | + if query.AffectRow, err = query.SelectAndCount(); err != nil { | ||
| 89 | + return 0, OrderBases, err | ||
| 90 | + } | ||
| 91 | + for _, OrderBaseModel := range OrderBaseModels { | ||
| 92 | + if OrderBase, err := repository.transformPgModelToDomainModel(OrderBaseModel); err != nil { | ||
| 93 | + return 0, OrderBases, err | ||
| 94 | + } else { | ||
| 95 | + OrderBases = append(OrderBases, OrderBase) | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | + return int64(query.AffectRow), OrderBases, nil | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +func (repository *OrderBaseRepository) transformPgModelToDomainModel(OrderBaseModel *models.OrderBase) (*domain.OrderBase, error) { | ||
| 102 | + m := &domain.OrderBase{} | ||
| 103 | + err := GobModelTransform(m, OrderBaseModel) | ||
| 104 | + return m, err | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +func NewOrderBaseRepository(transactionContext *transaction.TransactionContext) (*OrderBaseRepository, error) { | ||
| 108 | + if transactionContext == nil { | ||
| 109 | + return nil, ERR_EMPTY_TC | ||
| 110 | + } | ||
| 111 | + return &OrderBaseRepository{transactionContext: transactionContext}, nil | ||
| 112 | +} |
| @@ -7,14 +7,14 @@ import ( | @@ -7,14 +7,14 @@ import ( | ||
| 7 | . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | 7 | . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
| 8 | ) | 8 | ) |
| 9 | 9 | ||
| 10 | -type OrderRepository struct { | 10 | +type OrderGoodRepository struct { |
| 11 | transactionContext *transaction.TransactionContext | 11 | transactionContext *transaction.TransactionContext |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | -func (repository *OrderRepository) Save(dm *domain.Order) (*domain.Order, error) { | 14 | +func (repository *OrderGoodRepository) Save(dm *domain.OrderGood) (*domain.OrderGood, error) { |
| 15 | var ( | 15 | var ( |
| 16 | err error | 16 | err error |
| 17 | - m = &models.Order{} | 17 | + m = &models.OrderGood{} |
| 18 | tx = repository.transactionContext.PgTx | 18 | tx = repository.transactionContext.PgTx |
| 19 | ) | 19 | ) |
| 20 | if err = GobModelTransform(m, dm); err != nil { | 20 | if err = GobModelTransform(m, dm); err != nil { |
| @@ -36,69 +36,66 @@ func (repository *OrderRepository) Save(dm *domain.Order) (*domain.Order, error) | @@ -36,69 +36,66 @@ func (repository *OrderRepository) Save(dm *domain.Order) (*domain.Order, error) | ||
| 36 | return dm, nil | 36 | return dm, nil |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | -func (repository *OrderRepository) Remove(Order *domain.Order) (*domain.Order, error) { | 39 | +func (repository *OrderGoodRepository) Remove(OrderGood *domain.OrderGood) (*domain.OrderGood, error) { |
| 40 | var ( | 40 | var ( |
| 41 | tx = repository.transactionContext.PgTx | 41 | tx = repository.transactionContext.PgTx |
| 42 | - OrderModel = &models.Order{Id: Order.Identify().(int64)} | 42 | + OrderGoodModel = &models.OrderGood{Id: OrderGood.Identify().(int64)} |
| 43 | ) | 43 | ) |
| 44 | - if _, err := tx.Model(OrderModel).Where("id = ?", Order.Id).Delete(); err != nil { | ||
| 45 | - return Order, err | 44 | + if _, err := tx.Model(OrderGoodModel).Where("id = ?", OrderGood.Id).Delete(); err != nil { |
| 45 | + return OrderGood, err | ||
| 46 | } | 46 | } |
| 47 | - return Order, nil | 47 | + return OrderGood, nil |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | -func (repository *OrderRepository) FindOne(queryOptions map[string]interface{}) (*domain.Order, error) { | 50 | +func (repository *OrderGoodRepository) FindOne(queryOptions map[string]interface{}) (*domain.OrderGood, error) { |
| 51 | tx := repository.transactionContext.PgTx | 51 | tx := repository.transactionContext.PgTx |
| 52 | - OrderModel := new(models.Order) | ||
| 53 | - query := NewQuery(tx.Model(OrderModel), queryOptions) | ||
| 54 | - query.SetWhere(`"order".id = ?`, "id") | ||
| 55 | - query.SetWhere(`"order".order_code = ?`, "orderCode") | 52 | + OrderGoodModel := new(models.OrderGood) |
| 53 | + query := NewQuery(tx.Model(OrderGoodModel), queryOptions) | ||
| 54 | + query.SetWhere(`id = ?`, "id") | ||
| 56 | if err := query.First(); err != nil { | 55 | if err := query.First(); err != nil { |
| 57 | return nil, query.HandleError(err, "没有此订单") | 56 | return nil, query.HandleError(err, "没有此订单") |
| 58 | } | 57 | } |
| 59 | - if OrderModel.Id == 0 { | 58 | + if OrderGoodModel.Id == 0 { |
| 60 | return nil, nil | 59 | return nil, nil |
| 61 | } | 60 | } |
| 62 | - return repository.transformPgModelToDomainModel(OrderModel) | 61 | + return repository.transformPgModelToDomainModel(OrderGoodModel) |
| 63 | } | 62 | } |
| 64 | 63 | ||
| 65 | -func (repository *OrderRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Order, error) { | 64 | +func (repository *OrderGoodRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.OrderGood, error) { |
| 66 | tx := repository.transactionContext.PgTx | 65 | tx := repository.transactionContext.PgTx |
| 67 | - var OrderModels []*models.Order | ||
| 68 | - Orders := make([]*domain.Order, 0) | ||
| 69 | - query := NewQuery(tx.Model(&OrderModels), queryOptions) | 66 | + var OrderGoodModels []*models.OrderGood |
| 67 | + OrderGoods := make([]*domain.OrderGood, 0) | ||
| 68 | + query := NewQuery(tx.Model(&OrderGoodModels), queryOptions) | ||
| 70 | query. | 69 | query. |
| 71 | - SetWhere(`"order".partner_id= ?`, "partnerId"). | ||
| 72 | - SetWhere(`"order".order_type= ?`, "orderType"). | ||
| 73 | - SetWhere(`"order".order_status= ?`, "orderStatus"). | ||
| 74 | - SetWhere(`"order".create_at >= ?`, "beginTime"). | ||
| 75 | - SetWhere(`"order".create_at < ?`, "endTime"). | 70 | + SetWhere(`partner_id= ?`, "partnerId"). |
| 71 | + SetWhere(`create_at >= ?`, "beginTime"). | ||
| 72 | + SetWhere(`create_at < ?`, "endTime"). | ||
| 76 | SetLimit(). | 73 | SetLimit(). |
| 77 | - SetOrder(`order.create_at`, "sortByCreateTime"). | ||
| 78 | - SetOrder(`order.update_at`, "sortByUpdateTime") | 74 | + SetOrder(`create_at`, "sortByCreateTime"). |
| 75 | + SetOrder(`update_at`, "sortByUpdateTime") | ||
| 79 | var err error | 76 | var err error |
| 80 | if query.AffectRow, err = query.SelectAndCount(); err != nil { | 77 | if query.AffectRow, err = query.SelectAndCount(); err != nil { |
| 81 | - return 0, Orders, err | 78 | + return 0, OrderGoods, err |
| 82 | } | 79 | } |
| 83 | - for _, OrderModel := range OrderModels { | ||
| 84 | - if Order, err := repository.transformPgModelToDomainModel(OrderModel); err != nil { | ||
| 85 | - return 0, Orders, err | 80 | + for _, OrderGoodModel := range OrderGoodModels { |
| 81 | + if OrderGood, err := repository.transformPgModelToDomainModel(OrderGoodModel); err != nil { | ||
| 82 | + return 0, OrderGoods, err | ||
| 86 | } else { | 83 | } else { |
| 87 | - Orders = append(Orders, Order) | 84 | + OrderGoods = append(OrderGoods, OrderGood) |
| 88 | } | 85 | } |
| 89 | } | 86 | } |
| 90 | - return int64(query.AffectRow), Orders, nil | 87 | + return int64(query.AffectRow), OrderGoods, nil |
| 91 | } | 88 | } |
| 92 | 89 | ||
| 93 | -func (repository *OrderRepository) transformPgModelToDomainModel(OrderModel *models.Order) (*domain.Order, error) { | ||
| 94 | - m := &domain.Order{} | ||
| 95 | - err := GobModelTransform(m, OrderModel) | 90 | +func (repository *OrderGoodRepository) transformPgModelToDomainModel(OrderGoodModel *models.OrderGood) (*domain.OrderGood, error) { |
| 91 | + m := &domain.OrderGood{} | ||
| 92 | + err := GobModelTransform(m, OrderGoodModel) | ||
| 96 | return m, err | 93 | return m, err |
| 97 | } | 94 | } |
| 98 | 95 | ||
| 99 | -func NewOrderRepository(transactionContext *transaction.TransactionContext) (*OrderRepository, error) { | 96 | +func NewOrderGoodRepository(transactionContext *transaction.TransactionContext) (*OrderGoodRepository, error) { |
| 100 | if transactionContext == nil { | 97 | if transactionContext == nil { |
| 101 | return nil, ERR_EMPTY_TC | 98 | return nil, ERR_EMPTY_TC |
| 102 | } | 99 | } |
| 103 | - return &OrderRepository{transactionContext: transactionContext}, nil | 100 | + return &OrderGoodRepository{transactionContext: transactionContext}, nil |
| 104 | } | 101 | } |
pkg/infrastructure/utils/redis.go
0 → 100644
| 1 | +package utils | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +//redis键值 | ||
| 9 | +func RedisKey(businessKey string) string { | ||
| 10 | + //项目:环境:业务码 | ||
| 11 | + return fmt.Sprintf("%v:%v", constant.SERVICE_NAME, businessKey) | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +//redis键值 项标识 | ||
| 15 | +func RedisKeyWithId(businessKey string, id int64) string { | ||
| 16 | + //项目:环境:业务码 | ||
| 17 | + return fmt.Sprintf("%v:%v:%v", constant.SERVICE_NAME, businessKey, id) | ||
| 18 | +} |
| @@ -103,18 +103,18 @@ func (this *AuthController) Revoke() { | @@ -103,18 +103,18 @@ func (this *AuthController) Revoke() { | ||
| 103 | defer func() { | 103 | defer func() { |
| 104 | this.Resp(msg) | 104 | this.Resp(msg) |
| 105 | }() | 105 | }() |
| 106 | - //var request *protocol.RevokeRequest | ||
| 107 | - //if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 108 | - // log.Error(err) | ||
| 109 | - // msg = protocol.BadRequestParam(1) | ||
| 110 | - // return | ||
| 111 | - //} | ||
| 112 | - //if b, m := this.Valid(request); !b { | ||
| 113 | - // msg = m | ||
| 114 | - // return | ||
| 115 | - //} | ||
| 116 | - //header := controllers.GetRequestHeader(this.Ctx) | ||
| 117 | - //msg = protocol.NewReturnResponse(auth.Revoke(header, request)) | 106 | + var request *protocol.RevokeRequest |
| 107 | + if err := this.JsonUnmarshal(&request); err != nil { | ||
| 108 | + log.Error(err) | ||
| 109 | + msg = protocol.BadRequestParam(1) | ||
| 110 | + return | ||
| 111 | + } | ||
| 112 | + if b, m := this.Valid(request); !b { | ||
| 113 | + msg = m | ||
| 114 | + return | ||
| 115 | + } | ||
| 116 | + header := this.GetRequestHeader(this.Ctx) | ||
| 117 | + msg = protocol.NewReturnResponse(auth.Revoke(header, request)) | ||
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | //UpdateDevice | 120 | //UpdateDevice |
| @@ -25,7 +25,7 @@ func (this *DividendController) DividendStatistics() { | @@ -25,7 +25,7 @@ func (this *DividendController) DividendStatistics() { | ||
| 25 | return | 25 | return |
| 26 | } | 26 | } |
| 27 | header := this.GetRequestHeader(this.Ctx) | 27 | header := this.GetRequestHeader(this.Ctx) |
| 28 | - msg = protocol.NewReturnResponse(dividend.DividendStatistics(header, request)) | 28 | + msg = protocol.NewReturnResponse(dividend.Statistics(header, request)) |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | //DividendOrders 分红订单 | 31 | //DividendOrders 分红订单 |
| @@ -44,5 +44,5 @@ func (this *DividendController) DividendOrders() { | @@ -44,5 +44,5 @@ func (this *DividendController) DividendOrders() { | ||
| 44 | return | 44 | return |
| 45 | } | 45 | } |
| 46 | header := this.GetRequestHeader(this.Ctx) | 46 | header := this.GetRequestHeader(this.Ctx) |
| 47 | - msg = protocol.NewReturnResponse(dividend.DividendOrders(header, request)) | 47 | + msg = protocol.NewReturnResponse(dividend.OrderList(header, request)) |
| 48 | } | 48 | } |
| @@ -28,7 +28,7 @@ func (this *OrderController) Statistics() { | @@ -28,7 +28,7 @@ func (this *OrderController) Statistics() { | ||
| 28 | return | 28 | return |
| 29 | } | 29 | } |
| 30 | header := this.GetRequestHeader(this.Ctx) | 30 | header := this.GetRequestHeader(this.Ctx) |
| 31 | - msg = protocol.NewReturnResponse(order.OrderStatistics(header, request)) | 31 | + msg = protocol.NewReturnResponse(order.Statistics(header, request)) |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | //OrderDetail 订单详情 | 34 | //OrderDetail 订单详情 |
| @@ -48,7 +48,7 @@ func (this *OrderController) OrderDetail() { | @@ -48,7 +48,7 @@ func (this *OrderController) OrderDetail() { | ||
| 48 | return | 48 | return |
| 49 | } | 49 | } |
| 50 | header := this.GetRequestHeader(this.Ctx) | 50 | header := this.GetRequestHeader(this.Ctx) |
| 51 | - msg = protocol.NewReturnResponse(order.OrderDetail(header, request)) | 51 | + msg = protocol.NewReturnResponse(order.Detail(header, request)) |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | //OrderList | 54 | //OrderList |
| @@ -68,7 +68,7 @@ func (this *OrderController) OrderList() { | @@ -68,7 +68,7 @@ func (this *OrderController) OrderList() { | ||
| 68 | } | 68 | } |
| 69 | request.OrderType = domain.OrderReal | 69 | request.OrderType = domain.OrderReal |
| 70 | header := this.GetRequestHeader(this.Ctx) | 70 | header := this.GetRequestHeader(this.Ctx) |
| 71 | - msg = protocol.NewReturnResponse(order.OrderList(header, request)) | 71 | + msg = protocol.NewReturnResponse(order.List(header, request)) |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | //OrderList | 74 | //OrderList |
| @@ -89,5 +89,5 @@ func (this *OrderController) Intentions() { | @@ -89,5 +89,5 @@ func (this *OrderController) Intentions() { | ||
| 89 | request.EndTime = time.Now().Unix() * 1000 | 89 | request.EndTime = time.Now().Unix() * 1000 |
| 90 | request.OrderType = domain.OrderIntention | 90 | request.OrderType = domain.OrderIntention |
| 91 | header := this.GetRequestHeader(this.Ctx) | 91 | header := this.GetRequestHeader(this.Ctx) |
| 92 | - msg = protocol.NewReturnResponse(order.OrderList(header, request)) | 92 | + msg = protocol.NewReturnResponse(order.List(header, request)) |
| 93 | } | 93 | } |
| @@ -29,6 +29,16 @@ func CheckJWTToken(ctx *context.Context) { | @@ -29,6 +29,16 @@ func CheckJWTToken(ctx *context.Context) { | ||
| 29 | return | 29 | return |
| 30 | } else { | 30 | } else { |
| 31 | ctx.Input.SetData("UserId", u.UserId) | 31 | ctx.Input.SetData("UserId", u.UserId) |
| 32 | + | ||
| 33 | + //valid token | ||
| 34 | + //tokenAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(u.UserId)) | ||
| 35 | + //err := tokenAuth.Check( | ||
| 36 | + // userAuth.NewOptions(userAuth.WithAccessToken(token)), | ||
| 37 | + //) | ||
| 38 | + //if err != nil { | ||
| 39 | + // msg = protocol.NewMesage(4141) | ||
| 40 | + // return | ||
| 41 | + //} | ||
| 32 | } | 42 | } |
| 33 | return | 43 | return |
| 34 | } | 44 | } |
| @@ -91,3 +91,17 @@ type AuthCheckSmsCodeRequest struct { | @@ -91,3 +91,17 @@ type AuthCheckSmsCodeRequest struct { | ||
| 91 | type AuthCheckSmsCodeResponse struct { | 91 | type AuthCheckSmsCodeResponse struct { |
| 92 | CaptchaCertificate string `json:"captchaCertificate"` //短信验证码通过凭证 | 92 | CaptchaCertificate string `json:"captchaCertificate"` //短信验证码通过凭证 |
| 93 | } | 93 | } |
| 94 | + | ||
| 95 | +/*CheckIm */ | ||
| 96 | +type CheckImRequest struct { | ||
| 97 | + UserId int64 | ||
| 98 | + ImId string | ||
| 99 | + Uname string | ||
| 100 | + Icon string | ||
| 101 | + CustomerImId string | ||
| 102 | + IsCreated bool | ||
| 103 | +} | ||
| 104 | +type CheckImResponse struct { | ||
| 105 | + ImToken string //net im token | ||
| 106 | + CsAccount int64 //客服id | ||
| 107 | +} |
| @@ -19,13 +19,15 @@ type DividendStatisticsResponse struct { | @@ -19,13 +19,15 @@ type DividendStatisticsResponse struct { | ||
| 19 | type DividendStatistics struct { | 19 | type DividendStatistics struct { |
| 20 | Received float64 `json:"received"` //总已收分红 | 20 | Received float64 `json:"received"` //总已收分红 |
| 21 | Outstanding float64 `json:"outstanding"` //总未收分红/分红支出 | 21 | Outstanding float64 `json:"outstanding"` //总未收分红/分红支出 |
| 22 | + Receivable float64 `json:"receivable"` //总应收分红 | ||
| 22 | Quarters []Bonus `json:"quarters"` | 23 | Quarters []Bonus `json:"quarters"` |
| 23 | } | 24 | } |
| 24 | 25 | ||
| 25 | type Bonus struct { | 26 | type Bonus struct { |
| 27 | + Receivable float64 `json:"receivable"` //应收分红 | ||
| 26 | Received float64 `json:"received"` //已收分红 | 28 | Received float64 `json:"received"` //已收分红 |
| 27 | Outstanding float64 `json:"outstanding"` //未收分红 | 29 | Outstanding float64 `json:"outstanding"` //未收分红 |
| 28 | - Expend float64 `json:"expend"` //季度分红支出 | 30 | + Expend float64 `json:"-"` //季度分红支出 |
| 29 | } | 31 | } |
| 30 | 32 | ||
| 31 | /*DividendOrders 分红订单*/ | 33 | /*DividendOrders 分红订单*/ |
| @@ -45,7 +47,8 @@ type DividendOrdersResponse struct { | @@ -45,7 +47,8 @@ type DividendOrdersResponse struct { | ||
| 45 | 47 | ||
| 46 | type DividendOrderListItem struct { | 48 | type DividendOrderListItem struct { |
| 47 | Id int64 `json:"id"` | 49 | Id int64 `json:"id"` |
| 48 | - OrderNo string `json:"orderNo"` | 50 | + OrderNo string `json:"-"` |
| 51 | + DeliveryNo string `json:"deliveryNo"` | ||
| 49 | OrderAmount float64 `json:"orderAmount"` | 52 | OrderAmount float64 `json:"orderAmount"` |
| 50 | - MyDividend float64 `json:"myDividend"` | 53 | + DividendReceivable float64 `json:"dividendReceivable"` |
| 51 | } | 54 | } |
| @@ -7,21 +7,34 @@ type OrderDetailRequest struct { | @@ -7,21 +7,34 @@ type OrderDetailRequest struct { | ||
| 7 | type OrderDetailResponse struct { | 7 | type OrderDetailResponse struct { |
| 8 | Order interface{} `json:"order"` | 8 | Order interface{} `json:"order"` |
| 9 | } | 9 | } |
| 10 | + | ||
| 11 | +//type OrderDetail struct { | ||
| 12 | +// Id int64 `json:"id"` | ||
| 13 | +// OrderNo string `json:"orderNo"` | ||
| 14 | +// OrderName string `json:"orderName"` | ||
| 15 | +// OrderStatus int `json:"orderStatus"` | ||
| 16 | +// CreateTime int64 `json:"createTime"` | ||
| 17 | +// UpdateTime int64 `json:"updateTime"` | ||
| 18 | +// OrderQuantity int `json:"orderQuantity"` | ||
| 19 | +// OrderAmount float64 `json:"orderAmount"` | ||
| 20 | +// OrderAmountCancel float64 `json:"orderAmountCancel"` | ||
| 21 | +// OrderUpdateReason string `json:"orderUpdateReason"` | ||
| 22 | +// OrderDistrict interface{} `json:"orderDistrict"` | ||
| 23 | +// Customer Customer `json:"customer"` | ||
| 24 | +// MyDividend float64 `json:"myDividend"` | ||
| 25 | +// MyDividendPercent float64 `json:"myDividendPercent"` | ||
| 26 | +//} | ||
| 10 | type OrderDetail struct { | 27 | type OrderDetail struct { |
| 11 | Id int64 `json:"id"` | 28 | Id int64 `json:"id"` |
| 12 | - OrderNo string `json:"orderNo"` | ||
| 13 | - OrderName string `json:"orderName"` | ||
| 14 | - OrderStatus int `json:"orderStatus"` | 29 | + OrderNo string `json:"orderNo"` //订单号 |
| 30 | + DeliveryNo string `json:"deliveryNo"` //发货单号 | ||
| 31 | + OrderStatus int `json:"orderStatus"` //订单状态 1.待支付 2.已支付 3.已支付退货 4待支付退货 | ||
| 15 | CreateTime int64 `json:"createTime"` | 32 | CreateTime int64 `json:"createTime"` |
| 16 | UpdateTime int64 `json:"updateTime"` | 33 | UpdateTime int64 `json:"updateTime"` |
| 17 | - OrderQuantity int `json:"orderQuantity"` | ||
| 18 | - OrderAmount float64 `json:"orderAmount"` | ||
| 19 | - OrderAmountCancel float64 `json:"orderAmountCancel"` | ||
| 20 | - OrderUpdateReason string `json:"orderUpdateReason"` | ||
| 21 | OrderDistrict interface{} `json:"orderDistrict"` | 34 | OrderDistrict interface{} `json:"orderDistrict"` |
| 22 | Customer Customer `json:"customer"` | 35 | Customer Customer `json:"customer"` |
| 23 | - MyDividend float64 `json:"myDividend"` | ||
| 24 | - MyDividendPercent float64 `json:"myDividendPercent"` | 36 | + Products interface{} `json:"products"` |
| 37 | + Total interface{} `json:"total"` | ||
| 25 | } | 38 | } |
| 26 | type Customer struct { | 39 | type Customer struct { |
| 27 | Uname string `json:"uname"` | 40 | Uname string `json:"uname"` |
| @@ -35,8 +48,8 @@ type OrderStatisticsResponse struct { | @@ -35,8 +48,8 @@ type OrderStatisticsResponse struct { | ||
| 35 | Statistics OrderStatics `json:"statistics"` | 48 | Statistics OrderStatics `json:"statistics"` |
| 36 | } | 49 | } |
| 37 | type OrderStatics struct { | 50 | type OrderStatics struct { |
| 38 | - TodayIntentionQuantity int `json:"todayIntentionQuantity"` //今日新增意向订单 | ||
| 39 | - TodayIntentionMoney float64 `json:"todayIntentionMoney"` //今日新增意向订单金额 | 51 | + TodayIntentionQuantity int `json:"-"` //今日新增意向订单 |
| 52 | + TodayIntentionMoney float64 `json:"-"` //今日新增意向订单金额 | ||
| 40 | TodayRealQuantity int `json:"todayRealQuantity"` //今日新增实发订单 | 53 | TodayRealQuantity int `json:"todayRealQuantity"` //今日新增实发订单 |
| 41 | TodayRealMoney float64 `json:"todayRealMoney"` //今日新增实发订单金额 | 54 | TodayRealMoney float64 `json:"todayRealMoney"` //今日新增实发订单金额 |
| 42 | CumulativeQuantity int `json:"cumulativeQuantity"` //累计实发订单 | 55 | CumulativeQuantity int `json:"cumulativeQuantity"` //累计实发订单 |
| @@ -54,7 +67,8 @@ type OrderListRequest struct { | @@ -54,7 +67,8 @@ type OrderListRequest struct { | ||
| 54 | } | 67 | } |
| 55 | type OrderListResponse struct { | 68 | type OrderListResponse struct { |
| 56 | List []*OrderListItem `json:"list"` | 69 | List []*OrderListItem `json:"list"` |
| 57 | - Statistics map[string]interface{} `json:"statistics"` | 70 | + Statistics map[string]interface{} `json:"-"` |
| 71 | + Total int `json:"total"` | ||
| 58 | } | 72 | } |
| 59 | 73 | ||
| 60 | type OrderListItem struct { | 74 | type OrderListItem struct { |
| @@ -63,18 +77,20 @@ type OrderListItem struct { | @@ -63,18 +77,20 @@ type OrderListItem struct { | ||
| 63 | //订单类型 | 77 | //订单类型 |
| 64 | OrderType int `json:"orderType"` | 78 | OrderType int `json:"orderType"` |
| 65 | //订单编号 | 79 | //订单编号 |
| 66 | - OrderNo string `json:"orderNo"` | 80 | + OrderNo string `json:"-"` |
| 81 | + //发货编号 | ||
| 82 | + DeliveryNo string `json:"deliveryNo"` | ||
| 67 | //订单名称 | 83 | //订单名称 |
| 68 | - OrderName string `json:"orderName"` | 84 | + OrderName string `json:"-"` |
| 69 | //订单状态 | 85 | //订单状态 |
| 70 | - OrderStatus int `json:"orderStatus"` | 86 | + OrderStatus int `json:"-"` |
| 71 | //实际订单数量 | 87 | //实际订单数量 |
| 72 | - OrderActualCount int `json:"orderActualCount"` | 88 | + OrderActualCount int `json:"-"` |
| 73 | //订单金额 | 89 | //订单金额 |
| 74 | OrderAmount float64 `json:"orderAmount"` | 90 | OrderAmount float64 `json:"orderAmount"` |
| 75 | UpdateTime int64 `json:"updateTime"` | 91 | UpdateTime int64 `json:"updateTime"` |
| 76 | //我的分红 | 92 | //我的分红 |
| 77 | - MyDividend float64 `json:"myDividend"` | 93 | + MyDividend float64 `json:"dividendReceivable"` |
| 78 | //是否已读(0未读,1已读) | 94 | //是否已读(0未读,1已读) |
| 79 | IsRead int `json:"isRead"` | 95 | IsRead int `json:"isRead"` |
| 80 | } | 96 | } |
| @@ -28,6 +28,11 @@ type User struct { | @@ -28,6 +28,11 @@ type User struct { | ||
| 28 | //合作时间 | 28 | //合作时间 |
| 29 | CooperateTime int64 `json:"cooperationTime"` | 29 | CooperateTime int64 `json:"cooperationTime"` |
| 30 | Salesman interface{} `json:"salesman"` | 30 | Salesman interface{} `json:"salesman"` |
| 31 | + | ||
| 32 | + // 网易云信 | ||
| 33 | + AccountID int64 `json:"accid"` // 网易云信ID | ||
| 34 | + ImToken string `json:"imToken"` // 网易云信Token | ||
| 35 | + CsAccountID string `json:"csAccountID"` // 分配的客服ID | ||
| 31 | } | 36 | } |
| 32 | 37 | ||
| 33 | type Company struct { | 38 | type Company struct { |
-
请 注册 或 登录 后发表评论