user.go 36 KB

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