activity_special.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. package cygxService
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mobile_admin/models/cygx"
  6. "hongze/hongze_mobile_admin/models/tables/chart_permission"
  7. "hongze/hongze_mobile_admin/models/tables/company_contract_permission"
  8. "hongze/hongze_mobile_admin/utils"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. // 审批通过的时候专项调研次数更新
  14. //func ActivitySpecialCompanyApproval(companyId int, companyName string) (err error) {
  15. // userType, packageType, _, _, _ := GetUserType(companyId)
  16. // // 获取继承点数
  17. // inheritList, e := cygx.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
  18. // if e != nil && e.Error() != utils.ErrNoRow() {
  19. // err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
  20. // }
  21. // chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
  22. //
  23. // itemBill := new(cygx.CygxActivitySpecialTripBill)
  24. // itemBill.CreateTime = time.Now()
  25. // itemBill.CompanyId = companyId
  26. // itemBill.CompanyName = companyName
  27. // itemBill.Source = 2
  28. // itemBill.DoType = 2
  29. // itemBill.Way = 3
  30. // if userType == 2{
  31. // packageTypeMap := map[int]int{1: 16, 2: 10}
  32. // totalTrip := packageTypeMap[packageType]
  33. // if len(inheritList) > 0 {
  34. // for _, v := range inheritList {
  35. // if v.ChartPermissionId == 0 {
  36. // itemBill.BillDetailed = totalTrip + v.Points
  37. // } else {
  38. // itemBill.BillDetailed = totalTrip
  39. // }
  40. // }
  41. // } else {
  42. // itemBill.BillDetailed = totalTrip
  43. // }
  44. //
  45. // itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
  46. // if totalTrip == 10 {
  47. // itemBill.Content = "45w大套餐转正"
  48. // } else {
  49. // itemBill.Content = "70w大套餐转正"
  50. // }
  51. // } else {
  52. // list, e := models.GetCompanyReportPermissionByCompanyIdAndProductId(companyId, 2)
  53. // if e != nil && e.Error() != utils.ErrNoRow() {
  54. // err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  55. // }
  56. // if len(list) == 0 {
  57. // return
  58. // }
  59. // var chartPermissionIdSlice []string
  60. // mapChartName := make(map[string]int)
  61. // mapUpgradeId := make(map[int]int)
  62. // mapInheritChartName := make(map[string]int)
  63. // mapPermissionNameTrip := make(map[string]int)
  64. // //mapPermissionName := make(map[int]string)
  65. // for _, v := range list {
  66. // chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
  67. // //是升级套餐才有点数
  68. // if v.IsUpgrade == 1 {
  69. // mapUpgradeId[v.ChartPermissionId] = 1
  70. // }
  71. // }
  72. // chartList := make([]*chart_permission.ChartPermission, 0)
  73. // if len(chartPermissionIdSlice) > 0 {
  74. // chartList, e = chart_permission.GetChartPermissionByIds(chartPermissionIdSlice)
  75. // if e != nil {
  76. // err = errors.New("获取品种信息失败, Err:" + e.Error())
  77. // return
  78. // }
  79. // }
  80. // if len(chartList) == 0 {
  81. // return
  82. // }
  83. // for _, v := range chartList {
  84. // //如果是升级则加点
  85. // if _, ok := mapUpgradeId[v.ChartPermissionId]; ok {
  86. // mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.ChartPermissionName]
  87. // } else {
  88. // mapChartName[v.PermissionName] = mapPermissionNameTrip[v.ChartPermissionName]
  89. // }
  90. // }
  91. // // 通过继承获得的加点
  92. // for _, v := range inheritList {
  93. // mapInheritChartName[v.ChartPermissionName] = v.Points
  94. // }
  95. // for k, _ := range chartNameMap {
  96. // if _, ok := mapChartName[k]; ok {
  97. // if inherit, ok2 := mapInheritChartName[k]; ok2 {
  98. // mapChartName[k] += inherit
  99. // }
  100. // }
  101. // }
  102. // for k, v := range mapChartName {
  103. // if v > 0 {
  104. // itemBill.BillDetailed += v
  105. // itemBill.Total += k + strconv.Itoa(v) + "次+"
  106. // }
  107. // }
  108. // itemBill.Content = "行业升级套餐转正"
  109. // itemBill.Total = strings.TrimRight(itemBill.Total, "+")
  110. // }
  111. // err = cygx.AddCygxActivitySpecialTripBill(itemBill)
  112. // if err != nil {
  113. // return
  114. // }
  115. // return
  116. //}
  117. func ActivitySpecialCompanyApproval(companyId, companyContractId int, companyName string) (err error) {
  118. userType, packageType, _, _, _ := GetUserType(companyId)
  119. // 获取继承点数
  120. //inheritList, e := cygx.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
  121. //if e != nil && e.Error() != utils.ErrNoRow() {
  122. // err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
  123. //}
  124. //chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
  125. var items []*cygx.CygxActivitySpecialPermissionPoints
  126. itemBill := new(cygx.CygxActivitySpecialTripBill)
  127. itemBill.CreateTime = time.Now()
  128. itemBill.CompanyId = companyId
  129. itemBill.CompanyName = companyName
  130. itemBill.Source = 2
  131. itemBill.DoType = 2
  132. itemBill.Way = 3
  133. if userType == 2 {
  134. packageTypeMap := map[int]int{1: 16, 2: 10}
  135. totalTrip := packageTypeMap[packageType]
  136. itemBill.BillDetailed = totalTrip
  137. itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
  138. if totalTrip == 10 {
  139. itemBill.Content = "45w大套餐转正"
  140. } else {
  141. itemBill.Content = "70w大套餐转正"
  142. }
  143. //记录公司剩余点数
  144. item := new(cygx.CygxActivitySpecialPermissionPoints)
  145. item.Points = totalTrip
  146. item.CompanyId = companyId
  147. item.CompanyName = companyName
  148. item.CreateTime = time.Now()
  149. item.ModifyTime = time.Now()
  150. items = append(items, item)
  151. } else {
  152. //list, e := company.GetCompanyReportPermissionByCompanyIdAndProductId(companyId, 2)
  153. //if e != nil && e.Error() != utils.ErrNoRow() {
  154. // err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  155. //}
  156. //if len(list) == 0 {
  157. // return
  158. //}
  159. var condition string
  160. var pars []interface{}
  161. pars = make([]interface{}, 0)
  162. condition = " AND company_contract_id = ? AND is_upgrade = 1 "
  163. pars = append(pars, companyContractId)
  164. list, e := company_contract_permission.GetCompanyContractPermissionList(condition, pars) // 获取带有升级的权限
  165. if e != nil && e.Error() != utils.ErrNoRow() {
  166. err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
  167. return
  168. }
  169. if e != nil && e.Error() != utils.ErrNoRow() {
  170. err = errors.New("GetCygxAllocationCompanyContractPermissionListById, Err: " + e.Error())
  171. return
  172. }
  173. if len(list) == 0 {
  174. return
  175. }
  176. //获取权益主观权限
  177. listRaiSubjectivity, e := chart_permission.GetChartPermissionListRaiSubjectivity()
  178. if e != nil && e.Error() != utils.ErrNoRow() {
  179. err = errors.New("GetChartPermissionListRaiSubjectivity, Err: " + e.Error())
  180. }
  181. mapRaiSubjectivity := make(map[int]bool)
  182. mapPermissionName := make(map[int]string)
  183. for _, v := range listRaiSubjectivity {
  184. mapRaiSubjectivity[v.ChartPermissionId] = true
  185. mapPermissionName[v.ChartPermissionId] = v.ChartPermissionName
  186. }
  187. for _, v := range list {
  188. //如果是升级则加点
  189. if v.IsUpgrade == 1 && mapRaiSubjectivity[v.ChartPermissionId] {
  190. item := new(cygx.CygxActivitySpecialPermissionPoints)
  191. item.Points = 5
  192. item.CompanyId = companyId
  193. item.CompanyName = companyName
  194. item.ChartPermissionId = v.ChartPermissionId
  195. item.ChartPermissionName = mapPermissionName[v.ChartPermissionId]
  196. item.CreateTime = time.Now()
  197. item.ModifyTime = time.Now()
  198. items = append(items, item)
  199. }
  200. }
  201. itemBill.Content = "行业升级套餐转正"
  202. }
  203. e := cygx.MultiAddCygxActivitySpecialPermissionPoints(items)
  204. if e != nil {
  205. err = errors.New("MultiAddCygxActivitySpecialPermissionPoints, Err:" + e.Error())
  206. return
  207. }
  208. if userType != 2 && len(items) > 0 {
  209. var condition string
  210. var pars []interface{}
  211. pars = make([]interface{}, 0)
  212. condition = " AND company_id = ? AND points > 0 ORDER BY chart_permission_id DESC "
  213. pars = append(pars, companyId)
  214. activitySpecialPermissionPointsList, e := cygx.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  215. if e != nil && e.Error() != utils.ErrNoRow() {
  216. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  217. return
  218. }
  219. var itemBillTotal []string
  220. for _, v := range activitySpecialPermissionPointsList {
  221. itemBillTotal = append(itemBillTotal, fmt.Sprint(v.ChartPermissionName, v.Points, "次"))
  222. }
  223. itemBill.BillDetailed = 5 * len(items)
  224. itemBill.Total = strings.Join(itemBillTotal, "+")
  225. }
  226. //如果有升级行业权限,或者大套餐客户就写入流水信息
  227. if itemBill.Total != "" {
  228. e := cygx.AddCygxActivitySpecialTripBill(itemBill)
  229. if e != nil {
  230. err = errors.New("AddCygxActivitySpecialTripBill, Err:" + e.Error())
  231. return
  232. }
  233. }
  234. return
  235. }