package cygx

import (
	"github.com/beego/beego/v2/client/orm"
	"github.com/rdlucklib/rdluck_tools/paging"
	"time"
)

type CygxUserAdminShareHistory struct {
	UserAdminShareHistoryId int       `orm:"column(user_admin_share_history_id);pk";comment:"主键ID"`
	Action                  string    `comment:"动作内容"`
	UserId                  int       `comment:"用户ID"`
	Mobile                  string    `comment:"手机号"`
	Email                   string    `comment:"邮箱"`
	CompanyId               int       `comment:"公司ID"`
	CompanyName             string    `comment:"公司名称"`
	RealName                string    `comment:"用户实际名称"`
	SellerName              string    `comment:"所属销售名称"`
	SellerId                int       `comment:"所属销售ID"`
	ShareId                 int       `comment:"分享人ID"`
	ShareName               string    `comment:"分享人姓名"`
	Source                  string    `comment:"来源（article, activity, login）"`
	SourceId                int       `comment:"来源 ID"`
	SourceTitle             string    `comment:"来源名称，活动或者报告标题"`
	RegisterPlatform        int       `comment:"注册平台（1: 小程序, 2: 网页）"`
	CreateTime              time.Time `comment:"创建时间"`
	ModifyTime              time.Time `comment:"修改时间"`
}

type CygxUserAdminShareHistoryResp struct {
	UserAdminShareHistoryId int    `orm:"column(user_admin_share_history_id);pk";comment:"主键ID"`
	Action                  string `comment:"动作内容"`
	UserId                  int    `comment:"用户ID"`
	Mobile                  string `comment:"手机号"`
	Email                   string `comment:"邮箱"`
	CompanyId               int    `comment:"公司ID"`
	CompanyName             string `comment:"公司名称"`
	RealName                string `comment:"用户实际名称"`
	ShareId                 int    `comment:"分享人ID"`
	ShareName               string `comment:"分享人姓名"`
	Source                  string `comment:"来源（article, activity, login）"`
	SourceId                int    `comment:"来源 ID"`
	SourceTitle             string `comment:"来源名称，活动或者报告标题"`
	RegisterPlatform        int    `comment:"注册平台（1: 小程序, 2: 网页）"`
	RegisterPlatformText    string `comment:"注册平台（1: 小程序, 2: 网页）"`
	CreateTime              string `comment:"创建时间"`
	HttpUrl                 string `comment:"跳转地址"`
}

type GetCygxUserAdminShareHistoryListResp struct {
	Paging *paging.PagingItem `description:"分页数据"`
	List   []*CygxUserAdminShareHistoryResp
}

// 获取数量
func GetCygxUserAdminShareHistoryCount(condition string, pars []interface{}) (count int, err error) {
	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_user_admin_share_history as a WHERE 1= 1  `
	if condition != "" {
		sqlCount += condition
	}
	o := orm.NewOrmUsingDB("hz_cygx")
	err = o.Raw(sqlCount, pars).QueryRow(&count)
	return
}

// 列表
func GetCygxUserAdminShareHistoryList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxUserAdminShareHistoryResp, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT * FROM cygx_user_admin_share_history as a WHERE 1= 1 `
	if condition != "" {
		sql += condition
	}
	sql += ` LIMIT ?,?  `
	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
	return
}
