123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/utils"
- "strconv"
- "strings"
- )
- // 大套餐的
- func InitActivitySpecialTripBillBig() (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- }
- }()
- // 70w 16次
- list70, err := models.GetActivitySecialTirpBillForInit(1)
- if err != nil {
- return
- }
- items70 := make([]*models.CygxActivitySpecialTripBill, 0)
- for _, v := range list70 {
- itemBill := new(models.CygxActivitySpecialTripBill)
- itemBill.CreateTime = v.ApprovalTime
- itemBill.CompanyId = v.CompanyId
- itemBill.CompanyName = v.CompanyName
- itemBill.Source = 2
- itemBill.DoType = 2
- itemBill.Way = 3
- itemBill.Content = "70w大套餐转正"
- itemBill.BillDetailed = 16
- itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
- items70 = append(items70, itemBill)
- fmt.Println("CompanyId: ", v.CompanyId)
- fmt.Println("CompanyName: ", v.CompanyName)
- }
- err = models.AddCygxActivitySpecialTripBillMulti(items70)
- if err != nil {
- return
- }
- // 45w 10次
- list45, err := models.GetActivitySecialTirpBillForInit(2)
- if err != nil {
- return
- }
- items45 := make([]*models.CygxActivitySpecialTripBill, 0)
- for _, v := range list45 {
- itemBill := new(models.CygxActivitySpecialTripBill)
- itemBill.CreateTime = v.ApprovalTime
- itemBill.CompanyId = v.CompanyId
- itemBill.CompanyName = v.CompanyName
- itemBill.Source = 2
- itemBill.DoType = 2
- itemBill.Way = 3
- itemBill.Content = "45w大套餐转正"
- itemBill.BillDetailed = 10
- itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
- items45 = append(items45, itemBill)
- fmt.Println("CompanyId: ", v.CompanyId)
- fmt.Println("CompanyName: ", v.CompanyName)
- }
- err = models.AddCygxActivitySpecialTripBillMulti(items45)
- if err != nil {
- return
- }
- return
- }
- // 非大套餐的,根据行业权限添加
- func InitActivitySpecialTripBillNotBig() (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- }
- }()
- list, err := models.GetActivitySecialTirpBillForInitNotBig()
- if err != nil {
- return
- }
- items := make([]*models.CygxActivitySpecialTripBill, 0)
- for _, item := range list {
- chartPermissionIdSlice := strings.Split(item.ChartPermissionIds, ",")
- mapChartName := make(map[string]int)
- mapPermissionNameTrip := make(map[string]int)
- chartList, e := models.GetChartPermissionByIds(chartPermissionIdSlice)
- if e != nil {
- err = errors.New("获取品种信息失败, Err:" + e.Error())
- return
- }
- for _, v := range chartList {
- mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.PermissionName]
- }
- itemBill := new(models.CygxActivitySpecialTripBill)
- itemBill.CreateTime = item.ApprovalTime
- itemBill.CompanyId = item.CompanyId
- itemBill.CompanyName = item.CompanyName
- itemBill.Source = 2
- itemBill.DoType = 2
- itemBill.Way = 3
- for k, v := range mapChartName {
- if v > 0 {
- itemBill.BillDetailed += v
- itemBill.Total += k + strconv.Itoa(v) + "次+"
- }
- }
- itemBill.Content = "行业升级套餐转正"
- itemBill.Total = strings.TrimRight(itemBill.Total, "+")
- items = append(items, itemBill)
- fmt.Println("CompanyId: ", item.CompanyId)
- fmt.Println("CompanyName: ", item.CompanyName)
- }
- err = models.AddCygxActivitySpecialTripBillMulti(items)
- if err != nil {
- return
- }
- return
- }
- // 到期清零和加入继承表
- func ActivitySpecialCompanyTryOutReduce() (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- }
- }()
- list, err := models.GetActivitySecialTirpBillForReduce()
- if err != nil {
- return
- }
- for _, v := range list {
- userType, tripRemaining, mapChartName, e := GetChartPermissionSpecialSurplusByCompanyForInit(v.CompanyId)
- if e != nil {
- err = e
- fmt.Println("err :", err)
- continue
- }
- itemBill := new(models.CygxActivitySpecialTripBill)
- itemBill.CreateTime = v.CreateTime
- itemBill.Source = 2
- itemBill.DoType = 1
- itemBill.Way = 3
- itemBill.BillDetailed = -tripRemaining
- itemBill.CompanyId = v.CompanyId
- itemBill.CompanyName = v.CompanyName
- itemBill.Content = "到期清零"
- itemBill.Total = "0"
- if tripRemaining == 0 {
- continue
- }
- err = models.AddCygxActivitySpecialTripBill(itemBill)
- if err != nil {
- return
- }
- fmt.Println("CompanyId: ", v.CompanyId)
- fmt.Println("CompanyName: ", v.CompanyName)
- // 删除公司之前的继承表
- err = models.DelCygxActivitySpecialInheritPointsByCompanyId(v.CompanyId)
- if err != nil {
- return
- }
- chartMap := map[string]int{utils.YI_YAO_NAME: utils.YI_YAO_ID, utils.XIAO_FEI_NAME: utils.XIAO_FEI_ID, utils.KE_JI_NAME: utils.KE_JI_ID, utils.ZHI_ZAO_NAME: utils.ZHI_ZAO_ID}
- //添加继承点数表
- inheritItems := make([]*models.CygxActivitySpecialInheritPointsCompany, 0)
- if userType == 2 {
- inheritItem := new(models.CygxActivitySpecialInheritPointsCompany)
- inheritItem.CompanyId = v.CompanyId
- inheritItem.CompanyName = v.CompanyName
- inheritItem.CreateTime = v.CreateTime
- inheritItem.ModifyTime = v.CreateTime
- inheritItem.Points = tripRemaining
- if tripRemaining > 0 {
- inheritItems = append(inheritItems, inheritItem)
- }
- } else {
- for k, num := range mapChartName {
- inheritItem := new(models.CygxActivitySpecialInheritPointsCompany)
- inheritItem.CompanyId = v.CompanyId
- inheritItem.CompanyName = v.CompanyName
- inheritItem.CreateTime = v.CreateTime
- inheritItem.ModifyTime = v.CreateTime
- inheritItem.Points = num
- inheritItem.ChartPermissionName = k
- if _, ok := chartMap[k]; ok {
- inheritItem.ChartPermissionId = chartMap[k]
- }
- if num > 0 {
- inheritItems = append(inheritItems, inheritItem)
- }
- }
- }
- if len(inheritItems) > 0 {
- err = models.AddCygxActivitySpecialInheritPointsCompanyMulti(inheritItems)
- if err != nil {
- return
- }
- }
- }
- return
- }
- // 补充total
- func ActivitySpecialBillTotalInit() (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- }
- }()
- billList, err := models.GetCygxActivitySpecialTripBillForInit()
- if err != nil {
- return
- }
- 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}
- for _, billItem := range billList {
- userType, tripRemaining, mapChartName, e := GetChartPermissionSpecialSurplusByCompanyForInitTotal(billItem.CompanyId)
- if e != nil {
- err = e
- continue
- }
- fmt.Println("CompanyId: ", billItem.CompanyId)
- fmt.Println("CompanyName: ", billItem.CompanyName)
- list, e := models.GetCygxActivitySpecialTripBillByCompanyIdForInit(billItem.CompanyId)
- if e != nil {
- err = e
- return
- }
- if userType == 2 {
- for i, v := range list {
- if v.ActivityId == 0 {
- continue
- }
- if i == 0 {
- v.Total = strconv.Itoa(tripRemaining) + "次"
- } else {
- v.Total = strconv.Itoa(tripRemaining+v.BillDetailed) + "次"
- }
- fmt.Println("v.Total:",v.Total)
- err = models.UpdateCygxActivitySpecialTripBillByCompanyIdForInit(v.Total, v.Id)
- if err != nil {
- return
- }
- }
- } else {
- for i, v := range list {
- if chart, ok := chartMap[v.ChartPermissionId]; ok {
- v.Total = ``
- for k, num := range mapChartName {
- if k == chart {
- if i > 0 {
- num += v.BillDetailed
- }
- }
- v.Total += k + strconv.Itoa(num) + "次+"
- }
- v.Total = strings.TrimRight(v.Total, "+")
- fmt.Println("v.Total:",v.Total)
- err = models.UpdateCygxActivitySpecialTripBillByCompanyIdForInit(v.Total, v.Id)
- if err != nil {
- return
- }
- }
- }
- }
- }
- return
- }
|