123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type CygxActivitySpecialTripBill struct {
- Id int `orm:"column(id);pk"`
- UserId int `description:"用户id,多个用,隔开"`
- ActivityId int `description:"活动ID"`
- CreateTime time.Time `description:"创建时间"`
- Mobile string `description:"手机号"`
- Email string `description:"邮箱号"`
- CompanyId int `description:"公司ID"`
- CompanyName string `description:"公司名称"`
- RealName string `description:"用户实际名称"`
- AdminId int `description:"销售/管理员ID"`
- Source int `description:"来源,1小程序,2后台添加, 3开发人员手动添加"`
- BillDetailed float64 `description:"流水明细,判断是进账还是出账"`
- DoType int `description:"操作方式,1报名,2取消报名"`
- RegisterPlatform int `description:"来源 1小程序,2:网页"`
- ChartPermissionId int `description:"行业id"`
- ChartPermissionName string `description:"行业名称"`
- Way int `description:"1报名,取消报名。2到会取消到会 3转正或清零 4取消活动"`
- Content string `description:"内容"`
- Total string `description:"总和"`
- TableSource string `description:"活动类型来源 活动 :activity 、专项调研活动:activityspecial、路演:roadshow"`
- ResearcherId int `description:"研究员id"`
- ResearcherName string `description:"研究员名称"`
- }
- // 添加
- func AddCygxActivitySpecialTripBill(item *CygxActivitySpecialTripBill) (err error) {
- o := orm.NewOrm()
- _, err = o.Insert(item)
- if err != nil {
- return
- }
- return
- }
- func GetCygxActivitySpecialTripBill(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBill, err error) {
- o := orm.NewOrm()
- sql := `SELECT *
- FROM
- cygx_activity_special_trip_bill
- WHERE 1 = 1 ` + condition
- _, err = o.Raw(sql, pars).QueryRows(&item)
- return
- }
- type CygxActivitySpecialTripBillList struct {
- Id int `orm:"column(id);pk"`
- UserId int `description:"用户id,多个用,隔开"`
- ActivityId int `description:"活动ID"`
- CreateTime time.Time `description:"创建时间"`
- Mobile string `description:"手机号"`
- Email string `description:"邮箱号"`
- CompanyId int `description:"公司ID"`
- CompanyName string `description:"公司名称"`
- RealName string `description:"用户实际名称"`
- AdminId int `description:"销售/管理员ID"`
- Source int `description:"来源,1小程序,2后台添加, 3开发人员手动添加"`
- BillDetailed int `description:"流水明细,判断是进账还是出账"`
- DoType int `description:"操作方式,1报名,2取消报名"`
- RegisterPlatform int `description:"来源 1小程序,2:网页"`
- ChartPermissionId int `description:"行业id"`
- ChartPermissionName string `description:"行业名称"`
- Way int `description:"1报名,取消报名。2到会取消到会 3转正或清零 4取消活动"`
- Content string `description:"内容"`
- }
- func GetCygxActivitySpecialTripBillList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBillList, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- b.*
- FROM
- cygx_activity_special_trip_bill AS b
- WHERE
- 1 = 1` + condition
- _, err = o.Raw(sql, pars).QueryRows(&item)
- return
- }
- // 通过查询条件获取详情
- func GetCygxActivitySpecialTripBillByCondition(condition string, pars []interface{}) (item *CygxActivitySpecialTripBill, err error) {
- if condition == "" {
- return
- }
- o := orm.NewOrm()
- sql := `SELECT * FROM cygx_activity_special_trip_bill WHERE 1 = 1 ` + condition
- err = o.Raw(sql, pars).QueryRow(&item)
- return
- }
- // GetCygxActivitySpecialTripBillLastDetialByActivityId 根据活动ID获取最后一条扣点明细
- func GetCygxActivitySpecialTripBillLastDetialByActivityId(activityId, userId int) (item *CygxActivitySpecialTripBill, err error) {
- o := orm.NewOrm()
- sql := `SELECT *
- FROM
- cygx_activity_special_trip_bill
- WHERE 1 = 1 AND activity_id =? AND user_id = ? ORDER BY id DESC LIMIT 1 `
- err = o.Raw(sql, activityId, userId).QueryRow(&item)
- return
- }
- // AddCygxActivitySpecialTripBillMulti 批量添加
- func AddCygxActivitySpecialTripBillMulti(items []*CygxActivitySpecialTripBill, itemsUpdate []*CygxActivitySpecialPermissionPoints) (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_special_permission_points 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
- }
- // 删除
- func DelCygxActivitySpecialTripBillById(id int) (err error) {
- o := orm.NewOrm()
- sql := ` DELETE FROM cygx_activity_special_trip_bill WHERE id = ? `
- _, err = o.Raw(sql, id).Exec()
- return
- }
|