activity_points_set.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_task/models"
  6. "hongze/hongze_task/models/company_contract"
  7. "hongze/hongze_task/models/cygx"
  8. "hongze/hongze_task/models/data_manage"
  9. "hongze/hongze_task/services/alarm_msg"
  10. "hongze/hongze_task/utils"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type YanXuanActivityPointsRedis struct {
  16. UserId int `description:"用户ID"`
  17. ComapnyId int `description:"公司ID"`
  18. ActivityId int `description:"活动ID"`
  19. PublishStatus int `description:"发布状态 1已发布,0未发布"`
  20. SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会、6 研选审批通过的时候研选扣点更新。"`
  21. AdminId int `description:"管理员、销售ID"`
  22. Source int `description:" 来源,1客户端,2后台添加, 3开发人员手动添加、4定时任务"`
  23. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  24. CreateTime time.Time `description:"创建时间"`
  25. }
  26. //func init(){
  27. // log := &YanXuanActivityPointsRedis{ComapnyId: 16, SourceType: 7, Source: 4, CreateTime: time.Now()}
  28. // if utils.Re == nil {
  29. // err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
  30. // if err != nil {
  31. // fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
  32. // }
  33. // }
  34. //}
  35. // 6 研选审批通过的时候研选扣点更新
  36. func YanXuanCompanyApproval(comapnyId int) (err error) {
  37. defer func() {
  38. if err != nil {
  39. fmt.Println(err)
  40. msg := fmt.Sprint("comapnyId:", comapnyId)
  41. go alarm_msg.SendAlarmMsg("研选审批通过的时候研选扣点更新,写入Redis队列消息失败:"+err.Error()+msg, 2)
  42. }
  43. }()
  44. //SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。6 研选审批通过的时候研选扣点更新。7,正式专试用定时任务更新"`
  45. log := &YanXuanActivityPointsRedis{ComapnyId: comapnyId, SourceType: 6, Source: 2, CreateTime: time.Now()}
  46. if utils.Re == nil {
  47. err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
  48. if err != nil {
  49. fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
  50. }
  51. }
  52. return
  53. }
  54. // 7 正式专试用定时任务更新研选扣点
  55. func YanXuanCompanyCompanyTryOut(comapnyId int) (err error) {
  56. defer func() {
  57. if err != nil {
  58. fmt.Println(err)
  59. msg := fmt.Sprint("comapnyId:", comapnyId)
  60. go alarm_msg.SendAlarmMsg("正式专试用定时任务更新研选扣点,写入Redis队列消息失败:"+err.Error()+msg, 2)
  61. }
  62. }()
  63. //SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。6 研选审批通过的时候研选扣点更新。7,正式专试用定时任务更新"`
  64. log := &YanXuanActivityPointsRedis{ComapnyId: comapnyId, SourceType: 7, Source: 4, CreateTime: time.Now()}
  65. if utils.Re == nil {
  66. err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
  67. if err != nil {
  68. fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
  69. }
  70. }
  71. return
  72. }
  73. // 审批通过的时候专项调研次数更新
  74. //func ActivitySpecialCompanyApproval(companyId int) (err error) {
  75. // defer func() {
  76. // if err != nil {
  77. // fmt.Println(err)
  78. // msg := fmt.Sprint("companyId:", companyId)
  79. // go alarm_msg.SendAlarmMsg("审批通过试用转正式时专项调研次数更新失败:"+err.Error()+msg, 2)
  80. // }
  81. // }()
  82. // comapny, e := models.GetCompanyById(companyId)
  83. // if e != nil {
  84. // err = errors.New("GetCompanyById err:" + e.Error())
  85. // return
  86. // }
  87. // // 获取继承点数
  88. // inheritList, e := data_manage.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
  89. // if e != nil && e.Error() != utils.ErrNoRow() {
  90. // err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
  91. // }
  92. // chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
  93. //
  94. // userType, packageType, _, _, _ := GetUserType(companyId)
  95. // itemBill := new(data_manage.CygxActivitySpecialTripBill)
  96. // itemBill.CreateTime = time.Now()
  97. // itemBill.CompanyId = companyId
  98. // itemBill.CompanyName = comapny.CompanyName
  99. // itemBill.Source = 2
  100. // itemBill.DoType = 2
  101. // itemBill.Way = 3
  102. // if userType == 2{
  103. // packageTypeMap := map[int]int{1: 16, 2: 10}
  104. // totalTrip := packageTypeMap[packageType]
  105. // if len(inheritList) > 0 {
  106. // for _, v := range inheritList {
  107. // if v.ChartPermissionId == 0 {
  108. // itemBill.BillDetailed = totalTrip + v.Points
  109. // } else {
  110. // itemBill.BillDetailed = totalTrip
  111. // }
  112. // }
  113. // } else {
  114. // itemBill.BillDetailed = totalTrip
  115. // }
  116. //
  117. // itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
  118. // if totalTrip == 10 {
  119. // itemBill.Content = "45w大套餐转正"
  120. // } else {
  121. // itemBill.Content = "70w大套餐转正"
  122. // }
  123. // } else {
  124. // list, e := GetCompanyReportPermission(companyId, 2)
  125. // if e != nil && e.Error() != utils.ErrNoRow() {
  126. // err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  127. // }
  128. // if len(list) == 0 {
  129. // return
  130. // }
  131. // var chartPermissionIdSlice []string
  132. // mapChartName := make(map[string]int)
  133. // mapUpgradeId := make(map[int]int)
  134. // mapInheritChartName := make(map[string]int)
  135. // mapPermissionNameTrip := make(map[string]int)
  136. // //mapPermissionName := make(map[int]string)
  137. // for _, v := range list {
  138. // chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
  139. // //是升级套餐才有点数
  140. // if v.IsUpgrade == 1 {
  141. // mapUpgradeId[v.ChartPermissionId] = 1
  142. // }
  143. // }
  144. // chartList := make([]*models.ChartPermission, 0)
  145. // if len(chartPermissionIdSlice) > 0 {
  146. // chartList, e = models.GetChartPermissionByIds(chartPermissionIdSlice)
  147. // if e != nil {
  148. // err = errors.New("获取品种信息失败, Err:" + e.Error())
  149. // return
  150. // }
  151. // }
  152. // if len(chartList) == 0 {
  153. // return
  154. // }
  155. // for _, v := range chartList {
  156. // //如果是升级则加点
  157. // if _, ok := mapUpgradeId[v.ChartPermissionId]; ok {
  158. // mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.ChartPermissionName]
  159. // } else {
  160. // mapChartName[v.PermissionName] = mapPermissionNameTrip[v.ChartPermissionName]
  161. // }
  162. // }
  163. // // 通过继承获得的加点
  164. // for _, v := range inheritList {
  165. // mapInheritChartName[v.ChartPermissionName] = v.Points
  166. // }
  167. // for k, _ := range chartNameMap {
  168. // if _, ok := mapChartName[k]; ok {
  169. // if inherit, ok2 := mapInheritChartName[k]; ok2 {
  170. // mapChartName[k] += inherit
  171. // }
  172. // }
  173. // }
  174. // for k, v := range mapChartName {
  175. // if v > 0 {
  176. // itemBill.BillDetailed += v
  177. // itemBill.Total += k + strconv.Itoa(v) + "次+"
  178. // }
  179. // }
  180. // itemBill.Content = "行业升级套餐转正"
  181. // itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  182. // }
  183. // err = data_manage.AddCygxActivitySpecialTripBill(itemBill)
  184. // if err != nil {
  185. // return
  186. // }
  187. // return
  188. //}
  189. func ActivitySpecialCompanyApproval(companyId, companyContractId int, companyName string) (err error) {
  190. userType, packageType, _, _, _ := GetUserType(companyId)
  191. // 获取继承点数
  192. //inheritList, e := cygx.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
  193. //if e != nil && e.Error() != utils.ErrNoRow() {
  194. // err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
  195. //}
  196. //chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
  197. var items []*cygx.CygxActivitySpecialPermissionPoints
  198. itemBill := new(data_manage.CygxActivitySpecialTripBill)
  199. itemBill.CreateTime = time.Now()
  200. itemBill.CompanyId = companyId
  201. itemBill.CompanyName = companyName
  202. itemBill.Source = 2
  203. itemBill.DoType = 2
  204. itemBill.Way = 3
  205. if userType == 2 {
  206. packageTypeMap := map[int]int{1: 16, 2: 10}
  207. totalTrip := packageTypeMap[packageType]
  208. itemBill.BillDetailed = totalTrip
  209. itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
  210. if totalTrip == 10 {
  211. itemBill.Content = "45w大套餐转正"
  212. } else {
  213. itemBill.Content = "70w大套餐转正"
  214. }
  215. //记录公司剩余点数
  216. item := new(cygx.CygxActivitySpecialPermissionPoints)
  217. item.Points = totalTrip
  218. item.CompanyId = companyId
  219. item.CompanyName = companyName
  220. item.CreateTime = time.Now()
  221. item.ModifyTime = time.Now()
  222. items = append(items, item)
  223. } else {
  224. //list, e := company.GetCompanyReportPermissionByCompanyIdAndProductId(companyId, 2)
  225. //if e != nil && e.Error() != utils.ErrNoRow() {
  226. // err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  227. //}
  228. //if len(list) == 0 {
  229. // return
  230. //}
  231. var condition string
  232. var pars []interface{}
  233. pars = make([]interface{}, 0)
  234. condition = " AND company_contract_id = ? AND is_upgrade = 1 "
  235. pars = append(pars, companyContractId)
  236. list, e := company_contract.GetCompanyContractPermissionList(condition, pars) // 获取带有升级的权限
  237. if e != nil && e.Error() != utils.ErrNoRow() {
  238. err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
  239. return
  240. }
  241. if e != nil && e.Error() != utils.ErrNoRow() {
  242. err = errors.New("GetCygxAllocationCompanyContractPermissionListById, Err: " + e.Error())
  243. return
  244. }
  245. if len(list) == 0 {
  246. return
  247. }
  248. //获取权益主观权限
  249. listRaiSubjectivity, e := models.GetChartPermissionListRaiSubjectivity()
  250. if e != nil && e.Error() != utils.ErrNoRow() {
  251. err = errors.New("GetChartPermissionListRaiSubjectivity, Err: " + e.Error())
  252. }
  253. mapRaiSubjectivity := make(map[int]bool)
  254. mapPermissionName := make(map[int]string)
  255. for _, v := range listRaiSubjectivity {
  256. mapRaiSubjectivity[v.ChartPermissionId] = true
  257. mapPermissionName[v.ChartPermissionId] = v.ChartPermissionName
  258. }
  259. for _, v := range list {
  260. //如果是升级则加点
  261. if v.IsUpgrade == 1 && mapRaiSubjectivity[v.ChartPermissionId] {
  262. item := new(cygx.CygxActivitySpecialPermissionPoints)
  263. item.Points = 5
  264. item.CompanyId = companyId
  265. item.CompanyName = companyName
  266. item.ChartPermissionId = v.ChartPermissionId
  267. item.ChartPermissionName = mapPermissionName[v.ChartPermissionId]
  268. item.CreateTime = time.Now()
  269. item.ModifyTime = time.Now()
  270. items = append(items, item)
  271. }
  272. }
  273. itemBill.Content = "行业升级套餐转正"
  274. }
  275. e := cygx.MultiAddCygxActivitySpecialPermissionPoints(items)
  276. if e != nil {
  277. err = errors.New("MultiAddCygxActivitySpecialPermissionPoints, Err:" + e.Error())
  278. return
  279. }
  280. if userType != 2 && len(items) > 0 {
  281. var condition string
  282. var pars []interface{}
  283. pars = make([]interface{}, 0)
  284. condition = " AND company_id = ? AND points > 0 ORDER BY chart_permission_id DESC "
  285. pars = append(pars, companyId)
  286. activitySpecialPermissionPointsList, e := cygx.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  287. if e != nil && e.Error() != utils.ErrNoRow() {
  288. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  289. return
  290. }
  291. var itemBillTotal []string
  292. for _, v := range activitySpecialPermissionPointsList {
  293. itemBillTotal = append(itemBillTotal, fmt.Sprint(v.ChartPermissionName, v.Points, "次"))
  294. }
  295. itemBill.BillDetailed = 5 * len(items)
  296. itemBill.Total = strings.Join(itemBillTotal, "+")
  297. }
  298. //如果有升级行业权限,或者大套餐客户就写入流水信息
  299. if itemBill.Total != "" {
  300. e := data_manage.AddCygxActivitySpecialTripBill(itemBill)
  301. if e != nil {
  302. err = errors.New("AddCygxActivitySpecialTripBill, Err:" + e.Error())
  303. return
  304. }
  305. }
  306. return
  307. }