init_10.9.1.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/utils"
  7. "strconv"
  8. "strings"
  9. )
  10. // 大套餐的
  11. func InitActivitySpecialTripBillBig() (err error) {
  12. defer func() {
  13. if err != nil {
  14. fmt.Println(err)
  15. }
  16. }()
  17. // 70w 16次
  18. list70, err := models.GetActivitySecialTirpBillForInit(1)
  19. if err != nil {
  20. return
  21. }
  22. items70 := make([]*models.CygxActivitySpecialTripBill, 0)
  23. for _, v := range list70 {
  24. itemBill := new(models.CygxActivitySpecialTripBill)
  25. itemBill.CreateTime = v.ApprovalTime
  26. itemBill.CompanyId = v.CompanyId
  27. itemBill.CompanyName = v.CompanyName
  28. itemBill.Source = 2
  29. itemBill.DoType = 2
  30. itemBill.Way = 3
  31. itemBill.Content = "70w大套餐转正"
  32. itemBill.BillDetailed = 16
  33. itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
  34. items70 = append(items70, itemBill)
  35. fmt.Println("CompanyId: ", v.CompanyId)
  36. fmt.Println("CompanyName: ", v.CompanyName)
  37. }
  38. err = models.AddCygxActivitySpecialTripBillMulti(items70)
  39. if err != nil {
  40. return
  41. }
  42. // 45w 10次
  43. list45, err := models.GetActivitySecialTirpBillForInit(2)
  44. if err != nil {
  45. return
  46. }
  47. items45 := make([]*models.CygxActivitySpecialTripBill, 0)
  48. for _, v := range list45 {
  49. itemBill := new(models.CygxActivitySpecialTripBill)
  50. itemBill.CreateTime = v.ApprovalTime
  51. itemBill.CompanyId = v.CompanyId
  52. itemBill.CompanyName = v.CompanyName
  53. itemBill.Source = 2
  54. itemBill.DoType = 2
  55. itemBill.Way = 3
  56. itemBill.Content = "45w大套餐转正"
  57. itemBill.BillDetailed = 10
  58. itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
  59. items45 = append(items45, itemBill)
  60. fmt.Println("CompanyId: ", v.CompanyId)
  61. fmt.Println("CompanyName: ", v.CompanyName)
  62. }
  63. err = models.AddCygxActivitySpecialTripBillMulti(items45)
  64. if err != nil {
  65. return
  66. }
  67. return
  68. }
  69. // 非大套餐的,根据行业权限添加
  70. func InitActivitySpecialTripBillNotBig() (err error) {
  71. defer func() {
  72. if err != nil {
  73. fmt.Println(err)
  74. }
  75. }()
  76. list, err := models.GetActivitySecialTirpBillForInitNotBig()
  77. if err != nil {
  78. return
  79. }
  80. items := make([]*models.CygxActivitySpecialTripBill, 0)
  81. for _, item := range list {
  82. chartPermissionIdSlice := strings.Split(item.ChartPermissionIds, ",")
  83. mapChartName := make(map[string]int)
  84. mapPermissionNameTrip := make(map[string]int)
  85. chartList, e := models.GetChartPermissionByIds(chartPermissionIdSlice)
  86. if e != nil {
  87. err = errors.New("获取品种信息失败, Err:" + e.Error())
  88. return
  89. }
  90. for _, v := range chartList {
  91. mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.PermissionName]
  92. }
  93. itemBill := new(models.CygxActivitySpecialTripBill)
  94. itemBill.CreateTime = item.ApprovalTime
  95. itemBill.CompanyId = item.CompanyId
  96. itemBill.CompanyName = item.CompanyName
  97. itemBill.Source = 2
  98. itemBill.DoType = 2
  99. itemBill.Way = 3
  100. for k, v := range mapChartName {
  101. if v > 0 {
  102. itemBill.BillDetailed += v
  103. itemBill.Total += k + strconv.Itoa(v) + "次+"
  104. }
  105. }
  106. itemBill.Content = "行业升级套餐转正"
  107. itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  108. items = append(items, itemBill)
  109. fmt.Println("CompanyId: ", item.CompanyId)
  110. fmt.Println("CompanyName: ", item.CompanyName)
  111. }
  112. err = models.AddCygxActivitySpecialTripBillMulti(items)
  113. if err != nil {
  114. return
  115. }
  116. return
  117. }
  118. // 到期清零和加入继承表
  119. func ActivitySpecialCompanyTryOutReduce() (err error) {
  120. defer func() {
  121. if err != nil {
  122. fmt.Println(err)
  123. }
  124. }()
  125. list, err := models.GetActivitySecialTirpBillForReduce()
  126. if err != nil {
  127. return
  128. }
  129. for _, v := range list {
  130. userType, tripRemaining, mapChartName, e := GetChartPermissionSpecialSurplusByCompanyForInit(v.CompanyId)
  131. if e != nil {
  132. err = e
  133. fmt.Println("err :", err)
  134. continue
  135. }
  136. itemBill := new(models.CygxActivitySpecialTripBill)
  137. itemBill.CreateTime = v.CreateTime
  138. itemBill.Source = 2
  139. itemBill.DoType = 1
  140. itemBill.Way = 3
  141. itemBill.BillDetailed = -tripRemaining
  142. itemBill.CompanyId = v.CompanyId
  143. itemBill.CompanyName = v.CompanyName
  144. itemBill.Content = "到期清零"
  145. itemBill.Total = "0"
  146. if tripRemaining == 0 {
  147. continue
  148. }
  149. err = models.AddCygxActivitySpecialTripBill(itemBill)
  150. if err != nil {
  151. return
  152. }
  153. fmt.Println("CompanyId: ", v.CompanyId)
  154. fmt.Println("CompanyName: ", v.CompanyName)
  155. // 删除公司之前的继承表
  156. err = models.DelCygxActivitySpecialInheritPointsByCompanyId(v.CompanyId)
  157. if err != nil {
  158. return
  159. }
  160. 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}
  161. //添加继承点数表
  162. inheritItems := make([]*models.CygxActivitySpecialInheritPointsCompany, 0)
  163. if userType == 2 {
  164. inheritItem := new(models.CygxActivitySpecialInheritPointsCompany)
  165. inheritItem.CompanyId = v.CompanyId
  166. inheritItem.CompanyName = v.CompanyName
  167. inheritItem.CreateTime = v.CreateTime
  168. inheritItem.ModifyTime = v.CreateTime
  169. inheritItem.Points = tripRemaining
  170. if tripRemaining > 0 {
  171. inheritItems = append(inheritItems, inheritItem)
  172. }
  173. } else {
  174. for k, num := range mapChartName {
  175. inheritItem := new(models.CygxActivitySpecialInheritPointsCompany)
  176. inheritItem.CompanyId = v.CompanyId
  177. inheritItem.CompanyName = v.CompanyName
  178. inheritItem.CreateTime = v.CreateTime
  179. inheritItem.ModifyTime = v.CreateTime
  180. inheritItem.Points = num
  181. inheritItem.ChartPermissionName = k
  182. if _, ok := chartMap[k]; ok {
  183. inheritItem.ChartPermissionId = chartMap[k]
  184. }
  185. if num > 0 {
  186. inheritItems = append(inheritItems, inheritItem)
  187. }
  188. }
  189. }
  190. if len(inheritItems) > 0 {
  191. err = models.AddCygxActivitySpecialInheritPointsCompanyMulti(inheritItems)
  192. if err != nil {
  193. return
  194. }
  195. }
  196. }
  197. return
  198. }
  199. // 补充total
  200. func ActivitySpecialBillTotalInit() (err error) {
  201. defer func() {
  202. if err != nil {
  203. fmt.Println(err)
  204. }
  205. }()
  206. billList, err := models.GetCygxActivitySpecialTripBillForInit()
  207. if err != nil {
  208. return
  209. }
  210. 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}
  211. for _, billItem := range billList {
  212. userType, tripRemaining, mapChartName, e := GetChartPermissionSpecialSurplusByCompanyForInitTotal(billItem.CompanyId)
  213. if e != nil {
  214. err = e
  215. continue
  216. }
  217. fmt.Println("CompanyId: ", billItem.CompanyId)
  218. fmt.Println("CompanyName: ", billItem.CompanyName)
  219. list, e := models.GetCygxActivitySpecialTripBillByCompanyIdForInit(billItem.CompanyId)
  220. if e != nil {
  221. err = e
  222. return
  223. }
  224. if userType == 2 {
  225. for i, v := range list {
  226. if v.ActivityId == 0 {
  227. continue
  228. }
  229. if i == 0 {
  230. v.Total = strconv.Itoa(tripRemaining) + "次"
  231. } else {
  232. v.Total = strconv.Itoa(tripRemaining+v.BillDetailed) + "次"
  233. }
  234. fmt.Println("v.Total:",v.Total)
  235. err = models.UpdateCygxActivitySpecialTripBillByCompanyIdForInit(v.Total, v.Id)
  236. if err != nil {
  237. return
  238. }
  239. }
  240. } else {
  241. for i, v := range list {
  242. if chart, ok := chartMap[v.ChartPermissionId]; ok {
  243. v.Total = ``
  244. for k, num := range mapChartName {
  245. if k == chart {
  246. if i > 0 {
  247. num += v.BillDetailed
  248. }
  249. }
  250. v.Total += k + strconv.Itoa(num) + "次+"
  251. }
  252. v.Total = strings.TrimRight(v.Total, "+")
  253. fmt.Println("v.Total:",v.Total)
  254. err = models.UpdateCygxActivitySpecialTripBillByCompanyIdForInit(v.Total, v.Id)
  255. if err != nil {
  256. return
  257. }
  258. }
  259. }
  260. }
  261. }
  262. return
  263. }