activity_special.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/cygx"
  8. "hongze/hz_crm_api/models/system"
  9. "hongze/hz_crm_api/services/alarm_msg"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. // 处理产业与标签
  16. func HandleIndustrialLabel(temporaryLabel, industrialManagementIdS, industrialSubjectIdS string, activityId int) (industrialActivityItems []*cygx.CygxIndustrialActivityGroupManagement, subjectActivityItems []*cygx.CygxIndustrialActivityGroupSubject, err error, industrialNames, industrialSubjectNames string) {
  17. //如果临时标签是空的话,就去关联产业跟标的
  18. var temporarySubject string
  19. if temporaryLabel == "" {
  20. if industrialManagementIdS == "" {
  21. return
  22. }
  23. industrialManagementList := strings.Split(industrialManagementIdS, ",")
  24. for _, v := range industrialManagementList {
  25. industrialActivityItem := new(cygx.CygxIndustrialActivityGroupManagement)
  26. industrialManagementId, e := strconv.Atoi(v)
  27. if e != nil {
  28. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  29. return
  30. }
  31. industrialActivityItem.CreateTime = time.Now()
  32. industrialActivityItem.IndustrialManagementId = industrialManagementId
  33. industrialActivityItem.ActivityId = activityId
  34. industrialActivityItem.Source = 2
  35. industrialActivityItems = append(industrialActivityItems, industrialActivityItem)
  36. }
  37. if industrialSubjectIdS != "" {
  38. industrialSubjectIdList := strings.Split(industrialSubjectIdS, ",")
  39. for _, v := range industrialSubjectIdList {
  40. subjectActivityItem := new(cygx.CygxIndustrialActivityGroupSubject)
  41. industrialSubjectId, e := strconv.Atoi(v)
  42. if e != nil {
  43. err = errors.New("标的ID不规范,Err:" + e.Error() + industrialManagementIdS)
  44. return
  45. }
  46. subjectActivityItem.CreateTime = time.Now()
  47. subjectActivityItem.IndustrialSubjectId = industrialSubjectId
  48. subjectActivityItem.ActivityId = activityId
  49. subjectActivityItem.Source = 2
  50. subjectActivityItems = append(subjectActivityItems, subjectActivityItem)
  51. }
  52. }
  53. //产业名称
  54. if industrialManagementIdS != "" {
  55. industrialNames, err = cygx.GetindustrialManagementNames(industrialManagementIdS)
  56. if err != nil {
  57. return
  58. }
  59. }
  60. //标的名称
  61. if industrialSubjectIdS != "" {
  62. industrialSubjectNames, err = cygx.GetindustrialSubjectNames(industrialSubjectIdS)
  63. if err != nil {
  64. return
  65. }
  66. if temporarySubject != "" {
  67. industrialSubjectNames += "/" + strings.Replace(temporarySubject, ",", "/", -1)
  68. }
  69. } else {
  70. industrialSubjectNames = ""
  71. if temporarySubject != "" {
  72. industrialSubjectNames = strings.Replace(temporarySubject, ",", "/", -1)
  73. }
  74. }
  75. } else {
  76. industrialActivityItems = make([]*cygx.CygxIndustrialActivityGroupManagement, 0)
  77. subjectActivityItems = make([]*cygx.CygxIndustrialActivityGroupSubject, 0)
  78. }
  79. return
  80. }
  81. // HandleDateYmdList 处理时间
  82. func HandleDateYmdList(dateYmdList []*cygx.DateYmdList) (activityTimeTextByDay, activityTime, activityTimeEnd string, dateList []string, err error) {
  83. var timeStr string
  84. timeInit := time.Now()
  85. for k, v := range dateYmdList {
  86. for k2, v2 := range v.DateHmsList {
  87. for k3, v3 := range v2.DateHms {
  88. timeStr = v.DateYmd + " " + v3 + ":00"
  89. resultTime := utils.StrTimeToTime(timeStr) //时间字符串格式转时间格式
  90. timeStrYmd := resultTime.Format(utils.FormatDate)
  91. timeYmd := utils.StrTimeToTime(timeStrYmd + " 12:00:00") //拼接当天中午12点的时间
  92. var amOrPm string
  93. if resultTime.After(timeYmd) {
  94. amOrPm = " PM"
  95. } else {
  96. amOrPm = " AM"
  97. }
  98. week := utils.StrDateTimeToWeek(timeStr)
  99. if k == 0 && k2 == 0 && k3 == 0 {
  100. activityTimeTextByDay = timeStrYmd + "(" + week + ")" + v3 + amOrPm
  101. activityTime = timeStr
  102. }
  103. //下一个时间段必须晚于上一个时间段
  104. res := timeInit.After(resultTime)
  105. if res {
  106. err = errors.New("下一个时间段必须晚于上一个时间段!" + timeStr)
  107. return
  108. } else {
  109. timeInit = resultTime
  110. }
  111. dateList = append(dateList, timeStr)
  112. }
  113. }
  114. }
  115. if len(dateList) > 0 {
  116. activityTimeEnd = dateList[len(dateList)-1]
  117. }
  118. if len(dateList)%2 != 0 {
  119. err = errors.New("缺少开始时间或结束时间!")
  120. return
  121. }
  122. return
  123. }
  124. // 处理日期的插入
  125. func AddActivitySpecial(dateList []string, activityId int) (err error) {
  126. if len(dateList) == 0 {
  127. return
  128. }
  129. var items []*cygx.CygxActivitySpecialDay
  130. for _, v := range dateList {
  131. item := new(cygx.CygxActivitySpecialDay)
  132. item.ActivityId = activityId
  133. item.DayTime = v
  134. item.CreateTime = time.Now()
  135. items = append(items, item)
  136. }
  137. _, err = cygx.AddCygxActivitySpecialDay(items, activityId)
  138. return
  139. }
  140. // GetCygxActivitySpecialDay 处理日程编辑的回显日期格式
  141. func GetCygxActivitySpecialDay(activityId int) (items []*cygx.DateYmdList, err error) {
  142. list, e := cygx.GetCygxActivitySpecialDayByActivityId(activityId)
  143. if e != nil {
  144. err = e
  145. return
  146. }
  147. mapYmd := make(map[string]string)
  148. for _, v := range list {
  149. if _, ok := mapYmd[v.DayTime.Format(utils.FormatDate)]; !ok {
  150. mapYmd[v.DayTime.Format(utils.FormatDate)] = v.DayTime.Format(utils.FormatDate)
  151. var itemYmd = new(cygx.DateYmdList)
  152. itemYmd.DateYmd = v.DayTime.Format(utils.FormatDate)
  153. items = append(items, itemYmd)
  154. }
  155. }
  156. var itemHms = new(cygx.DateHmsList)
  157. for k, v := range list {
  158. for kI, vI := range items {
  159. if v.DayTime.Format(utils.FormatDate) == vI.DateYmd {
  160. itemHms.DateHms = append(itemHms.DateHms, v.DayTime.Format(utils.FormatTimeHm))
  161. if k%2 == 1 {
  162. items[kI].DateHmsList = append(items[kI].DateHmsList, itemHms)
  163. itemHms = new(cygx.DateHmsList)
  164. }
  165. }
  166. }
  167. }
  168. return
  169. }
  170. func HandleActivityListSpecial(list []*cygx.CygxActivitySpecialList, isTrip bool) (items []*cygx.CygxActivitySpecialList) {
  171. for k, v := range list {
  172. if list[k].IsDetermineTravel > 0 {
  173. list[k].IsDetermineTravel = 1
  174. }
  175. if !isTrip {
  176. if v.IsOffline > 0 {
  177. list[k].PublishStatus = 3
  178. }
  179. if v.IsDetermineTravel > 0 {
  180. list[k].PublishStatus = 4
  181. }
  182. }
  183. if v.Days > 0 {
  184. resultTime := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  185. res := time.Now().Before(resultTime)
  186. if !res && v.IsSubmitMeeting == 0 {
  187. list[k].IsShowSubmitMeeting = true
  188. }
  189. if !res && v.IsSubmitMeeting == 1 {
  190. list[k].IsShowAttendanceDetails = true
  191. list[k].IsShowUpdateMeeting = true
  192. }
  193. }
  194. }
  195. items = list
  196. return
  197. }
  198. //func init() {
  199. // specialSurplus, _ := GetSpecialSurplusByCompany(9892)
  200. // fmt.Println(specialSurplus)
  201. //}
  202. // TODO:GetSpecialSurplusByCompany 获取公司专项调研剩余次数
  203. func GetSpecialSurplusByCompany(companyId int) (specialSurplus string, err error) {
  204. companyDetail, e := cygx.GetCompanyDetailByIdGroup(companyId)
  205. if e != nil {
  206. err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
  207. }
  208. if companyDetail == nil {
  209. return
  210. }
  211. if companyDetail.Status != "永续" && companyDetail.Status != "正式" {
  212. return
  213. }
  214. if companyDetail.Status == "永续" {
  215. specialSurplus = "不限次数"
  216. }
  217. // 获取继承点数
  218. inheritList, e := cygx.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
  219. if e != nil && e.Error() != utils.ErrNoRow() {
  220. err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
  221. }
  222. //chartMap := map[int]string{utils.YI_YAO_ID:utils.YI_YAO_NAME, utils.XIAO_FEI_ID:utils.XIAO_FEI_NAME, utils.KE_JI_ID:utils.KE_JI_NAME, utils.ZHI_ZAO_ID:utils.ZHI_ZAO_NAME}
  223. //chartNumMap := map[int]int{utils.YI_YAO_ID:0, utils.XIAO_FEI_ID:0, utils.KE_JI_ID:0, utils.ZHI_ZAO_ID:0}
  224. chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
  225. var condition string
  226. var pars []interface{}
  227. condition += ` AND company_id = ? `
  228. pars = append(pars, companyId)
  229. //查询当年的数据
  230. //condition += ` AND b.create_time >= ? `
  231. //pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  232. listTripBill, e := cygx.GetCygxActivitySpecialTripBillList(condition, pars)
  233. if e != nil {
  234. err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
  235. return
  236. }
  237. if companyDetail.Status == "正式" {
  238. userType, _, _, _, _ := GetUserType(companyId)
  239. if userType == 2 {
  240. var tripBillNum int
  241. for _, v := range listTripBill {
  242. //if v.ActivityId == 0 {
  243. // continue
  244. //}
  245. tripBillNum += v.BillDetailed
  246. }
  247. if len(inheritList) > 0 {
  248. for _, v := range inheritList {
  249. if v.ChartPermissionId == 0 {
  250. tripBillNum += v.Points
  251. }
  252. }
  253. }
  254. tripRemaining := tripBillNum
  255. if tripRemaining < 0 {
  256. tripRemaining = 0
  257. }
  258. specialSurplus = strconv.Itoa(tripRemaining) + "次"
  259. } else {
  260. list, e := company.GetCompanyReportPermissionByCompanyIdAndProductId(companyId, 2)
  261. if e != nil && e.Error() != utils.ErrNoRow() {
  262. err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  263. }
  264. if len(list) == 0 {
  265. return
  266. }
  267. var chartPermissionIdSlice []string
  268. mapChartName := make(map[string]int)
  269. mapUpgradeId := make(map[int]int)
  270. mapPermissionNameTrip := make(map[string]int)
  271. mapInheritChartName := make(map[string]int)
  272. //mapPermissionName := make(map[int]string)
  273. for _, v := range list {
  274. chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
  275. //是升级套餐才有点数
  276. if v.IsUpgrade == 1 {
  277. mapUpgradeId[v.ChartPermissionId] = 1
  278. }
  279. }
  280. chartList := make([]*models.ChartPermission, 0)
  281. if len(chartPermissionIdSlice) > 0 {
  282. chartList, e = models.GetChartPermissionByIds(chartPermissionIdSlice)
  283. if e != nil {
  284. err = errors.New("获取品种信息失败, Err:" + e.Error())
  285. return
  286. }
  287. }
  288. if len(chartList) == 0 {
  289. return
  290. }
  291. //var TripBillNum int
  292. for _, v := range listTripBill {
  293. if v.ActivityId == 0 {
  294. continue
  295. }
  296. mapPermissionNameTrip[v.ChartPermissionName] += v.BillDetailed
  297. }
  298. for _, v := range chartList {
  299. //如果是升级则加点
  300. if _, ok := mapUpgradeId[v.ChartPermissionId]; ok {
  301. mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.ChartPermissionName]
  302. } else {
  303. mapChartName[v.PermissionName] = mapPermissionNameTrip[v.ChartPermissionName]
  304. }
  305. }
  306. // 通过继承获得的加点
  307. for _, v := range inheritList {
  308. mapInheritChartName[v.ChartPermissionName] = v.Points
  309. }
  310. for k, _ := range chartNameMap {
  311. if _, ok := mapChartName[k]; ok {
  312. if inherit, ok2 := mapInheritChartName[k]; ok2 {
  313. mapChartName[k] += inherit
  314. }
  315. }
  316. }
  317. for k, v := range mapChartName {
  318. if v > 0 {
  319. specialSurplus += k + strconv.Itoa(v) + "次+"
  320. }
  321. }
  322. specialSurplus = strings.TrimRight(specialSurplus, "+")
  323. }
  324. }
  325. return
  326. }
  327. // GetSpecialUserType 获取专项产业调研的用户身份类型
  328. func GetSpecialUserType(user *models.WxUser) (userType int, err error) {
  329. companyId := user.CompanyId
  330. companyDetail, e := cygx.GetCompanyDetailByIdGroup(companyId)
  331. if e != nil {
  332. err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
  333. }
  334. if companyId <= 1 {
  335. userType = 0
  336. } else {
  337. if companyDetail.Status == "永续" {
  338. userType = 1
  339. } else {
  340. if companyDetail.Status == "正式" {
  341. list, e := company.GetCompanyReportPermissionUpgrade(companyId, 2)
  342. if e != nil && e.Error() != utils.ErrNoRow() {
  343. err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  344. }
  345. if len(list) == 0 {
  346. return
  347. }
  348. if len(list) == 4 {
  349. totalName, e := company.GetCompanyPermissionNameCheck(companyId, 2, "策略")
  350. if e != nil {
  351. err = errors.New("获取品种信息失败, Err:" + e.Error())
  352. return
  353. }
  354. if totalName > 0 {
  355. userType = 2
  356. } else {
  357. userType = 8
  358. }
  359. } else {
  360. userType = 8
  361. }
  362. }
  363. }
  364. }
  365. return
  366. }
  367. // CheckActivitySpecialUpdatePower 校验专项调研活动后台管理员、销售是否有修改权限
  368. func CheckActivitySpecialUpdatePower(adminId int, activityInfo *cygx.ActivitySpecialDetail) (havePower bool, popupMsg string, err error) {
  369. defer func() {
  370. if err != nil {
  371. fmt.Println("err:", err)
  372. go alarm_msg.SendAlarmMsg("校验活动后台管理员、销售是否有修改权限失败,Err:"+err.Error(), 3)
  373. }
  374. }()
  375. adminInfo, e := system.GetSysUserById(adminId)
  376. if e != nil {
  377. err = errors.New("获取管理员身份失败,GetSysUserById" + e.Error())
  378. return
  379. }
  380. //如果这个活动不是自己建的会议,那么就对权益销售跟权益组长做身份限制判断
  381. if activityInfo.AdminId > 0 && activityInfo.AdminId != adminId && (adminInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || adminInfo.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP) {
  382. popupMsg = "只有建会销售可修改。"
  383. return
  384. }
  385. havePower = true
  386. return
  387. }
  388. // GetChartPermissionSpecialSurplusByCompany 获取公司专项调研次数-分品种
  389. func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tripRemaining int, mapChartName map[string]int, err error) {
  390. companyDetail, e := cygx.GetCompanyDetailByIdGroup(companyId)
  391. if e != nil {
  392. err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
  393. }
  394. if companyDetail == nil {
  395. return
  396. }
  397. if companyDetail.Status != "永续" && companyDetail.Status != "正式" {
  398. return
  399. }
  400. var specialSurplus string
  401. if companyDetail.Status == "永续" {
  402. specialSurplus = "不限次数"
  403. }
  404. //chartMap := map[int]string{utils.YI_YAO_ID:utils.YI_YAO_NAME, utils.XIAO_FEI_ID:utils.XIAO_FEI_NAME, utils.KE_JI_ID:utils.KE_JI_NAME, utils.ZHI_ZAO_ID:utils.ZHI_ZAO_NAME}
  405. //chartNumMap := map[int]int{utils.YI_YAO_ID:0, utils.XIAO_FEI_ID:0, utils.KE_JI_ID:0, utils.ZHI_ZAO_ID:0}
  406. chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
  407. if companyDetail.Status == "正式" {
  408. //var packageType int
  409. userType, _, _, _, _ = GetUserType(companyId)
  410. var condition string
  411. var pars []interface{}
  412. condition += ` AND company_id = ? `
  413. pars = append(pars, companyId)
  414. //查询当年的数据
  415. //condition += ` AND b.create_time >= ? `
  416. //pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  417. listTripBill, e := cygx.GetCygxActivitySpecialTripBillList(condition, pars)
  418. if e != nil {
  419. err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
  420. return
  421. }
  422. //// 获取继承点数
  423. //inheritList, e := cygx.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
  424. //if e != nil && e.Error() != utils.ErrNoRow() {
  425. // err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
  426. //}
  427. if userType == 2 {
  428. var tripBillNum int
  429. for _, v := range listTripBill {
  430. //if v.ActivityId == 0 {
  431. // continue
  432. //}
  433. tripBillNum += v.BillDetailed
  434. }
  435. //if len(inheritList) > 0 {
  436. // for _, v := range inheritList {
  437. // if v.ChartPermissionId == 0 {
  438. // tripBillNum += v.Points
  439. // }
  440. // }
  441. //}
  442. tripRemaining = tripBillNum
  443. if tripRemaining < 0 {
  444. tripRemaining = 0
  445. }
  446. } else {
  447. list, e := company.GetCompanyReportPermissionByCompanyIdAndProductId(companyId, 2)
  448. if e != nil && e.Error() != utils.ErrNoRow() {
  449. err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  450. }
  451. if len(list) == 0 {
  452. return
  453. }
  454. var chartPermissionIdSlice []string
  455. mapChartName = make(map[string]int)
  456. mapUpgradeId := make(map[int]int)
  457. mapPermissionNameTrip := make(map[string]int)
  458. mapInheritChartName := make(map[string]int)
  459. //mapPermissionName := make(map[int]string)
  460. for _, v := range list {
  461. chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
  462. //是升级套餐才有点数
  463. if v.IsUpgrade == 1 {
  464. mapUpgradeId[v.ChartPermissionId] = 1
  465. }
  466. }
  467. chartList := make([]*models.ChartPermission, 0)
  468. if len(chartPermissionIdSlice) > 0 {
  469. chartList, e = models.GetChartPermissionByIds(chartPermissionIdSlice)
  470. if e != nil {
  471. err = errors.New("获取品种信息失败, Err:" + e.Error())
  472. return
  473. }
  474. }
  475. if len(chartList) == 0 {
  476. return
  477. }
  478. for _, v := range listTripBill {
  479. if v.ActivityId == 0 {
  480. continue
  481. }
  482. mapPermissionNameTrip[v.ChartPermissionName] += v.BillDetailed
  483. }
  484. for _, v := range chartList {
  485. //如果是升级则加点
  486. if _, ok := mapUpgradeId[v.ChartPermissionId]; ok {
  487. mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.ChartPermissionName]
  488. } else {
  489. mapChartName[v.PermissionName] = mapPermissionNameTrip[v.ChartPermissionName]
  490. }
  491. }
  492. // 通过继承获得的加点
  493. //for _, v := range inheritList {
  494. // mapInheritChartName[v.ChartPermissionName] = v.Points
  495. //}
  496. for k, _ := range chartNameMap {
  497. if _, ok := mapChartName[k]; ok {
  498. if inherit, ok2 := mapInheritChartName[k]; ok2 {
  499. mapChartName[k] += inherit
  500. }
  501. }
  502. }
  503. for k, v := range mapChartName {
  504. if v > 0 {
  505. specialSurplus += k + strconv.Itoa(v) + "次+"
  506. }
  507. }
  508. specialSurplus = strings.TrimRight(specialSurplus, "+")
  509. }
  510. }
  511. return
  512. }
  513. //func init() {
  514. // ActivitySpecialCompanyApproval(7030, 1259, "怀民大套餐客户")
  515. // //格式化合同开始时间
  516. // contractStartDate, tmpErr := time.Parse(utils.FormatDate, "2023-12-19")
  517. //
  518. // if tmpErr != nil {
  519. // fmt.Println(tmpErr)
  520. // return
  521. // }
  522. //
  523. // if time.Now().After(contractStartDate) {
  524. // fmt.Println("go")
  525. // }
  526. //}
  527. // 审批通过的时候专项调研次数更新
  528. func ActivitySpecialCompanyApproval(companyId, companyContractId int, companyName string) (err error) {
  529. userType, packageType, _, _, _ := GetUserType(companyId)
  530. // 获取继承点数
  531. //inheritList, e := cygx.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
  532. //if e != nil && e.Error() != utils.ErrNoRow() {
  533. // err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
  534. //}
  535. //chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
  536. var items []*cygx.CygxActivitySpecialPermissionPoints
  537. itemBill := new(cygx.CygxActivitySpecialTripBill)
  538. itemBill.CreateTime = time.Now()
  539. itemBill.CompanyId = companyId
  540. itemBill.CompanyName = companyName
  541. itemBill.Source = 2
  542. itemBill.DoType = 2
  543. itemBill.Way = 3
  544. if userType == 2 {
  545. packageTypeMap := map[int]int{1: 16, 2: 12}
  546. totalTrip := packageTypeMap[packageType]
  547. itemBill.BillDetailed = totalTrip
  548. itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
  549. if packageType == 2 {
  550. itemBill.Content = "45w大套餐转正"
  551. } else {
  552. itemBill.Content = "70w大套餐转正"
  553. }
  554. //记录公司剩余点数
  555. item := new(cygx.CygxActivitySpecialPermissionPoints)
  556. item.Points = totalTrip
  557. item.CompanyId = companyId
  558. item.CompanyName = companyName
  559. item.CreateTime = time.Now()
  560. item.ModifyTime = time.Now()
  561. items = append(items, item)
  562. } else {
  563. //list, e := company.GetCompanyReportPermissionByCompanyIdAndProductId(companyId, 2)
  564. //if e != nil && e.Error() != utils.ErrNoRow() {
  565. // err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  566. //}
  567. //if len(list) == 0 {
  568. // return
  569. //}
  570. var condition string
  571. var pars []interface{}
  572. pars = make([]interface{}, 0)
  573. condition = " AND company_contract_id = ? AND is_upgrade = 1 "
  574. pars = append(pars, companyContractId)
  575. list, e := company.GetCompanyContractPermissionList(condition, pars) // 获取带有升级的权限
  576. if e != nil && e.Error() != utils.ErrNoRow() {
  577. err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
  578. return
  579. }
  580. if e != nil && e.Error() != utils.ErrNoRow() {
  581. err = errors.New("GetCygxAllocationCompanyContractPermissionListById, Err: " + e.Error())
  582. return
  583. }
  584. if len(list) == 0 {
  585. return
  586. }
  587. //获取权益主观权限
  588. listRaiSubjectivity, e := models.GetChartPermissionListRaiSubjectivity()
  589. if e != nil && e.Error() != utils.ErrNoRow() {
  590. err = errors.New("GetChartPermissionListRaiSubjectivity, Err: " + e.Error())
  591. }
  592. mapRaiSubjectivity := make(map[int]bool)
  593. mapPermissionName := make(map[int]string)
  594. for _, v := range listRaiSubjectivity {
  595. mapRaiSubjectivity[v.ChartPermissionId] = true
  596. mapPermissionName[v.ChartPermissionId] = v.ChartPermissionName
  597. }
  598. for _, v := range list {
  599. //如果是升级则加点
  600. if v.IsUpgrade == 1 && mapRaiSubjectivity[v.ChartPermissionId] {
  601. item := new(cygx.CygxActivitySpecialPermissionPoints)
  602. item.Points = 5
  603. item.CompanyId = companyId
  604. item.CompanyName = companyName
  605. item.ChartPermissionId = v.ChartPermissionId
  606. item.ChartPermissionName = mapPermissionName[v.ChartPermissionId]
  607. item.CreateTime = time.Now()
  608. item.ModifyTime = time.Now()
  609. items = append(items, item)
  610. }
  611. }
  612. itemBill.Content = "行业升级套餐转正"
  613. }
  614. e := cygx.MultiAddCygxActivitySpecialPermissionPoints(items)
  615. if e != nil {
  616. err = errors.New("MultiAddCygxActivitySpecialPermissionPoints, Err:" + e.Error())
  617. return
  618. }
  619. if userType != 2 && len(items) > 0 {
  620. var condition string
  621. var pars []interface{}
  622. pars = make([]interface{}, 0)
  623. condition = " AND company_id = ? AND points > 0 ORDER BY chart_permission_id DESC "
  624. pars = append(pars, companyId)
  625. activitySpecialPermissionPointsList, e := cygx.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  626. if e != nil && e.Error() != utils.ErrNoRow() {
  627. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  628. return
  629. }
  630. var itemBillTotal []string
  631. itemBillTotalMap := make(map[string]string)
  632. for _, v := range activitySpecialPermissionPointsList {
  633. itemBillTotal = append(itemBillTotal, fmt.Sprint(v.ChartPermissionName, v.Points, "次"))
  634. itemBillTotalMap[v.ChartPermissionName] = fmt.Sprint(v.ChartPermissionName, v.Points, "次")
  635. }
  636. itemBill.BillDetailed = 5 * len(items)
  637. permissionNameSlice := []string{"医药", "消费", "科技", "智造"}
  638. var itemBillTotalNew []string
  639. for _, v := range permissionNameSlice {
  640. if itemBillTotalMap[v] == "" {
  641. itemBillTotalNew = append(itemBillTotalNew, fmt.Sprint(v, "0次"))
  642. } else {
  643. itemBillTotalNew = append(itemBillTotalNew, itemBillTotalMap[v])
  644. }
  645. }
  646. itemBill.Total = strings.Join(itemBillTotalNew, "+")
  647. }
  648. //如果有升级行业权限,或者大套餐客户就写入流水信息
  649. if itemBill.Total != "" {
  650. e := cygx.AddCygxActivitySpecialTripBill(itemBill)
  651. if e != nil {
  652. err = errors.New("AddCygxActivitySpecialTripBill, Err:" + e.Error())
  653. return
  654. }
  655. }
  656. return
  657. }
  658. // 取消专项调研返点
  659. func ActivitySpecialPublishAndCancel(activityInfo *cygx.ActivitySpecialDetail) (err error) {
  660. //userType, tripRemaining, mapChartName, err := GetChartPermissionSpecialSurplusByCompany(companyId)
  661. //if err != nil {
  662. // br.Msg = "获取专项调研剩余次数失败"
  663. // br.ErrMsg = "获取专项调研剩余次数失败,err:" + err.Error()
  664. // return
  665. //}
  666. //itemBill := new(cygx.CygxActivitySpecialTripBill)
  667. //itemBill.CreateTime = time.Now()
  668. //itemBill.ActivityId = activityInfo.ActivityId
  669. //itemBill.Content = activityInfo.ResearchTheme + "--活动取消"
  670. //itemBill.Source = 2
  671. //itemBill.DoType = 2
  672. //itemBill.Way = 4
  673. //itemBill.BillDetailed = 1
  674. //err = cygx.AddCygxActivitySpecialTripBill(itemBill)
  675. //if err != nil {
  676. // return
  677. //}
  678. return
  679. }
  680. //func init() {
  681. // fmt.Println(GetSpecialSurplusByCompanyNew(16))
  682. //}
  683. // GetSpecialSurplusByCompanyNew 获取公司专项调研剩余次数-用流水表数据不计算了,计算都丢在流水里
  684. func GetSpecialSurplusByCompanyNew(companyId int) (specialSurplus string, err error) {
  685. companyDetail, e := cygx.GetCompanyDetailByIdGroup(companyId)
  686. if e != nil {
  687. err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
  688. }
  689. if companyDetail == nil {
  690. return
  691. }
  692. //if companyDetail.Status != "永续" && companyDetail.Status != "正式" {
  693. // return
  694. //}
  695. //if companyDetail.Status == "永续" {
  696. // specialSurplus = "不限次数"
  697. //}
  698. //chartMap := map[int]string{utils.YI_YAO_ID:utils.YI_YAO_NAME, utils.XIAO_FEI_ID:utils.XIAO_FEI_NAME, utils.KE_JI_ID:utils.KE_JI_NAME, utils.ZHI_ZAO_ID:utils.ZHI_ZAO_NAME}
  699. //chartNumMap := map[int]int{utils.YI_YAO_ID:0, utils.XIAO_FEI_ID:0, utils.KE_JI_ID:0, utils.ZHI_ZAO_ID:0}
  700. //if companyDetail.Status == "正式" {
  701. billItem, e := cygx.GetCygxActivitySpecialTripBillByCompanyId(companyId)
  702. if e != nil && e.Error() != utils.ErrNoRow() {
  703. err = e
  704. return
  705. }
  706. if billItem != nil {
  707. specialSurplus = billItem.Total
  708. } else {
  709. specialSurplus = "0次"
  710. }
  711. return
  712. //}
  713. //return
  714. }
  715. // GetSpecialBillMaxChartPermissionId 获取专项调研剩余点数最多的行业
  716. func GetSpecialBillMaxChartPermissionId(user *cygx.UserAndCompanyName) (maxChartPermissionId int, maxChartPermissionName string, err error) {
  717. companyId := user.CompanyId
  718. var condition string
  719. var pars []interface{}
  720. condition = " AND company_id = ? AND points > 0 ORDER BY points DESC LIMIT 1 "
  721. pars = append(pars, companyId)
  722. activitySpecialPermissionPointsList, e := cygx.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  723. if e != nil && e.Error() != utils.ErrNoRow() {
  724. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  725. return
  726. }
  727. for _, v := range activitySpecialPermissionPointsList {
  728. maxChartPermissionId = v.ChartPermissionId
  729. maxChartPermissionName = v.ChartPermissionName
  730. }
  731. return
  732. }
  733. // DeductTripRemainingtimesByUser 扣除用户专项调研剩余次数
  734. func DeductTripRemainingtimesByUser(user *cygx.UserAndCompanyName, activityInfo *cygx.ActivitySpecialDetail, roleTypeCode string) (err error) {
  735. msgTemplate := "您的专项调研次数已用完,如仍想参加,请与您的对口销售商议"
  736. companyId := user.CompanyId
  737. chartPermissionName := activityInfo.ChartPermissionName
  738. companyProduct, e := company.GetCompanyProductByCompanyIdAndProductId(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  739. if e != nil {
  740. err = errors.New("GetCompanyProductByCompanyIdAndProductId, Err:" + e.Error())
  741. return
  742. }
  743. var condition string
  744. var pars []interface{}
  745. condition = " AND company_id = ? ORDER BY points DESC LIMIT 1 "
  746. pars = append(pars, companyId)
  747. //判断是不是策略、固收行业的活动,如果不是策略就获取对应行业的点数 ,策略的任何一个行业有剩余点数都能参加
  748. if chartPermissionName != utils.CE_LUE_NAME && chartPermissionName != utils.GU_SHOU_NAME {
  749. pars = make([]interface{}, 0)
  750. condition = " AND company_id = ? AND (chart_permission_id = ? OR chart_permission_id = 0 ) ORDER BY points DESC LIMIT 1 "
  751. pars = append(pars, companyId, activityInfo.ChartPermissionId)
  752. }
  753. activitySpecialPermissionPointsList, e := cygx.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  754. if e != nil && e.Error() != utils.ErrNoRow() {
  755. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  756. return
  757. }
  758. //如果永续客户不存在单独的行业剩余点数记录,那么就添加一条 -1 的记录作为初始化数据
  759. if companyProduct.Status == utils.COMPANY_STATUS_FOREVER && len(activitySpecialPermissionPointsList) == 0 {
  760. item := new(cygx.CygxActivitySpecialPermissionPoints)
  761. item.CompanyId = companyProduct.CompanyId
  762. item.Points = -1
  763. item.CompanyName = companyProduct.CompanyName
  764. //item.ChartPermissionId = activityInfo.ChartPermissionId
  765. //item.ChartPermissionName = activityInfo.ChartPermissionName
  766. item.CreateTime = time.Now()
  767. item.ModifyTime = time.Now()
  768. e = cygx.AddCygxActivitySpecialPermissionPoints(item)
  769. if e != nil {
  770. err = errors.New("AddCygxActivitySpecialPermissionPoints, Err:" + e.Error())
  771. return
  772. }
  773. return
  774. }
  775. var maxPoints int // 获取最大剩余点数,(写的有点多余)
  776. for _, v := range activitySpecialPermissionPointsList {
  777. if maxPoints < v.Points {
  778. maxPoints = v.Points
  779. }
  780. }
  781. //如果是超管给一个没有行业权限的试用,冻结等相关客户报名,就写入一条对应的行业权限点数信息
  782. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN && len(activitySpecialPermissionPointsList) == 0 {
  783. item := new(cygx.CygxActivitySpecialPermissionPoints)
  784. item.CompanyId = companyProduct.CompanyId
  785. item.Points = -1
  786. item.CompanyName = companyProduct.CompanyName
  787. item.ChartPermissionId = activityInfo.ChartPermissionId
  788. item.ChartPermissionName = activityInfo.ChartPermissionName
  789. item.CreateTime = time.Now()
  790. item.ModifyTime = time.Now()
  791. e = cygx.AddCygxActivitySpecialPermissionPoints(item)
  792. if e != nil {
  793. err = errors.New("AddCygxActivitySpecialPermissionPoints, Err:" + e.Error())
  794. return
  795. }
  796. return
  797. }
  798. //永续客户不做判断、超管不做判断
  799. if companyProduct.Status != utils.COMPANY_STATUS_FOREVER {
  800. //如果没有剩余的点数,就返回
  801. if maxPoints <= 0 && roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  802. err = errors.New(msgTemplate)
  803. return
  804. }
  805. }
  806. var maxChartPermissionId int // 剩余点数最多的行业
  807. var points int // 剩余点数
  808. for _, v := range activitySpecialPermissionPointsList {
  809. maxChartPermissionId = v.ChartPermissionId
  810. points = v.Points - 1
  811. }
  812. //更新对应行业剩余点数
  813. e = cygx.UpdateCygxActivitySpecialPermissionPoints(points, companyId, maxChartPermissionId)
  814. if e != nil {
  815. err = errors.New("UpdateCygxActivitySpecialPermissionPoints, Err:" + e.Error())
  816. return
  817. }
  818. return
  819. }
  820. // RebateTripRemainingtimesByUser 返点用户专项调研剩余次数
  821. func RebateTripRemainingtimesByUser(user *cygx.UserAndCompanyName, activityInfo *cygx.ActivitySpecialDetail) (err error) {
  822. companyId := user.CompanyId
  823. chartPermissionName := activityInfo.ChartPermissionName
  824. var condition string
  825. var pars []interface{}
  826. condition = " AND company_id = ? ORDER BY points DESC LIMIT 1 "
  827. pars = append(pars, companyId)
  828. //判断是不是策略、固收行业的活动,如果不是策略就获取对应行业的点数 ,策略的任何一个行业有剩余点数都能参加
  829. if chartPermissionName != utils.CE_LUE_NAME && chartPermissionName != utils.GU_SHOU_NAME {
  830. pars = make([]interface{}, 0)
  831. condition = " AND company_id = ? AND (chart_permission_id = ? OR chart_permission_id = 0 ) LIMIT 1 "
  832. pars = append(pars, companyId, activityInfo.ChartPermissionId)
  833. } else {
  834. lastTripBill, e := cygx.GetCygxActivitySpecialTripBillLastDetialByActivityId(activityInfo.ActivityId, user.UserId)
  835. if e != nil {
  836. err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
  837. return
  838. }
  839. pars = make([]interface{}, 0)
  840. condition = " AND company_id = ? AND (chart_permission_id = ? OR chart_permission_id = 0 ) LIMIT 1 "
  841. pars = append(pars, companyId, lastTripBill.ChartPermissionId)
  842. }
  843. activitySpecialPermissionPointsList, e := cygx.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  844. if e != nil && e.Error() != utils.ErrNoRow() {
  845. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  846. return
  847. }
  848. var maxChartPermissionId int // 剩余点数最多的行业(返点行业)
  849. var points int // 剩余点数
  850. for _, v := range activitySpecialPermissionPointsList {
  851. maxChartPermissionId = v.ChartPermissionId
  852. points = v.Points + 1
  853. }
  854. //更新对应行业剩余点数
  855. e = cygx.UpdateCygxActivitySpecialPermissionPoints(points, companyId, maxChartPermissionId)
  856. if e != nil {
  857. err = errors.New("UpdateCygxActivitySpecialPermissionPoints, Err:" + e.Error())
  858. return
  859. }
  860. return
  861. }
  862. // 预处理专项调研流水明细表描述内容
  863. func HandleActivitySpecialTripBillTotalText(companyId int) (totalText string, err error) {
  864. //companyId := user.CompanyId
  865. companyDetail, e := cygx.GetCompanyDetailByIdGroup(companyId)
  866. if e != nil {
  867. err = errors.New("GetCompanyDetailByIdGroup, Err:" + e.Error())
  868. return
  869. }
  870. var condition string
  871. var pars []interface{}
  872. pars = make([]interface{}, 0)
  873. condition = " AND company_id = ? AND points != 0 ORDER BY chart_permission_id DESC "
  874. pars = append(pars, companyId)
  875. activitySpecialPermissionPointsList, e := cygx.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  876. if e != nil && e.Error() != utils.ErrNoRow() {
  877. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  878. return
  879. }
  880. //永续客户次数累加
  881. if companyDetail.Status == utils.COMPANY_STATUS_FOREVER {
  882. var points int
  883. for _, v := range activitySpecialPermissionPointsList {
  884. points += v.Points
  885. }
  886. totalText = fmt.Sprint(points, "次") //追加永续客户展示规则(2024-02-23)
  887. return
  888. }
  889. var itemBillTotal []string
  890. itemBillTotalMap := make(map[string]string)
  891. for _, v := range activitySpecialPermissionPointsList {
  892. if v.ChartPermissionId > 0 {
  893. itemBillTotal = append(itemBillTotal, fmt.Sprint(v.ChartPermissionName, v.Points, "次")) // 行业套餐客户展示规则
  894. itemBillTotalMap[v.ChartPermissionName] = fmt.Sprint(v.ChartPermissionName, v.Points, "次")
  895. }
  896. if v.ChartPermissionId == 0 {
  897. totalText = fmt.Sprint(v.Points, "次") // 大套餐客户展示规则,
  898. }
  899. }
  900. if len(itemBillTotal) > 0 {
  901. permissionNameSlice := []string{"医药", "消费", "科技", "智造"}
  902. var itemBillTotalNew []string
  903. for _, v := range permissionNameSlice {
  904. if itemBillTotalMap[v] == "" {
  905. itemBillTotalNew = append(itemBillTotalNew, fmt.Sprint(v, "0次"))
  906. } else {
  907. itemBillTotalNew = append(itemBillTotalNew, itemBillTotalMap[v])
  908. }
  909. }
  910. totalText = strings.Join(itemBillTotalNew, "+")
  911. }
  912. return
  913. }
  914. func initnee885() {
  915. list, err := cygx.GetBestNewBillList()
  916. if err != nil {
  917. fmt.Println(err)
  918. }
  919. var items []*cygx.CygxActivitySpecialPermissionPoints
  920. for _, v := range list {
  921. fmt.Println(v.Total)
  922. if v.Total == "" || v.Total == "0" || v.Total == "0次" {
  923. continue
  924. }
  925. //智造5次+科技5次+消费5次+医药4次
  926. sliceTotal := strings.Split(v.Total, "+")
  927. for _, vs := range sliceTotal {
  928. var points string
  929. item := new(cygx.CygxActivitySpecialPermissionPoints)
  930. if strings.Contains(vs, "医药") {
  931. item.ChartPermissionName = "医药"
  932. points := strings.Replace(vs, "医药", "", -1)
  933. fmt.Println(points)
  934. points = strings.Replace(points, "次", "", -1)
  935. item.Points, _ = strconv.Atoi(points)
  936. item.ChartPermissionId = 22
  937. } else if strings.Contains(vs, "消费") {
  938. item.ChartPermissionName = "消费"
  939. points := strings.Replace(vs, "消费", "", -1)
  940. points = strings.Replace(points, "次", "", -1)
  941. item.ChartPermissionId = 21
  942. item.Points, _ = strconv.Atoi(points)
  943. } else if strings.Contains(vs, "科技") {
  944. item.ChartPermissionName = "科技"
  945. points := strings.Replace(vs, "科技", "", -1)
  946. points = strings.Replace(points, "次", "", -1)
  947. item.ChartPermissionId = 20
  948. item.Points, _ = strconv.Atoi(points)
  949. } else if strings.Contains(vs, "智造") {
  950. item.ChartPermissionName = "智造"
  951. points := strings.Replace(vs, "智造", "", -1)
  952. points = strings.Replace(points, "次", "", -1)
  953. item.ChartPermissionId = 19
  954. item.Points, _ = strconv.Atoi(points)
  955. } else {
  956. points = strings.Replace(vs, "次", "", -1)
  957. item.Points, _ = strconv.Atoi(points)
  958. }
  959. fmt.Println("points", points)
  960. fmt.Println(vs)
  961. item.CompanyId = v.CompanyId
  962. item.CompanyName = v.CompanyName
  963. item.CreateTime = time.Now()
  964. item.ModifyTime = time.Now()
  965. fmt.Println(item)
  966. items = append(items, item)
  967. }
  968. }
  969. fmt.Println(len(items))
  970. err = cygx.MultiAddCygxActivitySpecialPermissionPoints(items)
  971. fmt.Println(err)
  972. }