123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- package cygx
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "hongze/hz_crm_api/utils"
- "strconv"
- "time"
- )
- //用户交流反馈表
- // 权益服务明细表
- type CygxUserFeedback struct {
- UserFeedbackId int `orm:"column(user_feedback_id);pk";comment:"主键id"`
- Content string `comment:"服务内容说明"`
- UserId int `comment:"用户ID"`
- Mobile string `comment:"手机号"`
- Email string `comment:"邮箱"`
- CompanyId int `comment:"公司ID"`
- CompanyName string `comment:"公司名称"`
- RealName string `comment:"用户实际名称"`
- AdminId int `comment:"操作人ID"`
- SellerId int `comment:"操作人ID"`
- CreateTime time.Time `comment:"创建时间"`
- }
- // 权益服务明细表
- type CygxUserFeedbackResp struct {
- UserFeedbackId int `comment:"主键id"`
- Content string `comment:"服务内容说明"`
- CreateTime string `comment:"创建时间"`
- }
- type AddCygxUserFeedbackReq struct {
- Content string `comment:"服务内容说明"`
- UserId int `comment:"用户ID"`
- }
- type CygxUserFeedbackIdReq struct {
- UserFeedbackId int `comment:"UserFeedbackId 主键ID"`
- }
- // 添加
- func AddCygxUserFeedback(item *CygxUserFeedback) (newId int64, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- newId, err = o.Insert(item)
- return
- }
- // 删除数据
- func DeleteCygxUserFeedback(userFeedbackId int) (err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` DELETE FROM cygx_user_feedback WHERE user_feedback_id = ? `
- _, err = o.Raw(sql, userFeedbackId).Exec()
- return
- }
- // 列表
- func GetCygxUserFeedbackListByUserId(userId int) (items []*CygxUserFeedbackResp, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_user_feedback WHERE user_id = ? `
- sql += ` ORDER BY user_feedback_id DESC LIMIT 1000 `
- _, err = o.Raw(sql, userId).QueryRows(&items)
- return
- }
- type CygxCygxUserFeedbackResp struct {
- List []*CygxUserFeedbackResp
- }
- func GetCygxUserFeedbackList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxUserFeedback, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT *
- FROM
- cygx_user_feedback
- WHERE 1 = 1 ` + condition
- sql += ` LIMIT ?,? `
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetCygxUserFeedbackListInit() (items []*CygxUserFeedback, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT *
- FROM
- cygx_user_feedback
- WHERE 1 = 1 `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetCygxUserFeedbackListIni2t() (items []*CygxUserFeedback, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- f.*,
- p.seller_id
- FROM
- cygx_user_feedback AS f
- INNER JOIN weekly_report.company_product AS p ON p.company_id = f.company_id
- AND p.product_id = 2
- WHERE
- admin_id IN ( SELECT admin_id FROM weekly_report.admin WHERE group_id IN ( 68, 72 ) )
- AND user_id IN ( SELECT user_id FROM weekly_report.wx_user WHERE is_maker = 1 )
- AND f.create_time > '2024-07-01'
- AND f.create_time < '2024-10-01'
- ORDER BY
- f.create_time DESC `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取数量
- func GetCygxUserFeedbackCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_feedback WHERE 1= 1 ` + condition
- err = o.Raw(sqlCount, pars).QueryRow(&count)
- return
- }
- // 用户交流反馈
- func GetCygxUserFeedback(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- var sql string
- sql += `SELECT
- r.content as key_word,
- r.user_id,
- r.mobile,
- r.real_name,
- r.company_id,
- r.company_name,
- r.create_time
- FROM
- cygx_user_feedback AS r
- WHERE 1 = 1 ` + condition
- totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
- err = o.Raw(totalSql).QueryRow(&total)
- if err != nil {
- return
- }
- sql += ` ORDER BY create_time DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 用户交流反馈
- func GetCygxUserFeedbackWeekly(condition string, startSize, pageSize int) (total int, items []*UserInteraction, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- var sql string
- sql += `SELECT
- r.content as key_word,
- r.user_id,
- r.mobile,
- r.real_name,
- r.company_id,
- r.company_name,
- r.create_time
- FROM
- cygx_user_feedback AS r
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1 = 1 ` + condition
- databaseName := utils.GetWeeklyDatabase()
- sql = fmt.Sprintf(sql, databaseName)
- totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
- err = o.Raw(totalSql).QueryRow(&total)
- if err != nil {
- return
- }
- sql += ` ORDER BY create_time DESC `
- if startSize > 0 || pageSize > 0 {
- sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
- }
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取数量
- func GetCygxUserFeedbackCountByUserModel(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_feedback as r
- WHERE 1= 1 `
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount, pars).QueryRow(&count)
- return
- }
- // 获取数量
- func GetCygxUserFeedbackCountByUserModelWeekly(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_feedback AS r
- INNER JOIN %s.user_seller_relation AS us ON us.user_id = r.user_id AND us.product_id = 2
- WHERE 1 = 1 `
- databaseName := utils.GetWeeklyDatabase()
- sqlCount = fmt.Sprintf(sqlCount, databaseName)
- if condition != "" {
- sqlCount += condition
- }
- err = o.Raw(sqlCount, pars).QueryRow(&count)
- return
- }
|