report.go 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  1. package roadshow
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models/company"
  5. "hongze/hz_crm_api/models/overseas_custom"
  6. "hongze/hz_crm_api/models/roadshow"
  7. "hongze/hz_crm_api/utils"
  8. "time"
  9. )
  10. // GetWeekData 周度数据
  11. func GetWeekData(adminType, dimensionType string) (adminDataList []AdminDataMap, firstDate time.Time, err error) {
  12. nowWeekMonday := utils.GetNowWeekMonday() //本周周一
  13. //fmt.Println(nowWeekMonday)
  14. nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日
  15. //fmt.Println(nowWeekSunday)
  16. //nowWeekMonday = nowWeekMonday.AddDate(0, 0, -30) //上周周一
  17. //nowWeekSunday = nowWeekSunday.AddDate(0, 0, -30) //上周周日
  18. //adminDataMap, err := getSectionData(nowWeekMonday, nowWeekSunday)
  19. //if err != nil {
  20. // fmt.Println(err)
  21. // return
  22. //}
  23. //fmt.Println(adminDataMap)
  24. lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7) //上周周一
  25. //fmt.Println(lastWeekMonday)
  26. //最早的一天
  27. firstDate = lastWeekMonday
  28. lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7) //上周周日
  29. //fmt.Println(lastWeekSunday)
  30. nextWeekMonday := nowWeekMonday.AddDate(0, 0, 7) //下周周一
  31. //fmt.Println(nextWeekMonday)
  32. nextWeekSunday := nowWeekSunday.AddDate(0, 0, 7) //下周周日
  33. //fmt.Println(nextWeekSunday)
  34. ch1 := make(chan AdminDataMap, 0)
  35. ch2 := make(chan AdminDataMap, 0)
  36. ch3 := make(chan AdminDataMap, 0)
  37. go getSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, ch1)
  38. go getSectionData(nowWeekMonday, nowWeekSunday, adminType, dimensionType, ch2)
  39. go getSectionData(nextWeekMonday, nextWeekSunday, adminType, dimensionType, ch3)
  40. var nowWeekAdminDataMap, lastWeekAdminDataMap, nextWeekAdminDataMap AdminDataMap
  41. lastWeekAdminDataMap = <-ch1
  42. close(ch1)
  43. nowWeekAdminDataMap = <-ch2
  44. close(ch2)
  45. nextWeekAdminDataMap = <-ch3
  46. close(ch3)
  47. adminDataList = make([]AdminDataMap, 0)
  48. adminDataList = append(adminDataList, lastWeekAdminDataMap, nowWeekAdminDataMap, nextWeekAdminDataMap)
  49. return
  50. }
  51. // GetWeekDataV2 周度数据
  52. func GetWeekDataV2(adminType, dimensionType string, weekNum int) (adminDataList []AdminDataMap, firstDate time.Time, err error) {
  53. nowWeekMonday := utils.GetNowWeekMonday() //本周周一
  54. //fmt.Println(nowWeekMonday)
  55. nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日
  56. chanList := make([]chan AdminDataMap, 0)
  57. for i := 0; i < weekNum; i++ {
  58. tmpCh := make(chan AdminDataMap, 0)
  59. chanList = append(chanList, tmpCh)
  60. lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7*i)
  61. lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7*i)
  62. // 第一个开始日期
  63. firstDate = lastWeekMonday
  64. go getSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, tmpCh)
  65. }
  66. adminDataList = make([]AdminDataMap, 0)
  67. for _, vChan := range chanList {
  68. var weekAdminDataMap AdminDataMap
  69. weekAdminDataMap = <-vChan
  70. close(vChan)
  71. adminDataList = append(adminDataList, weekAdminDataMap)
  72. }
  73. return
  74. }
  75. // GetMonthData 月度数据
  76. func GetMonthData(adminType, dimensionType string) (adminDataMapList []AdminDataMap, firstDate time.Time, err error) { //三个协程返回
  77. nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
  78. nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
  79. lastMonthFirstDay1 := nowMonthFirstDay.AddDate(0, -1, 0) //上个月第一天
  80. lastMonthLastDay1 := lastMonthFirstDay1.AddDate(0, 1, 0).Add(-1 * time.Second) //上个月最后一天
  81. lastMonthFirstDay2 := nowMonthFirstDay.AddDate(0, -2, 0) //上上个月第一天
  82. lastMonthLastDay2 := lastMonthFirstDay2.AddDate(0, 1, 0).Add(-1 * time.Second) //上上个月最后一天
  83. lastMonthFirstDay3 := nowMonthFirstDay.AddDate(0, -3, 0) //上上上个月第一天
  84. lastMonthLastDay3 := lastMonthFirstDay3.AddDate(0, 1, 0).Add(-1 * time.Second) //上上上个月最后一天
  85. //最早的一天
  86. firstDate = lastMonthFirstDay3
  87. ch1 := make(chan AdminDataMap, 0)
  88. ch2 := make(chan AdminDataMap, 0)
  89. ch3 := make(chan AdminDataMap, 0)
  90. ch4 := make(chan AdminDataMap, 0)
  91. go getSectionData(nowMonthFirstDay, nowMonthLastDay, adminType, dimensionType, ch1)
  92. go getSectionData(lastMonthFirstDay1, lastMonthLastDay1, adminType, dimensionType, ch2)
  93. go getSectionData(lastMonthFirstDay2, lastMonthLastDay2, adminType, dimensionType, ch3)
  94. go getSectionData(lastMonthFirstDay3, lastMonthLastDay3, adminType, dimensionType, ch4)
  95. var nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3 AdminDataMap
  96. nowMonthAdminDataMap = <-ch1
  97. close(ch1)
  98. lastMonthAdminDataMap1 = <-ch2
  99. close(ch2)
  100. lastMonthAdminDataMap2 = <-ch3
  101. close(ch3)
  102. lastMonthAdminDataMap3 = <-ch4
  103. close(ch4)
  104. adminDataMapList = make([]AdminDataMap, 0)
  105. adminDataMapList = append(adminDataMapList, nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3)
  106. return
  107. }
  108. // GetMonthDataV2 月度数据
  109. func GetMonthDataV2(adminType, dimensionType string, dataNum int) (adminDataMapList []AdminDataMap, firstDate time.Time, err error) { //三个协程返回
  110. nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
  111. //nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
  112. chanList := make([]chan AdminDataMap, 0)
  113. for i := 0; i < dataNum; i++ {
  114. tmpCh := make(chan AdminDataMap, 0)
  115. chanList = append(chanList, tmpCh)
  116. lastMonthFirstDay := nowMonthFirstDay.AddDate(0, -1*i, 0) //上个月第一天
  117. lastMonthLastDay := nowMonthFirstDay.AddDate(0, -1*(i-1), 0).Add(-1 * time.Second) //上个月最后一天
  118. // 第一个开始日期
  119. firstDate = lastMonthFirstDay
  120. go getSectionData(lastMonthFirstDay, lastMonthLastDay, adminType, dimensionType, tmpCh)
  121. }
  122. adminDataMapList = make([]AdminDataMap, 0)
  123. for _, vChan := range chanList {
  124. var monthAdminDataMap AdminDataMap
  125. monthAdminDataMap = <-vChan
  126. close(vChan)
  127. adminDataMapList = append(adminDataMapList, monthAdminDataMap)
  128. }
  129. return
  130. }
  131. // GetTimeIntervalData 区间数据
  132. func GetTimeIntervalData(startDate, endDate, adminType, dimensionType string) (adminDataMapList []AdminDataMap, firstDate time.Time, err error) { //三个协程返回
  133. startDateTimer, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  134. endDateTimer, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  135. endDateTimer = endDateTimer.AddDate(0, 0, 1).Add(-1 * time.Second) //本月最后一天
  136. //最早的一天
  137. firstDate = startDateTimer
  138. ch1 := make(chan AdminDataMap, 0)
  139. go getSectionData(startDateTimer, endDateTimer, adminType, dimensionType, ch1)
  140. var adminDataMap AdminDataMap
  141. adminDataMap = <-ch1
  142. close(ch1)
  143. adminDataMapList = make([]AdminDataMap, 0)
  144. adminDataMapList = append(adminDataMapList, adminDataMap)
  145. return
  146. }
  147. type AdminDataMap struct {
  148. TryOutMap map[int]int `description:"试用路演次数"`
  149. FormalMap map[int]int `description:"正式路演次数"`
  150. MeetingMap map[int]int `description:"会议次数"`
  151. OnlineMap map[int]int `description:"线上路演次数"`
  152. OfflineMap map[int]int `description:"线上路演次数"`
  153. RoadShowMap map[int]int `description:"路演总次数"`
  154. SalonMap map[int]int `description:"沙龙路演次数"`
  155. StartDate string `description:"开始日期"`
  156. EndDate string `description:"开始日期"`
  157. }
  158. // getSectionData 获取周期数据
  159. func getSectionData(startDate, endDate time.Time, adminType, dimensionType string, ch chan AdminDataMap) (adminDataMap AdminDataMap, err error) {
  160. defer func() {
  161. ch <- adminDataMap
  162. }()
  163. //adminType := `seller`
  164. switch adminType {
  165. case "researcher":
  166. adminDataMap, err = getResearcherSectionData(startDate, endDate)
  167. case "seller":
  168. adminDataMap, err = getSellerSectionData(startDate, endDate, dimensionType)
  169. }
  170. return
  171. }
  172. // getResearcherSectionData 获取研究员周期数据
  173. func getResearcherSectionData(startDate, endDate time.Time) (adminDataMap AdminDataMap, err error) {
  174. tryOutMap := make(map[int]int)
  175. formalMap := make(map[int]int)
  176. meetingMap := make(map[int]int)
  177. roadShowMap := make(map[int]int) // 路演总次数
  178. salonMap := make(map[int]int) //沙龙路演次数
  179. //正式客户
  180. {
  181. var condition string
  182. var pars []interface{}
  183. condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
  184. pars = append(pars, startDate, endDate, "正式")
  185. data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars)
  186. if tmpErr != nil {
  187. err = tmpErr
  188. return
  189. }
  190. for _, v := range data {
  191. formalMap[v.AdminId] = v.Num
  192. }
  193. }
  194. //试用客户
  195. {
  196. var condition string
  197. var pars []interface{}
  198. condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
  199. pars = append(pars, startDate, endDate, "试用")
  200. data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars)
  201. if tmpErr != nil {
  202. err = tmpErr
  203. return
  204. }
  205. for _, v := range data {
  206. //fmt.Println(v)
  207. tryOutMap[v.AdminId] = v.Num
  208. }
  209. }
  210. //试用客户
  211. {
  212. var condition string
  213. var pars []interface{}
  214. condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
  215. pars = append(pars, startDate, endDate, "公开会议")
  216. data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars)
  217. if tmpErr != nil {
  218. err = tmpErr
  219. return
  220. }
  221. for _, v := range data {
  222. //fmt.Println(v)
  223. meetingMap[v.AdminId] = v.Num
  224. }
  225. }
  226. //路演总次数
  227. {
  228. var condition string
  229. var pars []interface{}
  230. condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
  231. pars = append(pars, startDate, endDate, "路演")
  232. data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars)
  233. if tmpErr != nil {
  234. err = tmpErr
  235. return
  236. }
  237. for _, v := range data {
  238. //fmt.Println(v)
  239. roadShowMap[v.AdminId] = v.Num
  240. }
  241. }
  242. //沙龙路演次数
  243. {
  244. var condition string
  245. var pars []interface{}
  246. condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
  247. pars = append(pars, startDate, endDate, "沙龙")
  248. data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars)
  249. if tmpErr != nil {
  250. err = tmpErr
  251. return
  252. }
  253. for _, v := range data {
  254. //fmt.Println(v)
  255. salonMap[v.AdminId] = v.Num
  256. }
  257. }
  258. adminDataMap = AdminDataMap{
  259. TryOutMap: tryOutMap,
  260. FormalMap: formalMap,
  261. MeetingMap: meetingMap,
  262. RoadShowMap: roadShowMap,
  263. SalonMap: salonMap,
  264. StartDate: startDate.Format(utils.FormatDate),
  265. EndDate: endDate.Format(utils.FormatDate),
  266. }
  267. return
  268. }
  269. // getSellerSectionData 获取销售周期数据
  270. func getSellerSectionData(startDate, endDate time.Time, dimensionType string) (adminDataMap AdminDataMap, err error) {
  271. tryOutMap := make(map[int]int)
  272. formalMap := make(map[int]int)
  273. meetingMap := make(map[int]int)
  274. onlineMap := make(map[int]int)
  275. offlineMap := make(map[int]int)
  276. roadShowMap := make(map[int]int) // 路演总次数
  277. salonMap := make(map[int]int) //沙龙路演次数
  278. //fmt.Println()
  279. //客户状态维度
  280. if dimensionType == "company_status" {
  281. //正式客户
  282. {
  283. var condition string
  284. var pars []interface{}
  285. condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
  286. pars = append(pars, startDate, endDate, "正式")
  287. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  288. if tmpErr != nil {
  289. err = tmpErr
  290. return
  291. }
  292. for _, v := range data {
  293. formalMap[v.AdminId] = v.Num
  294. }
  295. }
  296. //试用客户
  297. {
  298. var condition string
  299. var pars []interface{}
  300. condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
  301. pars = append(pars, startDate, endDate, "试用")
  302. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  303. if tmpErr != nil {
  304. err = tmpErr
  305. return
  306. }
  307. for _, v := range data {
  308. //fmt.Println(v)
  309. tryOutMap[v.AdminId] = v.Num
  310. }
  311. }
  312. }
  313. //路演形式维度
  314. if dimensionType == "roadshow_type" {
  315. //线上路演
  316. {
  317. var condition string
  318. var pars []interface{}
  319. condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? `
  320. pars = append(pars, startDate, endDate, "线上")
  321. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  322. if tmpErr != nil {
  323. err = tmpErr
  324. return
  325. }
  326. for _, v := range data {
  327. //fmt.Println(v)
  328. onlineMap[v.AdminId] = v.Num
  329. }
  330. }
  331. //线下路演
  332. {
  333. var condition string
  334. var pars []interface{}
  335. condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? `
  336. pars = append(pars, startDate, endDate, "线下")
  337. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  338. if tmpErr != nil {
  339. err = tmpErr
  340. return
  341. }
  342. for _, v := range data {
  343. //fmt.Println(v)
  344. offlineMap[v.AdminId] = v.Num
  345. }
  346. }
  347. }
  348. //销售专项路演统计
  349. if dimensionType == "seller_special" {
  350. detail, errdetail := company.GetConfigDetailByCode("choice_researcher_adminid")
  351. if errdetail != nil {
  352. err = errdetail
  353. return
  354. }
  355. //正式客户
  356. {
  357. var condition string
  358. var pars []interface{}
  359. condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  360. pars = append(pars, startDate, endDate, "正式")
  361. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  362. if tmpErr != nil {
  363. err = tmpErr
  364. return
  365. }
  366. for _, v := range data {
  367. formalMap[v.AdminId] = v.Num
  368. }
  369. }
  370. //试用客户
  371. {
  372. var condition string
  373. var pars []interface{}
  374. condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  375. pars = append(pars, startDate, endDate, "试用")
  376. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  377. if tmpErr != nil {
  378. err = tmpErr
  379. return
  380. }
  381. for _, v := range data {
  382. //fmt.Println(v)
  383. tryOutMap[v.AdminId] = v.Num
  384. }
  385. }
  386. //公开会议
  387. {
  388. var condition string
  389. var pars []interface{}
  390. condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  391. pars = append(pars, startDate, endDate, "公开会议")
  392. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  393. if tmpErr != nil {
  394. err = tmpErr
  395. return
  396. }
  397. for _, v := range data {
  398. //fmt.Println(v)
  399. meetingMap[v.AdminId] = v.Num
  400. }
  401. }
  402. } else {
  403. //公开会议
  404. {
  405. var condition string
  406. var pars []interface{}
  407. condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
  408. pars = append(pars, startDate, endDate, "公开会议")
  409. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  410. if tmpErr != nil {
  411. err = tmpErr
  412. return
  413. }
  414. for _, v := range data {
  415. //fmt.Println(v)
  416. meetingMap[v.AdminId] = v.Num
  417. }
  418. }
  419. }
  420. //权益路演
  421. if dimensionType == "roadshow_rai" {
  422. //路演总次数
  423. {
  424. var condition string
  425. var pars []interface{}
  426. condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
  427. pars = append(pars, startDate, endDate, "路演")
  428. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  429. if tmpErr != nil {
  430. err = tmpErr
  431. return
  432. }
  433. for _, v := range data {
  434. //fmt.Println(v)
  435. roadShowMap[v.AdminId] = v.Num
  436. }
  437. }
  438. //沙龙路演次数
  439. {
  440. var condition string
  441. var pars []interface{}
  442. condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
  443. pars = append(pars, startDate, endDate, "沙龙")
  444. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  445. if tmpErr != nil {
  446. err = tmpErr
  447. return
  448. }
  449. for _, v := range data {
  450. //fmt.Println(v)
  451. salonMap[v.AdminId] = v.Num
  452. }
  453. }
  454. }
  455. adminDataMap = AdminDataMap{
  456. TryOutMap: tryOutMap,
  457. FormalMap: formalMap,
  458. MeetingMap: meetingMap,
  459. OfflineMap: offlineMap,
  460. OnlineMap: onlineMap,
  461. RoadShowMap: roadShowMap,
  462. SalonMap: salonMap,
  463. StartDate: startDate.Format(utils.FormatDate),
  464. EndDate: endDate.Format(utils.FormatDate),
  465. }
  466. return
  467. }
  468. type OverseasAdminDataMap struct {
  469. TryOutMap map[int]int `description:"试用路演次数"`
  470. FormalMap map[int]int `description:"正式路演次数"`
  471. CloseMap map[int]int `description:"关闭客户次数"`
  472. OnlineMap map[int]int `description:"线上路演次数"`
  473. OfflineMap map[int]int `description:"线上路演次数"`
  474. StartDate string `description:"开始日期"`
  475. EndDate string `description:"开始日期"`
  476. }
  477. // GetOverseasWeekDataV2 周度数据
  478. func GetOverseasWeekDataV2(adminType, dimensionType string, weekNum int) (adminDataList []OverseasAdminDataMap, firstDate time.Time, err error) {
  479. nowWeekMonday := utils.GetNowWeekMonday() //本周周一
  480. //fmt.Println(nowWeekMonday)
  481. nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日
  482. chanList := make([]chan OverseasAdminDataMap, 0)
  483. for i := 0; i < weekNum; i++ {
  484. tmpCh := make(chan OverseasAdminDataMap, 0)
  485. chanList = append(chanList, tmpCh)
  486. lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7*i)
  487. lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7*i)
  488. // 第一个开始日期
  489. firstDate = lastWeekMonday
  490. go getOverseasSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, tmpCh)
  491. }
  492. adminDataList = make([]OverseasAdminDataMap, 0)
  493. for _, vChan := range chanList {
  494. var weekAdminDataMap OverseasAdminDataMap
  495. weekAdminDataMap = <-vChan
  496. close(vChan)
  497. adminDataList = append(adminDataList, weekAdminDataMap)
  498. }
  499. return
  500. }
  501. // getOverseasSectionData 获取周期数据
  502. func getOverseasSectionData(startDate, endDate time.Time, adminType, dimensionType string, ch chan OverseasAdminDataMap) (adminDataMap OverseasAdminDataMap, err error) {
  503. defer func() {
  504. ch <- adminDataMap
  505. }()
  506. //adminType := `seller`
  507. switch adminType {
  508. case "researcher":
  509. adminDataMap, err = getOverseasResearcherSectionData(startDate, endDate)
  510. case "seller":
  511. adminDataMap, err = getOverseasSellerSectionData(startDate, endDate, dimensionType)
  512. }
  513. return
  514. }
  515. // getOverseasSellerSectionData 获取销售周期数据
  516. func getOverseasSellerSectionData(startDate, endDate time.Time, dimensionType string) (adminDataMap OverseasAdminDataMap, err error) {
  517. tryOutMap := make(map[int]int)
  518. formalMap := make(map[int]int)
  519. closeMap := make(map[int]int)
  520. onlineMap := make(map[int]int)
  521. offlineMap := make(map[int]int)
  522. //fmt.Println()
  523. //客户状态维度
  524. companylist, err := overseas_custom.GetOverseasCustomList("", nil)
  525. if err != nil {
  526. return
  527. }
  528. formalIdsArr := make([]int, 0)
  529. tryoutIdsArr := make([]int, 0)
  530. closeIdsArr := make([]int, 0)
  531. for _, v := range companylist {
  532. if v.OverseasStatus == "正式" {
  533. formalIdsArr = append(formalIdsArr, v.CompanyId)
  534. } else if v.OverseasStatus == "试用" {
  535. tryoutIdsArr = append(tryoutIdsArr, v.CompanyId)
  536. } else if v.OverseasStatus == "关闭" {
  537. closeIdsArr = append(closeIdsArr, v.CompanyId)
  538. }
  539. }
  540. if dimensionType == "company_status" {
  541. //正式客户
  542. {
  543. //var condition string
  544. //var pars []interface{}
  545. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(formalIdsArr)) + `)`
  546. //pars = append(pars, startDate, endDate, "正式", formalIdsArr)
  547. data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "正式")
  548. if tmpErr != nil {
  549. err = tmpErr
  550. return
  551. }
  552. for _, v := range data {
  553. fmt.Println(v)
  554. formalMap[v.AdminId] = v.Num
  555. }
  556. }
  557. //试用客户
  558. {
  559. //var condition string
  560. //var pars []interface{}
  561. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(tryoutIdsArr)) + `)`
  562. //pars = append(pars, startDate, endDate, "试用", tryoutIdsArr)
  563. data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "试用")
  564. if tmpErr != nil {
  565. err = tmpErr
  566. return
  567. }
  568. for _, v := range data {
  569. //fmt.Println(v)
  570. tryOutMap[v.AdminId] = v.Num
  571. }
  572. }
  573. //关闭客户
  574. {
  575. //var condition string
  576. //var pars []interface{}
  577. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(closeIdsArr)) + `)`
  578. //pars = append(pars, startDate, endDate, "关闭", closeIdsArr)
  579. data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "关闭")
  580. if tmpErr != nil {
  581. err = tmpErr
  582. return
  583. }
  584. for _, v := range data {
  585. //fmt.Println(v)
  586. closeMap[v.AdminId] = v.Num
  587. }
  588. }
  589. }
  590. //路演形式维度
  591. //if dimensionType == "roadshow_type" {
  592. // //线上路演
  593. // {
  594. // var condition string
  595. // var pars []interface{}
  596. // condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? and company_id IN (` + utils.GetOrmInReplace(len(idsArr)) + `)`
  597. // pars = append(pars, startDate, endDate, "线上", idsArr)
  598. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  599. // if tmpErr != nil {
  600. // err = tmpErr
  601. // return
  602. // }
  603. // for _, v := range data {
  604. // //fmt.Println(v)
  605. // onlineMap[v.AdminId] = v.Num
  606. // }
  607. // }
  608. //
  609. // //线下路演
  610. // {
  611. // var condition string
  612. // var pars []interface{}
  613. // condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? and company_id IN (` + utils.GetOrmInReplace(len(idsArr)) + `)`
  614. // pars = append(pars, startDate, endDate, "线下", idsArr)
  615. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  616. // if tmpErr != nil {
  617. // err = tmpErr
  618. // return
  619. // }
  620. // for _, v := range data {
  621. // //fmt.Println(v)
  622. // offlineMap[v.AdminId] = v.Num
  623. // }
  624. // }
  625. //}
  626. ////销售专项路演统计
  627. //if dimensionType == "seller_special" {
  628. //
  629. // detail, errdetail := company.GetConfigDetailByCode("choice_researcher_adminid")
  630. // if errdetail != nil {
  631. // err = errdetail
  632. // return
  633. // }
  634. // //正式客户
  635. // {
  636. // var condition string
  637. // var pars []interface{}
  638. // condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  639. // pars = append(pars, startDate, endDate, "正式")
  640. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  641. // if tmpErr != nil {
  642. // err = tmpErr
  643. // return
  644. // }
  645. // for _, v := range data {
  646. // formalMap[v.AdminId] = v.Num
  647. // }
  648. // }
  649. //
  650. // //试用客户
  651. // {
  652. // var condition string
  653. // var pars []interface{}
  654. // condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  655. // pars = append(pars, startDate, endDate, "试用")
  656. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  657. //
  658. // if tmpErr != nil {
  659. // err = tmpErr
  660. // return
  661. // }
  662. // for _, v := range data {
  663. // //fmt.Println(v)
  664. // tryOutMap[v.AdminId] = v.Num
  665. // }
  666. // }
  667. //
  668. // //公开会议
  669. // {
  670. // var condition string
  671. // var pars []interface{}
  672. // condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  673. // pars = append(pars, startDate, endDate, "公开会议")
  674. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  675. // if tmpErr != nil {
  676. // err = tmpErr
  677. // return
  678. // }
  679. // for _, v := range data {
  680. // //fmt.Println(v)
  681. // meetingMap[v.AdminId] = v.Num
  682. // }
  683. // }
  684. //} else {
  685. // //公开会议
  686. // {
  687. // var condition string
  688. // var pars []interface{}
  689. // condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
  690. // pars = append(pars, startDate, endDate, "公开会议")
  691. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  692. // if tmpErr != nil {
  693. // err = tmpErr
  694. // return
  695. // }
  696. // for _, v := range data {
  697. // //fmt.Println(v)
  698. // meetingMap[v.AdminId] = v.Num
  699. // }
  700. // }
  701. //}
  702. adminDataMap = OverseasAdminDataMap{
  703. TryOutMap: tryOutMap,
  704. FormalMap: formalMap,
  705. CloseMap: closeMap,
  706. OfflineMap: offlineMap,
  707. OnlineMap: onlineMap,
  708. StartDate: startDate.Format(utils.FormatDate),
  709. EndDate: endDate.Format(utils.FormatDate),
  710. }
  711. return
  712. }
  713. // getOverseasResearcherSectionData 获取研究员周期数据
  714. func getOverseasResearcherSectionData(startDate, endDate time.Time) (adminDataMap OverseasAdminDataMap, err error) {
  715. tryOutMap := make(map[int]int)
  716. formalMap := make(map[int]int)
  717. closemap := make(map[int]int)
  718. //companylist, err := overseas_custom.GetOverseasCustomList("", nil)
  719. //if err != nil {
  720. // return
  721. //}
  722. //formalIdsArr := make([]int, 0)
  723. //tryoutIdsArr := make([]int, 0)
  724. //closeIdsArr := make([]int, 0)
  725. //for _, v := range companylist {
  726. // if v.OverseasStatus == "正式" {
  727. // formalIdsArr = append(formalIdsArr, v.CompanyId)
  728. // } else if v.OverseasStatus == "试用" {
  729. // tryoutIdsArr = append(tryoutIdsArr, v.CompanyId)
  730. // } else if v.OverseasStatus == "关闭" {
  731. // closeIdsArr = append(closeIdsArr, v.CompanyId)
  732. // }
  733. //}
  734. //正式客户
  735. {
  736. //var condition string
  737. //var pars []interface{}
  738. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(formalIdsArr)) + `)`
  739. //pars = append(pars, startDate, endDate, "正式", formalIdsArr)
  740. data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "正式")
  741. if tmpErr != nil {
  742. err = tmpErr
  743. return
  744. }
  745. for _, v := range data {
  746. formalMap[v.AdminId] = v.Num
  747. }
  748. }
  749. //试用客户
  750. {
  751. //var condition string
  752. //var pars []interface{}
  753. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(tryoutIdsArr)) + `)`
  754. //pars = append(pars, startDate, endDate, "试用", tryoutIdsArr)
  755. data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "试用")
  756. if tmpErr != nil {
  757. err = tmpErr
  758. return
  759. }
  760. for _, v := range data {
  761. //fmt.Println(v)
  762. tryOutMap[v.AdminId] = v.Num
  763. }
  764. }
  765. //试用客户
  766. {
  767. //var condition string
  768. //var pars []interface{}
  769. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(closeIdsArr)) + `)`
  770. //pars = append(pars, startDate, endDate, "关闭", closeIdsArr)
  771. data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "关闭")
  772. if tmpErr != nil {
  773. err = tmpErr
  774. return
  775. }
  776. for _, v := range data {
  777. //fmt.Println(v)
  778. closemap[v.AdminId] = v.Num
  779. }
  780. }
  781. adminDataMap = OverseasAdminDataMap{
  782. TryOutMap: tryOutMap,
  783. FormalMap: formalMap,
  784. CloseMap: closemap,
  785. StartDate: startDate.Format(utils.FormatDate),
  786. EndDate: endDate.Format(utils.FormatDate),
  787. }
  788. return
  789. }
  790. // GetOverseasMonthDataV2 月度数据
  791. func GetOverseasMonthDataV2(adminType, dimensionType string, dataNum int) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回
  792. nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
  793. //nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
  794. chanList := make([]chan OverseasAdminDataMap, 0)
  795. for i := 0; i < dataNum; i++ {
  796. tmpCh := make(chan OverseasAdminDataMap, 0)
  797. chanList = append(chanList, tmpCh)
  798. lastMonthFirstDay := nowMonthFirstDay.AddDate(0, -1*i, 0) //上个月第一天
  799. lastMonthLastDay := nowMonthFirstDay.AddDate(0, -1*(i-1), 0).Add(-1 * time.Second) //上个月最后一天
  800. // 第一个开始日期
  801. firstDate = lastMonthFirstDay
  802. go getOverseasSectionData(lastMonthFirstDay, lastMonthLastDay, adminType, dimensionType, tmpCh)
  803. }
  804. adminDataMapList = make([]OverseasAdminDataMap, 0)
  805. for _, vChan := range chanList {
  806. var monthAdminDataMap OverseasAdminDataMap
  807. monthAdminDataMap = <-vChan
  808. close(vChan)
  809. adminDataMapList = append(adminDataMapList, monthAdminDataMap)
  810. }
  811. return
  812. }
  813. // GetOverseasTimeIntervalData 区间数据
  814. func GetOverseasTimeIntervalData(startDate, endDate, adminType, dimensionType string) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回
  815. startDateTimer, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  816. endDateTimer, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  817. endDateTimer = endDateTimer.AddDate(0, 0, 1).Add(-1 * time.Second) //本月最后一天
  818. //最早的一天
  819. firstDate = startDateTimer
  820. ch1 := make(chan OverseasAdminDataMap, 0)
  821. go getOverseasSectionData(startDateTimer, endDateTimer, adminType, dimensionType, ch1)
  822. var adminDataMap OverseasAdminDataMap
  823. adminDataMap = <-ch1
  824. close(ch1)
  825. adminDataMapList = make([]OverseasAdminDataMap, 0)
  826. adminDataMapList = append(adminDataMapList, adminDataMap)
  827. return
  828. }
  829. // GetOverseasWeekData 周度数据
  830. func GetOverseasWeekData(adminType, dimensionType string) (adminDataList []OverseasAdminDataMap, firstDate time.Time, err error) {
  831. nowWeekMonday := utils.GetNowWeekMonday() //本周周一
  832. //fmt.Println(nowWeekMonday)
  833. nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日
  834. //fmt.Println(nowWeekSunday)
  835. //nowWeekMonday = nowWeekMonday.AddDate(0, 0, -30) //上周周一
  836. //nowWeekSunday = nowWeekSunday.AddDate(0, 0, -30) //上周周日
  837. //adminDataMap, err := getSectionData(nowWeekMonday, nowWeekSunday)
  838. //if err != nil {
  839. // fmt.Println(err)
  840. // return
  841. //}
  842. //fmt.Println(adminDataMap)
  843. lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7) //上周周一
  844. //fmt.Println(lastWeekMonday)
  845. //最早的一天
  846. firstDate = lastWeekMonday
  847. lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7) //上周周日
  848. //fmt.Println(lastWeekSunday)
  849. nextWeekMonday := nowWeekMonday.AddDate(0, 0, 7) //下周周一
  850. //fmt.Println(nextWeekMonday)
  851. nextWeekSunday := nowWeekSunday.AddDate(0, 0, 7) //下周周日
  852. //fmt.Println(nextWeekSunday)
  853. ch1 := make(chan OverseasAdminDataMap, 0)
  854. ch2 := make(chan OverseasAdminDataMap, 0)
  855. ch3 := make(chan OverseasAdminDataMap, 0)
  856. go getOverseasSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, ch1)
  857. go getOverseasSectionData(nowWeekMonday, nowWeekSunday, adminType, dimensionType, ch2)
  858. go getOverseasSectionData(nextWeekMonday, nextWeekSunday, adminType, dimensionType, ch3)
  859. var nowWeekAdminDataMap, lastWeekAdminDataMap, nextWeekAdminDataMap OverseasAdminDataMap
  860. lastWeekAdminDataMap = <-ch1
  861. close(ch1)
  862. nowWeekAdminDataMap = <-ch2
  863. close(ch2)
  864. nextWeekAdminDataMap = <-ch3
  865. close(ch3)
  866. adminDataList = make([]OverseasAdminDataMap, 0)
  867. adminDataList = append(adminDataList, lastWeekAdminDataMap, nowWeekAdminDataMap, nextWeekAdminDataMap)
  868. return
  869. }
  870. // GetOverseasMonthData 月度数据
  871. func GetOverseasMonthData(adminType, dimensionType string) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回
  872. nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
  873. nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
  874. lastMonthFirstDay1 := nowMonthFirstDay.AddDate(0, -1, 0) //上个月第一天
  875. lastMonthLastDay1 := lastMonthFirstDay1.AddDate(0, 1, 0).Add(-1 * time.Second) //上个月最后一天
  876. lastMonthFirstDay2 := nowMonthFirstDay.AddDate(0, -2, 0) //上上个月第一天
  877. lastMonthLastDay2 := lastMonthFirstDay2.AddDate(0, 1, 0).Add(-1 * time.Second) //上上个月最后一天
  878. lastMonthFirstDay3 := nowMonthFirstDay.AddDate(0, -3, 0) //上上上个月第一天
  879. lastMonthLastDay3 := lastMonthFirstDay3.AddDate(0, 1, 0).Add(-1 * time.Second) //上上上个月最后一天
  880. //最早的一天
  881. firstDate = lastMonthFirstDay3
  882. ch1 := make(chan OverseasAdminDataMap, 0)
  883. ch2 := make(chan OverseasAdminDataMap, 0)
  884. ch3 := make(chan OverseasAdminDataMap, 0)
  885. ch4 := make(chan OverseasAdminDataMap, 0)
  886. go getOverseasSectionData(nowMonthFirstDay, nowMonthLastDay, adminType, dimensionType, ch1)
  887. go getOverseasSectionData(lastMonthFirstDay1, lastMonthLastDay1, adminType, dimensionType, ch2)
  888. go getOverseasSectionData(lastMonthFirstDay2, lastMonthLastDay2, adminType, dimensionType, ch3)
  889. go getOverseasSectionData(lastMonthFirstDay3, lastMonthLastDay3, adminType, dimensionType, ch4)
  890. var nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3 OverseasAdminDataMap
  891. nowMonthAdminDataMap = <-ch1
  892. close(ch1)
  893. lastMonthAdminDataMap1 = <-ch2
  894. close(ch2)
  895. lastMonthAdminDataMap2 = <-ch3
  896. close(ch3)
  897. lastMonthAdminDataMap3 = <-ch4
  898. close(ch4)
  899. adminDataMapList = make([]OverseasAdminDataMap, 0)
  900. adminDataMapList = append(adminDataMapList, nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3)
  901. return
  902. }