package models import ( "github.com/beego/beego/v2/client/orm" "hongze/hongze_cygx/utils" "time" ) type CygxXzsChooseSend struct { Id int `orm:"column(id);pk"` UserId int `description:"用户ID"` Mobile string `description:"手机号"` Email string `description:"邮箱"` CompanyId int `description:"公司id"` CompanyName string `description:"公司名称"` RealName string `description:"用户实际名称"` IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"` IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"` IsObjective int `description:"是否选择客观推送, 1 是 、 0否"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` AllInYiYao int `description:"是否选择医药全部赛道"` AllInXiaoFei int `description:"是否选择消费全部赛道"` AllInKeJi int `description:"是否选择科技全部赛道"` AllInZhiZao int `description:"是否选择智造全部赛道"` AllInCeLue int `description:"是否选择策略全部赛道"` AllInYanXuan int `description:"是否选择研选全部赛道"` } // 获取提交过推送规则用户的userId func GetCygxXzsChooseSend() (items []*CygxXzsChooseSend, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_xzs_choose_send ` _, err = o.Raw(sql).QueryRows(&items) return } // 获取某个行业勾选全部赛道的用户 func GetCygxXzsChooseSendByAllIn(allIn string) (items []*CygxXzsChooseSend, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_xzs_choose_send WHERE ` + allIn + ` = 1 ` _, err = o.Raw(sql).QueryRows(&items) return } // 修改某个用户的行业是否勾选全部赛道 func UpdateCygxXzsChooseSendIsAllIn(allIn string, isAllIn, userId int) (err error) { o := orm.NewOrm() sql := `UPDATE cygx_xzs_choose_send SET ` + allIn + ` = ? WHERE user_id = ?` _, err = o.Raw(sql, isAllIn, userId).Exec() return } type CygxXzsChooseSendResp struct { IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"` IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"` IsObjective int `description:"是否选择客观推送, 1 是 、 0否"` IsPush int `description:"是否接受推送,1是,0否"` List []*ChartPermissionXzsResp } // 获取数量 func GetXzsChooseSendCountByMobile(mobile string) (count int, err error) { o := orm.NewOrm() sql := ` SELECT COUNT(1) AS count FROM cygx_xzs_choose_send WHERE mobile = ? ` err = o.Raw(sql, mobile).QueryRow(&count) return } // 根据用户openid获取token func GetCygxXzsChooseSendByMobile(mobile string) (item *CygxXzsChooseSend, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_xzs_choose_send WHERE mobile=? LIMIT 1 ` err = o.Raw(sql, mobile).QueryRow(&item) return } type SubmitChooseSendFollowTypeResp struct { FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"` List []*SubmitChooseSendFollowTypeList } type SubmitChooseSendFollowTypeList struct { ChartPermissionName string `description:"权限名称"` CheckList []int `description:"所选择的ID"` } // 添加 func AddCygxXzsChooseSendFollow(mobile string, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory, itemsZhouqi []*CygxXzsChooseCategoryZhouqi, industryIds, celueIds, zhouqiIds []int) (err error) { o, err := orm.NewOrm().Begin() if err != nil { return } defer func() { if err == nil { o.Commit() } else { o.Rollback() } }() var sql string if len(industryIds) > 0 { //删除原有的关注记录 sql = `DELETE FROM cygx_industry_fllow WHERE mobile = ? AND industrial_management_id IN (` + utils.GetOrmInReplace(len(industryIds)) + `)` _, err = o.Raw(sql, mobile, industryIds).Exec() if err != nil { return err } } if len(itemsFllow) > 0 { //批量添加新的关注记录 _, err = o.InsertMulti(len(itemsFllow), itemsFllow) if err != nil { return err } } if len(celueIds) > 0 { //删除原有策略报告的关注记录 sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ? AND category_id IN (` + utils.GetOrmInReplace(len(celueIds)) + `) ` _, err = o.Raw(sql, mobile, celueIds).Exec() if err != nil { return err } } if len(itemsCategory) > 0 { //批量添加新的关注记录 _, err = o.InsertMulti(len(itemsCategory), itemsCategory) if err != nil { return err } } if len(zhouqiIds) > 0 { //删除原有周期的关注记录 sql = `DELETE FROM cygx_xzs_choose_category_zhouqi WHERE mobile = ? AND category_id IN (` + utils.GetOrmInReplace(len(zhouqiIds)) + `) ` _, err = o.Raw(sql, mobile, zhouqiIds).Exec() if err != nil { return err } } if len(itemsZhouqi) > 0 { //批量添加新的关注记录 _, err = o.InsertMulti(len(itemsZhouqi), itemsZhouqi) if err != nil { return err } } return } type SubmitChooseSendResp struct { IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"` IsPush int `description:"是否接受推送,1是,0否"` IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"` IsObjective int `description:"是否选择客观推送, 1 是 、 0否"` IndustrialManagementIds []*IndustrialManagementIdResp } type IndustrialManagementIdResp struct { IndustrialManagementIds string `description:"产业ID 多个用 ,隔开"` ChartPermissionId int `description:"权限id"` } // 添加 func AddCygxXzsChooseSendPush(item *CygxXzsChooseSend) (err error) { o := orm.NewOrm() //添加所勾选的消息类型 _, err = o.Insert(item) return } // 修改 func UpdateCygxXzsChooseSendPush(item *CygxXzsChooseSend) (err error) { o := orm.NewOrm() //修改现有的类型 updateParams := make(map[string]interface{}) updateParams["UserId"] = item.UserId updateParams["Mobile"] = item.Mobile updateParams["Email"] = item.Email updateParams["CompanyId"] = item.CompanyId updateParams["CompanyName"] = item.CompanyName updateParams["RealName"] = item.RealName updateParams["ModifyTime"] = time.Now() updateParams["IsRefuse"] = item.IsRefuse updateParams["IsSubjective"] = item.IsSubjective updateParams["IsObjective"] = item.IsObjective ptrStructOrTableName := "cygx_xzs_choose_send" whereParam := map[string]interface{}{"mobile": item.Mobile} qs := o.QueryTable(ptrStructOrTableName) for expr, exprV := range whereParam { qs = qs.Filter(expr, exprV) } _, err = qs.Update(updateParams) return }