123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- // CygxActivityPointsBill 活动扣点流水表
- type CygxActivityPointsBill struct {
- Id int `gorm:"column:id;primary_key;AUTO_INCREMENT" json:""`
- UserId int `gorm:"column:user_id;NOT NULL" json:""` // 用户ID
- ActivityId int `gorm:"column:activity_id;default:0;NOT NULL" json:""` // 活动ID
- CreateTime time.Time `gorm:"column:create_time" json:""` // 创建时间
- Mobile string `gorm:"column:mobile" json:""` // 手机号
- Email string `gorm:"column:email" json:""` // 邮箱
- CompanyId int `gorm:"column:company_id;default:0" json:""` // 公司ID
- CompanyName string `gorm:"column:company_name" json:""` // 公司名称
- RealName string `gorm:"column:real_name" json:""` // 用户实际名称
- AdminId int `gorm:"column:admin_id;NOT NULL" json:""` // 管理员、销售ID
- Source int `gorm:"column:source;default:1;NOT NULL" json:""` // 来源,1客户端,2后台添加, 3开发人员手动添加、4定时任务
- BillDetailed float64 `gorm:"column:bill_detailed;default:0;NOT NULL" json:""` // 流水明细,判断是进账还是出账
- RegisterPlatform int `gorm:"column:register_platform;default:0;NOT NULL" json:""` // 来源 1小程序,2:网页
- ChartPermissionId int `gorm:"column:chart_permission_id;default:0" json:""` // 表chart_permission中id
- DoType int `gorm:"column:do_type;default:1;NOT NULL" json:""` // 操作方式,1减少,2增加
- Content string `gorm:"column:content" json:""` // 内容说明
- Points float64 `gorm:"column:points;default:0;NOT NULL" json:""` // 公司剩余点数
- }
- // 获取列表
- func GetCygxActivityPointsBillList(condition string, pars []interface{}) (list []*CygxActivityPointsBill, err error) {
- sql := `SELECT * FROM cygx_activity_points_bill WHERE 1= 1 `
- if condition != "" {
- sql += condition
- }
- _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
- return
- }
- // 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:""` // 流水明细,判断是进账还是出账
- }
- // 获取数量
- func GetCygxActivityPointsBillCount(condition string, pars []interface{}) (count int, err error) {
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_points_bill as art WHERE 1= 1 `
- if condition != "" {
- sqlCount += condition
- }
- o := orm.NewOrm()
- err = o.Raw(sqlCount, pars).QueryRow(&count)
- return
- }
- // 通过查询条件获取详情
- func GetCygxActivityPointsBillDetailByCondition(condition string, pars []interface{}) (item *CygxActivityPointsBill, err error) {
- if condition == "" {
- return
- }
- o := orm.NewOrm()
- 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.NewOrm().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.NewOrm().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.NewOrm().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
- }
|