123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549 |
- package cygx
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- // 活动添加、修改入参
- type ActivitySpecialRep struct {
- ActivityId int `description:"活动ID 等于0新增活动,大于0修改活动"`
- DoType int `description:"操作类型 0,保存 、1,发布"`
- PermissionName string `description:"行业名称"`
- ResearchTheme string `description:"调研主题"`
- ActivityTimeText string `description:"活动预期时间带文字"`
- IndustrialManagementIdS string `description:"产业ID,多个ID用 , 隔开"`
- IndustrialSubjectIdS string `description:"标的ID,多个ID用 , 隔开"`
- CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
- TemporaryLabel string `description:"临时标签"`
- TemporarySubject string `description:"临时标的"`
- Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
- TripImgLink string `description:"行程图片链接"`
- SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
- City string `description:"调研城市"`
- IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0 否 默认0 "`
- }
- // 活动添加、修改入参
- type ActivitySpecialDateRep struct {
- ActivityId int `description:"活动ID"`
- PermissionName string `description:"行业名称"`
- ResearchTheme string `description:"调研主题"`
- ActivityTimeText string `description:"活动预期时间带文字"`
- IndustrialManagementIdS string `description:"产业ID,多个ID用 , 隔开"`
- IndustrialSubjectIdS string `description:"标的ID,多个ID用 , 隔开"`
- CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
- TemporaryLabel string `description:"临时标签"`
- TemporarySubject string `description:"临时标的"`
- Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
- TripImgLink string `description:"行程图片链接"`
- SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
- City string `description:"调研城市"`
- IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0 否 默认0 "`
- DateYmdList []*DateYmdList `description:"时间年月日"`
- Days int `description:"调研天数"`
- Host string `description:"主持人"`
- PersonInCharge string `description:"纪要负责人"`
- LimitPeopleNum int `description:"限制人数数量"`
- TripImgLinkFix string `description:"确定行程之后的图片链接"`
- ActivityTimeTextByDay string `description:"活动预期时间带文字"`
- }
- type DateYmdList struct {
- DateYmd string `description:"时间年月日"`
- DateHmsList []*DateHmsList `description:"时间时分秒"`
- }
- type DateHmsList struct {
- DateHms []string `description:"时间时分秒"`
- }
- // 活动详情
- type ActivitySpecialDetail struct {
- ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
- ChartPermissionId int `description:"行业id"`
- ChartPermissionName string `description:"行业名称"`
- CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
- PublishStatus int `description:"发布状态 1已发布,0未发布"`
- ResearchTheme string `description:"调研主题"`
- ActivityTimeText string `description:"活动预期时间带文字"`
- TemporaryLabel string `description:"临时标签"`
- TemporarySubject string `description:"临时标的"`
- Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
- TripImgLink string `description:"行程图片链接"`
- IndustrialName string `description:"产业名称"`
- IndustrialSubjectName string `description:"标的名称(相关公司)"`
- Label string `description:"标签"`
- CustomerName string `description:"活动可见—套餐类型"`
- SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
- City string `description:"调研城市"`
- IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0 否 默认0 "`
- AdminId int `description:"销售/管理员ID"`
- AdminName string `description:"销售/管理员姓名"`
- ListIndustrial []*IndustrialActivityGroupManagementRep
- ListSubject []*SubjectActivityGroupManagementRep
- Days int `description:"调研天数"`
- Host string `description:"主持人"`
- PersonInCharge string `description:"纪要负责人"`
- LimitPeopleNum int `description:"限制人数数量"`
- TripImgLinkFix string `description:"确定行程之后的图片链接"`
- ActivityTimeTextByDay string `description:"活动预期时间带周日"`
- ActivityTime string `description:"活动预期时间"`
- IsOffline int `description:"是否下线,1已下线,0未下线"`
- DateYmdList []*DateYmdList `description:"时间年月日"`
- IsSubmitMeeting int `description:"是否提交过到会信息 ,1是,0否"`
- LastUpdatedTime time.Time `description:"更新时间"`
- }
- type ActivityDetailSpecialRep struct {
- Detail *ActivityDetail
- ListIndustrial []*IndustrialActivityGroupManagementRep
- ListSubject []*SubjectActivityGroupManagementRep
- }
- // 活动详情
- type CygxActivitySpecial struct {
- ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
- ChartPermissionId int `description:"行业id"`
- ChartPermissionName string `description:"行业名称"`
- CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
- PublishStatus int `description:"发布状态 1已发布,0未发布"`
- ResearchTheme string `description:"调研主题"`
- ActivityTimeText string `description:"活动预期时间带文字"`
- Label string `description:"标签"`
- TemporaryLabel string `description:"临时标签"`
- TemporarySubject string `description:"临时标的"`
- Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
- TripImgLink string `description:"行程图片链接"`
- IndustrialName string `description:"产业名称"`
- IndustrialSubjectName string `description:"标的名称"`
- LastUpdatedTime time.Time `description:"更新时间"`
- CreateTime time.Time `description:"创建时间"`
- SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
- City string `description:"调研城市"`
- IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0否 默认0 "`
- AdminId int `description:"销售/管理员ID"`
- AdminName string `description:"销售/管理员姓名"`
- Days int `description:"调研天数"`
- Host string `description:"主持人"`
- PersonInCharge string `description:"纪要负责人"`
- LimitPeopleNum int `description:"限制人数数量"`
- TripImgLinkFix string `description:"确定行程之后的图片链接"`
- ActivityTimeTextByDay string `description:"活动预期时间带周日"`
- ActivityTime string `description:"活动预期时间"`
- PublishDate string `description:"活动发布时间"`
- ActivityTimeEnd string `description:"活动预期结束时间"`
- IsOffline int `description:"是否下线,1已下线,0未下线"`
- }
- // 添加活动
- func AddActivitySpecial(item *CygxActivitySpecial, industrialActivityItems []*CygxIndustrialActivityGroupManagement, subjectActivityItems []*CygxIndustrialActivityGroupSubject) (newId int64, err error) {
- o := orm.NewOrm()
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- fmt.Println(err)
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- newId, err = to.Insert(item)
- if err != nil {
- return
- }
- //添加关联的产业
- if len(industrialActivityItems) > 0 {
- for _, v := range industrialActivityItems {
- v.ActivityId = int(newId)
- _, err = to.Insert(v)
- if err != nil {
- return
- }
- }
- }
- //添加关联的标的
- if len(subjectActivityItems) > 0 {
- for _, v := range subjectActivityItems {
- v.ActivityId = int(newId)
- _, err = to.Insert(v)
- if err != nil {
- return
- }
- }
- }
- return
- }
- // 通过纪要ID获取活动详情
- func GetAddActivityInfoSpecialById(ActivityId int) (item *ActivitySpecialDetail, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM cygx_activity_special WHERE activity_id=?`
- err = o.Raw(sql, ActivityId).QueryRow(&item)
- return
- }
- // 通过纪要ID获取活动详情
- func GetCustomerName(ids string) (name string, err error) {
- o := orm.NewOrm()
- sql := `SELECT GROUP_CONCAT( DISTINCT c.customer_name SEPARATOR '、' ) AS name
- FROM cygx_customer_type AS c WHERE c.customer_type_id IN (` + ids + `)`
- err = o.Raw(sql).QueryRow(&name)
- return
- }
- // 修改
- func EditActivitySpecial(updateParams map[string]interface{}, item *CygxActivitySpecial, industrialActivityItems []*CygxIndustrialActivityGroupManagement, subjectActivityItems []*CygxIndustrialActivityGroupSubject) (err error) {
- o := orm.NewOrm()
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- fmt.Println(err)
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- activityId := item.ActivityId
- //修改活动信息
- ptrStructOrTableName := "cygx_activity_special"
- whereParam := map[string]interface{}{"activity_id": item.ActivityId}
- qs := to.QueryTable(ptrStructOrTableName)
- for expr, exprV := range whereParam {
- qs = qs.Filter(expr, exprV)
- }
- _, err = qs.Update(updateParams)
- //删除活动关联的产业
- sql := ` DELETE FROM cygx_industrial_activity_group_management WHERE activity_id = ? AND source =2`
- _, err = to.Raw(sql, activityId).Exec()
- if err != nil {
- return
- }
- //删除活动关联的标的
- sql = ` DELETE FROM cygx_industrial_activity_group_subject WHERE activity_id = ? AND source =2`
- _, err = to.Raw(sql, activityId).Exec()
- if err != nil {
- return
- }
- //添加关联的产业
- if len(industrialActivityItems) > 0 {
- for _, v := range industrialActivityItems {
- _, err = to.Insert(v)
- if err != nil {
- return
- }
- }
- }
- //添加关联的标的
- if len(subjectActivityItems) > 0 {
- for _, v := range subjectActivityItems {
- _, err = to.Insert(v)
- if err != nil {
- return
- }
- }
- }
- return
- }
- // 修改
- func EditActivitySpecialStatus(item *CygxActivitySpecial) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE cygx_activity_special SET publish_status=?, last_updated_time=NOW() WHERE activity_id=?`
- _, err = o.Raw(sql, item.PublishStatus, item.ActivityId).Exec()
- return
- }
- // 修改
- func UpdateActivitySpecial(updateParams map[string]interface{}, item *CygxActivitySpecial) (err error) {
- to := orm.NewOrm()
- //修改活动信息
- ptrStructOrTableName := "cygx_activity_special"
- whereParam := map[string]interface{}{"activity_id": item.ActivityId}
- qs := to.QueryTable(ptrStructOrTableName)
- for expr, exprV := range whereParam {
- qs = qs.Filter(expr, exprV)
- }
- _, err = qs.Update(updateParams)
- return
- }
- // 修改是否下线
- func EditActivitySpecialIsOffline(item *CygxActivitySpecial) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE cygx_activity_special SET is_offline=?,publish_status=?, last_updated_time=NOW() WHERE activity_id=?`
- _, err = o.Raw(sql, item.IsOffline, item.PublishStatus, item.ActivityId).Exec()
- return
- }
- // 活动详情
- type CygxActivitySpecialList struct {
- ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
- ResearchTheme string `description:"调研主题"`
- ChartPermissionName string `description:"行业名称"`
- ActivityTimeText string `description:"活动预期时间带文字"`
- ActivityTime string `description:"活动预期时间"`
- ActivityTimeTextByDay string `description:"活动预期时间带周几"`
- LastUpdatedTime string `description:"更新时间"`
- InterestedNum int `description:"感兴趣人数"`
- SignupPeopleNum int `description:"报名人数"`
- PublishStatus int `description:"发布状态 1已发布,0未发布"`
- SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
- City string `description:"调研城市"`
- AdminId int `description:"销售/管理员ID"`
- AdminName string `description:"销售/管理员姓名"`
- IsOffline int `description:"是否下线,1已下线,0未下线"`
- Days int `description:"调研天数"`
- IsDetermineTravel int `orm:"column(days)";description:"是否确定行程,1是,0否"`
- IsShowAttendanceDetails bool `description:"是否展示到会详情"`
- IsShowUpdateMeeting bool `description:"是否展示修改到会情况"`
- IsShowSubmitMeeting bool `description:"是否展示提交到会情况"`
- IsSubmitMeeting int `description:"是否提交过到会信息 ,1是,0否"`
- }
- type GetCygxActivityListSpecialRep struct {
- Paging *paging.PagingItem `description:"分页数据"`
- List []*CygxActivitySpecialList
- }
- // 列表
- func GetActivityListSpecialAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivitySpecialList, err error) {
- o := orm.NewOrm()
- sql := `SELECT (SELECT COUNT(1) FROM cygx_activity_special_signup AS h INNER JOIN wx_user AS u ON u.user_id = h.user_id WHERE h.activity_id=art.activity_id) AS interested_num ,
- (SELECT COUNT(1) FROM cygx_activity_special_trip AS h INNER JOIN wx_user AS u ON u.user_id = h.user_id WHERE h.activity_id=art.activity_id AND h.is_cancel =0 ) AS signup_people_num ,
- art.* FROM cygx_activity_special as art WHERE 1= 1 `
- if condition != "" {
- sql += condition
- }
- sql += ` LIMIT ?,?`
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- // 获取数量
- func GetActivitySpecialCount(condition string, pars []interface{}) (count int, err error) {
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_special as art WHERE 1= 1 `
- if condition != "" {
- sqlCount += condition
- }
- o := orm.NewOrm()
- err = o.Raw(sqlCount, pars).QueryRow(&count)
- return
- }
- // 删除数据
- func DeleteActivitySpecial(activityId int) (err error) {
- o := orm.NewOrm()
- sql := ` DELETE FROM cygx_activity_special WHERE activity_id = ?`
- _, err = o.Raw(sql, activityId).Exec()
- return
- }
- type CygxActivitySpecialSignup struct {
- Id int `orm:"column(id);pk"`
- ActivityId int `description:"活动ID"`
- UserId int `description:"用户ID"`
- CreateTime string `description:"创建时间"`
- Mobile string `description:"手机号"`
- CompanyName string `description:"公司名称"`
- CompanyId int `description:"公司ID"`
- RealName string `description:"姓名"`
- SellerName string `description:"销售姓名"`
- }
- type CygxActivitySpecialSignupListResp struct {
- List []*CygxActivitySpecialSignup
- }
- // 感兴趣列表
- func GetCygxActivitySpecialSignupList(activityId int) (items []*CygxActivitySpecialSignup, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- s.id,
- s.activity_id,
- s.user_id,
- s.mobile,
- s.create_time,
- u.real_name,
- c.company_name,
- ( SELECT p.seller_name FROM company_product AS p WHERE p.company_id = u.company_id AND p.product_id = 2 ) AS seller_name,
- GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS pseller_name
- FROM
- cygx_activity_special_signup AS s
- INNER JOIN wx_user AS u ON u.user_id = s.user_id
- LEFT JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
- LEFT JOIN company_product AS p ON p.company_id = u.company_id
- LEFT JOIN company AS c ON c.company_id = u.company_id
- WHERE
- a.activity_id = ?
- GROUP BY
- s.user_id
- ORDER BY
- s.id DESC`
- _, err = o.Raw(sql, activityId).QueryRows(&items)
- return
- }
- // 获取数量
- func GetCygxActivitySpecialSignupCount(condition string, pars []interface{}) (count int, err error) {
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_special_signup as s INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
- INNER JOIN wx_user AS u ON u.user_id = s.user_id WHERE 1= 1 `
- if condition != "" {
- sqlCount += condition
- }
- o := orm.NewOrm()
- err = o.Raw(sqlCount, pars).QueryRow(&count)
- return
- }
- type CygxActivitySpecialSignupResp struct {
- Id int `orm:"column(id);pk"`
- ActivityId int `description:"活动ID"`
- UserId int `description:"用户ID"`
- CreateTime string `description:"创建时间"`
- Mobile string `description:"手机号"`
- CompanyName string `description:"公司名称"`
- CompanyId int `description:"公司ID"`
- RealName string `description:"姓名"`
- SellerName string `description:"销售姓名"`
- ResearchTheme string `description:"调研主题"`
- Label string `description:"标签"`
- ChartPermissionName string `description:"行业"`
- PublishDate string `description:"发布时间"`
- }
- type CygxActivitySpecialSignupRespList struct {
- List []*CygxActivitySpecialSignupResp
- Paging *paging.PagingItem `description:"分页数据"`
- }
- // 列表
- func GetCygxActivitySpecialSignupListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivitySpecialSignupResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- s.id,
- s.activity_id,
- s.user_id,
- s.create_time,
- s.user_num,
- u.real_name,
- c.company_name,
- c.company_id,
- a.research_theme,
- a.label,
- a.chart_permission_name,
- a.create_time AS publish_date,
- ( SELECT p.seller_name FROM company_product AS p WHERE p.company_id = u.company_id AND p.product_id = 2 ) AS seller_name,
- GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS pseller_name
- FROM
- cygx_activity_special_signup AS s
- INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
- INNER JOIN wx_user AS u ON u.user_id = s.user_id
- LEFT JOIN company_product AS p ON p.company_id = u.company_id
- LEFT JOIN company AS c ON c.company_id = u.company_id
- WHERE
- 1 = 1 `
- if condition != "" {
- sql += condition
- }
- sql += ` LIMIT ?,?`
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- type AdminOpenIdList struct {
- OpenId string `description:"OpenId"`
- UserId int `description:"UserId"`
- Mobile string `description:"手机号"`
- CompanyId int `description:"手机号"`
- }
- // GetAdminOpendidByCompany 通过用户公司ID获取对应销售的openid
- func GetAdminOpendidByCompany(condition string, pars []interface{}) (list []*AdminOpenIdList, err error) {
- sql := `SELECT
- cr.open_id,a.mobile,p.company_id,cr.union_id
- FROM
- company_product AS p
- INNER JOIN admin AS a ON a.admin_id = p.seller_id
- INNER JOIN user_record as c ON c.bind_account = a.mobile
- INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
- WHERE
- 1 = 1
- AND p.product_id = 2
- AND create_platform = 4 ` + condition
- _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
- return
- }
- // 获取预约活动的用户的openID
- func GetActivitySpecialOpenIdList() (items []*AdminOpenIdList, err error) {
- sql := `SELECT DISTINCT cr.open_id,u.user_id,m.company_id
- FROM
- cygx_user_follow_special AS m
- INNER JOIN user_record AS u ON u.bind_account = m.mobile
- INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
- WHERE u.create_platform = 4 `
- _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
- return
- }
- func GetActivitySpecialByIndustryIds(condition string, pars []interface{}) (list []*CygxActivitySpecialSignup, err error) {
- sql := `SELECT
- m.activity_id
- FROM
- cygx_industrial_activity_group_management AS m
- INNER JOIN cygx_activity_special AS a ON a.activity_id = m.activity_id
- WHERE
- 1= 1
- AND m.source = 2
- AND a.publish_status = 1 AND a.is_offline = 0 AND a.days >0 ` + condition
- _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
- return
- }
- func GetWxOpenIdByMobileList(condition string, pars []interface{}) (items []*OpenIdList, err error) {
- sql := `SELECT cr.*,user_id FROM user_record as c
- INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
- WHERE 1= 1 AND create_platform = 4 ` + condition
- _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&items)
- return
- }
- func GetWxOpenIdBList(condition string, pars []interface{}) (items []*OpenIdList, err error) {
- sql := `SELECT
- cr.*,
- u.user_id
- FROM
- cygx_user_record AS cr
- INNER JOIN user_record AS c ON c.union_id = cr.union_id
- INNER JOIN wx_user AS u ON u.user_id = c.user_id
- WHERE
- 1 = 1
- AND c.create_platform = 4 ` + condition + ` GROUP BY cr.open_id `
- _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&items)
- return
- }
- // 通过产业名称获取关联的ID
- func GetactivitySpecilIdsByLabel(name string) (activityIds string, err error) {
- sql := ` SELECT
- GROUP_CONCAT( DISTINCT s.activity_id SEPARATOR ',' ) AS activityIds
- FROM
- cygx_activity_special AS s
- WHERE
- label LIKE '%` + name + `%' `
- o := orm.NewOrm()
- err = o.Raw(sql).QueryRow(&activityIds)
- return
- }
|