activity_special.go 8.2 KB

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