package merchant

import (
	"github.com/beego/beego/v2/client/orm"
	"github.com/beego/beego/v2/core/logs"
	"time"
)

type MerchantLoadInfo struct {
	Id          int
	Status      string
	MerchantUid string
	RoadUid     string
	LoadDate    string
	LoadAmount  float64
	UpdateTime  time.Time
	CreateTime  time.Time
}

const MERCHANT_LOAD_INFO = "merchant_load_info"

func GetMerchantLoadInfoByMap(params map[string]string) []MerchantLoadInfo {
	o := orm.NewOrm()
	qs := o.QueryTable(MERCHANT_LOAD_INFO)
	for k, v := range params {
		if len(v) > 0 {
			qs = qs.Filter(k, v)
		}
	}
	var merchantLoadList []MerchantLoadInfo
	_, err := qs.Limit(-11).All(&merchantLoadList)
	if err != nil {
		logs.Error("get merchant load info fail: ", err)
	}
	return merchantLoadList
}

func IsExistMerchantLoadByParams(params map[string]string) bool {
	o := orm.NewOrm()
	qs := o.QueryTable(MERCHANT_LOAD_INFO)
	for k, v := range params {
		if len(v) > 0 {
			qs = qs.Filter(k, v)
		}
	}

	return qs.Exist()
}
