user.go 23 KB

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