user.go 36 KB

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