activity_special.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. package cygx
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. // 活动添加、修改入参
  9. type ActivitySpecialRep struct {
  10. ActivityId int `description:"活动ID 等于0新增活动,大于0修改活动"`
  11. DoType int `description:"操作类型 0,保存 、1,发布"`
  12. PermissionName string `description:"行业名称"`
  13. ResearchTheme string `description:"调研主题"`
  14. ActivityTimeText string `description:"活动预期时间带文字"`
  15. IndustrialManagementIdS string `description:"产业ID,多个ID用 , 隔开"`
  16. IndustrialSubjectIdS string `description:"标的ID,多个ID用 , 隔开"`
  17. CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
  18. TemporaryLabel string `description:"临时标签"`
  19. TemporarySubject string `description:"临时标的"`
  20. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  21. TripImgLink string `description:"行程图片链接"`
  22. SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
  23. City string `description:"调研城市"`
  24. IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0 否 默认0 "`
  25. }
  26. // 活动添加、修改入参
  27. type ActivitySpecialDateRep struct {
  28. ActivityId int `description:"活动ID"`
  29. PermissionName string `description:"行业名称"`
  30. ResearchTheme string `description:"调研主题"`
  31. ActivityTimeText string `description:"活动预期时间带文字"`
  32. IndustrialManagementIdS string `description:"产业ID,多个ID用 , 隔开"`
  33. IndustrialSubjectIdS string `description:"标的ID,多个ID用 , 隔开"`
  34. CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
  35. TemporaryLabel string `description:"临时标签"`
  36. TemporarySubject string `description:"临时标的"`
  37. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  38. TripImgLink string `description:"行程图片链接"`
  39. SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
  40. City string `description:"调研城市"`
  41. IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0 否 默认0 "`
  42. DateYmdList []*DateYmdList `description:"时间年月日"`
  43. Days int `description:"调研天数"`
  44. Host string `description:"主持人"`
  45. PersonInCharge string `description:"纪要负责人"`
  46. LimitPeopleNum int `description:"限制人数数量"`
  47. TripImgLinkFix string `description:"确定行程之后的图片链接"`
  48. ActivityTimeTextByDay string `description:"活动预期时间带文字"`
  49. }
  50. type DateYmdList struct {
  51. DateYmd string `description:"时间年月日"`
  52. DateHmsList []*DateHmsList `description:"时间时分秒"`
  53. }
  54. type DateHmsList struct {
  55. DateHms []string `description:"时间时分秒"`
  56. }
  57. // 活动详情
  58. type ActivitySpecialDetail struct {
  59. ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
  60. ChartPermissionId int `description:"行业id"`
  61. ChartPermissionName string `description:"行业名称"`
  62. CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
  63. PublishStatus int `description:"发布状态 1已发布,0未发布"`
  64. ResearchTheme string `description:"调研主题"`
  65. ActivityTimeText string `description:"活动预期时间带文字"`
  66. TemporaryLabel string `description:"临时标签"`
  67. TemporarySubject string `description:"临时标的"`
  68. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  69. TripImgLink string `description:"行程图片链接"`
  70. IndustrialName string `description:"产业名称"`
  71. IndustrialSubjectName string `description:"标的名称(相关公司)"`
  72. Label string `description:"标签"`
  73. CustomerName string `description:"活动可见—套餐类型"`
  74. SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
  75. City string `description:"调研城市"`
  76. IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0 否 默认0 "`
  77. AdminId int `description:"销售/管理员ID"`
  78. AdminName string `description:"销售/管理员姓名"`
  79. ListIndustrial []*IndustrialActivityGroupManagementRep
  80. ListSubject []*SubjectActivityGroupManagementRep
  81. Days int `description:"调研天数"`
  82. Host string `description:"主持人"`
  83. PersonInCharge string `description:"纪要负责人"`
  84. LimitPeopleNum int `description:"限制人数数量"`
  85. TripImgLinkFix string `description:"确定行程之后的图片链接"`
  86. ActivityTimeTextByDay string `description:"活动预期时间带周日"`
  87. ActivityTime string `description:"活动预期时间"`
  88. IsOffline int `description:"是否下线,1已下线,0未下线"`
  89. DateYmdList []*DateYmdList `description:"时间年月日"`
  90. IsSubmitMeeting int `description:"是否提交过到会信息 ,1是,0否"`
  91. LastUpdatedTime time.Time `description:"更新时间"`
  92. PublishDate string `description:"发布时间"`
  93. }
  94. type ActivityDetailSpecialRep struct {
  95. Detail *ActivityDetail
  96. ListIndustrial []*IndustrialActivityGroupManagementRep
  97. ListSubject []*SubjectActivityGroupManagementRep
  98. }
  99. // 活动详情
  100. type CygxActivitySpecial struct {
  101. ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
  102. ChartPermissionId int `description:"行业id"`
  103. ChartPermissionName string `description:"行业名称"`
  104. CustomerTypeIds string `description:"活动可见的客户类型,多个ID用 , 隔开"`
  105. PublishStatus int `description:"发布状态 1已发布,0未发布"`
  106. ResearchTheme string `description:"调研主题"`
  107. ActivityTimeText string `description:"活动预期时间带文字"`
  108. Label string `description:"标签"`
  109. TemporaryLabel string `description:"临时标签"`
  110. TemporarySubject string `description:"临时标的"`
  111. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  112. TripImgLink string `description:"行程图片链接"`
  113. IndustrialName string `description:"产业名称"`
  114. IndustrialSubjectName string `description:"标的名称"`
  115. LastUpdatedTime time.Time `description:"更新时间"`
  116. CreateTime time.Time `description:"创建时间"`
  117. SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
  118. City string `description:"调研城市"`
  119. IsShowSubjectName int `description:"小程序内是否展示标的名称 1是 ,0否 默认0 "`
  120. AdminId int `description:"销售/管理员ID"`
  121. AdminName string `description:"销售/管理员姓名"`
  122. Days int `description:"调研天数"`
  123. Host string `description:"主持人"`
  124. PersonInCharge string `description:"纪要负责人"`
  125. LimitPeopleNum int `description:"限制人数数量"`
  126. TripImgLinkFix string `description:"确定行程之后的图片链接"`
  127. ActivityTimeTextByDay string `description:"活动预期时间带周日"`
  128. ActivityTime string `description:"活动预期时间"`
  129. PublishDate string `description:"活动发布时间"`
  130. ActivityTimeEnd string `description:"活动预期结束时间"`
  131. IsOffline int `description:"是否下线,1已下线,0未下线"`
  132. }
  133. // 添加活动
  134. func AddActivitySpecial(item *CygxActivitySpecial, industrialActivityItems []*CygxIndustrialActivityGroupManagement, subjectActivityItems []*CygxIndustrialActivityGroupSubject) (newId int64, err error) {
  135. o := orm.NewOrmUsingDB("hz_cygx")
  136. to, err := o.Begin()
  137. if err != nil {
  138. return
  139. }
  140. defer func() {
  141. if err != nil {
  142. fmt.Println(err)
  143. _ = to.Rollback()
  144. } else {
  145. _ = to.Commit()
  146. }
  147. }()
  148. newId, err = to.Insert(item)
  149. if err != nil {
  150. return
  151. }
  152. //添加关联的产业
  153. if len(industrialActivityItems) > 0 {
  154. for _, v := range industrialActivityItems {
  155. v.ActivityId = int(newId)
  156. _, err = to.Insert(v)
  157. if err != nil {
  158. return
  159. }
  160. }
  161. }
  162. //添加关联的标的
  163. if len(subjectActivityItems) > 0 {
  164. for _, v := range subjectActivityItems {
  165. v.ActivityId = int(newId)
  166. _, err = to.Insert(v)
  167. if err != nil {
  168. return
  169. }
  170. }
  171. }
  172. return
  173. }
  174. // 通过纪要ID获取活动详情
  175. func GetAddActivityInfoSpecialById(ActivityId int) (item *ActivitySpecialDetail, err error) {
  176. o := orm.NewOrmUsingDB("hz_cygx")
  177. sql := `SELECT * FROM cygx_activity_special WHERE activity_id=?`
  178. err = o.Raw(sql, ActivityId).QueryRow(&item)
  179. return
  180. }
  181. // 通过纪要ID获取活动详情
  182. func GetCustomerName(ids string) (name string, err error) {
  183. o := orm.NewOrmUsingDB("hz_cygx")
  184. sql := `SELECT GROUP_CONCAT( DISTINCT c.customer_name SEPARATOR '、' ) AS name
  185. FROM cygx_customer_type AS c WHERE c.customer_type_id IN (` + ids + `)`
  186. err = o.Raw(sql).QueryRow(&name)
  187. return
  188. }
  189. // 修改
  190. func EditActivitySpecial(updateParams map[string]interface{}, item *CygxActivitySpecial, industrialActivityItems []*CygxIndustrialActivityGroupManagement, subjectActivityItems []*CygxIndustrialActivityGroupSubject) (err error) {
  191. o := orm.NewOrmUsingDB("hz_cygx")
  192. to, err := o.Begin()
  193. if err != nil {
  194. return
  195. }
  196. defer func() {
  197. if err != nil {
  198. fmt.Println(err)
  199. _ = to.Rollback()
  200. } else {
  201. _ = to.Commit()
  202. }
  203. }()
  204. activityId := item.ActivityId
  205. //修改活动信息
  206. ptrStructOrTableName := "cygx_activity_special"
  207. whereParam := map[string]interface{}{"activity_id": item.ActivityId}
  208. qs := to.QueryTable(ptrStructOrTableName)
  209. for expr, exprV := range whereParam {
  210. qs = qs.Filter(expr, exprV)
  211. }
  212. _, err = qs.Update(updateParams)
  213. //删除活动关联的产业
  214. sql := ` DELETE FROM cygx_industrial_activity_group_management WHERE activity_id = ? AND source =2`
  215. _, err = to.Raw(sql, activityId).Exec()
  216. if err != nil {
  217. return
  218. }
  219. //删除活动关联的标的
  220. sql = ` DELETE FROM cygx_industrial_activity_group_subject WHERE activity_id = ? AND source =2`
  221. _, err = to.Raw(sql, activityId).Exec()
  222. if err != nil {
  223. return
  224. }
  225. //添加关联的产业
  226. if len(industrialActivityItems) > 0 {
  227. for _, v := range industrialActivityItems {
  228. _, err = to.Insert(v)
  229. if err != nil {
  230. return
  231. }
  232. }
  233. }
  234. //添加关联的标的
  235. if len(subjectActivityItems) > 0 {
  236. for _, v := range subjectActivityItems {
  237. _, err = to.Insert(v)
  238. if err != nil {
  239. return
  240. }
  241. }
  242. }
  243. return
  244. }
  245. // 修改
  246. func EditActivitySpecialStatus(item *CygxActivitySpecial) (err error) {
  247. o := orm.NewOrmUsingDB("hz_cygx")
  248. sql := `UPDATE cygx_activity_special SET publish_status=?, last_updated_time=NOW() WHERE activity_id=?`
  249. _, err = o.Raw(sql, item.PublishStatus, item.ActivityId).Exec()
  250. return
  251. }
  252. // 修改
  253. func UpdateActivitySpecial(updateParams map[string]interface{}, item *CygxActivitySpecial) (err error) {
  254. to := orm.NewOrmUsingDB("hz_cygx")
  255. //修改活动信息
  256. ptrStructOrTableName := "cygx_activity_special"
  257. whereParam := map[string]interface{}{"activity_id": item.ActivityId}
  258. qs := to.QueryTable(ptrStructOrTableName)
  259. for expr, exprV := range whereParam {
  260. qs = qs.Filter(expr, exprV)
  261. }
  262. _, err = qs.Update(updateParams)
  263. return
  264. }
  265. // 修改是否下线
  266. func EditActivitySpecialIsOffline(item *CygxActivitySpecial) (err error) {
  267. o := orm.NewOrmUsingDB("hz_cygx")
  268. sql := `UPDATE cygx_activity_special SET is_offline=?,publish_status=?, last_updated_time=NOW() WHERE activity_id=?`
  269. _, err = o.Raw(sql, item.IsOffline, item.PublishStatus, item.ActivityId).Exec()
  270. return
  271. }
  272. // 活动详情
  273. type CygxActivitySpecialList struct {
  274. ActivityId int `orm:"column(activity_id);pk";description:"活动ID 等于0新增活动,大于0修改活动"`
  275. ResearchTheme string `description:"调研主题"`
  276. ChartPermissionName string `description:"行业名称"`
  277. ActivityTimeText string `description:"活动预期时间带文字"`
  278. ActivityTime string `description:"活动预期时间"`
  279. ActivityTimeTextByDay string `description:"活动预期时间带周几"`
  280. LastUpdatedTime string `description:"更新时间"`
  281. InterestedNum int `description:"感兴趣人数"`
  282. SignupPeopleNum int `description:"报名人数"`
  283. PublishStatus int `description:"发布状态 1已发布,0未发布"`
  284. SpecialType int `description:"调研形式、 1 线上 , 2 线下"`
  285. City string `description:"调研城市"`
  286. AdminId int `description:"销售/管理员ID"`
  287. AdminName string `description:"销售/管理员姓名"`
  288. IsOffline int `description:"是否下线,1已下线,0未下线"`
  289. Days int `description:"调研天数"`
  290. IsDetermineTravel int `orm:"column(days)";description:"是否确定行程,1是,0否"`
  291. IsShowAttendanceDetails bool `description:"是否展示到会详情"`
  292. IsShowUpdateMeeting bool `description:"是否展示修改到会情况"`
  293. IsShowSubmitMeeting bool `description:"是否展示提交到会情况"`
  294. IsSubmitMeeting int `description:"是否提交过到会信息 ,1是,0否"`
  295. }
  296. type GetCygxActivityListSpecialRep struct {
  297. Paging *paging.PagingItem `description:"分页数据"`
  298. List []*CygxActivitySpecialList
  299. }
  300. // 列表
  301. func GetActivityListSpecialAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivitySpecialList, err error) {
  302. o := orm.NewOrmUsingDB("hz_cygx")
  303. sql := `SELECT (SELECT COUNT(1) FROM cygx_activity_special_signup AS h WHERE h.activity_id=art.activity_id) AS interested_num ,
  304. (SELECT COUNT(1) FROM cygx_activity_special_trip AS h WHERE h.activity_id=art.activity_id AND h.is_cancel =0 ) AS signup_people_num ,
  305. art.* FROM cygx_activity_special as art WHERE 1= 1 `
  306. if condition != "" {
  307. sql += condition
  308. }
  309. sql += ` LIMIT ?,?`
  310. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  311. return
  312. }
  313. // 获取数量
  314. func GetActivitySpecialCount(condition string, pars []interface{}) (count int, err error) {
  315. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_special as art WHERE 1= 1 `
  316. if condition != "" {
  317. sqlCount += condition
  318. }
  319. o := orm.NewOrmUsingDB("hz_cygx")
  320. err = o.Raw(sqlCount, pars).QueryRow(&count)
  321. return
  322. }
  323. // 删除数据
  324. func DeleteActivitySpecial(activityId int) (err error) {
  325. o := orm.NewOrmUsingDB("hz_cygx")
  326. sql := ` DELETE FROM cygx_activity_special WHERE activity_id = ?`
  327. _, err = o.Raw(sql, activityId).Exec()
  328. return
  329. }
  330. type CygxActivitySpecialSignup struct {
  331. Id int `orm:"column(id);pk"`
  332. ActivityId int `description:"活动ID"`
  333. UserId int `description:"用户ID"`
  334. CreateTime string `description:"创建时间"`
  335. Mobile string `description:"手机号"`
  336. CompanyName string `description:"公司名称"`
  337. CompanyId int `description:"公司ID"`
  338. RealName string `description:"姓名"`
  339. SellerName string `description:"销售姓名"`
  340. }
  341. type CygxActivitySpecialSignupListResp struct {
  342. List []*CygxActivitySpecialSignup
  343. }
  344. // 感兴趣列表
  345. func GetCygxActivitySpecialSignupList(activityId int) (items []*CygxActivitySpecialSignup, err error) {
  346. o := orm.NewOrmUsingDB("hz_cygx")
  347. sql := `SELECT
  348. s.*
  349. FROM
  350. cygx_activity_special_signup AS s
  351. LEFT JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  352. WHERE
  353. a.activity_id = ?
  354. GROUP BY
  355. s.user_id
  356. ORDER BY
  357. s.id DESC`
  358. _, err = o.Raw(sql, activityId).QueryRows(&items)
  359. return
  360. }
  361. // 获取数量
  362. func GetCygxActivitySpecialSignupCount(condition string, pars []interface{}) (count int, err error) {
  363. 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
  364. WHERE 1= 1 `
  365. if condition != "" {
  366. sqlCount += condition
  367. }
  368. o := orm.NewOrmUsingDB("hz_cygx")
  369. err = o.Raw(sqlCount, pars).QueryRow(&count)
  370. return
  371. }
  372. type CygxActivitySpecialSignupResp struct {
  373. Id int `orm:"column(id);pk"`
  374. ActivityId int `description:"活动ID"`
  375. UserId int `description:"用户ID"`
  376. CreateTime string `description:"创建时间"`
  377. Mobile string `description:"手机号"`
  378. CompanyName string `description:"公司名称"`
  379. CompanyId int `description:"公司ID"`
  380. RealName string `description:"姓名"`
  381. SellerName string `description:"销售姓名"`
  382. ResearchTheme string `description:"调研主题"`
  383. Label string `description:"标签"`
  384. ChartPermissionName string `description:"行业"`
  385. PublishDate string `description:"发布时间"`
  386. }
  387. type CygxActivitySpecialSignupRespList struct {
  388. List []*CygxActivitySpecialSignupResp
  389. Paging *paging.PagingItem `description:"分页数据"`
  390. }
  391. // 列表
  392. func GetCygxActivitySpecialSignupListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivitySpecialSignupResp, err error) {
  393. o := orm.NewOrmUsingDB("hz_cygx")
  394. sql := `SELECT
  395. s.*,
  396. a.research_theme,
  397. a.label,
  398. a.chart_permission_name,
  399. a.create_time AS publish_date
  400. FROM
  401. cygx_activity_special_signup AS s
  402. INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
  403. WHERE
  404. 1 = 1 `
  405. if condition != "" {
  406. sql += condition
  407. }
  408. sql += ` LIMIT ?,?`
  409. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  410. return
  411. }
  412. type AdminOpenIdList struct {
  413. OpenId string `description:"OpenId"`
  414. UserId int `description:"UserId"`
  415. Mobile string `description:"手机号"`
  416. CompanyId int `description:"手机号"`
  417. }
  418. // GetAdminOpendidByCompany 通过用户公司ID获取对应销售的openid
  419. func GetAdminMobileByCompany(condition string, pars []interface{}) (list []*AdminOpenIdList, err error) {
  420. sql := `SELECT
  421. a.mobile,p.company_id
  422. FROM
  423. company_product AS p
  424. INNER JOIN admin AS a ON a.admin_id = p.seller_id
  425. WHERE
  426. 1 = 1
  427. AND p.product_id = 2 ` + condition
  428. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  429. return
  430. }
  431. // 获取预约活动的用户的openID
  432. func GeFollowSpecialOpenIdList() (items []*AdminOpenIdList, err error) {
  433. o := orm.NewOrmUsingDB("hz_cygx")
  434. sql := `SELECT DISTINCT u.open_id,u.cygx_user_id as user_id ,m.company_id
  435. FROM
  436. cygx_user_follow_special AS m
  437. INNER JOIN cygx_user_record AS u ON u.cygx_bind_account = m.mobile `
  438. _, err = o.Raw(sql).QueryRows(&items)
  439. return
  440. }
  441. //func GetWxOpenIdBList(condition string, pars []interface{}) (items []*OpenIdList, err error) {
  442. // sql := `SELECT
  443. // cr.*,
  444. // u.user_id
  445. //FROM
  446. // cygx_user_record AS cr
  447. // INNER JOIN user_record AS c ON c.union_id = cr.union_id
  448. // INNER JOIN wx_user AS u ON u.user_id = c.user_id
  449. //WHERE
  450. // 1 = 1
  451. // AND c.create_platform = 4 ` + condition + ` GROUP BY cr.open_id `
  452. // _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&items)
  453. // return
  454. //}
  455. // 通过产业名称获取关联的ID
  456. func GetactivitySpecilIdsByLabel(name string) (activityIds string, err error) {
  457. o := orm.NewOrmUsingDB("hz_cygx")
  458. sql := ` SELECT
  459. GROUP_CONCAT( DISTINCT s.activity_id SEPARATOR ',' ) AS activityIds
  460. FROM
  461. cygx_activity_special AS s
  462. WHERE
  463. label LIKE '%` + name + `%' `
  464. err = o.Raw(sql).QueryRow(&activityIds)
  465. return
  466. }