diff --git a/internal/api/mobile/goods/common_list.go b/internal/api/mobile/goods/common_list.go index 5fd9316..6954987 100755 --- a/internal/api/mobile/goods/common_list.go +++ b/internal/api/mobile/goods/common_list.go @@ -227,7 +227,8 @@ func GetGoodsRespByInfoList(goodsList []goods.Information, userID uint, isSale b "MIN(original_price) AS original_price, "+ "MIN(discount_price) AS discount_price, "+ "MIN(commission) AS commission,"+ - "MIN(coupon) AS coupon"). + "MIN(coupon) AS coupon,"+ + "MIN(sale_purchase_price) as sale_purchase_price"). Group("goods_id"). Where("goods_id in (?)", ids). Find(&sku) diff --git a/internal/model/order/jyy.go b/internal/model/order/jyy.go index e719f87..b44ecea 100644 --- a/internal/model/order/jyy.go +++ b/internal/model/order/jyy.go @@ -31,6 +31,7 @@ const ( Company All Sale + Share ) var profitStr = map[IncomeType]string{ @@ -41,6 +42,7 @@ var profitStr = map[IncomeType]string{ Company: "店铺补贴", All: "子公司自购导购收益", Sale: "批发收益", + Share: "子公司分享", } func (o IncomeType) GetStr() string { @@ -55,6 +57,7 @@ var profitMap = map[IncomeType]decimal.Decimal{ Company: decimal.NewFromFloat(0.3), All: decimal.NewFromFloat(1), Sale: decimal.NewFromFloat(1), + Share: decimal.NewFromFloat(1), } func (o IncomeType) GetProfit() decimal.Decimal { diff --git a/internal/service/app/shop/benefit.go b/internal/service/app/shop/benefit.go index 94e9fbb..95ddf23 100644 --- a/internal/service/app/shop/benefit.go +++ b/internal/service/app/shop/benefit.go @@ -34,7 +34,7 @@ func OrderProfit(od order.Information, tx *gorm.DB) error { } else if s1.Level != 0 { if s1.Level == 10 { // 子公司导购获取全部导购收益 - if err := tx.Create(order.CreateProfit(u1.RootID, order.All, base, od.ID)).Error; err != nil { + if err := tx.Create(order.CreateProfit(u1.RootID, order.Share, base, od.ID)).Error; err != nil { return err } } else { diff --git a/internal/v2/controller/app/jyy/jyy.go b/internal/v2/controller/app/jyy/jyy.go index 8150e74..2830eb4 100644 --- a/internal/v2/controller/app/jyy/jyy.go +++ b/internal/v2/controller/app/jyy/jyy.go @@ -100,3 +100,39 @@ func (o Proxy) OrderUpdate(c *gin.Context) { func (o Proxy) Contact(c *gin.Context) { back.Suc(c, "ok", jyy.Logic.Contact()) } + +func (o Proxy) ProfitSaleList(c *gin.Context) { + var args jyy.ArgsProfitListReq + if err := tools.ParseParams(&args, c); err != nil { + back.Err(c, err.Error()) + return + } + + if data, err := jyy.Logic.ProfitSaleList(args); err != nil { + back.Fail(c, err.Error()) + } else { + back.Suc(c, "ok", data) + } +} + +func (o Proxy) ProfitSalePerson(c *gin.Context) { + var args jyy.ArgsProfitListReq + if err := tools.ParseParams(&args, c); err != nil { + back.Err(c, err.Error()) + return + } + + if data, err := jyy.Logic.ProfitSaleList(args); err != nil { + back.Fail(c, err.Error()) + } else { + back.Suc(c, "ok", data) + } +} + +func (o Proxy) ProfitShopList(c *gin.Context) { + +} + +func (o Proxy) ProfitSelfList(c *gin.Context) { + +} diff --git a/internal/v2/controller/app/user/Income.go b/internal/v2/controller/app/user/Income.go index da9e6d4..da3f1f9 100644 --- a/internal/v2/controller/app/user/Income.go +++ b/internal/v2/controller/app/user/Income.go @@ -1,9 +1,6 @@ package user import ( - "github.com/gin-gonic/gin" - "github.com/golangkit/formatime" - "github.com/shopspring/decimal" "recook/internal/dbc" user3 "recook/internal/model/user" "recook/internal/v2/lib/back" @@ -12,45 +9,19 @@ import ( "recook/internal/v2/model/http/profile" "recook/tools" "time" + + "github.com/gin-gonic/gin" + "github.com/golangkit/formatime" + "github.com/shopspring/decimal" ) type Income struct { } -//// @Style 获取会员收益 -//func (i *Income) Income(c *gin.Context) { -// userId, _ := common.GetAppUserId(c) -// income := user.IncomeLogic.Income(userId) -// back.Suc(c, "获取成功", income) -//} - -// @Style 累计收益 -//func (i *Income) Accumulate(c *gin.Context) { -// userId, _ := common.GetAppUserId(c) -// accumulate := user.IncomeLogic.Accumulate(userId) -// back.Suc(c, "获取成功", accumulate) -//} - type argsMonthIncome struct { Year int `json:"year" form:"year"` } -//// @Style 年度月收益 -//func (i *Income) MonthIncome(c *gin.Context) { -// args := argsMonthIncome{} -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// if args.Year <= 0 { -// back.Fail(c, "参数错误") -// return -// } -// userId, _ := common.GetAppUserId(c) -// accumulate := user.IncomeLogic.MonthIncome(userId, args.Year) -// back.Suc(c, "获取成功", accumulate) -//} - // PurchaseAccumulate @Style 累计自购收益 func (i *Income) PurchaseAccumulate(c *gin.Context) { userId, _ := common.GetAppUserId(c) @@ -86,259 +57,14 @@ type argsDayIncome struct { Month string `json:"month" form:"month"` } -//// @Style 月份每日收益 -//func (i *Income) DayIncome(c *gin.Context) { -// args := argsDayIncome{} -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// if args.Month == "" { -// back.Fail(c, "参数错误") -// return -// } -// monthObj, err := time.ParseInLocation("2006-01", args.Month, time.Local) -// if err != nil { -// back.Fail(c, "参数错误") -// return -// } -// month, _ := strconv.Atoi(monthObj.Format("200601")) -// userId, _ := common.GetAppUserId(c) -// accumulate := user.IncomeLogic.DayIncome(userId, month) -// back.Suc(c, "获取成功", accumulate) -//} - -// -//// @Style 团队收益 -//func (i *Income) TeamIncome(c *gin.Context) { -// userId, _ := common.GetAppUserId(c) -// teamIncome := user.IncomeLogic.TeamIncome(userId) -// back.Suc(c, "获取成功", teamIncome) -//} -// -//// @Style 推荐收益 -//func (i *Income) RecommendIncome(c *gin.Context) { -// userId, _ := common.GetAppUserId(c) -// recommendIncome := user.IncomeLogic.RecommendIncome(userId) -// back.Suc(c, "获取成功", recommendIncome) -//} -// -//// @Style 平台奖励收益 -//func (i *Income) RewardIncome(c *gin.Context) { -// userId, _ := common.GetAppUserId(c) -// rewardIncome := user.IncomeLogic.RewardIncome(userId) -// back.Suc(c, "获取成功", rewardIncome) -//} - type argsMonth struct { Month string `json:"month" form:"month"` } -// -//// @Style 团队月收益 -//func (i *Income) TeamMonthIncome(c *gin.Context) { -// args := argsMonth{} -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// if args.Month == "" { -// back.Fail(c, "参数错误") -// return -// } -// monthObj, err := time.ParseInLocation("2006-01", args.Month, time.Local) -// if err != nil { -// back.Fail(c, "参数错误") -// return -// } -// month, _ := strconv.Atoi(monthObj.Format("200601")) -// userId, _ := common.GetAppUserId(c) -// teamIncome := user.IncomeLogic.TeamMonthIncome(userId, month) -// back.Suc(c, "获取成功", teamIncome) -//} -// -//// @Style 月推荐收益 -//func (i *Income) RecommendMonthIncome(c *gin.Context) { -// args := argsMonth{} -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// if args.Month == "" { -// back.Fail(c, "参数错误") -// return -// } -// monthObj, err := time.ParseInLocation("2006-01", args.Month, time.Local) -// if err != nil { -// back.Fail(c, "参数错误") -// return -// } -// month, _ := strconv.Atoi(monthObj.Format("200601")) -// userId, _ := common.GetAppUserId(c) -// teamIncome := user.IncomeLogic.RecommendMonthIncome(userId, month) -// back.Suc(c, "获取成功", teamIncome) -//} -// -//// @Style 月平台奖励收益 -//func (i *Income) RewardMonthIncome(c *gin.Context) { -// args := argsMonth{} -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// if args.Month == "" { -// back.Fail(c, "参数错误") -// return -// } -// monthObj, err := time.ParseInLocation("2006-01", args.Month, time.Local) -// if err != nil { -// back.Fail(c, "参数错误") -// return -// } -// month, _ := strconv.Atoi(monthObj.Format("200601")) -// userId, _ := common.GetAppUserId(c) -// teamIncome := user.IncomeLogic.RewardMonthIncome(userId, month) -// back.Suc(c, "获取成功", teamIncome) -//} - type argsDayIncomes struct { Day string `json:"day" form:"day"` } -// -//// @Style 日收益详情 -//func (i *Income) DayIncomes(c *gin.Context) { -// args := argsDayIncomes{} -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// if args.Day == "" { -// back.Fail(c, "参数错误") -// return -// } -// dayObj, err := time.ParseInLocation("2006-01-02", args.Day, time.Local) -// if err != nil { -// back.Fail(c, "参数错误") -// return -// } -// day, _ := strconv.Atoi(dayObj.Format("20060102")) -// userId, _ := common.GetAppUserId(c) -// resule := user.IncomeLogic.DayIncomes(userId, day) -// back.Suc(c, "操作成功", resule) -//} -// -//// @Style 月收益详情 -//func (i *Income) MonthIncomes(c *gin.Context) { -// args := argsMonth{} -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// if args.Month == "" { -// back.Fail(c, "参数错误") -// return -// } -// monthObj, err := time.ParseInLocation("2006-01", args.Month, time.Local) -// if err != nil { -// back.Fail(c, "参数错误") -// return -// } -// month, _ := strconv.Atoi(monthObj.Format("200601")) -// userId, _ := common.GetAppUserId(c) -// resule := user.IncomeLogic.MonthIncomes(userId, month) -// back.Suc(c, "操作成功", resule) -//} - -//// @Style 日自购/导购预估收益 -//func (i *Income) DayExpect(c *gin.Context) { -// args := argsDayIncomes{} -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// if args.Day == "" { -// back.Fail(c, "参数错误") -// return -// } -// dayObj, err := time.ParseInLocation("2006-01-02", args.Day, time.Local) -// if err != nil { -// back.Fail(c, "参数错误") -// return -// } -// day, _ := strconv.Atoi(dayObj.Format("20060102")) -// userId, _ := common.GetAppUserId(c) -// resule := user.IncomeLogic.DayExpect(userId, day) -// back.Suc(c, "操作成功", resule) -//} - -// @Style 月自购/导购预估收益 -//func (i *Income) MonthExpect(c *gin.Context) { -// args := argsMonth{} -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// if args.Month == "" { -// back.Fail(c, "参数错误") -// return -// } -// monthObj, err := time.ParseInLocation("2006-01", args.Month, time.Local) -// if err != nil { -// back.Fail(c, "参数错误") -// return -// } -// month, _ := strconv.Atoi(monthObj.Format("200601")) -// userId, _ := common.GetAppUserId(c) -// resule := user.IncomeLogic.MonthExpect(userId, month) -// back.Suc(c, "操作成功", resule) -//} - -// -//// @Style 日团队预估收益 -//func (i *Income) DayExpectTeam(c *gin.Context) { -// args := argsDayIncomes{} -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// if args.Day == "" { -// back.Fail(c, "参数错误") -// return -// } -// dayObj, err := time.ParseInLocation("2006-01-02", args.Day, time.Local) -// if err != nil { -// back.Fail(c, "参数错误") -// return -// } -// day, _ := strconv.Atoi(dayObj.Format("20060102")) -// userId, _ := common.GetAppUserId(c) -// resule := user.IncomeLogic.DayExpectTeam(userId, day) -// back.Suc(c, "操作成功", resule) -//} -// -//// @Style 月团队预估收益 -//func (i *Income) MonthExpectTeam(c *gin.Context) { -// args := argsMonth{} -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// if args.Month == "" { -// back.Fail(c, "参数错误") -// return -// } -// monthObj, err := time.ParseInLocation("2006-01", args.Month, time.Local) -// if err != nil { -// back.Fail(c, "参数错误") -// return -// } -// month, _ := strconv.Atoi(monthObj.Format("200601")) -// userId, _ := common.GetAppUserId(c) -// resule := user.IncomeLogic.MonthExpectTeam(userId, month) -// back.Suc(c, "操作成功", resule) -//} - type respIncomeHistory struct { Total decimal.Decimal `json:"total"` Purchase decimal.Decimal `json:"purchase"` @@ -455,34 +181,3 @@ func (i *Income) IncomeDetail(c *gin.Context) { } back.Suc(c, "操作成功", result) } - -// IncomeTeamNotRecvDetail 团队月未到账详情. -//func (i *Income) IncomeTeamNotRecvDetail(c *gin.Context) { -// -// uid, _ := common.GetAppUserId(c) -// -// var args strict2.TeamDetailReq -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// args.UID = uid -// result := user.IncomeLogic.TeamIncomeDetailOfMonth(&args) -// -// back.Suc(c, "操作成功", result) -//} - -// IncomeTeamDetail 团队到账详情. -//func (i *Income) IncomeTeamDetail(c *gin.Context) { -// -// uid, _ := common.GetAppUserId(c) -// var args strict2.TeamDetailReq -// if err := tools.ParseParams(&args, c); err != nil { -// back.Fail(c, err.Error()) -// return -// } -// args.UID = uid -// result := user.IncomeLogic.TeamIncomeDetailOfYear(&args) -// -// back.Suc(c, "操作成功", result) -//} diff --git a/internal/v2/logic/app/jyy/jyy.go b/internal/v2/logic/app/jyy/jyy.go index f0430d4..e133648 100644 --- a/internal/v2/logic/app/jyy/jyy.go +++ b/internal/v2/logic/app/jyy/jyy.go @@ -3,10 +3,12 @@ package jyy import ( "errors" "fmt" + "recook/internal/model/order" "recook/internal/model/order_preview" user2 "recook/internal/model/user" "recook/internal/v2/model/jyy" goods2 "recook/internal/v2/model/recook/goods" + manage "recook/internal/v2/model/recook/order" "recook/internal/v2/model/recook/user" "time" @@ -437,3 +439,64 @@ func (o logic) Contact() (res jyy.Contact) { mysql.Db.First(&res) return } + +type ArgsProfitListReq struct { + UserID uint `json:"user_id"` + Date string `json:"date"` +} + +type ProfitSaleEntry struct { + Name string `json:"name"` + Amount decimal.Decimal `json:"amount"` + Income decimal.Decimal `json:"income"` + Count int `json:"count"` + ShopID uint `json:"shop_id"` +} + +type ProfitDetail struct { + All decimal.Decimal `json:"all"` + Entry []ProfitSaleEntry `json:"entry"` +} + +func (o logic) ProfitSaleList(args ArgsProfitListReq) (res ProfitDetail, err error) { + var p []order.Profit + now := time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local) + mysql.Db.Where("status = 2 and type = 7").Find(&p, "user_id = ? and created_at between ? and ?", args.UserID, now, now.AddDate(1, 0, 0)) + + ids := make([]uint, 0) + incomeMap := make(map[uint]decimal.Decimal) + for _, v := range p { + ids = append(ids, v.OrderID) + incomeMap[v.OrderID] = incomeMap[v.OrderID].Add(v.Income) + } + var ods []manage.RecookOrderInfoModel + mysql.Db.Preload("User").Find(&ods, "id in (?)", ids) + + userMap := make(map[uint][]manage.RecookOrderInfoModel) + for _, v := range ods { + userMap[v.UserId] = append(userMap[v.UserId], v) + } + + for id, v := range userMap { + amount := decimal.Zero + income := decimal.Zero + for _, j := range v { + amount = amount.Add(j.ActualTotalAmount) + income = income.Add(incomeMap[j.Id]) + } + res.Entry = append(res.Entry, ProfitSaleEntry{ + ShopID: id, + Name: v[0].User.Nickname, + Amount: amount, + Income: income, + Count: len(v), + }) + + } + + return +} + +type ArgsProfitPerson struct { + ShopID uint `json:"shop_id"` +} diff --git a/internal/v2/logic/app/user/income.go b/internal/v2/logic/app/user/income.go index 9190514..06df424 100644 --- a/internal/v2/logic/app/user/income.go +++ b/internal/v2/logic/app/user/income.go @@ -128,7 +128,7 @@ func (i *incomeLogic) Profit(userID uint) (res Profit) { case order.Company: res.ECount5 += 1 res.EAmount5 = res.EAmount5.Add(v.Income) - case order.All: + case order.All, order.Share: res.ECount6 += 1 res.EAmount6 = res.EAmount6.Add(v.Income) case order.Sale: @@ -153,7 +153,7 @@ func (i *incomeLogic) Profit(userID uint) (res Profit) { case order.Company: res.Count5 += 1 res.Amount5 = res.Amount5.Add(v.Income) - case order.All: + case order.All, order.Share: res.Count6 += 1 res.Amount6 = res.Amount6.Add(v.Income) case order.Sale: diff --git a/internal/v2/model/recook/order/recookOrderInfo.go b/internal/v2/model/recook/order/recookOrderInfo.go index ad52b36..c1f2800 100644 --- a/internal/v2/model/recook/order/recookOrderInfo.go +++ b/internal/v2/model/recook/order/recookOrderInfo.go @@ -1,12 +1,14 @@ package manage import ( - "github.com/golangkit/formatime" - "github.com/shopspring/decimal" "recook/internal/v2/lib/common" "recook/internal/v2/lib/db" "recook/internal/v2/model/recook/after" + "recook/internal/v2/model/recook/user" "strconv" + + "github.com/golangkit/formatime" + "github.com/shopspring/decimal" ) const ( @@ -168,6 +170,7 @@ type RecookOrderInfoModel struct { OrderSku []RecookOrderGoodsDetailModel `json:"-" gorm:"foreignKey:order_id"` After []after.RecookAfterSalesGoodsModel `json:"-" gorm:"foreignKey:order_id"` OrderType uint `json:"-"` + User user.RecookUserInfoModel `json:"-" gorm:"foreignKey:user_id"` } // TableName sets the insert table name for this struct type diff --git a/internal/v2/router/app.go b/internal/v2/router/app.go index 1f39ce2..7730ea9 100644 --- a/internal/v2/router/app.go +++ b/internal/v2/router/app.go @@ -60,6 +60,7 @@ func routerApp(appRouter *gin.RouterGroup) { userRouter.POST("income/nr/detail", incomeController.IncomeNotRecvDetail) // 未到账详情 userRouter.POST("income/detail", incomeController.IncomeDetail) // 到账详情 } + operateController := user.Operate{} { userRouter.POST("operation/destroy", operateController.DestroyWithCode) @@ -250,4 +251,15 @@ func routerApp(appRouter *gin.RouterGroup) { jyyRouter.POST("contact", proxy.Contact) } } + + profitRouter := appRouter.Group("profit") + { + proxy := jyy.Proxy{} + { + jyyRouter.POST("sale", proxy.ProfitSaleList) + jyyRouter.POST("sale/detail", proxy.Profi) + jyyRouter.POST("shop", proxy.ProfitShopList) + jyyRouter.POST("self", proxy.ProfitSelfList) + } + } }