user.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/utils"
  6. "strings"
  7. "time"
  8. )
  9. var ERR_NO_USER_RECORD = errors.New("用户关系没有入库")
  10. var ERR_USER_NOT_BIND = errors.New("用户没有绑定")
  11. // 通过用户 关系表记录 和 用户记录 格式化返回 用户数据
  12. func formatWxUserAndUserRecord(wxUser *models.WxUserItem, userRecord *models.UserRecord) {
  13. wxUser.OpenId = userRecord.OpenId
  14. wxUser.UnionId = userRecord.UnionId
  15. wxUser.NickName = userRecord.NickName
  16. //wxUser.RealName = userRecord.RealName
  17. //wxUser.BindAccount = userRecord.BindAccount
  18. wxUser.Headimgurl = userRecord.Headimgurl
  19. wxUser.SessionKey = userRecord.SessionKey
  20. }
  21. func GetWxUserItemByOpenId(unionId string) (item *models.WxUserItem, err error) {
  22. //通过openid获取用户关联信息
  23. item = new(models.WxUserItem)
  24. item.UnionId = unionId // 先写入 unionId
  25. userRecord, userRecordErr := models.GetUserRecordByUnionId(unionId)
  26. if userRecordErr != nil && userRecordErr.Error() != utils.ErrNoRow() {
  27. err = userRecordErr
  28. return
  29. }
  30. //如果 userRecord 表中的手机号不为空,那么就通过手机号来获取详情
  31. if userRecord != nil {
  32. if userRecord.BindAccount != "" {
  33. user, userErr := models.GetWxUserItemByUserMobile(userRecord.BindAccount)
  34. if userErr != nil && userErr.Error() != utils.ErrNoRow() {
  35. err = userErr
  36. return
  37. }
  38. if user != nil {
  39. item = user
  40. }
  41. }
  42. }
  43. return
  44. }
  45. // 获取 用户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户
  46. func GetUserType(companyId int) (userType int, permissionStrnew string, err error) {
  47. var permissionStr, permissionZhengShiStr string
  48. if companyId <= 1 {
  49. userType = 0
  50. } else {
  51. total, errs := models.GetCountCompanyDetailByIdGroup(companyId)
  52. if errs != nil {
  53. err = errs
  54. return
  55. }
  56. if total == 0 {
  57. userType = 0
  58. } else {
  59. companyDetail, errs := models.GetCompanyDetailByIdGroup(companyId)
  60. if errs != nil {
  61. err = errs
  62. return
  63. }
  64. permissionStr, errs = models.GetCompanyPermission(companyId)
  65. if errs != nil {
  66. err = errs
  67. return
  68. }
  69. permissionStrnew = permissionStr
  70. //大套餐客户,数据库添加标识,
  71. companyUserTypeDetail, errs := models.GetCygxCompanyUserType(companyId)
  72. if errs != nil && errs.Error() != utils.ErrNoRow() {
  73. err = errs
  74. return
  75. }
  76. if companyUserTypeDetail != nil {
  77. if companyUserTypeDetail.CustomerTypeId != 0 {
  78. userType = companyUserTypeDetail.CustomerTypeId
  79. return
  80. }
  81. }
  82. permissionZhengShiStr, errs = models.GetCompanyPermissionByUserZhengShi(companyId)
  83. if errs != nil {
  84. err = errs
  85. return
  86. }
  87. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户、 10: 30W套餐客户
  88. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  89. if companyDetail.Status == "永续" {
  90. userType = 1
  91. } else if companyDetail.Status == "试用" {
  92. userType = 5
  93. } else if companyDetail.Status == "冻结" {
  94. userType = 6
  95. } else if companyDetail.Status == "流失" {
  96. userType = 7
  97. }
  98. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  99. if userType == 0 && companyDetail.Status == "正式" {
  100. var permissionZhegnshiNum int
  101. if strings.Count(permissionZhengShiStr, "医药") == 2 {
  102. permissionZhegnshiNum++
  103. }
  104. if strings.Count(permissionZhengShiStr, "消费") == 2 {
  105. permissionZhegnshiNum++
  106. }
  107. if strings.Count(permissionZhengShiStr, "科技") == 2 {
  108. permissionZhegnshiNum++
  109. }
  110. if strings.Count(permissionZhengShiStr, "智造") == 2 {
  111. permissionZhegnshiNum++
  112. }
  113. if strings.Count(permissionZhengShiStr, "策略") == 1 {
  114. permissionZhegnshiNum++
  115. }
  116. if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
  117. permissionZhegnshiNum++
  118. }
  119. //if permissionZhegnshiNum == 6 {
  120. // userType = 2
  121. //} else
  122. //大套餐客户,数据库添加标识,条件大于等于四的都是 30W套餐客户
  123. if permissionZhegnshiNum >= 4 {
  124. userType = 10
  125. } else {
  126. userType = 3
  127. }
  128. }
  129. }
  130. }
  131. permissionStrnew = permissionStr
  132. return
  133. }
  134. func GetUserTypeZhengShi(companyId int) (userType int, permissionStrnew, permissionStrZhengShinew string, err error) {
  135. var permissionStr, permissionZhengShiStr string
  136. if companyId <= 1 {
  137. userType = 0
  138. } else {
  139. total, errs := models.GetCountCompanyDetailByIdGroup(companyId)
  140. if errs != nil {
  141. err = errs
  142. return
  143. }
  144. if total == 0 {
  145. userType = 0
  146. } else {
  147. companyDetail, errs := models.GetCompanyDetailByIdGroup(companyId)
  148. if errs != nil {
  149. err = errs
  150. return
  151. }
  152. permissionStr, errs = models.GetCompanyPermission(companyId)
  153. if errs != nil {
  154. err = errs
  155. return
  156. }
  157. permissionStrnew = permissionStr
  158. permissionZhengShiStr, errs = models.GetCompanyPermissionByUserZhengShi(companyId)
  159. if errs != nil {
  160. err = errs
  161. return
  162. }
  163. permissionStrZhengShinew = permissionZhengShiStr
  164. //大套餐客户,数据库添加标识,
  165. companyUserTypeDetail, errs := models.GetCygxCompanyUserType(companyId)
  166. if errs != nil && errs.Error() != utils.ErrNoRow() {
  167. err = errs
  168. return
  169. }
  170. if companyUserTypeDetail != nil {
  171. if companyUserTypeDetail.CustomerTypeId != 0 {
  172. userType = companyUserTypeDetail.CustomerTypeId
  173. return
  174. }
  175. }
  176. //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户、 10: 30W套餐客户
  177. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  178. if companyDetail.Status == "永续" {
  179. userType = 1
  180. } else if companyDetail.Status == "试用" {
  181. userType = 5
  182. } else if companyDetail.Status == "冻结" {
  183. userType = 6
  184. } else if companyDetail.Status == "流失" {
  185. userType = 7
  186. }
  187. //大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
  188. if userType == 0 && companyDetail.Status == "正式" {
  189. var permissionZhegnshiNum int
  190. if strings.Count(permissionZhengShiStr, "医药") == 2 {
  191. permissionZhegnshiNum++
  192. }
  193. if strings.Count(permissionZhengShiStr, "消费") == 2 {
  194. permissionZhegnshiNum++
  195. }
  196. if strings.Count(permissionZhengShiStr, "科技") == 2 {
  197. permissionZhegnshiNum++
  198. }
  199. if strings.Count(permissionZhengShiStr, "智造") == 2 {
  200. permissionZhegnshiNum++
  201. }
  202. if strings.Count(permissionZhengShiStr, "策略") == 1 {
  203. permissionZhegnshiNum++
  204. }
  205. if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
  206. permissionZhegnshiNum++
  207. }
  208. //if permissionZhegnshiNum == 6 {
  209. // userType = 2
  210. //} else
  211. //大套餐客户,数据库添加标识,条件大于等于四的都是 30W套餐客户
  212. if permissionZhegnshiNum >= 4 {
  213. userType = 10
  214. } else {
  215. userType = 3
  216. }
  217. }
  218. }
  219. }
  220. permissionStrnew = permissionStr
  221. permissionStrZhengShinew = permissionZhengShiStr
  222. return
  223. }
  224. // 用户绑定
  225. func BindWxUser(mobile, countryCode string) (wxUser *models.WxUserItem, err error) {
  226. if mobile == "" {
  227. err = errors.New("手机号或邮箱必填一个")
  228. return
  229. }
  230. //根据手机号获取用户信息
  231. if mobile != "" {
  232. tmpWxUser, wxUserErr := models.GetWxUserItemByMobile(mobile)
  233. if wxUserErr != nil && wxUserErr.Error() != utils.ErrNoRow() {
  234. err = wxUserErr
  235. return
  236. }
  237. wxUser = tmpWxUser
  238. }
  239. var userId int
  240. //如果查询出来的用户是nil,那么需要新增用户
  241. if wxUser == nil {
  242. user := &models.WxUser{
  243. CompanyId: 1,
  244. CreatedTime: time.Now(),
  245. FirstLogin: 1,
  246. Enabled: 1,
  247. RegisterPlatform: 7,
  248. RegisterTime: time.Now(),
  249. Mobile: mobile,
  250. //Email: email,
  251. IsRegister: 1,
  252. Source: 3,
  253. CountryCode: countryCode,
  254. OutboundMobile: mobile,
  255. OutboundCountryCode: countryCode,
  256. }
  257. tmpUserId, addUserErr := models.AddWxUser(user)
  258. if addUserErr != nil {
  259. err = addUserErr
  260. return
  261. }
  262. user.UserId = int(tmpUserId)
  263. userId = int(tmpUserId)
  264. wxUser, err = models.GetWxUserItemByUserId(userId)
  265. } else {
  266. userId = wxUser.UserId
  267. err = models.BindUserOutboundMobile(mobile, countryCode, userId)
  268. if err != nil {
  269. return
  270. }
  271. if wxUser.IsRegister == 0 {
  272. models.ModifyWxUserRegisterStatus(userId)
  273. }
  274. }
  275. return
  276. }
  277. // 用户绑定用户手机号以及openid
  278. func BindWxUserMobileAndOpenid(mobile, openid, countryCode string) (wxUser *models.WxUserItem, err error) {
  279. if mobile == "" {
  280. err = errors.New("手机号或邮箱必填一个")
  281. return
  282. }
  283. var bindAccount string
  284. //根据手机号获取用户信息
  285. if mobile != "" {
  286. tmpWxUser, wxUserErr := models.GetWxUserItemByMobile(mobile)
  287. if wxUserErr != nil && wxUserErr.Error() != utils.ErrNoRow() {
  288. err = wxUserErr
  289. return
  290. }
  291. wxUser = tmpWxUser
  292. bindAccount = mobile
  293. }
  294. //查询openid的第三方(微信)信息
  295. userRecord, err := models.GetUserRecordByOpenId(openid)
  296. if err != nil {
  297. return
  298. }
  299. var userId int
  300. //如果查询出来的用户是nil,那么需要新增用户
  301. if wxUser == nil {
  302. user := &models.WxUser{
  303. CompanyId: 1,
  304. CreatedTime: time.Now(),
  305. FirstLogin: 1,
  306. Enabled: 1,
  307. RegisterPlatform: 7,
  308. RegisterTime: time.Now(),
  309. Mobile: mobile,
  310. //Email: email,
  311. IsRegister: 1,
  312. Source: 3,
  313. CountryCode: countryCode,
  314. OutboundMobile: mobile,
  315. OutboundCountryCode: countryCode,
  316. }
  317. tmpUserId, addUserErr := models.AddWxUser(user)
  318. if addUserErr != nil {
  319. err = addUserErr
  320. return
  321. }
  322. user.UserId = int(tmpUserId)
  323. userId = int(tmpUserId)
  324. wxUser, err = models.GetWxUserItemByUserId(userId)
  325. } else {
  326. userId = wxUser.UserId
  327. err = models.BindUserOutboundMobile(mobile, countryCode, userId)
  328. if err != nil {
  329. return
  330. }
  331. if wxUser.IsRegister == 0 {
  332. models.ModifyWxUserRegisterStatus(userId)
  333. }
  334. }
  335. //如果存在该手机号/邮箱,那么需要校验
  336. if userRecord.UserId > 0 && userRecord.UserId != userId {
  337. err = errors.New("用户已绑定,不允许重复绑定")
  338. return
  339. }
  340. err = models.BindUserRecordByOpenid(userId, openid, bindAccount)
  341. if err != nil {
  342. return
  343. }
  344. userRecord.UserId = userId
  345. //如果当前该第三方用户信息的昵称为空串的话,那么需要去查询该用户的第一个绑定信息的数据作为来源做数据修复
  346. if userRecord.NickName == "" {
  347. oldUserRecord, err := models.GetUserThirdRecordByUserId(userId)
  348. if err == nil && oldUserRecord != nil {
  349. //如果该用户绑定的第一条数据的头像信息不为空串,那么就去做新数据的修复
  350. if oldUserRecord.NickName != "" {
  351. _ = models.ModifyUserRecordByDetail(userRecord.OpenId, userRecord.UnionId, oldUserRecord.NickName, oldUserRecord.Headimgurl, oldUserRecord.City, oldUserRecord.Province, oldUserRecord.Country, oldUserRecord.Sex, userId)
  352. }
  353. }
  354. }
  355. //格式化用户数据
  356. formatWxUserAndUserRecord(wxUser, userRecord)
  357. return
  358. }
  359. // 添加第三方用户(微信)记录
  360. func AddUserRecord(openId, unionId, nickName, realName, province, city, country, headimgurl, sessionKey string, platform, sex, subscribe int) (userRecord *models.UserRecord, err error) {
  361. find, err := models.GetUserRecordByOpenId(openId)
  362. if err != nil && err.Error() != utils.ErrNoRow() {
  363. return
  364. }
  365. if find != nil {
  366. userRecord = find
  367. return
  368. }
  369. userRecord = &models.UserRecord{
  370. OpenId: openId, //用户open_id
  371. UnionId: unionId, //用户union_id
  372. Subscribe: subscribe,
  373. NickName: nickName, //用户昵称,最大长度:32
  374. RealName: realName, //用户实际名称,最大长度:32
  375. Sex: sex, //普通用户性别,1为男性,2为女性
  376. Province: province, //普通用户个人资料填写的省份,最大长度:30
  377. City: city, //普通用户个人资料填写的城市,最大长度:30
  378. Country: country, //国家,如中国为CN,最大长度:30
  379. Headimgurl: headimgurl, //用户第三方(微信)头像,最大长度:512
  380. CreateTime: time.Now(), //创建时间,关系添加时间、用户授权时间
  381. CreatePlatform: platform, //注册平台,1:日度点评公众号,2:管理后台,3:pc端网站,4:查研观向小程序;默认:1
  382. SessionKey: sessionKey, //微信小程序会话密钥,最大长度:255
  383. }
  384. //recordId, err := models.AddUserRecord(userRecord)
  385. if err != nil {
  386. return
  387. }
  388. //userRecord.UserRecordId = int(recordId)
  389. return
  390. }
  391. // 用户绑定
  392. func BindSession(mobile, countryCode string) (wxUser *models.WxUserItem, err error) {
  393. if mobile == "" {
  394. err = errors.New("手机号或邮箱必填一个")
  395. return
  396. }
  397. //var bindAccount string
  398. //根据手机号获取用户信息
  399. if mobile != "" {
  400. tmpWxUser, wxUserErr := models.GetWxUserItemByMobile(mobile)
  401. if wxUserErr != nil && wxUserErr.Error() != utils.ErrNoRow() {
  402. err = wxUserErr
  403. return
  404. }
  405. wxUser = tmpWxUser
  406. //bindAccount = mobile
  407. }
  408. var userId int
  409. //如果查询出来的用户是nil,那么需要新增用户
  410. if wxUser == nil {
  411. user := &models.WxUser{
  412. CompanyId: 1,
  413. CreatedTime: time.Now(),
  414. FirstLogin: 1,
  415. Enabled: 1,
  416. RegisterPlatform: 7,
  417. RegisterTime: time.Now(),
  418. Mobile: mobile,
  419. //Email: email,
  420. IsRegister: 1,
  421. Source: 3,
  422. CountryCode: countryCode,
  423. OutboundMobile: mobile,
  424. OutboundCountryCode: countryCode,
  425. }
  426. tmpUserId, addUserErr := models.AddWxUser(user)
  427. if addUserErr != nil {
  428. err = addUserErr
  429. return
  430. }
  431. user.UserId = int(tmpUserId)
  432. userId = int(tmpUserId)
  433. wxUser, err = models.GetWxUserItemByUserId(userId)
  434. } else {
  435. userId = wxUser.UserId
  436. err = models.BindUserOutboundMobile(mobile, countryCode, userId)
  437. if err != nil {
  438. return
  439. }
  440. if wxUser.IsRegister == 0 {
  441. models.ModifyWxUserRegisterStatus(userId)
  442. }
  443. }
  444. return
  445. }
  446. // 我的收藏
  447. func GetMicroRoadShowMycollect(pageSize, currentIndex int, audioIds, videoIds, activityVideoIds string) (respList []*models.MicroRoadShowPageList, total int, err error) {
  448. var e error
  449. // 根据每页数据量获取音视频配比
  450. startSize := utils.StartIndex(currentIndex, pageSize)
  451. videoList := make([]*models.MicroRoadShowPageList, 0)
  452. //音频的查询
  453. var audioCond string
  454. var audioPars []interface{}
  455. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  456. // 活动已发布且已结束
  457. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  458. if audioIds != "" {
  459. sliceId := strings.Split(audioIds, ",")
  460. var idSqlStr string
  461. for _, v := range sliceId {
  462. idSqlStr += "'" + v + "',"
  463. }
  464. idSqlStr = strings.TrimRight(idSqlStr, ",")
  465. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  466. } else {
  467. audioCond += ` AND a.activity_voice_id = 0 `
  468. }
  469. //视频的处理
  470. var videoCond string
  471. var videoCondAct string
  472. if activityVideoIds != "" {
  473. sliceId := strings.Split(activityVideoIds, ",")
  474. var idSqlStr string
  475. for _, v := range sliceId {
  476. idSqlStr += "'" + v + "',"
  477. }
  478. idSqlStr = strings.TrimRight(idSqlStr, ",")
  479. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  480. } else {
  481. videoCondAct += ` AND v.video_id = 0 `
  482. }
  483. var videoPars []interface{}
  484. var videoParsAct []interface{}
  485. if videoIds != "" {
  486. sliceId := strings.Split(videoIds, ",")
  487. var idSqlStr string
  488. for _, v := range sliceId {
  489. idSqlStr += "'" + v + "',"
  490. }
  491. idSqlStr = strings.TrimRight(idSqlStr, ",")
  492. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  493. } else {
  494. videoCond += ` AND video_id = 0 `
  495. }
  496. videoCond += ` AND publish_status = 1`
  497. total, videoList, e = models.GetMicroRoadShowVideoPageListV8(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars, 0, 0, 0, 0)
  498. if e != nil {
  499. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  500. return
  501. }
  502. respList = videoList
  503. return
  504. }
  505. // 我的收藏
  506. func GetMicroRoadShowMycollectV12(pageSize, currentIndex int, audioIds, activityVideoIds, roadshowIdsStr, askserieVideoIds string, user *models.WxUserItem) (respList []*models.MicroRoadShowPageList, total int, err error) {
  507. //Type int `description:"类型: 1-活动音频; 2-活动视频; 3-产业视频; 4-系列问答"`
  508. var e error
  509. // 根据每页数据量获取音视频配比
  510. startSize := utils.StartIndex(currentIndex, pageSize)
  511. videoList := make([]*models.MicroRoadShowPageList, 0)
  512. var audioAct string // 活动音频 1
  513. var audioActPars []interface{}
  514. var videoAct string // 活动视频 2
  515. var videoActPars []interface{}
  516. //视频的处理
  517. var videoMico string //产业视频 3
  518. var videoMicoPars []interface{}
  519. var conditionAskserie string // 系列问答 4
  520. var askseriePars []interface{}
  521. if audioIds != "" {
  522. sliceId := strings.Split(audioIds, ",")
  523. audioAct += ` AND a.activity_voice_id IN (` + strings.Join(sliceId, ",") + `)`
  524. } else {
  525. audioAct += ` AND a.activity_voice_id = 0 `
  526. }
  527. if activityVideoIds != "" {
  528. sliceId := strings.Split(activityVideoIds, ",")
  529. videoAct += ` AND a.video_id IN (` + strings.Join(sliceId, ",") + `)`
  530. } else {
  531. videoAct += ` AND a.video_id = 0 `
  532. }
  533. if roadshowIdsStr != "" {
  534. sliceId := strings.Split(roadshowIdsStr, ",")
  535. videoMico += ` AND a.video_id IN (` + strings.Join(sliceId, ",") + `)`
  536. } else {
  537. videoMico += ` AND a.video_id = 0 `
  538. }
  539. if askserieVideoIds != "" {
  540. sliceId := strings.Split(askserieVideoIds, ",")
  541. conditionAskserie += ` AND a.askserie_video_id IN (` + strings.Join(sliceId, ",") + `)`
  542. } else {
  543. conditionAskserie += ` AND a.askserie_video_id = 0 `
  544. }
  545. //发布状态
  546. audioAct += ` AND b.publish_status = 1 `
  547. videoAct += ` AND b.publish_status = 1 `
  548. videoMico += ` AND a.publish_status = 1 `
  549. conditionAskserie += ` AND a.publish_status = 1 `
  550. total, videoList, e = models.GetMicroRoadShowVideoPageListV12(startSize, pageSize, audioAct, audioActPars, videoAct, videoActPars, videoMico, videoMicoPars, conditionAskserie, askseriePars)
  551. if e != nil {
  552. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  553. return
  554. }
  555. userId := user.UserId
  556. listMycollect, e := models.GetUserMicroRoadshowCollectList(userId)
  557. if e != nil {
  558. err = errors.New("GetUserMicroRoadshowCollectList, Err: " + e.Error())
  559. return
  560. }
  561. mapaudioIds := make(map[int]int) //活动音频
  562. mapvideoIds := make(map[int]int) // 微路演视频
  563. mapactivityVideoIds := make(map[int]int) // 活动视频
  564. mapAskserieVideoIds := make(map[int]int) // 活动视频
  565. for _, item := range listMycollect {
  566. if item.ActivityVoiceId > 0 {
  567. mapaudioIds[item.ActivityVoiceId] = item.ActivityVoiceId
  568. } else if item.VideoId > 0 {
  569. mapvideoIds[item.VideoId] = item.VideoId
  570. } else if item.ActivityVideoId > 0 {
  571. mapactivityVideoIds[item.ActivityVideoId] = item.ActivityVideoId
  572. }
  573. }
  574. listAskserieVideoCollect, e := models.GetUserCygxAskserieVideoCollectList(userId)
  575. if e != nil {
  576. err = errors.New("GetUserCygxAskserieVideoCollectList, Err: " + e.Error())
  577. return
  578. }
  579. for _, v := range listAskserieVideoCollect {
  580. if v.AskserieVideoId > 0 {
  581. mapAskserieVideoIds[v.AskserieVideoId] = v.AskserieVideoId
  582. }
  583. }
  584. for _, item := range videoList {
  585. if item.Type == 1 {
  586. //音频
  587. if mapaudioIds[item.Id] > 0 {
  588. item.IsCollect = true
  589. }
  590. } else if item.Type == 2 {
  591. //活动视频
  592. if mapactivityVideoIds[item.Id] > 0 {
  593. item.IsCollect = true
  594. }
  595. } else if item.Type == 3 {
  596. //微路演视频
  597. if mapvideoIds[item.Id] > 0 {
  598. item.IsCollect = true
  599. }
  600. } else if item.Type == 4 {
  601. //系列问答视频
  602. if mapAskserieVideoIds[item.SourceId] > 0 {
  603. item.IsCollect = true
  604. }
  605. }
  606. }
  607. for _, v := range videoList {
  608. v.LabelType = v.Type
  609. if v.Type == 1 || v.Type == 2 {
  610. v.LabelType = v.ActivityFileType
  611. }
  612. }
  613. respList = videoList
  614. return
  615. }
  616. // 获取用户权限
  617. func GetUserhasPermission(user *models.WxUserItem) (hasPermission int, err error) {
  618. //判断是否已经申请过
  619. applyCount, err := models.GetApplyRecordCount(user.UserId)
  620. if err != nil && err.Error() != utils.ErrNoRow() {
  621. return
  622. }
  623. if applyCount > 0 {
  624. hasPermission = 3
  625. } else {
  626. hasPermission = 5
  627. }
  628. //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  629. if user.CompanyId > 1 {
  630. companyPermission, errPer := models.GetCompanyPermission(user.CompanyId)
  631. if errPer != nil {
  632. err = errPer
  633. return
  634. }
  635. if companyPermission == "" {
  636. if applyCount > 0 {
  637. hasPermission = 3
  638. } else {
  639. hasPermission = 4
  640. }
  641. } else {
  642. if strings.Contains(companyPermission, "医药") || strings.Contains(companyPermission, "科技") || strings.Contains(companyPermission, "消费") || strings.Contains(companyPermission, "智造") || strings.Contains(companyPermission, "策略") {
  643. hasPermission = 1
  644. }
  645. }
  646. }
  647. return
  648. }