activity_special.go 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. func ActivityLabelSpecialSql(chartPermissionIds, whichDay, activeState string) (condition string) {
  13. //行业名称
  14. if len(chartPermissionIds) > 0 {
  15. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  16. }
  17. if whichDay != "" {
  18. var startDate string
  19. var endDate string
  20. if whichDay == "1" {
  21. startDate = time.Now().Format(utils.FormatDate)
  22. endDate = startDate
  23. } else if whichDay == "2" {
  24. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  25. endDate = startDate
  26. } else if whichDay == "1,2" || whichDay == "2,1" {
  27. startDate = time.Now().Format(utils.FormatDate)
  28. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  29. } else if whichDay == "3" {
  30. startDate = utils.GetNowWeekMonday().Format(utils.FormatDate)
  31. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  32. } else if whichDay == "4" {
  33. startDate = utils.GetLastWeekMonday().Format(utils.FormatDate)
  34. endDate = utils.GetLastWeekSunday().Format(utils.FormatDate)
  35. } else if whichDay == "5" {
  36. startDate = utils.GetNowMonthFirstDay().Format(utils.FormatDate)
  37. endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate)
  38. } else if whichDay == "6" {
  39. startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate)
  40. endDate = utils.GetLastMonthLastDay().Format(utils.FormatDate)
  41. } else if whichDay == "3,4" || whichDay == "4,3" {
  42. startDate = utils.GetLastWeekMonday().Format(utils.FormatDate)
  43. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  44. } else if whichDay == "5,6" || whichDay == "6,5" {
  45. startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate)
  46. endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate)
  47. } else {
  48. startDate = utils.GetNowWeekMonday().Format(utils.FormatDate)
  49. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  50. }
  51. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  52. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  53. }
  54. if activeState == "2" {
  55. condition += ` AND art.days > 0 AND art.activity_time <= ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
  56. condition += ` AND art.activity_time_end >= ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
  57. }
  58. if activeState == "3" {
  59. condition += ` AND art.days > 0 AND art.activity_time_end <= ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
  60. }
  61. //if activeState != "3" {
  62. // condition += ` AND art.activity_time_end > ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
  63. //}
  64. //if activeState == "" && whichDay == "" {
  65. // condition += ` AND art.activity_time_end > ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
  66. //}
  67. if whichDay != "" {
  68. condition += ` AND art.days > 0 `
  69. }
  70. condition += ` AND art.label != '' AND art.is_offline = 0 `
  71. if activeState == "1" {
  72. condition = condition + ` AND art.days > 0 AND art.activity_time_end > ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
  73. }
  74. return
  75. }
  76. // ActivityLabelSpecialUserSql 专项产业调研用户权限查询数据预处理
  77. func ActivityLabelSpecialUserSql(user *models.WxUserItem) (conditionShengji, conditionZhengshi, conditionHangYe string, err error) {
  78. _, userType, e := HandleActivityLabelSpecialTripPermission(user)
  79. if e != nil {
  80. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  81. return
  82. }
  83. // 8: 行业升级套餐客户:该活动对应行业为升级权限的客户
  84. permissionShengji, errs := models.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId)
  85. if errs != nil {
  86. err = errs
  87. return
  88. }
  89. if permissionShengji != "" {
  90. slicePerShengji := strings.Split(permissionShengji, ",")
  91. permissionShengji = ""
  92. for _, v := range slicePerShengji {
  93. permissionShengji += "'" + v + "',"
  94. }
  95. permissionShengji = strings.TrimRight(permissionShengji, ",")
  96. conditionShengji = ` art.customer_type_ids LIKE '%8%' AND art.chart_permission_name IN (` + permissionShengji + `)`
  97. }
  98. //9:其他行业正式客户:前述所有正式客户以外的正式客户 查询处理
  99. permissionZhengShiStr, errs := models.GetCompanyPermissionByUserZhengShi(user.CompanyId)
  100. if errs != nil {
  101. err = errs
  102. return
  103. }
  104. if permissionZhengShiStr != "" {
  105. slicePerZhengshi := strings.Split(permissionZhengShiStr, ",")
  106. permissionZhengShiStr = ""
  107. for _, v := range slicePerZhengshi {
  108. if userType == 1 {
  109. //研选权限处理(永续客户无法查看研选)
  110. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  111. permissionZhengShiStr += "'" + v + "',"
  112. }
  113. } else {
  114. permissionZhengShiStr += "'" + v + "',"
  115. }
  116. }
  117. permissionZhengShiStr = strings.Replace(permissionZhengShiStr, "(主观)", "", -1)
  118. permissionZhengShiStr = strings.Replace(permissionZhengShiStr, "(客观)", "", -1)
  119. permissionZhengShiStr = strings.TrimRight(permissionZhengShiStr, ",")
  120. permissionZhengShiStr += `, '宏观'`
  121. if userType != 1 && userType != 2 && userType != 10 {
  122. conditionHangYe = ` art.customer_type_ids LIKE '%3%' AND art.chart_permission_name IN (` + permissionZhengShiStr + `)`
  123. }
  124. if userType == 3 {
  125. conditionZhengshi = ` art.customer_type_ids LIKE '%9%' AND art.chart_permission_name NOT IN (` + permissionZhengShiStr + `)`
  126. }
  127. }
  128. return
  129. }
  130. // 修改专项调研,用户与公司的参与数量
  131. func UpdateCygxActivitySpecialSignupNum(cont context.Context) (err error) {
  132. defer func() {
  133. if err != nil {
  134. fmt.Println(err)
  135. go utils.SendAlarmMsg("修改活动状态至进行中失败"+err.Error(), 2)
  136. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改活动状态至进行中失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  137. }
  138. }()
  139. //根据手机号分组获取列表以及数量
  140. var condition string
  141. var pars []interface{}
  142. condition += ` AND s.create_time < ? `
  143. pars = append(pars, time.Now().Format(utils.FormatDate))
  144. listSpecial, err := models.GetActivityListSpecialGroupByMobile(condition, pars)
  145. if err != nil {
  146. return err
  147. }
  148. var mapMobile []string
  149. for _, v := range listSpecial {
  150. mapMobile = append(mapMobile, v.Mobile)
  151. }
  152. //根据手机号获取这些用户的信息
  153. userList, err := models.GetWxUserByMobiles(mapMobile)
  154. if err != nil {
  155. return err
  156. }
  157. //更改这些手机对应的关注关注数量
  158. err = models.UpdateActivitySpecialSignupNumMulti(listSpecial)
  159. if err != nil {
  160. return err
  161. }
  162. //更改这些手机对应的公司ID
  163. err = models.UpdateActivitySpecialSignupCompanyIdMulti(userList)
  164. if err != nil {
  165. return err
  166. }
  167. //根据CompanyId分组获取列表以及数量
  168. listSpecialByCompanyId, err := models.GetActivityListSpecialGroupByCompanyId(condition, pars)
  169. if err != nil {
  170. return err
  171. }
  172. //更改这些公司对应的关注关注数量
  173. err = models.UpdateActivitySpecialSignupCompanyNumMulti(listSpecialByCompanyId)
  174. if err != nil {
  175. return err
  176. }
  177. fmt.Println("UpdateCygxActivitySpecialSignupNum end")
  178. return
  179. }
  180. // 处理专项调研的展示
  181. func GetActivityLabelSpecialList(user *models.WxUserItem, conditionActivitySpecial, activeState string) (item *models.ActivityTypeHome, err error) {
  182. itemList := new(models.ActivityTypeHome)
  183. if user.CompanyId <= 1 {
  184. itemList.List = make([]*models.CygxActivityLabelList, 0)
  185. item = itemList
  186. return
  187. }
  188. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  189. if e != nil && e.Error() != utils.ErrNoRow() {
  190. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  191. return
  192. }
  193. if companyDetail == nil {
  194. return
  195. }
  196. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  197. var condition string
  198. var conditionUser string
  199. //var userType int
  200. if companyDetail.Status == "永续" {
  201. conditionUser, e = HandleActivityLabelSpecialPermission(user)
  202. if e != nil {
  203. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  204. return
  205. }
  206. } else {
  207. conditionUser, _, e = HandleActivityLabelSpecialTripPermission(user)
  208. if e != nil {
  209. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  210. return
  211. }
  212. }
  213. var pars []interface{}
  214. condition += ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 ` + conditionActivitySpecial
  215. conditionTrip := condition
  216. conditionTripSql := condition
  217. conditionNoTrip := condition
  218. conditionNoTripSql := condition
  219. //condition += conditionUser
  220. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  221. if e != nil {
  222. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  223. return
  224. }
  225. conditionTrip += ` AND art.days > 0 AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + ` '`
  226. var conditionZhengshiTrip string
  227. var conditionShengjiTrip string
  228. var conditionHangYeTrip string
  229. //处理专项调研确认行程的其它正式客户权限查询
  230. if conditionZhengshi != "" {
  231. conditionZhengshiTrip = ` OR ( ` + conditionZhengshi + conditionTrip + ` )`
  232. }
  233. //处理升级权限查询
  234. if conditionShengji != "" {
  235. conditionShengjiTrip = ` OR ( ` + conditionShengji + conditionTrip + ` )`
  236. }
  237. //处理行业套餐客户权限查询
  238. if conditionHangYe != "" {
  239. conditionHangYeTrip = ` OR ( ` + conditionHangYe + conditionTrip + ` )`
  240. }
  241. if conditionZhengshi != "" {
  242. conditionTrip += conditionZhengshiTrip
  243. }
  244. if conditionShengjiTrip != "" {
  245. conditionTrip += conditionShengjiTrip
  246. }
  247. if conditionHangYeTrip != "" {
  248. conditionTrip += conditionHangYeTrip
  249. }
  250. conditionTripSql += conditionUser + conditionTrip + ` ORDER BY art.activity_time ASC `
  251. specialList, err := models.GetActivityLabelSpecialListAll(conditionTripSql, pars, 0, 80)
  252. if err != nil {
  253. return
  254. }
  255. //if len(specialList) < 80 {
  256. if activeState == "" {
  257. conditionNoTrip += ` AND art.days = 0 `
  258. }
  259. var conditionShengjiNoTrip string
  260. var conditionZhengshiNoTrip string
  261. var conditionHangYeNoTrip string
  262. if conditionShengji != "" {
  263. conditionShengjiNoTrip = ` OR ( ` + conditionShengji + conditionNoTrip + ` )`
  264. }
  265. if conditionZhengshi != "" {
  266. conditionZhengshiNoTrip = ` OR ( ` + conditionZhengshi + conditionNoTrip + ` )`
  267. }
  268. if conditionHangYe != "" {
  269. conditionHangYeNoTrip = ` OR ( ` + conditionHangYe + conditionNoTrip + ` )`
  270. }
  271. if conditionShengji != "" {
  272. conditionNoTrip += conditionShengjiNoTrip
  273. }
  274. if conditionZhengshi != "" {
  275. conditionNoTrip += conditionZhengshiNoTrip
  276. }
  277. if conditionHangYe != "" {
  278. conditionNoTrip += conditionHangYeNoTrip
  279. }
  280. conditionNoTripSql += conditionUser + conditionNoTrip + ` ORDER BY art.last_updated_time DESC`
  281. specialListNotrip, e := models.GetActivityLabelSpecialListAll(conditionNoTripSql, pars, 0, 200)
  282. if e != nil {
  283. err = e
  284. return
  285. }
  286. for _, v := range specialListNotrip {
  287. specialList = append(specialList, v)
  288. }
  289. //}
  290. for k2, v2 := range specialList {
  291. v2.Resource = 2
  292. if v2.Days == 0 {
  293. specialList[k2].TripStatus = 1
  294. } else {
  295. specialList[k2].TripStatus = 2
  296. }
  297. specialList[k2].KeyWord = LabelStrV5(v2.KeyWord, v2.IsShowSubjectName, v2.TemporaryLabel)
  298. specialList[k2].ImgUrlBg = "https://hzstatic.hzinsights.com/static/temp/20220426202204/20220426/XDLLsjC9XAAy8LIzQr7GsjrBbtX6.png"
  299. specialList[k2].ImgUrlBg = utils.ACTIVITY_ZXDY_ImgUrl3
  300. }
  301. itemList.ActivityTypeName = "专项产业调研"
  302. itemList.Resource = 2
  303. itemList.List = specialList
  304. itemList.ActivityTypeId = 7
  305. itemList.ImgUrl = utils.ACTIVITY_ZXDY_ImgUrl1
  306. itemList.ImgUrlBg = utils.ACTIVITY_ZXDY_ImgUrl2
  307. item = itemList
  308. return
  309. }
  310. // HandleActivityLabelSpecialPermission 处理专项产业调研的查询权限sql 永续
  311. func HandleActivityLabelSpecialPermission(user *models.WxUserItem) (condition string, err error) {
  312. permissionStr, e := GetCompanyPermission(user.CompanyId)
  313. if e != nil {
  314. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  315. return
  316. }
  317. userType, e := GetSpecialUserType(user)
  318. if e != nil {
  319. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  320. return
  321. }
  322. slicePer := strings.Split(permissionStr, ",")
  323. var permissionSqlStr string
  324. for _, v := range slicePer {
  325. if userType == 1 {
  326. if !strings.Contains(v, "研选") {
  327. permissionSqlStr += "'" + v + "',"
  328. }
  329. } else {
  330. permissionSqlStr += "'" + v + "',"
  331. }
  332. }
  333. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  334. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
  335. //if permissionSqlStr != "" {
  336. // condition += ` AND art.chart_permission_name IN (` + permissionSqlStr + `) `
  337. //}
  338. condition += ` AND art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  339. return
  340. }
  341. // HandleActivityLabelSpecialPermisseion 处理专项产业调研的查询权限sql
  342. func HandleActivityLabelSpecialTripPermission(user *models.WxUserItem) (condition string, userType int, err error) {
  343. permissionStr, e := GetCompanyPermission(user.CompanyId)
  344. if e != nil {
  345. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  346. return
  347. }
  348. userType, _, e = GetUserType(user.CompanyId)
  349. //userType, e := GetSpecialUserType(user)
  350. if e != nil {
  351. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  352. return
  353. }
  354. mapUserType, e := GetActivityCcustomerTypeList()
  355. if e != nil {
  356. err = e
  357. return
  358. }
  359. var userTypeStr string
  360. userTypeStr = mapUserType[userType]
  361. //fmt.Println(userType)
  362. slicePer := strings.Split(permissionStr, ",")
  363. var permissionSqlStr string
  364. for _, v := range slicePer {
  365. if userType == 1 {
  366. if !strings.Contains(v, "研选") {
  367. permissionSqlStr += "'" + v + "',"
  368. }
  369. } else {
  370. permissionSqlStr += "'" + v + "',"
  371. }
  372. }
  373. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  374. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
  375. if permissionSqlStr != "" && userType == 3 {
  376. condition += ` AND art.chart_permission_name IN (` + permissionSqlStr + `) `
  377. }
  378. condition += ` AND art.customer_type_ids LIKE '%` + userTypeStr + `%' `
  379. //if userType != 2 {
  380. return
  381. }
  382. // 获取预报名列表
  383. func GetActivitySpecialPrepareList(user *models.WxUserItem, startSize, pageSize int, keywords string) (list []*models.CygxActivitySpecialDetail, totalPrepare int, err error) {
  384. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  385. if e != nil {
  386. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  387. return
  388. }
  389. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  390. var condition string
  391. var conditionUser string
  392. if companyDetail.Status == "永续" {
  393. conditionUser, e = HandleActivityLabelSpecialPermission(user)
  394. if e != nil {
  395. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  396. return
  397. }
  398. } else {
  399. conditionUser, _, e = HandleActivityLabelSpecialTripPermission(user)
  400. if e != nil {
  401. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  402. return
  403. }
  404. }
  405. var pars []interface{}
  406. condition += ` AND art.days = 0 AND art.publish_status = 1 AND art.is_offline = 0 `
  407. if keywords != "" {
  408. keywords = "%" + keywords + "%"
  409. condition += ` AND art.research_theme LIKE ? `
  410. pars = append(pars, keywords)
  411. }
  412. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  413. if e != nil {
  414. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  415. return
  416. }
  417. conditionNoTrip := condition
  418. var conditionShengjiNoTrip string
  419. var conditionZhengshiNoTrip string
  420. var conditionHangYeNoTrip string
  421. if conditionShengji != "" {
  422. conditionShengjiNoTrip = ` OR ( ` + conditionShengji + conditionNoTrip + ` )`
  423. }
  424. if conditionZhengshi != "" {
  425. conditionZhengshiNoTrip = ` OR ( ` + conditionZhengshi + conditionNoTrip + ` )`
  426. }
  427. //处理行业套餐权限查询
  428. if conditionHangYe != "" {
  429. conditionHangYeNoTrip = ` OR ( ` + conditionHangYe + conditionNoTrip + ` )`
  430. }
  431. if conditionShengji != "" {
  432. conditionNoTrip += conditionShengjiNoTrip
  433. }
  434. if conditionZhengshi != "" {
  435. conditionNoTrip += conditionZhengshiNoTrip
  436. }
  437. if conditionHangYe != "" {
  438. conditionNoTrip += conditionHangYeNoTrip
  439. }
  440. conditionNoTripSql := conditionUser + conditionNoTrip
  441. //condition += conditionUser + conditionOr
  442. totalPrepare, e = models.GetActivitySpecialCount(conditionNoTripSql, pars)
  443. if e != nil {
  444. err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
  445. return
  446. }
  447. conditionNoTripSql += ` ORDER BY art.last_updated_time DESC `
  448. list, e = models.GetCygxActivitySpecialDetailList(conditionNoTripSql, pars, user.UserId, startSize, pageSize)
  449. if e != nil {
  450. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  451. return
  452. }
  453. return
  454. }
  455. /*
  456. 确定行程的查询 GetActivityLabelSpecialConfirmList
  457. state 进行状态 1:未开始,2:进行中,3:已结束,4:未开始、进行中 不传默认查询全部items []*CygxActivitySpecialDetail
  458. */
  459. func GetActivityLabelSpecialConfirmList(user *models.WxUserItem, startSize, pageSize, state int, keywords string) (list []*models.CygxActivitySpecialDetail, totalConfirm int, err error) {
  460. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  461. if e != nil && e.Error() != utils.ErrNoRow() {
  462. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  463. return
  464. }
  465. if companyDetail == nil {
  466. return
  467. }
  468. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  469. var condition string
  470. var conditionUser string
  471. //var userType int
  472. if companyDetail.Status == "永续" {
  473. conditionUser, e = HandleActivityLabelSpecialPermission(user)
  474. if e != nil {
  475. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  476. return
  477. }
  478. } else {
  479. conditionUser, _, e = HandleActivityLabelSpecialTripPermission(user)
  480. if e != nil {
  481. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  482. return
  483. }
  484. }
  485. var pars []interface{}
  486. condition += ` AND art.days >0 AND art.publish_status =1 AND art.is_offline = 0 `
  487. if state == 1 {
  488. condition += ` AND art.activity_time > '` + time.Now().Format(utils.FormatDateTime) + `'`
  489. }
  490. if state == 2 {
  491. condition += ` AND art.activity_time < '` + time.Now().Format(utils.FormatDateTime) + `'`
  492. condition += ` AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + `'`
  493. }
  494. if state == 3 {
  495. condition += ` AND art.activity_time_end < '` + time.Now().Format(utils.FormatDateTime) + `'`
  496. }
  497. if state == 4 {
  498. condition += ` AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + `'`
  499. }
  500. if keywords != "" {
  501. keywords = "%" + keywords + "%"
  502. condition += ` AND art.research_theme LIKE ` + keywords
  503. //pars = append(pars, keywords)
  504. }
  505. conditionTrip := condition
  506. conditionTripSql := condition
  507. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  508. if e != nil {
  509. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  510. return
  511. }
  512. conditionTrip += ` AND art.days > 0 AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + ` '`
  513. var conditionZhengshiTrip string
  514. var conditionShengjiTrip string
  515. var conditionHangYeTrip string
  516. //处理专项调研确认行程的其它正式客户权限查询
  517. if conditionZhengshi != "" {
  518. conditionZhengshiTrip = ` OR ( ` + conditionZhengshi + conditionTrip + ` )`
  519. }
  520. //处理专项调研确认行程的升级权限查询
  521. if conditionShengji != "" {
  522. conditionShengjiTrip = ` OR ( ` + conditionShengji + conditionTrip + ` )`
  523. }
  524. //处理行业套餐客户权限查询
  525. if conditionHangYe != "" {
  526. conditionHangYeTrip = ` OR ( ` + conditionHangYe + conditionTrip + ` )`
  527. }
  528. if conditionZhengshi != "" {
  529. conditionTrip += conditionZhengshiTrip
  530. }
  531. if conditionShengjiTrip != "" {
  532. conditionTrip += conditionShengjiTrip
  533. }
  534. if conditionHangYeTrip != "" {
  535. conditionTrip += conditionHangYeTrip
  536. }
  537. conditionTripSql += conditionUser + conditionTrip + ` ORDER BY art.activity_time ASC `
  538. totalConfirm, e = models.GetActivitySpecialCount(conditionTripSql, pars)
  539. if e != nil {
  540. err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
  541. return
  542. }
  543. condition += ` ORDER BY art.activity_time ASC `
  544. list, e = models.GetCygxActivitySpecialDetailList(conditionTripSql, pars, user.UserId, startSize, pageSize)
  545. if e != nil {
  546. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  547. return
  548. }
  549. var activityIds []int
  550. for k, v := range list {
  551. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  552. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  553. if resultTimeStart.After(time.Now()) {
  554. list[k].ActiveState = 1
  555. } else if time.Now().After(resultTimeEnd) {
  556. list[k].ActiveState = 3
  557. } else {
  558. list[k].ActiveState = 2
  559. }
  560. if list[k].Days == 0 {
  561. list[k].TripStatus = 1
  562. } else {
  563. list[k].TripStatus = 2
  564. }
  565. activityIds = append(activityIds, v.ActivityId)
  566. }
  567. //处理用户已经报名了的行程
  568. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  569. if e != nil {
  570. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  571. return
  572. }
  573. for k, v := range list {
  574. if _, ok := UserMap[v.ActivityId]; ok {
  575. list[k].IsTrip = 1
  576. }
  577. }
  578. return
  579. }
  580. // 获取用户已经报名的活动
  581. func GetSpecialTripUserMap(activityIds []int, userId int) (mapUserId map[int]int, err error) {
  582. var condition string
  583. var pars []interface{}
  584. activityIdsLen := len(activityIds)
  585. if activityIdsLen > 0 {
  586. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
  587. pars = append(pars, activityIds)
  588. }
  589. condition += ` AND user_id = ? AND is_cancel = 0 `
  590. pars = append(pars, userId)
  591. list, e := models.GetCygxActivitySpecialTripList(condition, pars)
  592. if e != nil {
  593. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  594. return
  595. }
  596. mapUid := make(map[int]int)
  597. for _, v := range list {
  598. mapUid[v.ActivityId] = v.UserId
  599. }
  600. mapUserId = mapUid
  601. return
  602. }
  603. // 获取用户已经报名的活动数量
  604. func GetSpecialTripUserSchedule(userId int) (total int, err error) {
  605. var condition string
  606. var pars []interface{}
  607. condition += ` AND t.user_id = ? AND t.is_cancel = 0 `
  608. pars = append(pars, userId)
  609. condition += ` AND a.activity_time_end >= ? `
  610. pars = append(pars, time.Now())
  611. condition += ` AND is_valid = 1 `
  612. total, err = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
  613. return
  614. }
  615. // GetActivitySpecialList 获取专项调研列表
  616. func GetActivitySpecialList(user *models.WxUserItem, currentIndex, pageSize int, keywords string) (list []*models.CygxActivitySpecialDetail, total int, err error) {
  617. if user.CompanyId <= 1 {
  618. return
  619. }
  620. listConfirm, totalConfirm, e := GetActivityLabelSpecialConfirmList(user, (currentIndex-1)*pageSize, pageSize, 4, keywords)
  621. if e != nil && e.Error() != utils.ErrNoRow() {
  622. err = errors.New("GetActivityLabelSpecialConfirmList11, Err: " + e.Error())
  623. return
  624. }
  625. //if totalConfirm == 0 {
  626. // return
  627. //}
  628. if currentIndex == 1 && len(listConfirm) > 0 {
  629. listConfirm[0].Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  630. }
  631. list = listConfirm
  632. total = totalConfirm
  633. var startSizePrepare, pageSizePrepare int
  634. //全是确定行程的查询数据
  635. if totalConfirm >= currentIndex*pageSize {
  636. startSizePrepare = 0
  637. pageSizePrepare = 0
  638. } else if totalConfirm > (currentIndex-1)*pageSize && totalConfirm < currentIndex*pageSize {
  639. //一半确认行程一半预报名
  640. startSizePrepare = 0
  641. pageSizePrepare = pageSize - len(listConfirm)
  642. } else {
  643. //全是预报名
  644. startSizePrepare = (currentIndex-1)*pageSize - totalConfirm
  645. pageSizePrepare = pageSize - len(listConfirm)
  646. }
  647. listPrepare, totalPrepare, e := GetActivitySpecialPrepareList(user, startSizePrepare, pageSizePrepare, keywords)
  648. if e != nil && e.Error() != utils.ErrNoRow() {
  649. err = errors.New("GetActivityLabelSpecialConfirmList, Err: " + e.Error())
  650. return
  651. }
  652. if len(listPrepare) > 0 {
  653. for _, v := range listPrepare {
  654. list = append(list, v)
  655. }
  656. if startSizePrepare == 0 {
  657. listPrepare[0].Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  658. }
  659. }
  660. total = totalConfirm + totalPrepare
  661. //处理封面图片
  662. detail, e := models.GetConfigByCode("city_img_url")
  663. if e != nil {
  664. err = errors.New("GetConfigByCode, Err: " + e.Error())
  665. return
  666. }
  667. detailChart, e := models.GetConfigByCode("chart_img_url")
  668. if e != nil {
  669. err = errors.New("GetConfigByCode, Err: " + e.Error())
  670. return
  671. }
  672. addressList := strings.Split(detail.ConfigValue, "{|}")
  673. mapAddress := make(map[string]string)
  674. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  675. mapChart := make(map[string]string)
  676. var cityName string
  677. var chartName string
  678. var imgUrl string
  679. var imgUrlChart string
  680. for _, v := range addressList {
  681. vslice := strings.Split(v, "_")
  682. cityName = vslice[0]
  683. imgUrl = vslice[len(vslice)-1]
  684. mapAddress[cityName] = imgUrl
  685. }
  686. for _, v := range chartList {
  687. vslice := strings.Split(v, "_")
  688. chartName = vslice[0]
  689. imgUrlChart = vslice[len(vslice)-1]
  690. mapChart[chartName] = imgUrlChart
  691. }
  692. for k, v := range list {
  693. //list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
  694. if mapChart[v.ChartPermissionName] != "" {
  695. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  696. }
  697. list[k].ActivityTypeName = "专项调研"
  698. if list[k].Days == 0 {
  699. list[k].TripStatus = 1
  700. } else {
  701. list[k].TripStatus = 2
  702. list[k].TripImgLink = list[k].TripImgLinkFix
  703. }
  704. }
  705. return
  706. }
  707. // HandleActivitySpecialShow 处理活动的状态
  708. func HandleActivitySpecialShow(activityDetail *models.CygxActivitySpecialDetail, user *models.WxUserItem) (item *models.CygxActivitySpecialDetail, err error) {
  709. var activityIds []int
  710. resultTimeStart := utils.StrTimeToTime(activityDetail.ActivityTime) //时间字符串格式转时间格式
  711. resultTimeEnd := utils.StrTimeToTime(activityDetail.ActivityTimeEnd) //时间字符串格式转时间格式
  712. if resultTimeStart.After(time.Now()) {
  713. activityDetail.ActiveState = 1
  714. } else if time.Now().After(resultTimeEnd) {
  715. activityDetail.ActiveState = 3
  716. } else {
  717. activityDetail.ActiveState = 2
  718. }
  719. activityIds = append(activityIds, activityDetail.ActivityId)
  720. //处理用户已经报名了的行程
  721. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  722. if e != nil {
  723. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  724. return
  725. }
  726. if activityDetail.Days == 0 {
  727. activityDetail.TripStatus = 1
  728. activityDetail.Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  729. } else {
  730. activityDetail.TripStatus = 2
  731. activityDetail.TripImgLink = activityDetail.TripImgLinkFix
  732. activityDetail.Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  733. }
  734. if _, ok := UserMap[activityDetail.ActivityId]; ok {
  735. activityDetail.IsTrip = 1
  736. }
  737. item = activityDetail
  738. return
  739. }
  740. // 活动与专项调研搜索 GetActivitySpecialSearcheList
  741. func GetActivitySpecialSearcheList(user *models.WxUserItem, condition string, startSize, pageSize int, keywords string) (items []*models.ActivityDetail, total int, err error) {
  742. var conditionSpecil string
  743. var pars, parsSpecil []interface{}
  744. keyword := keywords
  745. if user.UserId == 0 {
  746. conditionSpecil += ` AND art.activity_id = 0 ` // 未登录的用户不查看专项调研活动 v12.2.1
  747. }
  748. if keywords != "" {
  749. keywords = "%" + keywords + "%"
  750. conditionSpecil += ` AND art.days > 0 AND (art.research_theme LIKE ? OR art.label LIKE ? OR art.industrial_name LIKE ? OR art.industrial_subject_name LIKE ? ) `
  751. parsSpecil = append(parsSpecil, keywords, keywords, keywords, keywords)
  752. }
  753. list, totalSearche, e := models.GetActivitySpecialSearcheList(condition, pars, conditionSpecil, parsSpecil, startSize, pageSize)
  754. if e != nil {
  755. err = errors.New("GetActivitySpecialSearcheList, Err: " + e.Error())
  756. return
  757. }
  758. keyWordArr, e := GetIndustryMapNameSliceV3(keywords)
  759. if e != nil {
  760. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  761. return
  762. }
  763. var totalIk int
  764. if len(keyWordArr) > 1 {
  765. // 查询IK分词后那一部分的数据
  766. conditionActivityIk, e := GetActivityonditionList(user, "", "", "", "", "", 0, 1, keyword, 0, 2)
  767. if e != nil && e.Error() != utils.ErrNoRow() {
  768. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  769. return
  770. }
  771. conditionActivityIk += " AND art.is_limit_people = 1 AND art.publish_status = 1 "
  772. totalIk, e = models.GetActivityCount(conditionActivityIk, 0, pars, 0)
  773. if e != nil {
  774. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  775. return
  776. }
  777. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  778. startSizeIk := startSize - totalSearche
  779. if startSizeIk < 0 {
  780. startSizeIk = 0
  781. }
  782. var pageSizeIk int
  783. pageSizeIk = pageSize - len(list)
  784. if pageSizeIk > 0 {
  785. //搜索关键词联想
  786. conditionActivityIk += ` ORDER BY art.activity_time DESC , art.active_state ASC `
  787. listIk, e := models.GetActivityListNew(conditionActivityIk, pars, user.UserId, startSizeIk, pageSizeIk, 0, 0, "")
  788. if e != nil {
  789. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  790. return
  791. }
  792. for _, item := range listIk {
  793. list = append(list, item)
  794. }
  795. }
  796. }
  797. total = totalSearche + totalIk
  798. items, e = HandleActivityListButton(list, user)
  799. if e != nil {
  800. err = errors.New("HandleActivityListButton, Err: " + e.Error())
  801. return
  802. }
  803. return
  804. }
  805. // 获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
  806. func GetActivitySpecialUserType(companyId int) (userType int, permissionStrnew string, err error) {
  807. var permissionStr string
  808. if companyId <= 1 {
  809. userType = 0
  810. } else {
  811. total, e := models.GetCountCompanyDetailByIdGroupTrip(companyId)
  812. if e != nil {
  813. err = errors.New("GetCountCompanyDetailByIdGroupTrip, Err: " + e.Error())
  814. return
  815. }
  816. if total == 0 {
  817. userType = 0
  818. } else {
  819. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
  820. if e != nil {
  821. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  822. return
  823. }
  824. permissionStr, e = models.GetCompanyPermissionByUserTrip(companyId)
  825. if e != nil {
  826. err = errors.New("GetCompanyPermissionByUserTrip, Err: " + e.Error())
  827. return
  828. }
  829. //permissionZhengShiStr, e = models.GetCompanyPermissionByUserZhengShiTrip(companyId)
  830. //if e != nil {
  831. // err = errors.New("GetCompanyPermissionByUserZhengShiTrip, Err: " + e.Error())
  832. // return
  833. //}
  834. //大套餐客户定义:医药、消费、科技、智造。4个行业中为升级,策略是正式,属于大套餐客户
  835. if companyDetail.Status == "永续" {
  836. userType = 1
  837. } else if companyDetail.Status == "试用" {
  838. userType = 5
  839. } else if companyDetail.Status == "正式" {
  840. if permissionStr == "专家" {
  841. userType = 4
  842. } else if strings.Count(permissionStr, "医药") == 2 && strings.Count(permissionStr, "消费") == 2 && strings.Count(permissionStr, "科技") == 2 && strings.Count(permissionStr, "智造") == 2 && strings.Count(permissionStr, "策略") == 1 {
  843. userType = 2
  844. } else {
  845. userType = 3
  846. }
  847. if userType == 3 {
  848. if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
  849. userType = 4
  850. }
  851. }
  852. } else if companyDetail.Status == "冻结" {
  853. userType = 6
  854. } else if companyDetail.Status == "流失" {
  855. userType = 7
  856. }
  857. }
  858. }
  859. permissionStrnew = permissionStr
  860. return
  861. }
  862. // GetSpecialUserType 获取专项产业调研的用户身份类型
  863. // 获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
  864. func GetSpecialUserType(user *models.WxUserItem) (userType int, err error) {
  865. companyId := user.CompanyId
  866. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
  867. if e != nil && e.Error() != utils.ErrNoRow() {
  868. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  869. return
  870. }
  871. if companyDetail == nil {
  872. return
  873. }
  874. if companyId <= 1 {
  875. userType = 0
  876. } else {
  877. if companyDetail.Status == "永续" {
  878. userType = 1
  879. } else {
  880. if companyDetail.Status == "正式" {
  881. list, e := models.GetCompanyReportPermissionUpgrade(companyId, 2)
  882. if e != nil && e.Error() != utils.ErrNoRow() {
  883. err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  884. }
  885. if len(list) == 0 {
  886. userType = 9
  887. }
  888. if len(list) == 4 {
  889. totalName, e := models.GetCompanyPermissionNameCheck(companyId, 2, "策略")
  890. if e != nil {
  891. err = errors.New("获取品种信息失败, Err:" + e.Error())
  892. return
  893. }
  894. if totalName > 0 {
  895. userType = 2
  896. } else {
  897. userType = 8
  898. }
  899. } else {
  900. userType = 8
  901. }
  902. } else if companyDetail.Status == "试用" {
  903. userType = 5
  904. }
  905. }
  906. }
  907. return
  908. }
  909. // GetSpecialDetailUserPower 处理用户查看专项调研详情的权限
  910. func GetSpecialDetailUserPower(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (havePower bool, err error) {
  911. if user.CompanyId == utils.HZ_COMPANY_ID {
  912. havePower = true
  913. return
  914. }
  915. userType, _, e := GetUserType(user.CompanyId)
  916. if e != nil {
  917. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  918. return
  919. }
  920. if userType == 0 {
  921. return
  922. }
  923. mapUserType, e := GetActivityCcustomerTypeList()
  924. if e != nil {
  925. err = e
  926. return
  927. }
  928. var userTypeStr string
  929. userTypeStr = mapUserType[userType]
  930. // 永续客户、大套餐客户可以查看行业升级套餐客户 权限
  931. if userTypeStr == "1" || userTypeStr == "2" {
  932. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) || strings.Contains(activityInfo.CustomerTypeIds, "8") {
  933. havePower = true
  934. return
  935. }
  936. }
  937. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  938. if e != nil {
  939. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  940. return
  941. }
  942. //如果有升级权限的自动添加策略、固收的升级权限
  943. if permissionStr != "" {
  944. if activityInfo.ChartPermissionName == utils.CE_LUE_NAME {
  945. permissionStr += "," + utils.CE_LUE_NAME
  946. }
  947. if activityInfo.ChartPermissionName == utils.GU_SHOU_NAME {
  948. permissionStr += "," + utils.GU_SHOU_NAME
  949. }
  950. }
  951. //如果没有对应的升级权限,则返回
  952. if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  953. return
  954. }
  955. //userType, e := GetSpecialUserType(user)
  956. var pars []interface{}
  957. var condition string
  958. var userTypes string
  959. condition += ` AND art.publish_status = 1 AND art.is_offline = 0 `
  960. userTypes = "%" + userTypeStr + "%"
  961. condition += ` AND art.customer_type_ids LIKE ? `
  962. pars = append(pars, userTypes)
  963. condition += ` AND art.activity_id = ? `
  964. pars = append(pars, activityInfo.ActivityId)
  965. total, e := models.GetActivitySpecialCount(condition, pars)
  966. if e != nil {
  967. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  968. return
  969. }
  970. if total == 1 {
  971. havePower = true
  972. return
  973. }
  974. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  975. havePower = true
  976. return
  977. }
  978. return
  979. }
  980. // 预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳
  981. func SendWxMsgActivitySpecial10(activityInfo *models.CygxActivitySpecialDetail) (err error) {
  982. activityId := activityInfo.ActivityId
  983. var msg string
  984. defer func() {
  985. if err != nil {
  986. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  987. go utils.SendAlarmMsg(fmt.Sprint("预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳消息发送失败", activityInfo.ResearchTheme, ", activityId"), 2)
  988. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  989. }
  990. }()
  991. var first string
  992. var keyword1 string
  993. var keyword2 string
  994. var keyword3 string
  995. var keyword4 string
  996. var remark string
  997. adminUser, e := models.GetSellerByAdminId(activityInfo.AdminId)
  998. if e != nil {
  999. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1000. return
  1001. }
  1002. cnf, _ := models.GetConfigByCode("tpl_msg")
  1003. mobile := adminUser.Mobile + "," + cnf.ConfigValue
  1004. specialSignupList, e := models.GetActivityListSpecialByActivityId(activityId)
  1005. if e != nil {
  1006. err = errors.New("GetActivityListSpecialAll, Err: " + e.Error())
  1007. return
  1008. }
  1009. for _, v := range specialSignupList {
  1010. keyword1 += "【" + v.RealName + "--" + v.CompanyName + "】"
  1011. }
  1012. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  1013. if e != nil {
  1014. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1015. return
  1016. }
  1017. first = "【" + activityInfo.ResearchTheme + "】已有10人预报名"
  1018. keyword3 = "-"
  1019. keyword2 = "-"
  1020. keyword4 = "【" + activityInfo.ResearchTheme + "】已有10人预报名"
  1021. openIdArr := make([]string, 0)
  1022. for _, v := range openIdList {
  1023. openIdArr = append(openIdArr, v.OpenId)
  1024. }
  1025. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  1026. sendInfo := new(SendWxTemplate)
  1027. sendInfo.First = first
  1028. sendInfo.Keyword1 = keyword1
  1029. sendInfo.Keyword2 = keyword2
  1030. sendInfo.Keyword3 = keyword3
  1031. sendInfo.Keyword4 = keyword4
  1032. sendInfo.Remark = remark
  1033. sendInfo.TemplateId = utils.WxMsgTemplateIdAskMsgXzs
  1034. sendInfo.RedirectUrl = redirectUrl
  1035. sendInfo.RedirectTarget = 3
  1036. sendInfo.Resource = strconv.Itoa(activityId)
  1037. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  1038. sendInfo.OpenIdArr = openIdArr
  1039. err = PublicSendTemplateMsg(sendInfo)
  1040. if err != nil {
  1041. return
  1042. }
  1043. return
  1044. }
  1045. // SendWxMsgActivitySpecialTwoDays 活动开始前两天08:00,提醒报名客户 \提醒报名客户的对口销售
  1046. func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
  1047. //func SendWxMsgActivitySpecialTwoDays() (err error) {
  1048. var msg string
  1049. defer func() {
  1050. if err != nil {
  1051. fmt.Println(err)
  1052. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  1053. go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
  1054. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  1055. }
  1056. }()
  1057. twoDayTime := time.Now().AddDate(0, 0, 2)
  1058. startTime := twoDayTime.Format(utils.FormatDate) + " 00:00:00"
  1059. endTime := twoDayTime.Format(utils.FormatDate) + " 23:59:59"
  1060. var condition string
  1061. var pars []interface{}
  1062. condition = ` AND days >0 AND activity_time BETWEEN ? AND ? `
  1063. pars = append(pars, startTime, endTime)
  1064. listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
  1065. if e != nil {
  1066. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1067. return
  1068. }
  1069. if len(listActivitySpecial) == 0 {
  1070. return
  1071. }
  1072. var activityIds []int
  1073. for _, v := range listActivitySpecial {
  1074. activityIds = append(activityIds, v.ActivityId)
  1075. condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
  1076. pars = make([]interface{}, 0)
  1077. listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
  1078. if e != nil {
  1079. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  1080. return
  1081. }
  1082. if len(listSpecialTrip) == 0 {
  1083. return
  1084. }
  1085. var mobile string
  1086. var companyIds []int
  1087. for _, vT := range listSpecialTrip {
  1088. mobile += "'" + vT.Mobile + "',"
  1089. companyIds = append(companyIds, vT.CompanyId)
  1090. }
  1091. mobile = strings.TrimRight(mobile, ",")
  1092. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  1093. if e != nil {
  1094. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1095. return
  1096. }
  1097. first := ""
  1098. keyword1 := "专项调研【" + v.ResearchTheme + "】"
  1099. keyword2 := "将在两天后进行,如不能参加,请及时取消报名"
  1100. keyword3 := ""
  1101. keyword4 := ""
  1102. remark := "点击查看活动详情"
  1103. SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
  1104. //活动开始前两天08:00,提醒报名客户的对口销售
  1105. companyIdsLen := len(companyIds)
  1106. if companyIdsLen == 0 {
  1107. continue
  1108. } else {
  1109. pars = make([]interface{}, 0)
  1110. condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
  1111. pars = append(pars, companyIds)
  1112. //获取销售的手机号
  1113. listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
  1114. if e != nil && e.Error() != utils.ErrNoRow() {
  1115. err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
  1116. return
  1117. }
  1118. if len(listSeller) == 0 {
  1119. continue
  1120. }
  1121. var mobileArr []string
  1122. for _, v := range listSeller {
  1123. if v.Mobile != "" {
  1124. mobileArr = append(mobileArr, v.Mobile)
  1125. }
  1126. }
  1127. mobileLen := len(mobileArr)
  1128. if mobileLen == 0 {
  1129. return
  1130. }
  1131. //获取手机号对应的Openid
  1132. listSellerOpenid, e := models.GetWxOpenIdByMobileSliceList(mobileArr)
  1133. if e != nil && e.Error() != utils.ErrNoRow() {
  1134. err = errors.New("GetWxOpenIdByMobileSliceList, Err: " + e.Error())
  1135. return
  1136. }
  1137. mapMobileOpenid := make(map[string]string)
  1138. for _, v := range listSellerOpenid {
  1139. mapMobileOpenid[v.Mobile] = v.OpenId
  1140. }
  1141. mapSller := make(map[string]string)
  1142. mapSllerOpenid := make(map[string]string)
  1143. for _, vS := range listSeller {
  1144. for _, vT := range listSpecialTrip {
  1145. if vT.CompanyId == vS.CompanyId {
  1146. mapSller[vS.Mobile] += "【" + vT.RealName + "--" + vT.CompanyName + "】"
  1147. mapSllerOpenid[vS.Mobile] = mapMobileOpenid[vS.Mobile]
  1148. }
  1149. }
  1150. }
  1151. for k, _ := range mapSller {
  1152. keyword2 = "将在两天后进行,请及时提醒您的报名客户"
  1153. openIdList = make([]*models.OpenIdList, 0)
  1154. openIdList = append(openIdList, &models.OpenIdList{OpenId: mapSllerOpenid[k]})
  1155. SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
  1156. }
  1157. }
  1158. }
  1159. return
  1160. }
  1161. // SendWxMsgActivitySpecialCancel 线下活动前4天08:00报名人数不足7人,线上活动前3天08:00报名人数不足10人,活动自动取消发布,并推送模板消息至报名客户及对口销售
  1162. func SendWxMsgActivitySpecialCancel(cont context.Context) (err error) {
  1163. var msg string
  1164. defer func() {
  1165. if err != nil {
  1166. fmt.Println(err)
  1167. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  1168. go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
  1169. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  1170. }
  1171. }()
  1172. dayTime3 := time.Now().AddDate(0, 0, 3)
  1173. startTime := dayTime3.Format(utils.FormatDate) + " 00:00:00"
  1174. endTime := dayTime3.Format(utils.FormatDate) + " 23:59:59"
  1175. dayTime4 := time.Now().AddDate(0, 0, 4)
  1176. startTime4 := dayTime4.Format(utils.FormatDate) + " 00:00:00"
  1177. endTime4 := dayTime4.Format(utils.FormatDate) + " 23:59:59"
  1178. var condition string
  1179. var pars []interface{}
  1180. condition = ` AND days >0 AND activity_time BETWEEN ? AND ? AND special_type= 1 `
  1181. pars = append(pars, startTime, endTime)
  1182. condition += ` OR ( days >0 AND activity_time BETWEEN ? AND ? AND special_type= 2 ) `
  1183. pars = append(pars, startTime4, endTime4)
  1184. listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
  1185. if e != nil {
  1186. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1187. return
  1188. }
  1189. if len(listActivitySpecial) == 0 {
  1190. return
  1191. }
  1192. var activityIds []int
  1193. for _, v := range listActivitySpecial {
  1194. activityIds = append(activityIds, v.ActivityId)
  1195. condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
  1196. pars = make([]interface{}, 0)
  1197. listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
  1198. if e != nil {
  1199. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  1200. return
  1201. }
  1202. if v.SpecialType == 1 {
  1203. if len(listSpecialTrip) >= 10 {
  1204. continue
  1205. }
  1206. }
  1207. if v.SpecialType == 2 {
  1208. if len(listSpecialTrip) >= 7 {
  1209. continue
  1210. }
  1211. }
  1212. e = models.UpdateActivitySpecialPublishStatus(0, v.ActivityId)
  1213. if e != nil {
  1214. err = errors.New("UpdateActivitySpecialPublishStatus,自动取消专项调研日程失败 Err: " + e.Error() + strconv.Itoa(v.ActivityId))
  1215. return
  1216. }
  1217. if len(listSpecialTrip) < 0 {
  1218. return
  1219. }
  1220. var mobile string
  1221. var companyIds []int
  1222. for _, vT := range listSpecialTrip {
  1223. mobile += "'" + vT.Mobile + "',"
  1224. companyIds = append(companyIds, vT.CompanyId)
  1225. }
  1226. mobile = strings.TrimRight(mobile, ",")
  1227. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  1228. if e != nil {
  1229. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1230. return
  1231. }
  1232. first := "【" + v.ResearchTheme + "】专项调研因专家安排变动,本次调研活动延期举办,具体时间另行通知"
  1233. keyword1 := v.ResearchTheme
  1234. keyword2 := "已取消"
  1235. keyword3 := ""
  1236. keyword4 := ""
  1237. remark := ""
  1238. openIdArr := make([]string, 0)
  1239. for _, vOpenid := range openIdList {
  1240. openIdArr = append(openIdArr, vOpenid.OpenId)
  1241. }
  1242. companyIdsLen := len(companyIds)
  1243. if len(companyIds) > 0 {
  1244. pars = make([]interface{}, 0)
  1245. condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
  1246. pars = append(pars, companyIds)
  1247. listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
  1248. if e != nil && e.Error() != utils.ErrNoRow() {
  1249. err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
  1250. return
  1251. }
  1252. if len(listSeller) == 0 {
  1253. continue
  1254. }
  1255. var mobileArr []string
  1256. for _, v := range listSeller {
  1257. if v.Mobile != "" {
  1258. mobileArr = append(mobileArr, v.Mobile)
  1259. }
  1260. }
  1261. mobileLen := len(mobileArr)
  1262. if mobileLen == 0 {
  1263. return
  1264. }
  1265. //获取手机号对应的Openid
  1266. listSellerOpenid, e := models.GetWxOpenIdByMobileSliceList(mobileArr)
  1267. if e != nil && e.Error() != utils.ErrNoRow() {
  1268. err = errors.New("GetWxOpenIdByMobileSliceList, Err: " + e.Error())
  1269. return
  1270. }
  1271. if len(listSellerOpenid) > 0 {
  1272. for _, vOpenid := range listSellerOpenid {
  1273. openIdArr = append(openIdArr, vOpenid.OpenId)
  1274. }
  1275. }
  1276. }
  1277. redirectUrl := ""
  1278. sendInfo := new(SendWxTemplate)
  1279. sendInfo.First = first
  1280. sendInfo.Keyword1 = keyword1
  1281. sendInfo.Keyword2 = keyword2
  1282. sendInfo.Keyword3 = keyword3
  1283. sendInfo.Keyword4 = keyword4
  1284. sendInfo.Remark = remark
  1285. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  1286. sendInfo.RedirectUrl = redirectUrl
  1287. sendInfo.RedirectTarget = 3
  1288. sendInfo.Resource = strconv.Itoa(v.ActivityId)
  1289. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  1290. sendInfo.OpenIdArr = openIdArr
  1291. fmt.Println(sendInfo)
  1292. err = PublicSendTemplateMsg(sendInfo)
  1293. }
  1294. return
  1295. }
  1296. func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tripRemaining int, mapChartName map[string]int, err error) {
  1297. companyDetail, e := models.GetCompanyDetailByIdGroup(companyId)
  1298. if e != nil {
  1299. err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
  1300. }
  1301. if companyDetail == nil {
  1302. return
  1303. }
  1304. if companyDetail.Status != "永续" && companyDetail.Status != "正式" {
  1305. return
  1306. }
  1307. var specialSurplus string
  1308. if companyDetail.Status == "永续" {
  1309. specialSurplus = "不限次数"
  1310. }
  1311. //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}
  1312. //chartNumMap := map[int]int{utils.YI_YAO_ID:0, utils.XIAO_FEI_ID:0, utils.KE_JI_ID:0, utils.ZHI_ZAO_ID:0}
  1313. chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
  1314. if companyDetail.Status == "正式" {
  1315. //var packageType int
  1316. userType, _, _ = GetUserType(companyId)
  1317. var condition string
  1318. var pars []interface{}
  1319. condition += ` AND company_id = ? `
  1320. pars = append(pars, companyId)
  1321. //查询当年的数据
  1322. condition += ` AND b.create_time >= ? `
  1323. pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  1324. listTripBill, e := models.GetCygxActivitySpecialTripBillList(condition, pars)
  1325. if e != nil {
  1326. err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
  1327. return
  1328. }
  1329. PermissionNameMap, e := GetPermissionNameMap()
  1330. if e != nil {
  1331. err = errors.New("GetPermissionNameMap, Err: " + e.Error())
  1332. return
  1333. }
  1334. for k, v := range listTripBill {
  1335. listTripBill[k].ChartPermissionName = PermissionNameMap[v.ChartPermissionId]
  1336. }
  1337. // 获取继承点数
  1338. //inheritList, e := models.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
  1339. //if e != nil && e.Error() != utils.ErrNoRow() {
  1340. // err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
  1341. //}
  1342. if userType == 2 {
  1343. var tripBillNum int
  1344. for _, v := range listTripBill {
  1345. //if v.ActivityId == 0 {
  1346. // continue
  1347. //}
  1348. tripBillNum += v.BillDetailed
  1349. }
  1350. //if len(inheritList) > 0 {
  1351. // for _, v := range inheritList {
  1352. // if v.ChartPermissionId == 0 {
  1353. // tripBillNum += v.Points
  1354. // }
  1355. // }
  1356. //}
  1357. tripRemaining = tripBillNum
  1358. if tripRemaining < 0 {
  1359. tripRemaining = 0
  1360. }
  1361. } else {
  1362. list, e := models.GetCompanyReportPermissionByCompanyIdAndProductId(companyId, 2)
  1363. if e != nil && e.Error() != utils.ErrNoRow() {
  1364. err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  1365. }
  1366. if len(list) == 0 {
  1367. return
  1368. }
  1369. var chartPermissionIdSlice []string
  1370. mapChartName = make(map[string]int)
  1371. mapUpgradeId := make(map[int]int)
  1372. mapPermissionNameTrip := make(map[string]int)
  1373. mapInheritChartName := make(map[string]int)
  1374. //mapPermissionName := make(map[int]string)
  1375. for _, v := range list {
  1376. chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
  1377. //是升级套餐才有点数
  1378. if v.IsUpgrade == 1 {
  1379. mapUpgradeId[v.ChartPermissionId] = 1
  1380. }
  1381. }
  1382. chartList := make([]*models.ChartPermission, 0)
  1383. if len(chartPermissionIdSlice) > 0 {
  1384. chartList, e = models.GetChartPermissionByIds(chartPermissionIdSlice)
  1385. if e != nil {
  1386. err = errors.New("获取品种信息失败, Err:" + e.Error())
  1387. return
  1388. }
  1389. }
  1390. if len(chartList) == 0 {
  1391. return
  1392. }
  1393. for _, v := range listTripBill {
  1394. if v.ActivityId == 0 {
  1395. continue
  1396. }
  1397. mapPermissionNameTrip[v.ChartPermissionName] += v.BillDetailed
  1398. }
  1399. for _, v := range chartList {
  1400. //如果是升级则加点
  1401. if _, ok := mapUpgradeId[v.ChartPermissionId]; ok {
  1402. mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.PermissionName]
  1403. } else {
  1404. mapChartName[v.PermissionName] = mapPermissionNameTrip[v.PermissionName]
  1405. }
  1406. }
  1407. // 通过继承获得的加点
  1408. //for _, v := range inheritList {
  1409. // mapInheritChartName[v.ChartPermissionName] = v.Points
  1410. //}
  1411. for k, _ := range chartNameMap {
  1412. if _, ok := mapChartName[k]; ok {
  1413. if inherit, ok2 := mapInheritChartName[k]; ok2 {
  1414. mapChartName[k] += inherit
  1415. }
  1416. }
  1417. }
  1418. for k, v := range mapChartName {
  1419. if v > 0 {
  1420. specialSurplus += k + strconv.Itoa(v) + "次+"
  1421. }
  1422. }
  1423. specialSurplus = strings.TrimRight(specialSurplus, "+")
  1424. }
  1425. }
  1426. return
  1427. }
  1428. // 清零初始化用-去掉了正式用户的判断
  1429. func GetChartPermissionSpecialSurplusByCompanyForInit(companyId int) (userType int, tripRemaining int, mapChartName map[string]int, err error) {
  1430. companyDetail, e := models.GetCompanyDetailByIdGroup(companyId)
  1431. if e != nil {
  1432. err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
  1433. }
  1434. if companyDetail == nil {
  1435. return
  1436. }
  1437. //if companyDetail.Status != "永续" && companyDetail.Status != "正式" {
  1438. // return
  1439. //}
  1440. //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}
  1441. chartNumMap := map[int]int{utils.YI_YAO_ID: 0, utils.XIAO_FEI_ID: 0, utils.KE_JI_ID: 0, utils.ZHI_ZAO_ID: 0}
  1442. //var packageType int
  1443. userType, _, _ = GetUserType(companyId)
  1444. var condition string
  1445. var pars []interface{}
  1446. condition += ` AND company_id = ? `
  1447. pars = append(pars, companyId)
  1448. //查询当年的数据
  1449. condition += ` AND b.create_time >= ? `
  1450. pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  1451. listTripBill, e := models.GetCygxActivitySpecialTripBillList(condition, pars)
  1452. if e != nil {
  1453. err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
  1454. return
  1455. }
  1456. // 获取继承点数
  1457. inheritList, e := models.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
  1458. if e != nil && e.Error() != utils.ErrNoRow() {
  1459. err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
  1460. }
  1461. if userType == 2 {
  1462. var tripBillNum int
  1463. for _, v := range listTripBill {
  1464. //if v.ActivityId == 0 {
  1465. // continue
  1466. //}
  1467. tripBillNum += v.BillDetailed
  1468. }
  1469. if len(inheritList) > 0 {
  1470. for _, v := range inheritList {
  1471. if v.ChartPermissionId == 0 {
  1472. tripBillNum += v.Points
  1473. }
  1474. }
  1475. }
  1476. tripRemaining = tripBillNum
  1477. if tripRemaining < 0 {
  1478. tripRemaining = 0
  1479. }
  1480. } else {
  1481. list, e := models.GetCompanyReportPermissionByCompanyIdAndProductIdForInit(companyId, 2)
  1482. if e != nil && e.Error() != utils.ErrNoRow() {
  1483. err = errors.New("GetCompanyReportPermissionByCompanyIdAndProductIdForInit, Err: " + e.Error())
  1484. }
  1485. if len(list) == 0 {
  1486. return
  1487. }
  1488. var chartPermissionIdSlice []string
  1489. mapChartName = make(map[string]int)
  1490. mapUpgradeId := make(map[int]int)
  1491. mapPermissionNameTrip := make(map[string]int)
  1492. mapInheritChartName := make(map[string]int)
  1493. //mapPermissionName := make(map[int]string)
  1494. for _, v := range list {
  1495. chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
  1496. //是升级套餐才有点数
  1497. if v.IsUpgrade == 1 {
  1498. mapUpgradeId[v.ChartPermissionId] = 1
  1499. }
  1500. }
  1501. chartList := make([]*models.ChartPermission, 0)
  1502. if len(chartPermissionIdSlice) > 0 {
  1503. chartList, e = models.GetChartPermissionByIds(chartPermissionIdSlice)
  1504. if e != nil {
  1505. err = errors.New("获取品种信息失败, Err:" + e.Error())
  1506. return
  1507. }
  1508. }
  1509. if len(chartList) == 0 {
  1510. return
  1511. }
  1512. for _, v := range listTripBill {
  1513. if v.ActivityId == 0 {
  1514. continue
  1515. }
  1516. mapPermissionNameTrip[v.ChartPermissionName] += v.BillDetailed
  1517. }
  1518. for _, v := range chartList {
  1519. if _, ok := chartNumMap[v.ChartPermissionId]; ok {
  1520. //如果是升级则加点
  1521. if _, ok := mapUpgradeId[v.ChartPermissionId]; ok {
  1522. mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.PermissionName]
  1523. } else {
  1524. mapChartName[v.PermissionName] = mapPermissionNameTrip[v.PermissionName]
  1525. }
  1526. }
  1527. }
  1528. // 通过继承获得的加点
  1529. for _, v := range inheritList {
  1530. mapInheritChartName[v.ChartPermissionName] = v.Points
  1531. }
  1532. for _, v := range mapChartName {
  1533. if v > 0 {
  1534. tripRemaining += v
  1535. }
  1536. }
  1537. }
  1538. return
  1539. }
  1540. // total初始化用-去掉了正式用户的判断
  1541. func GetChartPermissionSpecialSurplusByCompanyForInitTotal(companyId int) (userType int, tripRemaining int, mapChartName map[string]int, err error) {
  1542. companyDetail, e := models.GetCompanyDetailByIdGroup(companyId)
  1543. if e != nil {
  1544. err = errors.New("GetCompanyDetailByIdGroup, Err: " + e.Error())
  1545. }
  1546. if companyDetail == nil {
  1547. return
  1548. }
  1549. //if companyDetail.Status != "永续" && companyDetail.Status != "正式" {
  1550. // return
  1551. //}
  1552. //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}
  1553. chartNumMap := map[int]int{utils.YI_YAO_ID: 0, utils.XIAO_FEI_ID: 0, utils.KE_JI_ID: 0, utils.ZHI_ZAO_ID: 0}
  1554. //var packageType int
  1555. userType, _, _ = GetUserType(companyId)
  1556. var condition string
  1557. var pars []interface{}
  1558. condition += ` AND company_id = ? `
  1559. pars = append(pars, companyId)
  1560. //查询当年的数据
  1561. condition += ` AND b.create_time >= ? `
  1562. pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  1563. listTripBill, e := models.GetCygxActivitySpecialTripBillList(condition, pars)
  1564. if e != nil {
  1565. err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
  1566. return
  1567. }
  1568. // 获取继承点数
  1569. inheritList, e := models.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
  1570. if e != nil && e.Error() != utils.ErrNoRow() {
  1571. err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
  1572. }
  1573. if userType == 2 {
  1574. var tripBillNum int
  1575. for _, v := range listTripBill {
  1576. //if v.ActivityId == 0 {
  1577. // continue
  1578. //}
  1579. tripBillNum += v.BillDetailed
  1580. }
  1581. if len(inheritList) > 0 {
  1582. for _, v := range inheritList {
  1583. if v.ChartPermissionId == 0 {
  1584. tripBillNum += v.Points
  1585. }
  1586. }
  1587. }
  1588. tripRemaining = tripBillNum
  1589. if tripRemaining < 0 {
  1590. tripRemaining = 0
  1591. }
  1592. } else {
  1593. list, e := models.GetCompanyReportPermissionByCompanyIdAndProductIdForInit2(companyId, 2)
  1594. if e != nil && e.Error() != utils.ErrNoRow() {
  1595. err = errors.New("GetCompanyReportPermissionByCompanyIdAndProductIdForInit, Err: " + e.Error())
  1596. }
  1597. if len(list) == 0 {
  1598. return
  1599. }
  1600. var chartPermissionIdSlice []string
  1601. mapChartName = make(map[string]int)
  1602. mapUpgradeId := make(map[int]int)
  1603. mapPermissionNameTrip := make(map[string]int)
  1604. mapInheritChartName := make(map[string]int)
  1605. //mapPermissionName := make(map[int]string)
  1606. for _, v := range list {
  1607. chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
  1608. //是升级套餐才有点数
  1609. if v.IsUpgrade == 1 {
  1610. mapUpgradeId[v.ChartPermissionId] = 1
  1611. }
  1612. }
  1613. chartList := make([]*models.ChartPermission, 0)
  1614. if len(chartPermissionIdSlice) > 0 {
  1615. chartList, e = models.GetChartPermissionByIds(chartPermissionIdSlice)
  1616. if e != nil {
  1617. err = errors.New("获取品种信息失败, Err:" + e.Error())
  1618. return
  1619. }
  1620. }
  1621. if len(chartList) == 0 {
  1622. return
  1623. }
  1624. for _, v := range listTripBill {
  1625. if v.ActivityId == 0 {
  1626. continue
  1627. }
  1628. mapPermissionNameTrip[v.ChartPermissionName] += v.BillDetailed
  1629. }
  1630. for _, v := range chartList {
  1631. if _, ok := chartNumMap[v.ChartPermissionId]; ok {
  1632. //如果是升级则加点
  1633. if _, ok := mapUpgradeId[v.ChartPermissionId]; ok {
  1634. mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.PermissionName]
  1635. } else {
  1636. mapChartName[v.PermissionName] = mapPermissionNameTrip[v.PermissionName]
  1637. }
  1638. }
  1639. }
  1640. // 通过继承获得的加点
  1641. for _, v := range inheritList {
  1642. mapInheritChartName[v.ChartPermissionName] = v.Points
  1643. }
  1644. for _, v := range mapChartName {
  1645. if v > 0 {
  1646. tripRemaining += v
  1647. }
  1648. }
  1649. }
  1650. return
  1651. }
  1652. // 获取活动封面图片
  1653. func GetActivitySpecialImgMap(items []*models.CygxActivitySpecialDetail) (mapResp map[int]*models.ActivityImgUrlMapResp) {
  1654. var err error
  1655. defer func() {
  1656. if err != nil {
  1657. fmt.Println(err)
  1658. go utils.SendAlarmMsg("获取活动封面图片,失败,GetActivityImgMap:Err "+err.Error(), 2)
  1659. }
  1660. }()
  1661. detailChart, e := models.GetConfigByCode("chart_img_url")
  1662. if e != nil {
  1663. err = errors.New("GetConfigByCode chart_img_url , Err: " + e.Error())
  1664. return
  1665. }
  1666. mapResp = make(map[int]*models.ActivityImgUrlMapResp, 0)
  1667. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  1668. mapChart := make(map[string]string)
  1669. var chartName string
  1670. var imgUrlChart string
  1671. for _, v := range chartList {
  1672. vslice := strings.Split(v, "_")
  1673. chartName = vslice[0]
  1674. imgUrlChart = vslice[len(vslice)-1]
  1675. mapChart[chartName] = imgUrlChart
  1676. }
  1677. for _, v := range items {
  1678. item := new(models.ActivityImgUrlMapResp)
  1679. if mapChart[v.ChartPermissionName] != "" {
  1680. item.ImgUrl = mapChart[v.ChartPermissionName]
  1681. }
  1682. mapResp[v.ActivityId] = item
  1683. }
  1684. return
  1685. }