You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.2 KiB
62 lines
2.2 KiB
package user
|
|
|
|
import (
|
|
"github.com/jinzhu/gorm"
|
|
"github.com/shopspring/decimal"
|
|
"recook/internal/v2/lib/db"
|
|
)
|
|
|
|
type RecookUserDayIncomeModel struct {
|
|
db.BaseModel
|
|
Id uint `gorm:"column:id;primary_key" json:"id"`
|
|
UserId uint `json:"userId"`
|
|
Day int `json:"day"`
|
|
PurchaseAmount decimal.Decimal `json:"purchaseAmount"`
|
|
PurchaseCount int `json:"purchaseCount"`
|
|
PurchaseSalesVolume decimal.Decimal `json:"purchaseSalesVolume"`
|
|
GuideAmount decimal.Decimal `json:"guideAmount"`
|
|
GuideCount uint `json:"guideCount"`
|
|
GuideSalesVolume decimal.Decimal `json:"guideSalesVolume"`
|
|
}
|
|
|
|
// TableName sets the insert table name for this struct type
|
|
func (r *RecookUserDayIncomeModel) TableName() string {
|
|
return "recook_user_day_income"
|
|
}
|
|
|
|
// @Style 查询单条信息
|
|
func (r *RecookUserDayIncomeModel) FindByUserIdAndDay(userId uint, day int) (info RecookUserDayIncomeModel) {
|
|
r.GetDb().First(&info, "user_id = ? and day = ?", userId, day)
|
|
return
|
|
}
|
|
|
|
// @Style 添加
|
|
func (r *RecookUserDayIncomeModel) Create(data *RecookUserDayIncomeModel) {
|
|
r.GetDb().Create(data)
|
|
}
|
|
|
|
// @Style 添加
|
|
func (r *RecookUserDayIncomeModel) CreateSubQuery(fields string, sql *gorm.SqlExpr) error {
|
|
return r.GetDb().Exec("insert into recook_user_day_income("+fields+") ?", sql).Error
|
|
}
|
|
|
|
// @Style 编辑
|
|
func (r *RecookUserDayIncomeModel) Updates(value interface{}, query interface{}, args ...interface{}) error {
|
|
return r.GetDb().Model(&RecookUserDayIncomeModel{}).Where(query, args...).Updates(value).Error
|
|
}
|
|
|
|
// @Style 统计团队总销售额
|
|
func (r *RecookUserDayIncomeModel) GetTeamAmoutSum(query interface{}, args ...interface{}) (result RecookUserDayIncomeModel) {
|
|
r.GetDb().Model(RecookUserDayIncomeModel{}).
|
|
Select("sum(amount) as amount").
|
|
Where(query, args...).
|
|
First(&result)
|
|
return
|
|
}
|
|
|
|
// @Style 根据userId 和 date获取数据
|
|
func (r *RecookUserDayIncomeModel) FindByUserIdMonth(userId uint, month int) (result []RecookUserDayIncomeModel) {
|
|
r.GetDb().Model(&RecookUserDayIncomeModel{}).Order("id desc").Find(&result, "user_id = ? and day between ? and ?", userId, month*100, month*100+12)
|
|
return
|
|
}
|