user.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hongze_mfyx/models"
  8. "hongze/hongze_mfyx/utils"
  9. "os"
  10. "path/filepath"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. var ERR_NO_USER_RECORD = errors.New("用户关系没有入库")
  16. var ERR_USER_NOT_BIND = errors.New("用户没有绑定")
  17. // 通过openid获取用户信息
  18. func GetWxUserItemByOpenId(openid string) (item *models.WxUserItem, err error) {
  19. //通过openid获取用户关联信息
  20. userRecord, userRecordErr := models.GetUserRecordByOpenId(openid)
  21. fmt.Println(userRecordErr)
  22. //fmt.Println("userRecordErr", userRecordErr)
  23. if userRecordErr != nil {
  24. if userRecordErr.Error() == utils.ErrNoRow() {
  25. err = ERR_NO_USER_RECORD
  26. return
  27. } else {
  28. err = userRecordErr
  29. return
  30. }
  31. }
  32. //该openid在系统中没有关联关系
  33. if userRecord == nil {
  34. err = ERR_NO_USER_RECORD
  35. return
  36. }
  37. //该openid没有绑定用户
  38. if userRecord.UserId <= 0 {
  39. err = ERR_USER_NOT_BIND
  40. item = new(models.WxUserItem)
  41. //格式化返回用户数据
  42. formatWxUserAndUserRecord(item, userRecord)
  43. return
  44. }
  45. fmt.Println("userRecord.UserId ", userRecord.UserId)
  46. //获取用户信息
  47. item, wxUserErr := models.GetWxUserItemByUserId(userRecord.UserId)
  48. //fmt.Println("wxUserErr", wxUserErr)
  49. if wxUserErr != nil {
  50. err = wxUserErr
  51. //如果是找不到数据,那么可能是该用户被删除了,但是user_record没有删除对应的关系
  52. if wxUserErr.Error() == utils.ErrNoRow() {
  53. //用户被删除了,但是user_record没有删除对应的关系,那么去解除绑定
  54. userUnbindErr := models.UnBindUserRecordByOpenid(openid)
  55. if userUnbindErr != nil {
  56. err = userUnbindErr
  57. return
  58. }
  59. //返回状态为 用户未绑定 逻辑代码
  60. err = ERR_USER_NOT_BIND
  61. item = new(models.WxUserItem)
  62. //格式化返回用户数据
  63. formatWxUserAndUserRecord(item, userRecord)
  64. return
  65. }
  66. return
  67. }
  68. if item.RealName == "" {
  69. item.RealName = userRecord.RealName
  70. }
  71. //格式化返回用户数据
  72. formatWxUserAndUserRecord(item, userRecord)
  73. return
  74. }
  75. // 根据用户id和平台id获取用户信息
  76. func GetWxUserItemByUserId(userId, platform int) (wxUserItem *models.WxUserItem, err error) {
  77. //获取用户信息
  78. wxUserItem, wxUserErr := models.GetWxUserItemByUserId(userId)
  79. if wxUserErr != nil {
  80. err = wxUserErr
  81. return
  82. }
  83. //格式化返回用户数据
  84. formatWxUser(wxUserItem, platform)
  85. return
  86. }
  87. // 根据用户邮箱和平台id获取用户信息
  88. func GetWxUserItemByEmail(email string, platform int) (wxUserItem *models.WxUserItem, err error) {
  89. //获取用户信息
  90. wxUserItem, wxUserErr := models.GetWxUserItemByEmail(email)
  91. if wxUserErr != nil {
  92. err = wxUserErr
  93. return
  94. }
  95. //格式化返回用户数据
  96. formatWxUser(wxUserItem, platform)
  97. return
  98. }
  99. // 根据用户手机号和平台id获取用户信息
  100. func GetWxUserItemByMobile(mobile string, platform int) (wxUserItem *models.WxUserItem, err error) {
  101. //获取用户信息
  102. wxUserItem, wxUserErr := models.GetWxUserItemByMobile(mobile)
  103. if wxUserErr != nil {
  104. err = wxUserErr
  105. return
  106. }
  107. //格式化返回用户数据
  108. formatWxUser(wxUserItem, platform)
  109. return
  110. }
  111. // 根据用户unionid和平台id获取用户信息
  112. func GetWxUserItemByUnionId(unionId string, platform int) (wxUserItem *models.WxUserItem, err error) {
  113. //获取用户信息
  114. wxUserItem, wxUserErr := models.GetWxUserItemByUnionid(unionId)
  115. if wxUserErr != nil {
  116. err = wxUserErr
  117. return
  118. }
  119. //格式化返回用户数据
  120. formatWxUser(wxUserItem, platform)
  121. return
  122. }
  123. // 通过用户 关系表记录 和 用户记录 格式化返回 用户数据
  124. func formatWxUserAndUserRecord(wxUser *models.WxUserItem, userRecord *models.UserRecord) {
  125. wxUser.OpenId = userRecord.OpenId
  126. wxUser.UnionId = userRecord.UnionId
  127. wxUser.NickName = userRecord.NickName
  128. //wxUser.RealName = userRecord.RealName
  129. //wxUser.BindAccount = userRecord.BindAccount
  130. wxUser.Headimgurl = userRecord.Headimgurl
  131. wxUser.SessionKey = userRecord.SessionKey
  132. }
  133. // 通过用户 用户记录 和 来源平台 格式化返回 用户数据
  134. func formatWxUser(wxUser *models.WxUserItem, platform int) {
  135. //根据用户id和平台id获取用户关系
  136. userRecord, userRecordErr := models.GetUserRecordByUserId(wxUser.UserId, platform)
  137. if userRecordErr != nil {
  138. if userRecordErr.Error() != utils.ErrNoRow() {
  139. return
  140. }
  141. if userRecordErr.Error() == utils.ErrNoRow() {
  142. return
  143. }
  144. }
  145. //该openid在系统中没有关联关系
  146. if userRecord == nil {
  147. return
  148. }
  149. wxUser.OpenId = userRecord.OpenId
  150. wxUser.UnionId = userRecord.UnionId
  151. wxUser.NickName = userRecord.NickName
  152. //wxUser.RealName = userRecord.RealName
  153. //wxUser.BindAccount = userRecord.BindAccount
  154. wxUser.Headimgurl = userRecord.Headimgurl
  155. wxUser.SessionKey = userRecord.SessionKey
  156. return
  157. }
  158. // 用户绑定
  159. func BindWxUser(openid, mobile, email, countryCode string) (wxUser *models.WxUserItem, err error) {
  160. if mobile == "" && email == "" {
  161. err = errors.New("手机号或邮箱必填一个")
  162. return
  163. }
  164. var bindAccount string
  165. //根据手机号获取用户信息
  166. if mobile != "" {
  167. tmpWxUser, wxUserErr := models.GetWxUserItemByMobile(mobile)
  168. if wxUserErr != nil && wxUserErr.Error() != utils.ErrNoRow() {
  169. err = wxUserErr
  170. return
  171. }
  172. wxUser = tmpWxUser
  173. bindAccount = mobile
  174. }
  175. //根据邮箱获取用户信息
  176. if wxUser == nil && email != "" {
  177. tmpWxUser, wxUserErr := models.GetWxUserItemByEmail(email)
  178. if wxUserErr != nil && wxUserErr.Error() != utils.ErrNoRow() {
  179. err = wxUserErr
  180. return
  181. }
  182. wxUser = tmpWxUser
  183. bindAccount = email
  184. }
  185. //查询openid的第三方(微信)信息
  186. userRecord, err := models.GetUserRecordByOpenId(openid)
  187. if err != nil {
  188. return
  189. }
  190. var userId int
  191. //如果查询出来的用户是nil,那么需要新增用户
  192. if wxUser == nil {
  193. user := &models.WxUser{
  194. CompanyId: 1,
  195. CreatedTime: time.Now(),
  196. FirstLogin: 1,
  197. Enabled: 1,
  198. RegisterPlatform: 4,
  199. RegisterTime: time.Now(),
  200. Mobile: mobile,
  201. Email: email,
  202. IsRegister: 1,
  203. Source: 3,
  204. CountryCode: countryCode,
  205. OutboundMobile: mobile,
  206. OutboundCountryCode: countryCode,
  207. }
  208. tmpUserId, addUserErr := models.AddWxUser(user)
  209. if addUserErr != nil {
  210. err = addUserErr
  211. return
  212. }
  213. user.UserId = int(tmpUserId)
  214. userId = int(tmpUserId)
  215. wxUser, err = models.GetWxUserItemByUserId(userId)
  216. } else {
  217. userId = wxUser.UserId
  218. err = models.BindUserOutboundMobile(mobile, countryCode, userId)
  219. if err != nil {
  220. return
  221. }
  222. if wxUser.IsRegister == 0 {
  223. models.ModifyWxUserRegisterStatus(userId)
  224. }
  225. }
  226. //如果存在该手机号/邮箱,那么需要校验
  227. if userRecord.UserId > 0 && userRecord.UserId != userId {
  228. err = errors.New("用户已绑定,不允许重复绑定")
  229. return
  230. }
  231. err = models.BindUserRecordByOpenid(userId, openid, bindAccount)
  232. if err != nil {
  233. return
  234. }
  235. userRecord.UserId = userId
  236. //如果当前该第三方用户信息的昵称为空串的话,那么需要去查询该用户的第一个绑定信息的数据作为来源做数据修复
  237. if userRecord.NickName == "" {
  238. oldUserRecord, err := models.GetUserThirdRecordByUserId(userId)
  239. if err == nil && oldUserRecord != nil {
  240. //如果该用户绑定的第一条数据的头像信息不为空串,那么就去做新数据的修复
  241. if oldUserRecord.NickName != "" {
  242. _ = models.ModifyUserRecordByDetail(userRecord.OpenId, userRecord.UnionId, oldUserRecord.NickName, oldUserRecord.Headimgurl, oldUserRecord.City, oldUserRecord.Province, oldUserRecord.Country, oldUserRecord.Sex, userId)
  243. }
  244. }
  245. }
  246. //格式化用户数据
  247. formatWxUserAndUserRecord(wxUser, userRecord)
  248. return
  249. }
  250. // 微信登录
  251. func WxLogin(code, openId, unionId string, wxUserInfo *WxUserInfo) (token string, userId, firstLogin, permission int, err error) {
  252. if unionId == "" {
  253. unionId = wxUserInfo.Unionid
  254. }
  255. //firstLogin==1,强制绑定手机号或者邮箱
  256. firstLogin = 1
  257. fmt.Println("GetWxUserItemByOpenId ", openId)
  258. QUERY_WX_USER:
  259. wxUser, wxUserErr := GetWxUserItemByOpenId(openId)
  260. fmt.Println("wxUserErr", wxUserErr)
  261. if wxUserErr == ERR_NO_USER_RECORD { //没有用户openid记录
  262. // 如果查研观向小程序已经绑定过相关信息了,那么拿过来复用
  263. userRecordCygx, userRecordErrCygx := models.GetUserRecordByUnionId(unionId, 4)
  264. if userRecordErrCygx != nil && userRecordErrCygx.Error() != utils.ErrNoRow() {
  265. err = userRecordErrCygx
  266. return
  267. }
  268. if userRecordCygx != nil {
  269. _, recordErr := AddUserRecordByCygx(openId, unionId, wxUserInfo.Nickname, userRecordCygx.RealName, wxUserInfo.Province, wxUserInfo.City, wxUserInfo.Country, wxUserInfo.Headimgurl, wxUserInfo.SessionKey, utils.WxPlatform, wxUserInfo.Sex, 0, userRecordCygx.UserId)
  270. //如果插入失败,那么直接将错误信息返回
  271. if recordErr != nil {
  272. err = recordErr
  273. return
  274. }
  275. } else {
  276. //先添加第三方信息(openid等信息)
  277. _, recordErr := AddUserRecord(openId, unionId, wxUserInfo.Nickname, "", wxUserInfo.Province, wxUserInfo.City, wxUserInfo.Country, wxUserInfo.Headimgurl, wxUserInfo.SessionKey, utils.WxPlatform, wxUserInfo.Sex, 0)
  278. //如果插入失败,那么直接将错误信息返回
  279. if recordErr != nil {
  280. err = recordErr
  281. return
  282. }
  283. }
  284. //插入成功后,需要重新查询该用户,并进入下面的逻辑
  285. goto QUERY_WX_USER
  286. } else if wxUserErr == ERR_USER_NOT_BIND {
  287. //没有用户信息
  288. //wxUser.FirstLogin = 1
  289. } else if wxUserErr != nil {
  290. err = wxUserErr
  291. return
  292. }
  293. fmt.Println("wxUserInfo", wxUserInfo)
  294. fmt.Println("wxUserInfo.Nickname", wxUserInfo.Nickname)
  295. fmt.Println("SessionKey", wxUserInfo.SessionKey)
  296. if wxUserInfo != nil {
  297. fmt.Println("ModifyUserRecordSessionKey")
  298. err = models.ModifyUserRecordSessionKey(openId, wxUserInfo.SessionKey)
  299. fmt.Println("ModifyUserRecordSessionKey Err", err)
  300. }
  301. //如果已经登录注册绑定的情况下
  302. if wxUser != nil && wxUserErr == nil {
  303. //获取用户权限
  304. firstLogin = wxUser.FirstLogin
  305. userId = wxUser.UserId
  306. {
  307. codeLog := new(models.WxUserCode)
  308. codeLog.WxCode = code
  309. codeLog.UserId = userId
  310. codeLog.Code = 0
  311. codeLog.FirstLogin = firstLogin
  312. codeLog.Authorization = token
  313. codeLog.UserPermission = permission
  314. codeLog.CreateTime = time.Now()
  315. go models.AddWxUserCode(codeLog)
  316. }
  317. if wxUser.Mobile == "" && wxUser.Email == "" {
  318. firstLogin = 1
  319. }
  320. }
  321. //获取登录token
  322. tokenItem, tokenErr := models.GetTokenByOpenId(openId)
  323. if tokenErr != nil && tokenErr.Error() != utils.ErrNoRow() {
  324. err = errors.New("登录失败,获取token失败:" + tokenErr.Error())
  325. return
  326. }
  327. fmt.Println("line 271 ", openId)
  328. if tokenItem == nil || (tokenErr != nil && tokenErr.Error() == utils.ErrNoRow()) {
  329. timeUnix := time.Now().Unix()
  330. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  331. token = utils.MD5(openId) + utils.MD5(timeUnixStr)
  332. //新增session
  333. {
  334. session := new(models.CygxSession)
  335. session.OpenId = openId
  336. session.UserId = userId
  337. session.CreatedTime = time.Now()
  338. session.LastUpdatedTime = time.Now()
  339. session.ExpireTime = time.Now().AddDate(0, 3, 0)
  340. session.AccessToken = token
  341. sessionErr := models.AddSession(session)
  342. if err != nil {
  343. err = errors.New("登录失败,新增用户session信息失败:" + sessionErr.Error())
  344. return
  345. }
  346. }
  347. } else {
  348. token = tokenItem.AccessToken
  349. }
  350. fmt.Println("line 294 ", token)
  351. //新增登录日志
  352. {
  353. loginLog := new(models.WxUserLog)
  354. loginLog.UserId = userId
  355. loginLog.OpenId = openId
  356. loginLog.UnionId = unionId
  357. loginLog.CreateTime = time.Now()
  358. loginLog.Handle = "wechat_login_mfyx"
  359. loginLog.Remark = token
  360. go models.AddWxUserLog(loginLog)
  361. }
  362. return
  363. }
  364. func UserLogin() {
  365. }
  366. // 添加第三方用户(微信)记录
  367. func AddUserRecord(openId, unionId, nickName, realName, province, city, country, headimgurl, sessionKey string, platform, sex, subscribe int) (userRecord *models.UserRecord, err error) {
  368. find, err := models.GetUserRecordByOpenId(openId)
  369. if err != nil && err.Error() != utils.ErrNoRow() {
  370. return
  371. }
  372. if find != nil {
  373. userRecord = find
  374. return
  375. }
  376. userRecord = &models.UserRecord{
  377. OpenId: openId, //用户open_id
  378. UnionId: unionId, //用户union_id
  379. Subscribe: subscribe,
  380. NickName: nickName, //用户昵称,最大长度:32
  381. RealName: realName, //用户实际名称,最大长度:32
  382. Sex: sex, //普通用户性别,1为男性,2为女性
  383. Province: province, //普通用户个人资料填写的省份,最大长度:30
  384. City: city, //普通用户个人资料填写的城市,最大长度:30
  385. Country: country, //国家,如中国为CN,最大长度:30
  386. Headimgurl: headimgurl, //用户第三方(微信)头像,最大长度:512
  387. CreateTime: time.Now(), //创建时间,关系添加时间、用户授权时间
  388. CreatePlatform: platform, //注册平台,1:日度点评公众号,2:管理后台,3:pc端网站,4:查研观向小程序;默认:1
  389. SessionKey: sessionKey, //微信小程序会话密钥,最大长度:255
  390. }
  391. recordId, err := models.AddUserRecord(userRecord)
  392. if err != nil {
  393. return
  394. }
  395. userRecord.UserRecordId = int(recordId)
  396. return
  397. }
  398. // 添加第三方用户(微信)记录
  399. func AddUserRecordByCygx(openId, unionId, nickName, realName, province, city, country, headimgurl, sessionKey string, platform, sex, subscribe, userId int) (userRecord *models.UserRecord, err error) {
  400. find, err := models.GetUserRecordByOpenId(openId)
  401. if err != nil && err.Error() != utils.ErrNoRow() {
  402. return
  403. }
  404. if find != nil {
  405. userRecord = find
  406. return
  407. }
  408. userRecord = &models.UserRecord{
  409. OpenId: openId, //用户open_id
  410. UnionId: unionId, //用户union_id
  411. Subscribe: subscribe,
  412. NickName: nickName, //用户昵称,最大长度:32
  413. RealName: realName, //用户实际名称,最大长度:32
  414. Sex: sex, //普通用户性别,1为男性,2为女性
  415. Province: province, //普通用户个人资料填写的省份,最大长度:30
  416. City: city, //普通用户个人资料填写的城市,最大长度:30
  417. Country: country, //国家,如中国为CN,最大长度:30
  418. Headimgurl: headimgurl, //用户第三方(微信)头像,最大长度:512
  419. CreateTime: time.Now(), //创建时间,关系添加时间、用户授权时间
  420. CreatePlatform: platform, //注册平台,1:日度点评公众号,2:管理后台,3:pc端网站,4:查研观向小程序;默认:1
  421. SessionKey: sessionKey, //微信小程序会话密钥,最大长度:255
  422. UserId: userId, //微信小程序会话密钥,最大长度:255
  423. }
  424. recordId, err := models.AddUserRecord(userRecord)
  425. if err != nil {
  426. return
  427. }
  428. userRecord.UserRecordId = int(recordId)
  429. return
  430. }
  431. // 每天新增,删除的白名单
  432. func SendEmailUserWhiteListChange(cont context.Context) (err error) {
  433. var msg string
  434. var fieldStr string
  435. var condition string
  436. defer func() {
  437. if err != nil {
  438. go utils.SendAlarmMsg("发送附件模版消息失败", 2)
  439. fmt.Println("err:", err, time.Now())
  440. go utils.SendEmail("发送附件模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  441. utils.FileLog.Info("发送附件模版消息失败,Err:%s", err.Error())
  442. }
  443. if msg != "" {
  444. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  445. }
  446. }()
  447. mobileStr, err := models.GetWxUserWhiteMobile()
  448. if err != nil {
  449. msg = "获取失败,Err:" + err.Error()
  450. return
  451. }
  452. if mobileStr == "" {
  453. mobileStr = "1"
  454. }
  455. mobileStr = strings.Replace(mobileStr, " ", "", -1)
  456. mobileStr = strings.Replace(mobileStr, ",", "','", -1)
  457. mobileStr = "'" + mobileStr + "'"
  458. //手机号新增
  459. fieldStr = ` u.mobile,u.country_code,u.real_name,c.company_name,u.company_id,cp.seller_name,cp.status,`
  460. condition = ` AND cp.status IN ( '正式', '试用' ) AND u.mobile IN (` + mobileStr + `) `
  461. condition += ` AND u.mobile !='' AND DATE_SUB(CURDATE(), INTERVAL 2 DAY) <= DATE(u.created_time )`
  462. listMobile, err := models.GetFormalUserWhiteList(fieldStr, condition)
  463. if err != nil {
  464. msg = "获取失败,Err:" + err.Error()
  465. return
  466. }
  467. //外呼手机号新增
  468. outboundMobileStr, err := models.GetWxUserWhiteOutboundMobile()
  469. if outboundMobileStr == "" {
  470. outboundMobileStr = "1"
  471. }
  472. outboundMobileStr = strings.Replace(outboundMobileStr, " ", "", -1)
  473. fieldStr = ` u.outbound_mobile as mobile,u.outbound_country_code as country_code,u.real_name,c.company_name,u.company_id,cp.status,`
  474. condition = ` AND cp.status IN ( '正式', '试用' ) AND u.outbound_mobile IN (` + outboundMobileStr + `) `
  475. condition += ` AND DATE_SUB(CURDATE(), INTERVAL 2 DAY) <= DATE(u.created_time )`
  476. listOutboundMobile, err := models.GetFormalUserWhiteList(fieldStr, condition)
  477. if err != nil {
  478. msg = "获取失败,Err:" + err.Error()
  479. return
  480. }
  481. var rep models.UserWhiteListRep
  482. var repList []*models.UserWhiteList
  483. repList = listMobile
  484. if len(listOutboundMobile) > 0 {
  485. for _, v := range listOutboundMobile {
  486. repList = append(listMobile, v)
  487. }
  488. }
  489. //新增用户,过滤手机号为空的
  490. for _, v := range repList {
  491. if v.Mobile == "" {
  492. continue
  493. }
  494. rep.List = append(rep.List, v)
  495. }
  496. //rep.List = repList
  497. //创建excel
  498. dir, errFile := os.Executable()
  499. exPath := filepath.Dir(dir)
  500. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandDigit(5) + ".xlsx"
  501. xlsxFile := xlsx.NewFile()
  502. if errFile != nil {
  503. msg = "生成文件失败Err:" + errFile.Error()
  504. return
  505. }
  506. style := xlsx.NewStyle()
  507. alignment := xlsx.Alignment{
  508. Horizontal: "center",
  509. Vertical: "center",
  510. WrapText: true,
  511. }
  512. style.Alignment = alignment
  513. style.ApplyAlignment = true
  514. sheet, err := xlsxFile.AddSheet("白名单")
  515. if err != nil {
  516. msg = "新增Sheet失败,Err:" + err.Error()
  517. return
  518. }
  519. //设置宽度
  520. _ = sheet.SetColWidth(2, 2, 15)
  521. _ = sheet.SetColWidth(6, 6, 30)
  522. _ = sheet.SetColWidth(13, 13, 35)
  523. //标头
  524. rowTitle := sheet.AddRow()
  525. cellA := rowTitle.AddCell()
  526. cellA.Value = "姓名"
  527. cellB := rowTitle.AddCell()
  528. cellB.Value = "国际代码1"
  529. cellC := rowTitle.AddCell()
  530. cellC.Value = "手机号"
  531. cellD := rowTitle.AddCell()
  532. cellD.Value = "国际代码2"
  533. cellE := rowTitle.AddCell()
  534. cellE.Value = "备用号"
  535. cellF := rowTitle.AddCell()
  536. cellF.Value = "电子邮箱"
  537. cellG := rowTitle.AddCell()
  538. cellG.Value = "公司名称"
  539. cellH := rowTitle.AddCell()
  540. cellH.Value = "职位名称"
  541. cellI := rowTitle.AddCell()
  542. cellI.Value = "客户类型"
  543. cellJ := rowTitle.AddCell()
  544. cellJ.Value = "对口销售"
  545. cellK := rowTitle.AddCell()
  546. cellK.Value = "归属部门"
  547. cellL := rowTitle.AddCell()
  548. cellL.Value = "有效开始时间"
  549. cellM := rowTitle.AddCell()
  550. cellM.Value = "有效结束时间"
  551. cellN := rowTitle.AddCell()
  552. cellN.Value = "备注"
  553. cellO := rowTitle.AddCell()
  554. cellO.Value = "权限(消费,医药,智造,科技,策略)"
  555. if len(rep.List) > 0 {
  556. for _, item := range rep.List {
  557. row := sheet.AddRow()
  558. cellA := row.AddCell()
  559. cellA.Value = item.RealName
  560. cellB := row.AddCell()
  561. cellB.Value = item.CountryCode
  562. if len(item.Mobile) >= 11 && item.CountryCode == "" {
  563. cellB.Value = "86"
  564. }
  565. cellC := row.AddCell()
  566. cellC.Value = item.Mobile
  567. cellD := row.AddCell()
  568. cellD.Value = ""
  569. cellE := row.AddCell()
  570. cellE.Value = ""
  571. cellF := row.AddCell()
  572. cellF.Value = ""
  573. cellG := row.AddCell()
  574. cellG.Value = item.CompanyName
  575. cellH := row.AddCell()
  576. cellH.Value = ""
  577. cellI := row.AddCell()
  578. cellI.Value = ""
  579. cellJ := row.AddCell()
  580. cellJ.Value = item.SellerName
  581. cellK := row.AddCell()
  582. cellK.Value = ""
  583. cellL := row.AddCell()
  584. cellL.Value = ""
  585. cellM := row.AddCell()
  586. cellM.Value = ""
  587. cellN := row.AddCell()
  588. cellN.Value = ""
  589. cellO := row.AddCell()
  590. if item.Permission == "" {
  591. item.Permission = "专家/医药/智造/消费/研选/科技/策略/路演服务"
  592. }
  593. cellO.Value = item.Permission
  594. }
  595. }
  596. errFile = xlsxFile.Save(downLoadnFilePath)
  597. if errFile != nil {
  598. msg = "保存文件失败Err:" + errFile.Error()
  599. return
  600. }
  601. title := time.Now().Format("2006-01-02") + "新增白名单用户"
  602. content := time.Now().Format("2006-01-02") + "新增白名单用户"
  603. fileName := downLoadnFilePath
  604. var sendResult bool
  605. if len(rep.List) > 0 {
  606. sendResult = utils.SendEmailByHongze(title, content, utils.EmaiWhiteUserList, fileName, title+".xlsx")
  607. }
  608. os.Remove(downLoadnFilePath)
  609. //创建冻结excel
  610. dir, errFile = os.Executable()
  611. exPath = filepath.Dir(dir)
  612. downLoadnFilePaths := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandDigit(5) + ".xlsx"
  613. xlsxFile = xlsx.NewFile()
  614. if errFile != nil {
  615. msg = "生成文件失败Err:" + errFile.Error()
  616. return
  617. }
  618. style = xlsx.NewStyle()
  619. alignment = xlsx.Alignment{
  620. Horizontal: "center",
  621. Vertical: "center",
  622. WrapText: true,
  623. }
  624. style.Alignment = alignment
  625. style.ApplyAlignment = true
  626. sheet, err = xlsxFile.AddSheet("白名单")
  627. if err != nil {
  628. msg = "新增Sheet失败,Err:" + err.Error()
  629. return
  630. }
  631. //设置宽度
  632. _ = sheet.SetColWidth(2, 2, 15)
  633. _ = sheet.SetColWidth(6, 6, 30)
  634. _ = sheet.SetColWidth(13, 13, 35)
  635. //标头
  636. rowTitle = sheet.AddRow()
  637. cellA = rowTitle.AddCell()
  638. cellA.Value = "姓名"
  639. cellB = rowTitle.AddCell()
  640. cellB.Value = "国际代码1"
  641. cellC = rowTitle.AddCell()
  642. cellC.Value = "手机号"
  643. cellD = rowTitle.AddCell()
  644. cellD.Value = "国际代码2"
  645. cellE = rowTitle.AddCell()
  646. cellE.Value = "备用号"
  647. cellF = rowTitle.AddCell()
  648. cellF.Value = "电子邮箱"
  649. cellG = rowTitle.AddCell()
  650. cellG.Value = "公司名称"
  651. cellH = rowTitle.AddCell()
  652. cellH.Value = "职位名称"
  653. cellI = rowTitle.AddCell()
  654. cellI.Value = "客户类型"
  655. cellJ = rowTitle.AddCell()
  656. cellJ.Value = "对口销售"
  657. cellK = rowTitle.AddCell()
  658. cellK.Value = "归属部门"
  659. cellL = rowTitle.AddCell()
  660. cellL.Value = "有效开始时间"
  661. cellM = rowTitle.AddCell()
  662. cellM.Value = "有效结束时间"
  663. cellN = rowTitle.AddCell()
  664. cellN.Value = "备注"
  665. cellO = rowTitle.AddCell()
  666. cellO.Value = "权限(消费,医药,智造,科技,策略)"
  667. //手机号冻结
  668. listFrozen, err := models.GetFrozenUserWhiteList() //手机号用户修改
  669. listFrozenOutbound, err := models.GetFrozenUserWhiteListOutbound() //外呼手机号用户修改
  670. if err != nil {
  671. msg = "获取失败,Err:" + err.Error()
  672. return
  673. }
  674. if len(listFrozenOutbound) > 0 {
  675. for _, v := range listFrozenOutbound {
  676. listFrozen = append(listFrozen, v)
  677. }
  678. }
  679. var listFrozenUser []*models.WxUserWhite
  680. for _, v := range listFrozen {
  681. if v.Mobile == "" {
  682. continue
  683. }
  684. listFrozenUser = append(listFrozenUser, v)
  685. }
  686. if len(listFrozenUser) > 0 {
  687. for _, item := range listFrozenUser {
  688. row := sheet.AddRow()
  689. cellA := row.AddCell()
  690. cellA.Value = item.RealName
  691. cellB := row.AddCell()
  692. cellB.Value = item.CountryCode
  693. if len(item.Mobile) >= 11 && item.CountryCode == "" {
  694. cellB.Value = "86"
  695. }
  696. cellC := row.AddCell()
  697. cellC.Value = item.Mobile
  698. cellD := row.AddCell()
  699. cellD.Value = ""
  700. cellE := row.AddCell()
  701. cellE.Value = ""
  702. cellF := row.AddCell()
  703. cellF.Value = ""
  704. cellG := row.AddCell()
  705. cellG.Value = item.CompanyName
  706. cellH := row.AddCell()
  707. cellH.Value = ""
  708. cellI := row.AddCell()
  709. cellI.Value = ""
  710. cellJ := row.AddCell()
  711. cellJ.Value = item.SellerName
  712. cellK := row.AddCell()
  713. cellK.Value = ""
  714. cellL := row.AddCell()
  715. cellL.Value = ""
  716. cellM := row.AddCell()
  717. cellM.Value = ""
  718. cellN := row.AddCell()
  719. cellN.Value = ""
  720. cellO := row.AddCell()
  721. cellO.Value = item.PermissionName
  722. }
  723. }
  724. errFile = xlsxFile.Save(downLoadnFilePaths)
  725. if errFile != nil {
  726. msg = "保存文件失败Err:" + errFile.Error()
  727. return
  728. }
  729. title = time.Now().Format("2006-01-02") + "删除白名单用户"
  730. content = time.Now().Format("2006-01-02") + "删除白名单用户"
  731. fileName = downLoadnFilePaths
  732. var sendResult2 bool
  733. if len(listFrozenOutbound) > 0 {
  734. sendResult2 = utils.SendEmailByHongze(title, content, utils.EmaiWhiteUserList, fileName, title+".xlsx")
  735. }
  736. os.Remove(downLoadnFilePaths)
  737. //更新名单表
  738. if sendResult {
  739. if len(listMobile) > 0 {
  740. for _, v := range listMobile {
  741. item := new(models.WxUserWhite)
  742. item.Mobile = v.Mobile
  743. item.CountryCode = v.CountryCode
  744. item.CreatedTime = time.Now()
  745. item.CompanyName = v.CompanyName
  746. item.PermissionName = v.Permission
  747. item.UserCreatedTime = v.CreatedTime
  748. item.RealName = v.RealName
  749. item.SellerName = v.SellerName
  750. item.Status = v.Status
  751. _, err = models.AddWxUserWhite(item)
  752. if err != nil {
  753. msg = "获取失败,Err:" + err.Error()
  754. return
  755. }
  756. }
  757. }
  758. if len(listOutboundMobile) > 0 {
  759. for _, v := range listOutboundMobile {
  760. item := new(models.WxUserWhite)
  761. item.Mobile = v.Mobile
  762. item.OutboundMobile = v.Mobile
  763. item.OutboundCountryCode = v.CountryCode
  764. item.CreatedTime = time.Now()
  765. item.CompanyName = v.CompanyName
  766. item.PermissionName = v.Permission
  767. item.UserCreatedTime = v.CreatedTime
  768. item.RealName = v.RealName
  769. item.SellerName = v.SellerName
  770. item.Status = v.Status
  771. _, err = models.AddWxUserWhite(item)
  772. if err != nil {
  773. msg = "获取失败,Err:" + err.Error()
  774. return
  775. }
  776. }
  777. }
  778. }
  779. if sendResult2 {
  780. for _, v := range listFrozen {
  781. err = models.DeleteWxUserWhite(v)
  782. if err != nil {
  783. msg = "删除信息失败,Err:" + err.Error()
  784. return
  785. }
  786. }
  787. }
  788. fmt.Println("发送附件完成", len(listFrozen))
  789. return
  790. }
  791. // 获取用户权限
  792. func GetUserhasPermission(user *models.WxUserItem) (hasPermission int, err error) {
  793. //判断是否已经申请过
  794. applyCount, err := models.GetApplyRecordCount(user.UserId)
  795. if err != nil && err.Error() != utils.ErrNoRow() {
  796. return
  797. }
  798. if applyCount > 0 {
  799. hasPermission = 3
  800. } else {
  801. hasPermission = 4
  802. }
  803. //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  804. if user.CompanyId > 1 {
  805. companyPermission, errPer := models.GetCompanyPermission(user.CompanyId)
  806. if errPer != nil {
  807. err = errPer
  808. return
  809. }
  810. if companyPermission == "" {
  811. if applyCount > 0 {
  812. hasPermission = 3
  813. } else {
  814. hasPermission = 4
  815. }
  816. } else {
  817. if strings.Contains(companyPermission, "医药") || strings.Contains(companyPermission, "科技") || strings.Contains(companyPermission, "消费") || strings.Contains(companyPermission, "智造") || strings.Contains(companyPermission, "策略") {
  818. hasPermission = 1
  819. }
  820. }
  821. }
  822. return
  823. }
  824. // 获取用户有没有开通任意一个行业权限
  825. func GetUserhasPermissionOne(user *models.WxUserItem) (hasPermission int, err error) {
  826. //判断是否已经申请过
  827. applyCount, err := models.GetApplyRecordCount(user.UserId)
  828. if err != nil && err.Error() != utils.ErrNoRow() {
  829. return
  830. }
  831. if applyCount > 0 {
  832. hasPermission = 3
  833. } else {
  834. hasPermission = 4
  835. }
  836. //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  837. if user.CompanyId > 1 {
  838. companyPermission, errPer := models.GetCompanyPermission(user.CompanyId)
  839. if errPer != nil {
  840. err = errPer
  841. return
  842. }
  843. if companyPermission == "" {
  844. if applyCount > 0 {
  845. hasPermission = 3
  846. } else {
  847. hasPermission = 4
  848. }
  849. } else {
  850. hasPermission = 1
  851. }
  852. }
  853. return
  854. }
  855. // 每周五发送当前所有的权益用户
  856. func SendEmailAllUserWithRAI() (err error) {
  857. defer func() {
  858. if err != nil {
  859. fmt.Println("err:", err, time.Now())
  860. go utils.SendEmail("发送权益用户邮件失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), ";Err:"+err.Error(), utils.EmailSendToUsers)
  861. utils.FileLog.Info("发送权益用户邮件失败,Err:%s", err.Error())
  862. }
  863. }()
  864. list, err := models.GetSendEmailAllUserWithRAI()
  865. if err != nil {
  866. return
  867. }
  868. //创建excel
  869. dir, err := os.Executable()
  870. exPath := filepath.Dir(dir)
  871. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandDigit(5) + ".xlsx"
  872. xlsxFile := xlsx.NewFile()
  873. if err != nil {
  874. return
  875. }
  876. style := xlsx.NewStyle()
  877. alignment := xlsx.Alignment{
  878. Horizontal: "center",
  879. Vertical: "center",
  880. WrapText: true,
  881. }
  882. style.Alignment = alignment
  883. style.ApplyAlignment = true
  884. sheet, err := xlsxFile.AddSheet("权益用户名单")
  885. if err != nil {
  886. return
  887. }
  888. //设置宽度
  889. _ = sheet.SetColWidth(0, 0, 30)
  890. _ = sheet.SetColWidth(1, 1, 22)
  891. _ = sheet.SetColWidth(3, 3, 18)
  892. _ = sheet.SetColWidth(5, 5, 15)
  893. _ = sheet.SetColWidth(7, 8, 12)
  894. _ = sheet.SetColWidth(9, 9, 17)
  895. _ = sheet.SetColWidth(10, 10, 35)
  896. //标头
  897. rowTitle := sheet.AddRow()
  898. cellA := rowTitle.AddCell()
  899. cellA.Value = "客户名称"
  900. cellB := rowTitle.AddCell()
  901. cellB.Value = "社会信用码"
  902. cellC := rowTitle.AddCell()
  903. cellC.Value = "客户类型"
  904. cellD := rowTitle.AddCell()
  905. cellD.Value = "行业"
  906. cellE := rowTitle.AddCell()
  907. cellE.Value = "所属销售"
  908. cellF := rowTitle.AddCell()
  909. cellF.Value = "销售手机号"
  910. cellG := rowTitle.AddCell()
  911. cellG.Value = "状态"
  912. cellH := rowTitle.AddCell()
  913. cellH.Value = "服务起始期限"
  914. cellI := rowTitle.AddCell()
  915. cellI.Value = "服务结束期限"
  916. cellJ := rowTitle.AddCell()
  917. cellJ.Value = "创建时间"
  918. cellK := rowTitle.AddCell()
  919. cellK.Value = "权限"
  920. if len(list) > 0 {
  921. for _, item := range list {
  922. row := sheet.AddRow()
  923. cellA := row.AddCell()
  924. cellA.Value = item.CompanyName
  925. cellB := row.AddCell()
  926. cellB.Value = item.CreditCode
  927. cellC := row.AddCell()
  928. cellC.Value = item.ProductName
  929. cellD := row.AddCell()
  930. cellD.Value = item.IndustryName
  931. cellE := row.AddCell()
  932. cellE.Value = item.RealName
  933. cellF := row.AddCell()
  934. cellF.Value = item.Mobile
  935. cellG := row.AddCell()
  936. cellG.Value = item.Status
  937. cellH := row.AddCell()
  938. cellH.Value = item.StartDate
  939. cellI := row.AddCell()
  940. cellI.Value = item.EndDate
  941. cellJ := row.AddCell()
  942. cellJ.Value = item.CreatedTime
  943. cellK := row.AddCell()
  944. cellK.Value = item.Permission
  945. }
  946. }
  947. err = xlsxFile.Save(downLoadnFilePath)
  948. if err != nil {
  949. return
  950. }
  951. title := time.Now().Format(utils.FormatDate) + "权益用户名单"
  952. content := time.Now().Format(utils.FormatDate) + "权益用户名单"
  953. fileName := downLoadnFilePath
  954. if len(list) > 0 {
  955. utils.SendEmailByHongze(title, content, "cxzhang@hzinsights.com;tshen@hzinsights.com", fileName, title+".xlsx")
  956. }
  957. os.Remove(downLoadnFilePath)
  958. return
  959. }
  960. // 每周五发送发送这些公司下的用户
  961. func SendEmailAllUserWithCompany() (err error) {
  962. defer func() {
  963. if err != nil {
  964. fmt.Println("err:", err, time.Now())
  965. go utils.SendEmail("发送权益用户邮件失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), ";Err:"+err.Error(), utils.EmailSendToUsers)
  966. utils.FileLog.Info("发送权益用户邮件失败,Err:%s", err.Error())
  967. }
  968. }()
  969. list, err := models.GetSendEmailAllUserWithCompany()
  970. if err != nil {
  971. return
  972. }
  973. //创建excel
  974. dir, err := os.Executable()
  975. exPath := filepath.Dir(dir)
  976. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandDigit(5) + ".xlsx"
  977. xlsxFile := xlsx.NewFile()
  978. if err != nil {
  979. return
  980. }
  981. style := xlsx.NewStyle()
  982. alignment := xlsx.Alignment{
  983. Horizontal: "center",
  984. Vertical: "center",
  985. WrapText: true,
  986. }
  987. style.Alignment = alignment
  988. style.ApplyAlignment = true
  989. sheet, err := xlsxFile.AddSheet("私募客户联系人名单")
  990. if err != nil {
  991. return
  992. }
  993. //设置宽度
  994. _ = sheet.SetColWidth(1, 1, 15)
  995. _ = sheet.SetColWidth(6, 6, 22)
  996. _ = sheet.SetColWidth(7, 7, 32)
  997. //标头
  998. rowTitle := sheet.AddRow()
  999. cellA := rowTitle.AddCell()
  1000. cellA.Value = "*姓名"
  1001. cellB := rowTitle.AddCell()
  1002. cellB.Value = "*手机号1"
  1003. cellC := rowTitle.AddCell()
  1004. cellC.Value = "国家号1"
  1005. cellD := rowTitle.AddCell()
  1006. cellD.Value = "手机号2"
  1007. cellE := rowTitle.AddCell()
  1008. cellE.Value = "国家号2"
  1009. cellF := rowTitle.AddCell()
  1010. cellF.Value = "座机"
  1011. cellG := rowTitle.AddCell()
  1012. cellG.Value = "*邮箱"
  1013. cellH := rowTitle.AddCell()
  1014. cellH.Value = "*所属公司"
  1015. cellI := rowTitle.AddCell()
  1016. cellI.Value = "性别"
  1017. cellJ := rowTitle.AddCell()
  1018. cellJ.Value = "*是否决策人"
  1019. cellK := rowTitle.AddCell()
  1020. cellK.Value = "部门"
  1021. cellL := rowTitle.AddCell()
  1022. cellL.Value = "职位"
  1023. cellM := rowTitle.AddCell()
  1024. cellM.Value = "所属销售"
  1025. cellN := rowTitle.AddCell()
  1026. cellN.Value = "等级"
  1027. cellO := rowTitle.AddCell()
  1028. cellO.Value = "附件权限"
  1029. cellP := rowTitle.AddCell()
  1030. cellP.Value = "标签"
  1031. cellQ := rowTitle.AddCell()
  1032. cellQ.Value = "近期调研"
  1033. cellR := rowTitle.AddCell()
  1034. cellR.Value = "创建时间"
  1035. if len(list) > 0 {
  1036. for _, item := range list {
  1037. row := sheet.AddRow()
  1038. cellA := row.AddCell()
  1039. cellA.Value = item.RealName
  1040. cellB := row.AddCell()
  1041. cellB.Value = item.Mobile
  1042. cellC := row.AddCell()
  1043. if item.CountryCode != "" && item.Mobile != "" {
  1044. cellC.Value = "+" + item.CountryCode
  1045. }
  1046. if item.CountryCode == "" && item.Mobile != "" {
  1047. cellC.Value = "+86"
  1048. }
  1049. cellD := row.AddCell()
  1050. cellD.Value = ""
  1051. cellE := row.AddCell()
  1052. cellE.Value = ""
  1053. cellF := row.AddCell()
  1054. cellF.Value = ""
  1055. cellG := row.AddCell()
  1056. cellG.Value = item.Email
  1057. cellH := row.AddCell()
  1058. cellH.Value = item.CompanyName
  1059. cellI := row.AddCell()
  1060. cellI.Value = ""
  1061. cellJ := row.AddCell()
  1062. if item.IsMaker == "1" {
  1063. cellJ.Value = "是"
  1064. } else {
  1065. cellJ.Value = "否"
  1066. }
  1067. }
  1068. }
  1069. err = xlsxFile.Save(downLoadnFilePath)
  1070. if err != nil {
  1071. return
  1072. }
  1073. title := time.Now().Format(utils.FormatDate) + "私募客户联系人名单"
  1074. content := time.Now().Format(utils.FormatDate) + "私募客户联系人名单"
  1075. fileName := downLoadnFilePath
  1076. if len(list) > 0 {
  1077. utils.SendEmailByHongze(title, content, "cxzhang@hzinsights.com;tshen@hzinsights.com", fileName, title+".xlsx")
  1078. }
  1079. os.Remove(downLoadnFilePath)
  1080. return
  1081. }
  1082. // 先关注后登录,更新用户是否关注过查研观向小助手公众号
  1083. func UpdateCygxSubscribe(uid int, unionId string) (err error) {
  1084. defer func() {
  1085. if err != nil && err.Error() != utils.ErrNoRow() {
  1086. go utils.SendAlarmMsg("先关注后登录,更新用户是否关注过查研观向小助手公众号失败"+err.Error()+"uid:"+strconv.Itoa(uid)+"unionId:"+unionId, 2)
  1087. }
  1088. }()
  1089. if unionId == "" {
  1090. err = errors.New("unionId为空,用户ID:" + strconv.Itoa(uid))
  1091. return
  1092. }
  1093. detail, err := models.GetCygxUserRecordSubscribe(unionId)
  1094. if err != nil && err.Error() != utils.ErrNoRow() {
  1095. return
  1096. }
  1097. if detail != nil {
  1098. err = models.UserSubscribe(detail.SubscribeTime, uid)
  1099. }
  1100. return
  1101. }
  1102. // SendPermissionApplyTemplateMsgAdmin 处理试用申请给王芳,汪洋发消息
  1103. func SendPermissionApplyTemplateMsgAdmin(req models.ApplyTryReq, usermobile, applyMethod string, isResearch bool) (err error) {
  1104. defer func() {
  1105. if err != nil {
  1106. go utils.SendAlarmMsg("处理试用申请给王芳,汪洋发消息失败, ErrMsg: "+err.Error(), 3)
  1107. }
  1108. }()
  1109. var configCode string
  1110. //如果是研选的就推送给汪洋跟王芳,否则就推送给王芳
  1111. configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
  1112. cnf, e := models.GetConfigByCode(configCode)
  1113. if e != nil {
  1114. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  1115. return
  1116. }
  1117. openIdList, e := models.GetUserRecordListByMobile(4, cnf.ConfigValue)
  1118. if e != nil && e.Error() != utils.ErrNoRow() {
  1119. err = errors.New("GetUserRecordListByMobile, Err: " + e.Error() + cnf.ConfigValue)
  1120. return err
  1121. }
  1122. for _, v := range openIdList {
  1123. go SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, usermobile, applyMethod, v)
  1124. }
  1125. //openIpItem, e := models.GetUserRecordByMobile(4, cnf.ConfigValue)
  1126. //if e != nil {
  1127. // err = errors.New("GetUserRecordByMobile, Err: " + e.Error() + cnf.ConfigValue)
  1128. // return
  1129. //}
  1130. return
  1131. }