report.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  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. StartDate string `description:"开始日期"`
  154. EndDate string `description:"开始日期"`
  155. }
  156. // getSectionData 获取周期数据
  157. func getSectionData(startDate, endDate time.Time, adminType, dimensionType string, ch chan AdminDataMap) (adminDataMap AdminDataMap, err error) {
  158. defer func() {
  159. ch <- adminDataMap
  160. }()
  161. //adminType := `seller`
  162. switch adminType {
  163. case "researcher":
  164. adminDataMap, err = getResearcherSectionData(startDate, endDate)
  165. case "seller":
  166. adminDataMap, err = getSellerSectionData(startDate, endDate, dimensionType)
  167. }
  168. return
  169. }
  170. // getResearcherSectionData 获取研究员周期数据
  171. func getResearcherSectionData(startDate, endDate time.Time) (adminDataMap AdminDataMap, err error) {
  172. tryOutMap := make(map[int]int)
  173. formalMap := make(map[int]int)
  174. meetingMap := make(map[int]int)
  175. //正式客户
  176. {
  177. var condition string
  178. var pars []interface{}
  179. condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
  180. pars = append(pars, startDate, endDate, "正式")
  181. data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars)
  182. if tmpErr != nil {
  183. err = tmpErr
  184. return
  185. }
  186. for _, v := range data {
  187. formalMap[v.AdminId] = v.Num
  188. }
  189. }
  190. //试用客户
  191. {
  192. var condition string
  193. var pars []interface{}
  194. condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
  195. pars = append(pars, startDate, endDate, "试用")
  196. data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars)
  197. if tmpErr != nil {
  198. err = tmpErr
  199. return
  200. }
  201. for _, v := range data {
  202. //fmt.Println(v)
  203. tryOutMap[v.AdminId] = v.Num
  204. }
  205. }
  206. //试用客户
  207. {
  208. var condition string
  209. var pars []interface{}
  210. condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
  211. pars = append(pars, startDate, endDate, "公开会议")
  212. data, tmpErr := roadshow.GetGroupResearcherRecordList(condition, pars)
  213. if tmpErr != nil {
  214. err = tmpErr
  215. return
  216. }
  217. for _, v := range data {
  218. //fmt.Println(v)
  219. meetingMap[v.AdminId] = v.Num
  220. }
  221. }
  222. adminDataMap = AdminDataMap{
  223. TryOutMap: tryOutMap,
  224. FormalMap: formalMap,
  225. MeetingMap: meetingMap,
  226. StartDate: startDate.Format(utils.FormatDate),
  227. EndDate: endDate.Format(utils.FormatDate),
  228. }
  229. return
  230. }
  231. // getSellerSectionData 获取销售周期数据
  232. func getSellerSectionData(startDate, endDate time.Time, dimensionType string) (adminDataMap AdminDataMap, err error) {
  233. tryOutMap := make(map[int]int)
  234. formalMap := make(map[int]int)
  235. meetingMap := make(map[int]int)
  236. onlineMap := make(map[int]int)
  237. offlineMap := make(map[int]int)
  238. //fmt.Println()
  239. //客户状态维度
  240. if dimensionType == "company_status" {
  241. //正式客户
  242. {
  243. var condition string
  244. var pars []interface{}
  245. condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
  246. pars = append(pars, startDate, endDate, "正式")
  247. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  248. if tmpErr != nil {
  249. err = tmpErr
  250. return
  251. }
  252. for _, v := range data {
  253. formalMap[v.AdminId] = v.Num
  254. }
  255. }
  256. //试用客户
  257. {
  258. var condition string
  259. var pars []interface{}
  260. condition = ` and start_date >= ? and end_date <= ? and company_status = ? `
  261. pars = append(pars, startDate, endDate, "试用")
  262. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  263. if tmpErr != nil {
  264. err = tmpErr
  265. return
  266. }
  267. for _, v := range data {
  268. //fmt.Println(v)
  269. tryOutMap[v.AdminId] = v.Num
  270. }
  271. }
  272. }
  273. //路演形式维度
  274. if dimensionType == "roadshow_type" {
  275. //线上路演
  276. {
  277. var condition string
  278. var pars []interface{}
  279. condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? `
  280. pars = append(pars, startDate, endDate, "线上")
  281. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  282. if tmpErr != nil {
  283. err = tmpErr
  284. return
  285. }
  286. for _, v := range data {
  287. //fmt.Println(v)
  288. onlineMap[v.AdminId] = v.Num
  289. }
  290. }
  291. //线下路演
  292. {
  293. var condition string
  294. var pars []interface{}
  295. condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? `
  296. pars = append(pars, startDate, endDate, "线下")
  297. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  298. if tmpErr != nil {
  299. err = tmpErr
  300. return
  301. }
  302. for _, v := range data {
  303. //fmt.Println(v)
  304. offlineMap[v.AdminId] = v.Num
  305. }
  306. }
  307. }
  308. //销售专项路演统计
  309. if dimensionType == "seller_special" {
  310. detail, errdetail := company.GetConfigDetailByCode("choice_researcher_adminid")
  311. if errdetail != nil {
  312. err = errdetail
  313. return
  314. }
  315. //正式客户
  316. {
  317. var condition string
  318. var pars []interface{}
  319. condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  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. formalMap[v.AdminId] = v.Num
  328. }
  329. }
  330. //试用客户
  331. {
  332. var condition string
  333. var pars []interface{}
  334. condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  335. pars = append(pars, startDate, endDate, "试用")
  336. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  337. if tmpErr != nil {
  338. err = tmpErr
  339. return
  340. }
  341. for _, v := range data {
  342. //fmt.Println(v)
  343. tryOutMap[v.AdminId] = v.Num
  344. }
  345. }
  346. //公开会议
  347. {
  348. var condition string
  349. var pars []interface{}
  350. condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  351. pars = append(pars, startDate, endDate, "公开会议")
  352. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  353. if tmpErr != nil {
  354. err = tmpErr
  355. return
  356. }
  357. for _, v := range data {
  358. //fmt.Println(v)
  359. meetingMap[v.AdminId] = v.Num
  360. }
  361. }
  362. } else {
  363. //公开会议
  364. {
  365. var condition string
  366. var pars []interface{}
  367. condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
  368. pars = append(pars, startDate, endDate, "公开会议")
  369. data, tmpErr := roadshow.GetGroupSellerRecordList(condition, pars)
  370. if tmpErr != nil {
  371. err = tmpErr
  372. return
  373. }
  374. for _, v := range data {
  375. //fmt.Println(v)
  376. meetingMap[v.AdminId] = v.Num
  377. }
  378. }
  379. }
  380. adminDataMap = AdminDataMap{
  381. TryOutMap: tryOutMap,
  382. FormalMap: formalMap,
  383. MeetingMap: meetingMap,
  384. OfflineMap: offlineMap,
  385. OnlineMap: onlineMap,
  386. StartDate: startDate.Format(utils.FormatDate),
  387. EndDate: endDate.Format(utils.FormatDate),
  388. }
  389. return
  390. }
  391. type OverseasAdminDataMap struct {
  392. TryOutMap map[int]int `description:"试用路演次数"`
  393. FormalMap map[int]int `description:"正式路演次数"`
  394. CloseMap map[int]int `description:"关闭客户次数"`
  395. OnlineMap map[int]int `description:"线上路演次数"`
  396. OfflineMap map[int]int `description:"线上路演次数"`
  397. StartDate string `description:"开始日期"`
  398. EndDate string `description:"开始日期"`
  399. }
  400. // GetOverseasWeekDataV2 周度数据
  401. func GetOverseasWeekDataV2(adminType, dimensionType string, weekNum int) (adminDataList []OverseasAdminDataMap, firstDate time.Time, err error) {
  402. nowWeekMonday := utils.GetNowWeekMonday() //本周周一
  403. //fmt.Println(nowWeekMonday)
  404. nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日
  405. chanList := make([]chan OverseasAdminDataMap, 0)
  406. for i := 0; i < weekNum; i++ {
  407. tmpCh := make(chan OverseasAdminDataMap, 0)
  408. chanList = append(chanList, tmpCh)
  409. lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7*i)
  410. lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7*i)
  411. // 第一个开始日期
  412. firstDate = lastWeekMonday
  413. go getOverseasSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, tmpCh)
  414. }
  415. adminDataList = make([]OverseasAdminDataMap, 0)
  416. for _, vChan := range chanList {
  417. var weekAdminDataMap OverseasAdminDataMap
  418. weekAdminDataMap = <-vChan
  419. close(vChan)
  420. adminDataList = append(adminDataList, weekAdminDataMap)
  421. }
  422. return
  423. }
  424. // getOverseasSectionData 获取周期数据
  425. func getOverseasSectionData(startDate, endDate time.Time, adminType, dimensionType string, ch chan OverseasAdminDataMap) (adminDataMap OverseasAdminDataMap, err error) {
  426. defer func() {
  427. ch <- adminDataMap
  428. }()
  429. //adminType := `seller`
  430. switch adminType {
  431. case "researcher":
  432. adminDataMap, err = getOverseasResearcherSectionData(startDate, endDate)
  433. case "seller":
  434. adminDataMap, err = getOverseasSellerSectionData(startDate, endDate, dimensionType)
  435. }
  436. return
  437. }
  438. // getOverseasSellerSectionData 获取销售周期数据
  439. func getOverseasSellerSectionData(startDate, endDate time.Time, dimensionType string) (adminDataMap OverseasAdminDataMap, err error) {
  440. tryOutMap := make(map[int]int)
  441. formalMap := make(map[int]int)
  442. closeMap := make(map[int]int)
  443. onlineMap := make(map[int]int)
  444. offlineMap := make(map[int]int)
  445. //fmt.Println()
  446. //客户状态维度
  447. companylist, err := overseas_custom.GetOverseasCustomList("", nil)
  448. if err != nil {
  449. return
  450. }
  451. formalIdsArr := make([]int, 0)
  452. tryoutIdsArr := make([]int, 0)
  453. closeIdsArr := make([]int, 0)
  454. for _, v := range companylist {
  455. if v.OverseasStatus == "正式" {
  456. formalIdsArr = append(formalIdsArr, v.CompanyId)
  457. } else if v.OverseasStatus == "试用" {
  458. tryoutIdsArr = append(tryoutIdsArr, v.CompanyId)
  459. } else if v.OverseasStatus == "关闭" {
  460. closeIdsArr = append(closeIdsArr, v.CompanyId)
  461. }
  462. }
  463. if dimensionType == "company_status" {
  464. //正式客户
  465. {
  466. //var condition string
  467. //var pars []interface{}
  468. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(formalIdsArr)) + `)`
  469. //pars = append(pars, startDate, endDate, "正式", formalIdsArr)
  470. data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "正式")
  471. if tmpErr != nil {
  472. err = tmpErr
  473. return
  474. }
  475. for _, v := range data {
  476. fmt.Println(v)
  477. formalMap[v.AdminId] = v.Num
  478. }
  479. }
  480. //试用客户
  481. {
  482. //var condition string
  483. //var pars []interface{}
  484. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(tryoutIdsArr)) + `)`
  485. //pars = append(pars, startDate, endDate, "试用", tryoutIdsArr)
  486. data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "试用")
  487. if tmpErr != nil {
  488. err = tmpErr
  489. return
  490. }
  491. for _, v := range data {
  492. //fmt.Println(v)
  493. tryOutMap[v.AdminId] = v.Num
  494. }
  495. }
  496. //关闭客户
  497. {
  498. //var condition string
  499. //var pars []interface{}
  500. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(closeIdsArr)) + `)`
  501. //pars = append(pars, startDate, endDate, "关闭", closeIdsArr)
  502. data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "关闭")
  503. if tmpErr != nil {
  504. err = tmpErr
  505. return
  506. }
  507. for _, v := range data {
  508. //fmt.Println(v)
  509. closeMap[v.AdminId] = v.Num
  510. }
  511. }
  512. }
  513. //路演形式维度
  514. //if dimensionType == "roadshow_type" {
  515. // //线上路演
  516. // {
  517. // var condition string
  518. // var pars []interface{}
  519. // condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? and company_id IN (` + utils.GetOrmInReplace(len(idsArr)) + `)`
  520. // pars = append(pars, startDate, endDate, "线上", idsArr)
  521. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  522. // if tmpErr != nil {
  523. // err = tmpErr
  524. // return
  525. // }
  526. // for _, v := range data {
  527. // //fmt.Println(v)
  528. // onlineMap[v.AdminId] = v.Num
  529. // }
  530. // }
  531. //
  532. // //线下路演
  533. // {
  534. // var condition string
  535. // var pars []interface{}
  536. // condition = ` and start_date >= ? and end_date <= ? and roadshow_type = ? and company_id IN (` + utils.GetOrmInReplace(len(idsArr)) + `)`
  537. // pars = append(pars, startDate, endDate, "线下", idsArr)
  538. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  539. // if tmpErr != nil {
  540. // err = tmpErr
  541. // return
  542. // }
  543. // for _, v := range data {
  544. // //fmt.Println(v)
  545. // offlineMap[v.AdminId] = v.Num
  546. // }
  547. // }
  548. //}
  549. ////销售专项路演统计
  550. //if dimensionType == "seller_special" {
  551. //
  552. // detail, errdetail := company.GetConfigDetailByCode("choice_researcher_adminid")
  553. // if errdetail != nil {
  554. // err = errdetail
  555. // return
  556. // }
  557. // //正式客户
  558. // {
  559. // var condition string
  560. // var pars []interface{}
  561. // condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  562. // pars = append(pars, startDate, endDate, "正式")
  563. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  564. // if tmpErr != nil {
  565. // err = tmpErr
  566. // return
  567. // }
  568. // for _, v := range data {
  569. // formalMap[v.AdminId] = v.Num
  570. // }
  571. // }
  572. //
  573. // //试用客户
  574. // {
  575. // var condition string
  576. // var pars []interface{}
  577. // condition = ` and start_date >= ? and end_date <= ? and company_status = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  578. // pars = append(pars, startDate, endDate, "试用")
  579. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  580. //
  581. // if tmpErr != nil {
  582. // err = tmpErr
  583. // return
  584. // }
  585. // for _, v := range data {
  586. // //fmt.Println(v)
  587. // tryOutMap[v.AdminId] = v.Num
  588. // }
  589. // }
  590. //
  591. // //公开会议
  592. // {
  593. // var condition string
  594. // var pars []interface{}
  595. // condition = ` and start_date >= ? and end_date <= ? and activity_type = ? ` + ` and researcher_id IN (` + detail.ConfigValue + `) `
  596. // pars = append(pars, startDate, endDate, "公开会议")
  597. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  598. // if tmpErr != nil {
  599. // err = tmpErr
  600. // return
  601. // }
  602. // for _, v := range data {
  603. // //fmt.Println(v)
  604. // meetingMap[v.AdminId] = v.Num
  605. // }
  606. // }
  607. //} else {
  608. // //公开会议
  609. // {
  610. // var condition string
  611. // var pars []interface{}
  612. // condition = ` and start_date >= ? and end_date <= ? and activity_type = ? `
  613. // pars = append(pars, startDate, endDate, "公开会议")
  614. // data, tmpErr := roadshow.GetOverseasGroupSellerRecordList(condition, pars)
  615. // if tmpErr != nil {
  616. // err = tmpErr
  617. // return
  618. // }
  619. // for _, v := range data {
  620. // //fmt.Println(v)
  621. // meetingMap[v.AdminId] = v.Num
  622. // }
  623. // }
  624. //}
  625. adminDataMap = OverseasAdminDataMap{
  626. TryOutMap: tryOutMap,
  627. FormalMap: formalMap,
  628. CloseMap: closeMap,
  629. OfflineMap: offlineMap,
  630. OnlineMap: onlineMap,
  631. StartDate: startDate.Format(utils.FormatDate),
  632. EndDate: endDate.Format(utils.FormatDate),
  633. }
  634. return
  635. }
  636. // getOverseasResearcherSectionData 获取研究员周期数据
  637. func getOverseasResearcherSectionData(startDate, endDate time.Time) (adminDataMap OverseasAdminDataMap, err error) {
  638. tryOutMap := make(map[int]int)
  639. formalMap := make(map[int]int)
  640. closemap := make(map[int]int)
  641. //companylist, err := overseas_custom.GetOverseasCustomList("", nil)
  642. //if err != nil {
  643. // return
  644. //}
  645. //formalIdsArr := make([]int, 0)
  646. //tryoutIdsArr := make([]int, 0)
  647. //closeIdsArr := make([]int, 0)
  648. //for _, v := range companylist {
  649. // if v.OverseasStatus == "正式" {
  650. // formalIdsArr = append(formalIdsArr, v.CompanyId)
  651. // } else if v.OverseasStatus == "试用" {
  652. // tryoutIdsArr = append(tryoutIdsArr, v.CompanyId)
  653. // } else if v.OverseasStatus == "关闭" {
  654. // closeIdsArr = append(closeIdsArr, v.CompanyId)
  655. // }
  656. //}
  657. //正式客户
  658. {
  659. //var condition string
  660. //var pars []interface{}
  661. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(formalIdsArr)) + `)`
  662. //pars = append(pars, startDate, endDate, "正式", formalIdsArr)
  663. data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "正式")
  664. if tmpErr != nil {
  665. err = tmpErr
  666. return
  667. }
  668. for _, v := range data {
  669. formalMap[v.AdminId] = v.Num
  670. }
  671. }
  672. //试用客户
  673. {
  674. //var condition string
  675. //var pars []interface{}
  676. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(tryoutIdsArr)) + `)`
  677. //pars = append(pars, startDate, endDate, "试用", tryoutIdsArr)
  678. data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "试用")
  679. if tmpErr != nil {
  680. err = tmpErr
  681. return
  682. }
  683. for _, v := range data {
  684. //fmt.Println(v)
  685. tryOutMap[v.AdminId] = v.Num
  686. }
  687. }
  688. //试用客户
  689. {
  690. //var condition string
  691. //var pars []interface{}
  692. //condition = ` and start_date >= ? and end_date <= ? and company_status = ? and company_id IN (` + utils.GetOrmInReplace(len(closeIdsArr)) + `)`
  693. //pars = append(pars, startDate, endDate, "关闭", closeIdsArr)
  694. data, tmpErr := roadshow.GetOverseasGroupResearcherRecordList(startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate), "关闭")
  695. if tmpErr != nil {
  696. err = tmpErr
  697. return
  698. }
  699. for _, v := range data {
  700. //fmt.Println(v)
  701. closemap[v.AdminId] = v.Num
  702. }
  703. }
  704. adminDataMap = OverseasAdminDataMap{
  705. TryOutMap: tryOutMap,
  706. FormalMap: formalMap,
  707. CloseMap: closemap,
  708. StartDate: startDate.Format(utils.FormatDate),
  709. EndDate: endDate.Format(utils.FormatDate),
  710. }
  711. return
  712. }
  713. // GetOverseasMonthDataV2 月度数据
  714. func GetOverseasMonthDataV2(adminType, dimensionType string, dataNum int) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回
  715. nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
  716. //nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
  717. chanList := make([]chan OverseasAdminDataMap, 0)
  718. for i := 0; i < dataNum; i++ {
  719. tmpCh := make(chan OverseasAdminDataMap, 0)
  720. chanList = append(chanList, tmpCh)
  721. lastMonthFirstDay := nowMonthFirstDay.AddDate(0, -1*i, 0) //上个月第一天
  722. lastMonthLastDay := nowMonthFirstDay.AddDate(0, -1*(i-1), 0).Add(-1 * time.Second) //上个月最后一天
  723. // 第一个开始日期
  724. firstDate = lastMonthFirstDay
  725. go getOverseasSectionData(lastMonthFirstDay, lastMonthLastDay, adminType, dimensionType, tmpCh)
  726. }
  727. adminDataMapList = make([]OverseasAdminDataMap, 0)
  728. for _, vChan := range chanList {
  729. var monthAdminDataMap OverseasAdminDataMap
  730. monthAdminDataMap = <-vChan
  731. close(vChan)
  732. adminDataMapList = append(adminDataMapList, monthAdminDataMap)
  733. }
  734. return
  735. }
  736. // GetOverseasTimeIntervalData 区间数据
  737. func GetOverseasTimeIntervalData(startDate, endDate, adminType, dimensionType string) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回
  738. startDateTimer, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  739. endDateTimer, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  740. endDateTimer = endDateTimer.AddDate(0, 0, 1).Add(-1 * time.Second) //本月最后一天
  741. //最早的一天
  742. firstDate = startDateTimer
  743. ch1 := make(chan OverseasAdminDataMap, 0)
  744. go getOverseasSectionData(startDateTimer, endDateTimer, adminType, dimensionType, ch1)
  745. var adminDataMap OverseasAdminDataMap
  746. adminDataMap = <-ch1
  747. close(ch1)
  748. adminDataMapList = make([]OverseasAdminDataMap, 0)
  749. adminDataMapList = append(adminDataMapList, adminDataMap)
  750. return
  751. }
  752. // GetOverseasWeekData 周度数据
  753. func GetOverseasWeekData(adminType, dimensionType string) (adminDataList []OverseasAdminDataMap, firstDate time.Time, err error) {
  754. nowWeekMonday := utils.GetNowWeekMonday() //本周周一
  755. //fmt.Println(nowWeekMonday)
  756. nowWeekSunday := nowWeekMonday.AddDate(0, 0, 7).Add(-1 * time.Second) //本周周日
  757. //fmt.Println(nowWeekSunday)
  758. //nowWeekMonday = nowWeekMonday.AddDate(0, 0, -30) //上周周一
  759. //nowWeekSunday = nowWeekSunday.AddDate(0, 0, -30) //上周周日
  760. //adminDataMap, err := getSectionData(nowWeekMonday, nowWeekSunday)
  761. //if err != nil {
  762. // fmt.Println(err)
  763. // return
  764. //}
  765. //fmt.Println(adminDataMap)
  766. lastWeekMonday := nowWeekMonday.AddDate(0, 0, -7) //上周周一
  767. //fmt.Println(lastWeekMonday)
  768. //最早的一天
  769. firstDate = lastWeekMonday
  770. lastWeekSunday := nowWeekSunday.AddDate(0, 0, -7) //上周周日
  771. //fmt.Println(lastWeekSunday)
  772. nextWeekMonday := nowWeekMonday.AddDate(0, 0, 7) //下周周一
  773. //fmt.Println(nextWeekMonday)
  774. nextWeekSunday := nowWeekSunday.AddDate(0, 0, 7) //下周周日
  775. //fmt.Println(nextWeekSunday)
  776. ch1 := make(chan OverseasAdminDataMap, 0)
  777. ch2 := make(chan OverseasAdminDataMap, 0)
  778. ch3 := make(chan OverseasAdminDataMap, 0)
  779. go getOverseasSectionData(lastWeekMonday, lastWeekSunday, adminType, dimensionType, ch1)
  780. go getOverseasSectionData(nowWeekMonday, nowWeekSunday, adminType, dimensionType, ch2)
  781. go getOverseasSectionData(nextWeekMonday, nextWeekSunday, adminType, dimensionType, ch3)
  782. var nowWeekAdminDataMap, lastWeekAdminDataMap, nextWeekAdminDataMap OverseasAdminDataMap
  783. lastWeekAdminDataMap = <-ch1
  784. close(ch1)
  785. nowWeekAdminDataMap = <-ch2
  786. close(ch2)
  787. nextWeekAdminDataMap = <-ch3
  788. close(ch3)
  789. adminDataList = make([]OverseasAdminDataMap, 0)
  790. adminDataList = append(adminDataList, lastWeekAdminDataMap, nowWeekAdminDataMap, nextWeekAdminDataMap)
  791. return
  792. }
  793. // GetOverseasMonthData 月度数据
  794. func GetOverseasMonthData(adminType, dimensionType string) (adminDataMapList []OverseasAdminDataMap, firstDate time.Time, err error) { //三个协程返回
  795. nowMonthFirstDay := utils.GetNowMonthFirstDay() //本月第一天
  796. nowMonthLastDay := nowMonthFirstDay.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
  797. lastMonthFirstDay1 := nowMonthFirstDay.AddDate(0, -1, 0) //上个月第一天
  798. lastMonthLastDay1 := lastMonthFirstDay1.AddDate(0, 1, 0).Add(-1 * time.Second) //上个月最后一天
  799. lastMonthFirstDay2 := nowMonthFirstDay.AddDate(0, -2, 0) //上上个月第一天
  800. lastMonthLastDay2 := lastMonthFirstDay2.AddDate(0, 1, 0).Add(-1 * time.Second) //上上个月最后一天
  801. lastMonthFirstDay3 := nowMonthFirstDay.AddDate(0, -3, 0) //上上上个月第一天
  802. lastMonthLastDay3 := lastMonthFirstDay3.AddDate(0, 1, 0).Add(-1 * time.Second) //上上上个月最后一天
  803. //最早的一天
  804. firstDate = lastMonthFirstDay3
  805. ch1 := make(chan OverseasAdminDataMap, 0)
  806. ch2 := make(chan OverseasAdminDataMap, 0)
  807. ch3 := make(chan OverseasAdminDataMap, 0)
  808. ch4 := make(chan OverseasAdminDataMap, 0)
  809. go getOverseasSectionData(nowMonthFirstDay, nowMonthLastDay, adminType, dimensionType, ch1)
  810. go getOverseasSectionData(lastMonthFirstDay1, lastMonthLastDay1, adminType, dimensionType, ch2)
  811. go getOverseasSectionData(lastMonthFirstDay2, lastMonthLastDay2, adminType, dimensionType, ch3)
  812. go getOverseasSectionData(lastMonthFirstDay3, lastMonthLastDay3, adminType, dimensionType, ch4)
  813. var nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3 OverseasAdminDataMap
  814. nowMonthAdminDataMap = <-ch1
  815. close(ch1)
  816. lastMonthAdminDataMap1 = <-ch2
  817. close(ch2)
  818. lastMonthAdminDataMap2 = <-ch3
  819. close(ch3)
  820. lastMonthAdminDataMap3 = <-ch4
  821. close(ch4)
  822. adminDataMapList = make([]OverseasAdminDataMap, 0)
  823. adminDataMapList = append(adminDataMapList, nowMonthAdminDataMap, lastMonthAdminDataMap1, lastMonthAdminDataMap2, lastMonthAdminDataMap3)
  824. return
  825. }