fix: 添加分享收一收

master
howell 3 years ago
parent cdda6c484e
commit 7d687103d8

@ -85,6 +85,15 @@ func PaySuccessCallback(tx *gorm.DB, orderInfo order.Information, completeTime f
}
} else {
// 虚拟订单用户升级
if orderInfo.SharerID != 0 && orderInfo.SharerID != orderInfo.UserID {
if err := tx.Create(order.CreateProfit(
orderInfo.SharerID,
order.Card,
orderInfo.ActualTotalAmount,
orderInfo.ID, 2)).Error; err != nil {
return err
}
}
var u1 user.Information
if err := tx.First(&u1, "id = ?", orderInfo.UserID).Error; err != nil {
return err

@ -3,6 +3,7 @@ package order
import (
"recook/internal/define"
"recook/internal/model/order_preview"
"recook/internal/v2/model/recook/goods"
"github.com/golangkit/formatime"
"github.com/shopspring/decimal"
@ -64,20 +65,21 @@ type GoodsDetail struct {
IsClosed int `gorm:"is_closed" json:"isClosed"`
RStatus string `gorm:"-" json:"rStatus"`
DetailInfo string
Bill int `gorm:"bill" json:"bill"` //是否开发票0代表未开1处理中2已成功3失败
Fpqqlsh string `gorm:"fpqqlsh" json:"fpqqlsh"` //流水号
IsExport int `gorm:"is_export" json:"is_export"` //舶茂的是否导出
BomaoNo string `gorm:"bomao_no" json:"bomao_no"` //舶茂的订单编号
EvaluatedId int `gorm:"evaluated_id" json:"evaluated_id"` //评价id
ReportMsg string `gorm:"report_msg" json:"reportMsg"`
Report int `gorm:"report" json:"report"`
IsImport int `gorm:"column:is_import" json:"isImport"` //是否进口商品
Storehouse int `gorm:"column:storehouse" json:"storehouse"` //进口商品仓库
IsFerme int `gorm:"column:is_ferme" json:"isFerme"` //是否包税
ActivityStatus uint `gorm:"column:activity_status" json:"activity_status"`
ActivityId uint `gorm:"column:activity_id" json:"activity_id"` //活动id
MakeUpStatus uint `json:"make_up_status"`
ExtraPrice decimal.Decimal `json:"-"`
Bill int `gorm:"bill" json:"bill"` //是否开发票0代表未开1处理中2已成功3失败
Fpqqlsh string `gorm:"fpqqlsh" json:"fpqqlsh"` //流水号
IsExport int `gorm:"is_export" json:"is_export"` //舶茂的是否导出
BomaoNo string `gorm:"bomao_no" json:"bomao_no"` //舶茂的订单编号
EvaluatedId int `gorm:"evaluated_id" json:"evaluated_id"` //评价id
ReportMsg string `gorm:"report_msg" json:"reportMsg"`
Report int `gorm:"report" json:"report"`
IsImport int `gorm:"column:is_import" json:"isImport"` //是否进口商品
Storehouse int `gorm:"column:storehouse" json:"storehouse"` //进口商品仓库
IsFerme int `gorm:"column:is_ferme" json:"isFerme"` //是否包税
ActivityStatus uint `gorm:"column:activity_status" json:"activity_status"`
ActivityId uint `gorm:"column:activity_id" json:"activity_id"` //活动id
MakeUpStatus uint `json:"make_up_status"`
ExtraPrice decimal.Decimal `json:"-"`
Sku goods.RecookGoodsSkuModel `json:"-" gorm:"foreignKey:sku_id"`
}
// TableName sets the insert table name for this struct type

@ -54,6 +54,8 @@ type Information struct {
ShaMaOrderID uint `gorm:"column:shama_order_id" json:"-"`
OrderType uint `gorm:"column:order_type" json:"-"`
CanPay bool `gorm:"column:can_pay" json:"-"`
OrderSku []GoodsDetail `json:"-" gorm:"foreignKey:order_id"`
Address Addr `json:"-" gorm:"foreignKey:order_id"`
}
const (
@ -101,6 +103,5 @@ func (*Information) Reflect(r *order_preview.Information) *Information {
Cost: r.Cost,
OrderType: r.OrderType,
IsSplit: r.IsVirtual,
}
}

@ -35,6 +35,7 @@ const (
Sale
Share
Vip
Card
)
var profitStr = map[IncomeType]string{
@ -47,6 +48,7 @@ var profitStr = map[IncomeType]string{
Sale: "批发收益",
Share: "子公司分享收益",
Vip: "vip穿透收益",
Card: "买卡收益",
}
func (o IncomeType) GetStr() string {
@ -63,13 +65,18 @@ var profitMap = map[IncomeType]decimal.Decimal{
Sale: decimal.NewFromFloat(1),
Share: decimal.NewFromFloat(1),
Vip: decimal.NewFromFloat(0.2),
Card: decimal.NewFromFloat(0.6),
}
func (o IncomeType) GetProfit() decimal.Decimal {
return profitMap[o]
}
func CreateProfit(id uint, t1 IncomeType, base decimal.Decimal, orderID uint) *Profit {
func CreateProfit(id uint, t1 IncomeType, base decimal.Decimal, orderID uint, status ...int) *Profit {
s := 0
if len(status) != 0 {
s = status[0]
}
return &Profit{
OrderID: orderID,
Base: base,
@ -77,7 +84,7 @@ func CreateProfit(id uint, t1 IncomeType, base decimal.Decimal, orderID uint) *P
Income: base.Mul(profitMap[t1]).Round(2),
UserID: id,
CreatedAt: formatime.NewSecondNow(),
Status: 0,
Status: s,
Version: 2,
}
}

@ -42,6 +42,18 @@ func (i *Income) Profit(c *gin.Context) {
back.Suc(c, "获取成功", res)
}
func (i *Income) ProfitCard(c *gin.Context) {
userId, _ := common.GetAppUserId(c)
var args user.EntryDate
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
args.UserID = userId
res := user.IncomeLogic.ProfitCard(args)
back.Suc(c, "获取成功", res)
}
func (i *Income) Team(c *gin.Context) {
args := keyword{}
if err := tools.ParseParams(&args, c); err != nil {

@ -736,9 +736,14 @@ func (o logic) CompanyAllAmount(id uint) (res Data) {
if !u.IsEnterprise {
// 普通用户
rate := decimal.NewFromFloat(0.13)
cr := decimal.NewFromFloat(0.07)
for _, v := range record {
res.Balance = res.Balance.Add(v.Income)
res.TaxAmount = v.Income.Mul(rate).Round(2)
if v.Type == order.Card {
res.TaxAmount = v.Income.Mul(rate).Round(2)
} else {
res.TaxAmount = v.Income.Mul(cr).Round(2)
}
}
res.ActualAmount = res.Balance.Sub(res.TaxAmount)
} else {
@ -748,8 +753,17 @@ func (o logic) CompanyAllAmount(id uint) (res Data) {
}
for _, v := range record {
res.Balance = res.Balance.Add(v.Income)
res.TaxAmount = res.TaxAmount.
Add(v.Income.Div(decimal.NewFromFloat(1.13)).Mul(rate).Mul(decimal.NewFromFloat(1.12)).Round(2))
if v.Type == order.Card && enterprise.TaxType != "一般纳税人" {
res.TaxAmount = res.TaxAmount.
Add(
v.Income.
Div(decimal.NewFromFloat(1.06)).
Mul(decimal.NewFromFloat(0.06)).
Mul(decimal.NewFromFloat(1.12)).Round(2))
} else {
res.TaxAmount = res.TaxAmount.
Add(v.Income.Div(decimal.NewFromFloat(1.13)).Mul(rate).Mul(decimal.NewFromFloat(1.12)).Round(2))
}
}
res.ActualAmount = res.Balance.Sub(res.TaxAmount)
}

@ -44,22 +44,24 @@ type Profit struct {
ECount9 uint // 批发收益未到账补贴
EAmount9 decimal.Decimal // 批发收益未到账金额
Count1 uint
Amount1 decimal.Decimal
Count2 uint
Amount2 decimal.Decimal
Count3 uint
Amount3 decimal.Decimal
Count4 uint
Amount4 decimal.Decimal
Count5 uint
Amount5 decimal.Decimal
Count6 uint
Amount6 decimal.Decimal
Count7 uint
Amount7 decimal.Decimal
Count9 uint
Amount9 decimal.Decimal
Count1 uint
Amount1 decimal.Decimal
Count2 uint
Amount2 decimal.Decimal
Count3 uint
Amount3 decimal.Decimal
Count4 uint
Amount4 decimal.Decimal
Count5 uint
Amount5 decimal.Decimal
Count6 uint
Amount6 decimal.Decimal
Count7 uint
Amount7 decimal.Decimal
Count9 uint
Amount9 decimal.Decimal
Count10 uint // 批发收益未到账补贴
Amount10 decimal.Decimal // 批发收益未到账金额
Total decimal.Decimal // 全部到账金额
ETotal decimal.Decimal // 全部未到账金额
@ -202,6 +204,9 @@ func (i *incomeLogic) Profit(userID uint) (res Profit) {
case order.Vip:
res.Count9 += 1
res.Amount9 = res.Amount9.Add(v.Income)
case order.Card:
res.Count10 += 1
res.Amount10 = res.Amount10.Add(v.Income)
}
res.Total = res.Total.Add(v.Income)
}
@ -209,6 +214,50 @@ func (i *incomeLogic) Profit(userID uint) (res Profit) {
return
}
type Entry struct {
Name string `json:"name"`
Mobile string `json:"mobile"`
TypeStr string `json:"int"`
Amount decimal.Decimal `json:"amount"`
}
type EntryDate struct {
UserID uint `json:"-"`
Date string `json:"date"`
}
func (i *incomeLogic) ProfitCard(args EntryDate) (res []Entry) {
od := make([]order.Information, 0)
now, err := time.ParseInLocation("2006-01", args.Date, time.Local)
if err != nil {
return
}
next := now.AddDate(0, 1, 0)
mysql.Db.Preload("Address").Preload("OrderSku.Sku").
Where("created_at between ? and ?", now, next).
Where("is_split = 1").
Where("jcook_order_id = 0 or shama_order_id = 0").
Find(&od, "sharer_id = ? AND sharer_id != user_id", args.UserID)
for _, v := range od {
s := ""
switch v.OrderSku[0].Sku.EffectTime {
case 1:
s = "月卡"
case 3:
s = "季卡"
case 12:
s = "年卡"
}
res = append(res, Entry{
Name: v.Address.ReceiverName,
Mobile: v.Address.Mobile,
TypeStr: s,
Amount: v.ActualTotalAmount,
})
}
return
}
type PurchaseAccumulate struct {
PurchaseAmount decimal.Decimal `json:"purchaseAmount"`
PurchaseSalesVolume decimal.Decimal `json:"purchaseSalesVolume"`

@ -53,8 +53,8 @@ func routerApp(appRouter *gin.RouterGroup) {
incomeController := user.Income{}
{
userRouter.POST("profit", incomeController.Profit)
userRouter.POST("profit/card", incomeController.ProfitCard)
userRouter.POST("team", incomeController.Team)
userRouter.POST("income/purchase_accumulate", incomeController.PurchaseAccumulate) // 累计自购收益
userRouter.POST("income/guide_accumulate", incomeController.GuideAccumulate) // 累计导购收益

Loading…
Cancel
Save