Parcourir la source

更新

master
huangjiajun il y a 10 mois
Parent
révision
0c6796fa45
5 fichiers modifiés avec 68 ajouts et 8 suppressions
  1. +34
    -0
      db/db_subsidy_with_month.go
  2. +1
    -0
      db/model/subsidy_with_user.go
  3. +7
    -4
      db/model/subsidy_with_user_flow.go
  4. +8
    -0
      db/model/subsidy_with_user_month.go
  5. +18
    -4
      rule/consume_integral_settlement.go

+ 34
- 0
db/db_subsidy_with_month.go Voir le fichier

@@ -0,0 +1,34 @@
package db

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils"
"github.com/shopspring/decimal"
"xorm.io/xorm"
)

// SubsidyWithUserFlowInsert 插入单条数据
func SubsidyWithMonthInsert(session *xorm.Session, SubsidyWithUserFlow *model.SubsidyWithUserMonth) (int, error) {
var data model.SubsidyWithUserMonth
session.Where("date=? and uid=?", SubsidyWithUserFlow.Date, SubsidyWithUserFlow.Uid).Get(&data)
if data.Id == 0 {
data = model.SubsidyWithUserMonth{
Uid: SubsidyWithUserFlow.Uid,
Date: SubsidyWithUserFlow.Date,
Amount: "",
}
_, err := session.InsertOne(&SubsidyWithUserFlow)
if err != nil {
return 0, err
}

}
userAmountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(data.Amount))
amountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(SubsidyWithUserFlow.Amount))
data.Amount = userAmountValue.Add(amountValue).RoundFloor(8).String()
_, err := session.Where("id=?", data.Id).Cols("amount").Update(&data)
if err != nil {
return 0, err
}
return SubsidyWithUserFlow.Id, nil
}

+ 1
- 0
db/model/subsidy_with_user.go Voir le fichier

@@ -11,4 +11,5 @@ type SubsidyWithUser struct {
Date string `json:"date" xorm:"not null default '0000-00-00' comment('购入日期') CHAR(50)"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
IsCanSubsidy int `json:"is_can_subsidy" xorm:"not null default 1 comment('()') INT(1)"`
}

+ 7
- 4
db/model/subsidy_with_user_flow.go Voir le fichier

@@ -3,8 +3,11 @@ package model
type SubsidyWithUserFlow struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
RecordsId int `json:"records_id" xorm:"not null default 0 comment('记录id') INT(11)"`
Amount string `json:"amount" xorm:"not null default 0.00 comment('金额') DECIMAL(6,2)"`
BalanceAmount string `json:"balance_amount" xorm:"not null default 0.00 comment('余额') DECIMAL(6,2)"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
Amount string `json:"amount" xorm:"not null default 0.00 comment('金额') DECIMAL(20,2)"`
BalanceAmount string `json:"balance_amount" xorm:"not null default 0.00 comment('余额') DECIMAL(20,2)"`
CreateAt string `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP DATETIME"`
Kind int `json:"kind" xorm:"default 1 comment('类型(1:消费补贴 2:体验补贴)') INT(1)"`
Month int `json:"month" xorm:"default 0 comment('202312') INT(11)"`
Uid int `json:"uid" xorm:"default 0 INT(11)"`
}

+ 8
- 0
db/model/subsidy_with_user_month.go Voir le fichier

@@ -0,0 +1,8 @@
package model

type SubsidyWithUserMonth struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"default 0 INT(11)"`
Date string `json:"date" xorm:"comment('2023-12') VARCHAR(255)"`
Amount string `json:"amount" xorm:"default 0.00 DECIMAL(20,2)"`
}

+ 18
- 4
rule/consume_integral_settlement.go Voir le fichier

@@ -85,7 +85,7 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask
//1、统计当前拥有多少份消费补贴
startAt := time.Now().Add(time.Duration(subsidyBase.ConsumptionDay) * -24 * time.Hour).Format("2006-01-02") //起始时间
var subsidyWithUserForConsumeList []model.SubsidyWithUser
hasConsumeTotal, err := session.Where("date <= ?", startAt).And("kind = ?", 1).FindAndCount(&subsidyWithUserForConsumeList)
hasConsumeTotal, err := session.Where("date <= ?", startAt).And("kind = ? and is_can_subsidy=?", 1, 1).FindAndCount(&subsidyWithUserForConsumeList)
if err != nil {
return
}
@@ -106,7 +106,7 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask

//2、统计当前拥有多少份体验补贴
var subsidyWithUserForExperienceList []model.SubsidyWithUser
hasExperienceTotal, err := session.Where("date <= ?", startAt).And("kind = ?", 2).FindAndCount(&subsidyWithUserForExperienceList)
hasExperienceTotal, err := session.Where("date <= ?", startAt).And("kind = ? and is_can_subsidy=?", 2, 1).FindAndCount(&subsidyWithUserForExperienceList)
if err != nil {
return
}
@@ -256,9 +256,12 @@ func DealUserExperienceIntegral(session *xorm.Session, subsidyWithUser *model.Su
//2、新增 subsidy_with_user_flow 记录
var subsidyWitUserFlow = &model.SubsidyWithUserFlow{
RecordsId: subsidyWithUser.Id,
Uid: subsidyWithUser.Uid,
Kind: subsidyWithUser.Kind,
Amount: zhios_order_relate_utils.Float64ToStr(experienceIntegralValue),
BalanceAmount: zhios_order_relate_utils.Float64ToStr(afterAmount),
CreateAt: now.Format("2006-01-02 15:04:05"),
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")),
UpdateAt: now.Format("2006-01-02 15:04:05"),
}
insertAffected, err := db.SubsidyWithUserFlowInsert(session, subsidyWitUserFlow)
@@ -268,8 +271,19 @@ func DealUserExperienceIntegral(session *xorm.Session, subsidyWithUser *model.Su
if insertAffected <= 0 {
return errors.New("新增 subsidy_with_user_flow 记录失败")
}

//3、给用户添加余额
//3、加入每月统计
if experienceIntegralValue > 0 {
var subsidyWitUserMonth = &model.SubsidyWithUserMonth{
Uid: subsidyWithUser.Uid,
Amount: zhios_order_relate_utils.Float64ToStr(experienceIntegralValue),
Date: now.Format("2006-01"),
}
_, err1 := db.SubsidyWithMonthInsert(session, subsidyWitUserMonth)
if err1 != nil {
return err
}
}
//4、给用户添加余额
orderType := enum.FinUserFlowOrderActionString(md.ExperienceSubsidyOrdActionForFinUserFlow)
var dealUserAmount = md.DealUserAmount{
Kind: "add",


Chargement…
Annuler
Enregistrer