order_base.go 2.1 KB
package models

import (
	"context"
	"time"

	"github.com/go-pg/pg/v10"
	"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)

//OrderBase 订单基础
type OrderBase struct {
	tableName struct{} `pg:"order_base"`
	//表id
	Id int64 `pg:",pk"`
	//订单类型
	OrderType int
	//订单编号
	OrderCode string
	//交货编号
	DeliveryCode string
	//买家
	Buyer domain.Buyer
	//订单区域信息
	RegionInfo domain.RegionInfo
	//订单对应的合伙人
	PartnerId int64
	//业务员抽成比例
	SalesmanBonusPercent float64 `pg:",use_zero"`
	//业务员抽成
	SalesmanBonus float64 `pg:",use_zero"`
	//预计的订单内货品总数
	PlanOrderCount int `pg:",use_zero"`
	//预计的订单的总金额
	PlanOrderAmount float64 `pg:",use_zero"`
	//按需使用的订单内货品总数 (初始值=-1)
	//业务判定时0是有效值,负值无效
	UseOrderCount int `pg:",use_zero"`
	//按需使用的订单内货总金额 (初始值=-1)
	//业务判定时0是有效值,负值无效
	UseOrderAmount float64 `pg:",use_zero"`
	//订单的创建时间
	CreateTime time.Time
	//发货时间
	DeliveryTime time.Time
	//更新时间
	UpdateTime time.Time
	//合伙人应收分红
	PlanPartnerBonus float64 `pg:",use_zero"`
	//调整后的合伙人应收分红 (初始值=-1);
	//业务判定时0是有效值,负值无效
	UsePartnerBonus float64 `pg:",use_zero"`
	//合伙人已收分红
	PartnerBonusHas float64 `pg:",use_zero"`
	//合伙人未收分红
	PartnerBonusNot float64
	//合伙人分红支出
	PartnerBonusExpense float64 `pg:",use_zero"`
	//上一次查看时间 已读情况
	LastViewTime time.Time
	//是否关闭订单
	IsDisable int `pg:",use_zero"`
	//分红支付状态
	BonusStatus int
	CompanyId   int64

	//数据来源
	DataFrom domain.OrderDataFrom ``
}

var _ pg.BeforeUpdateHook = (*OrderBase)(nil)

func (order *OrderBase) BeforeUpdate(ctx context.Context) (context.Context, error) {
	order.UpdateTime = time.Now()
	return ctx, nil
}

var _ pg.BeforeInsertHook = (*OrderBase)(nil)

func (order *OrderBase) BeforeInsert(ctx context.Context) (context.Context, error) {
	order.CreateTime = time.Now()
	order.UpdateTime = time.Now()
	return ctx, nil
}