package models

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

type CygxChartRecord struct {
	RecordId         int       `orm:"column(record_id);pk"`
	ChartId          int       `description:"图表ID"`
	UserId           int       `description:"用户ID"`
	Mobile           string    `description:"手机号"`
	Email            string    `description:"邮箱"`
	CompanyId        int       `description:"公司id"`
	CompanyName      string    `description:"公司名称"`
	RealName         string    `description:"用户实际名称"`
	CreateTime       time.Time `description:"创建时间"`
	RegisterPlatform int       `description:"来源 1小程序，2：网页"`
}

// 添加历史信息
func AddCygxChartRecord(item *CygxChartRecord) (lastId int64, err error) {
	o := orm.NewOrm()
	lastId, err = o.Insert(item)
	return
}

type CygxChartRecordResp struct {
	ChartId          int    `description:"图表ID"`
	Title            string `description:"标题"`
	UserId           int    `description:"用户ID"`
	Mobile           string `description:"手机号"`
	Email            string `description:"邮箱"`
	CompanyId        int    `description:"公司id"`
	CompanyName      string `description:"公司名称"`
	RealName         string `description:"用户实际名称"`
	CreateTime       string `description:"创建时间"`
	RegisterPlatform int    `description:"来源 1小程序，2：网页"`
	RecordId         int    `description:"来源 1小程序，2：网页"`
}

// 列表
func GetCygxChartRecordListNoLimit(condition string, pars []interface{}) (items []*CygxChartRecordResp, err error) {
	o := orm.NewOrm()
	sql := `SELECT
			a.title,
			a.chart_id,
			b.record_id,
			b.user_id,
			b.real_name,
			b.mobile,
			b.email,
			b.company_id,
			b.company_name,
			b.create_time 
		FROM
			cygx_chart AS a
			INNER JOIN cygx_chart_record AS b ON a.chart_id = b.chart_id    WHERE 1= 1 `
	if condition != "" {
		sql += condition
	}
	_, err = o.Raw(sql, pars).QueryRows(&items)
	return
}
