user.go 36 KB

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