123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package cygx
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- // CygxActivityPointsBill 活动扣点流水表
- type CygxActivityPointsBill struct {
- Id int `gorm:"column:id;primary_key;AUTO_INCREMENT" json:"id"`
- UserId int `gorm:"column:user_id;NOT NULL" json:"user_id"` // 用户ID
- ActivityId int `gorm:"column:activity_id;default:0;NOT NULL" json:"activity_id"` // 活动ID
- CreateTime time.Time `gorm:"column:create_time" json:"create_time"` // 创建时间
- Mobile string `gorm:"column:mobile" json:"mobile"` // 手机号
- Email string `gorm:"column:email" json:"email"` // 邮箱
- CompanyId int `gorm:"column:company_id;default:0" json:"company_id"` // 公司ID
- CompanyName string `gorm:"column:company_name" json:"company_name"` // 公司名称
- RealName string `gorm:"column:real_name" json:"real_name"` // 用户实际名称
- AdminId int64 `gorm:"column:admin_id;NOT NULL" json:"admin_id"` // 管理员、销售ID
- Source int `gorm:"column:source;default:1;NOT NULL" json:"source"` // 来源,1客户端,2后台添加, 3开发人员手动添加、4定时任务
- BillDetailed float64 `gorm:"column:bill_detailed;default:0;NOT NULL" json:"bill_detailed"` // 流水明细,判断是进账还是出账
- RegisterPlatform int `gorm:"column:register_platform;default:0;NOT NULL" json:"register_platform"` // 来源 1小程序,2:网页
- ChartPermissionId int `gorm:"column:chart_permission_id;default:0" json:"chart_permission_id"` // 表chart_permission中id
- DoType int `gorm:"column:do_type;default:1;NOT NULL" json:"do_type"` // 操作方式,1报名,2取消报名
- Content string `gorm:"column:content" json:"content"` // 内容说明
- Points float64 `gorm:"column:points;default:0;NOT NULL" json:"points"` // 公司剩余点数
- }
- // CompanyTryOutDayListResp 客户累计试用天数
- type CygxActivityPointsBillListResp struct {
- List []*CygxActivityPointsBillResp
- }
- type CygxActivityPointsBillResp struct {
- Id int `gorm:"column:id;primary_key;AUTO_INCREMENT"`
- Content string `gorm:"column:content" ` // 内容说明
- Points float64 `gorm:"column:points;default:0;NOT NULL" ` // 公司剩余点数
- CreateTime string `gorm:"column:create_time" ` // 创建时间
- CompanyId int `gorm:"column:company_id;default:0" ` // 公司ID
- CompanyName string `gorm:"column:company_name" ` // 公司名称
- RealName string `gorm:"column:real_name"` // 用户实际名称
- BillDetailed float64 `gorm:"column:bill_detailed;default:0;NOT NULL" json:""` // 流水明细,判断是进账还是出账
- }
- // CygxActivityPointsBillByCompanyId 根据公司名称获取机构流水表
- func CygxActivityPointsBillByCompanyId(companyId int) (items []*CygxActivityPointsBillResp, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT * FROM cygx_activity_points_bill WHERE company_id =? ORDER BY id DESC `
- _, err = o.Raw(sql, companyId).QueryRows(&items)
- return
- }
- // 通过查询条件获取详情
- func GetCygxActivityPointsBillDetailByCondition(condition string, pars []interface{}) (item *CygxActivityPointsBill, err error) {
- if condition == "" {
- return
- }
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_activity_points_bill WHERE 1 = 1 ` + condition
- err = o.Raw(sql, pars).QueryRow(&item)
- return
- }
- // AddCygxActivityPointsBillMulti 批量添加
- func AddCygxActivityPointsBillMulti(items []*CygxActivityPointsBill, itemsUpdate []*CygxActivityPointsCompany) (err error) {
- o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
- if err != nil {
- return
- }
- defer func() {
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- if len(items) > 0 {
- //批量添加流水信息
- _, err = o.InsertMulti(len(items), items)
- }
- //批量修改公司剩余点数
- p, err := o.Raw("UPDATE cygx_activity_points_company SET points = ?, modify_time = ? WHERE company_id = ?").Prepare()
- if err != nil {
- return
- }
- defer func() {
- _ = p.Close() // 别忘记关闭 statement
- }()
- for _, v := range itemsUpdate {
- _, err = p.Exec(v.Points, v.ModifyTime, v.CompanyId)
- if err != nil {
- return
- }
- }
- return
- }
- // AddCygxActivityPointsBillAndCompanyMulti 批量添加
- func AddCygxActivityPointsBillAndCompanyMulti(items []*CygxActivityPointsBill, itemsCompany []*CygxActivityPointsCompany) (err error) {
- o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
- if err != nil {
- return
- }
- defer func() {
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- if len(items) > 0 {
- //批量添加流水信息
- _, err = o.InsertMulti(len(items), items)
- }
- if len(itemsCompany) > 0 {
- //批量添加流水信息
- _, err = o.InsertMulti(len(itemsCompany), itemsCompany)
- }
- return
- }
- // UpdateCygxActivityPointsBillMulti 批量修改
- func UpdateCygxActivityPointsBillMulti(items []*CygxActivityPointsBill, itemsUpdate []*CygxActivityPointsCompany) (err error) {
- o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
- if err != nil {
- return
- }
- defer func() {
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- //批量修改公司剩余点数
- p, err := o.Raw("UPDATE cygx_activity_points_bill SET points = ?, bill_detailed = ? WHERE id = ?").Prepare()
- if err != nil {
- return
- }
- defer func() {
- _ = p.Close() // 别忘记关闭 statement
- }()
- for _, v := range items {
- _, err = p.Exec(v.Points, v.BillDetailed, v.Id)
- if err != nil {
- return
- }
- }
- //批量修改公司剩余点数
- p, err = o.Raw("UPDATE cygx_activity_points_company SET points = ?, modify_time = ? WHERE company_id = ?").Prepare()
- if err != nil {
- return
- }
- defer func() {
- _ = p.Close() // 别忘记关闭 statement
- }()
- for _, v := range itemsUpdate {
- _, err = p.Exec(v.Points, v.ModifyTime, v.CompanyId)
- if err != nil {
- return
- }
- }
- return
- }
|