contract_allocation.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. package cygx
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/cygx"
  8. "hongze/hz_crm_api/models/system"
  9. "hongze/hz_crm_api/services/alarm_msg"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. //
  16. //func init() {
  17. // fmt.Println(GetCompanyContractPermissionNameMapBymapCompamy(map[int]string{6991: "1138"}))
  18. //}
  19. // GetCompanyContractPermissionNameMapBymapCompamy 获取合并之后的合同所对应的权限种类名称
  20. func GetCompanyContractPermissionNameMapBymapCompamy(mapCompamy map[int]string) (mapContractResp map[int]string, err error) {
  21. if len(mapCompamy) == 0 {
  22. return
  23. }
  24. mapContracIdCompanyId := make(map[int]int) //建立合同ID与公司ID的map对应关系
  25. var companyContractIds []int
  26. //var companyContractIdGroup string //多个合同ID
  27. for k, v := range mapCompamy {
  28. //companyContractIdGroup += v + ","
  29. sliceContract := strings.Split(v, ",")
  30. for _, compamyContracId := range sliceContract {
  31. companyContractIdInt, _ := strconv.Atoi(compamyContracId)
  32. mapContracIdCompanyId[companyContractIdInt] = k
  33. companyContractIds = append(companyContractIds, companyContractIdInt)
  34. }
  35. }
  36. // 获取单个合同所对应的权限名称
  37. contractPermissionNameMap, e := GetCompanyContractPermissionNameMapById(companyContractIds)
  38. if e != nil {
  39. err = errors.New("GetCompanyContractPermissionNameMapById, Err: " + e.Error())
  40. return
  41. }
  42. mapContractResp = make(map[int]string, 0)
  43. for k, v := range mapCompamy {
  44. sliceContract := strings.Split(v, ",")
  45. for _, compamyContracId := range sliceContract {
  46. companyContractIdInt, _ := strconv.Atoi(compamyContracId)
  47. for k2, v2 := range contractPermissionNameMap {
  48. if companyContractIdInt == k2 {
  49. mapContractResp[k] += v2 + ","
  50. }
  51. }
  52. }
  53. }
  54. for k, v := range mapContractResp {
  55. mapContractResp[k] = strings.TrimRight(v, ",")
  56. }
  57. return
  58. }
  59. // GetCompanyContractPermissionNameMapById 获取合并之后的合同所对应的权限种类名称
  60. func GetCompanyContractPermissionNameMapById(companyContractIds []int) (mapContractResp map[int]string, err error) {
  61. //return
  62. lenArr := len(companyContractIds)
  63. if lenArr == 0 {
  64. return
  65. }
  66. var condition string
  67. var pars []interface{}
  68. condition += " AND company_contract_id IN (" + utils.GetOrmInReplace(lenArr) + ")"
  69. pars = append(pars, companyContractIds)
  70. companyContractList, e := company.GetCompanyContractList(condition, pars)
  71. if e != nil && e.Error() != utils.ErrNoRow() {
  72. err = errors.New("GetCompanyContractList, Err: " + e.Error())
  73. return
  74. }
  75. permissionList, e := models.GetChartPermissionList()
  76. if e != nil && e.Error() != utils.ErrNoRow() {
  77. err = errors.New("GetChartPermissionList, Err: " + e.Error())
  78. return
  79. }
  80. mappermissionName := make(map[int]string)
  81. for _, v := range permissionList {
  82. if v.ProductId == 2 {
  83. mappermissionName[v.ChartPermissionId] = v.Remark
  84. }
  85. }
  86. mapContractIdPerssion := make(map[int]string) //单个合同ID所对应的套餐或者权限名称
  87. for _, v := range companyContractList {
  88. if v.RaiPackageType == 1 {
  89. mapContractIdPerssion[v.CompanyContractId] = "70w套餐,"
  90. }
  91. if v.RaiPackageType == 2 {
  92. mapContractIdPerssion[v.CompanyContractId] = "45w套餐,"
  93. }
  94. }
  95. companyContractPermissionList, e := company.GetCompanyContractPermissionList(condition, pars)
  96. if e != nil && e.Error() != utils.ErrNoRow() {
  97. err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
  98. return
  99. }
  100. mapIsUpgrade := make(map[string]bool) //合同ID对应的行业是否有升级
  101. for _, v := range companyContractPermissionList {
  102. //如果开通的不是整个套餐,那么就做单独的子权限处理
  103. if strings.Count(mapContractIdPerssion[(v.CompanyContractId)], "w套餐") == 0 {
  104. if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  105. if v.ExpensiveYx == 1 {
  106. mapContractIdPerssion[(v.CompanyContractId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(5w),"
  107. } else if v.ExpensiveYx == 2 {
  108. mapContractIdPerssion[(v.CompanyContractId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(10w),"
  109. } else {
  110. mapContractIdPerssion[(v.CompanyContractId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + ","
  111. }
  112. } else {
  113. mapContractIdPerssion[(v.CompanyContractId)] += mappermissionName[v.ChartPermissionId] + ","
  114. if v.IsUpgrade == 1 {
  115. //合同ID,权限名称形成唯一的主键索引
  116. perssionName := mappermissionName[v.ChartPermissionId]
  117. perssionName = strings.Replace(perssionName, "(客观)", "", -1)
  118. perssionName = strings.Replace(perssionName, "(主观)", "", -1)
  119. mapIsUpgrade[fmt.Sprint(v.CompanyContractId, "perssionName", perssionName)] = true
  120. }
  121. }
  122. } else {
  123. if v.ChartPermissionId == utils.ZHUAN_JIA_ID {
  124. mapContractIdPerssion[(v.CompanyContractId)] += utils.ZHUAN_JIA_NAME + ","
  125. }
  126. if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  127. if v.ExpensiveYx == 1 {
  128. mapContractIdPerssion[(v.CompanyContractId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(5w),"
  129. } else if v.ExpensiveYx == 2 {
  130. mapContractIdPerssion[(v.CompanyContractId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(10w),"
  131. } else {
  132. mapContractIdPerssion[(v.CompanyContractId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + ","
  133. }
  134. }
  135. if v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  136. mapContractIdPerssion[(v.CompanyContractId)] += utils.YAN_XUAN_KOU_DIAN_BAO_NAME + ","
  137. }
  138. }
  139. }
  140. //合并客观权限
  141. for k, v := range mapContractIdPerssion {
  142. perssionName := v
  143. if strings.Count(v, utils.YI_YAO_NAME) == 2 {
  144. perssionName = strings.Replace(perssionName, "医药(主观)", "医药", -1)
  145. perssionName = strings.Replace(perssionName, "医药(客观)", "", -1)
  146. }
  147. if strings.Count(v, utils.XIAO_FEI_NAME) == 2 {
  148. perssionName = strings.Replace(perssionName, "消费(主观)", "消费", -1)
  149. perssionName = strings.Replace(perssionName, "消费(客观)", "", -1)
  150. }
  151. if strings.Count(v, utils.KE_JI_NAME) == 2 {
  152. perssionName = strings.Replace(perssionName, "科技(主观)", "科技", -1)
  153. perssionName = strings.Replace(perssionName, "科技(客观)", "", -1)
  154. }
  155. if strings.Count(v, utils.ZHI_ZAO_NAME) == 2 {
  156. perssionName = strings.Replace(perssionName, "智造(主观)", "智造", -1)
  157. perssionName = strings.Replace(perssionName, "智造(客观)", "", -1)
  158. }
  159. perssionName = strings.TrimRight(perssionName, ",")
  160. mapContractIdPerssion[k] = perssionName
  161. }
  162. mapContractResp = make(map[int]string, 0)
  163. //过滤多余的","
  164. for k, v := range mapContractIdPerssion {
  165. sliceName := strings.Split(v, ",")
  166. var nameArr []string
  167. for _, vName := range sliceName {
  168. if vName == "" {
  169. continue
  170. }
  171. if mapIsUpgrade[fmt.Sprint(k, "perssionName", vName)] {
  172. vName += "(升级)"
  173. }
  174. nameArr = append(nameArr, vName)
  175. }
  176. mapContractResp[k] = strings.Join(nameArr, ",")
  177. }
  178. return
  179. }
  180. func GetCompanyContractPermissionNameMapByIds(companyIds []int) (mapContractResp map[int]string, err error) {
  181. //return
  182. lenArr := len(companyIds)
  183. if lenArr == 0 {
  184. return
  185. }
  186. var condition string
  187. var pars []interface{}
  188. condition += " AND company_id IN (" + utils.GetOrmInReplace(lenArr) + ") AND product_id = 2 AND status = '正式' "
  189. pars = append(pars, companyIds)
  190. //获取所有开通买方研选正式试用的客户列表
  191. listCompanyPermission, e := company.GetCompanyReportPermissionList(condition, pars, 0, 0)
  192. if e != nil && e.Error() != utils.ErrNoRow() {
  193. err = errors.New("GetCompanyReportPermissionList, Err: " + e.Error())
  194. return
  195. }
  196. //companyContractList, e := company.GetCompanyContractList(condition, pars)
  197. //if e != nil && e.Error() != utils.ErrNoRow() {
  198. // err = errors.New("GetCompanyContractList, Err: " + e.Error())
  199. // return
  200. //}
  201. permissionList, e := models.GetChartPermissionList()
  202. if e != nil && e.Error() != utils.ErrNoRow() {
  203. err = errors.New("GetChartPermissionList, Err: " + e.Error())
  204. return
  205. }
  206. mappermissionName := make(map[int]string)
  207. for _, v := range permissionList {
  208. if v.ProductId == 2 {
  209. mappermissionName[v.ChartPermissionId] = v.Remark
  210. }
  211. }
  212. mapContractIdPerssion := make(map[int]string) //单个合同ID所对应的套餐或者权限名称
  213. //for _, v := range companyContractList {
  214. // if v.RaiPackageType == 1 {
  215. // mapContractIdPerssion[v.CompanyContractId] = "70w套餐,"
  216. // }
  217. // if v.RaiPackageType == 2 {
  218. // mapContractIdPerssion[v.CompanyContractId] = "45w套餐,"
  219. // }
  220. //}
  221. //
  222. //companyContractPermissionList, e := company.GetCompanyContractPermissionList(condition, pars)
  223. //if e != nil && e.Error() != utils.ErrNoRow() {
  224. // err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
  225. // return
  226. //}
  227. mapIsUpgrade := make(map[string]bool) //合同ID对应的行业是否有升级
  228. for _, v := range listCompanyPermission {
  229. //如果开通的不是整个套餐,那么就做单独的子权限处理
  230. if strings.Count(mapContractIdPerssion[(v.CompanyId)], "w套餐") == 0 {
  231. if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  232. if v.ExpensiveYx == 1 {
  233. mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(5w),"
  234. } else if v.ExpensiveYx == 2 {
  235. mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(10w),"
  236. } else {
  237. mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + ","
  238. }
  239. } else {
  240. mapContractIdPerssion[(v.CompanyId)] += mappermissionName[v.ChartPermissionId] + ","
  241. if v.IsUpgrade == 1 {
  242. //合同ID,权限名称形成唯一的主键索引
  243. perssionName := mappermissionName[v.ChartPermissionId]
  244. perssionName = strings.Replace(perssionName, "(客观)", "", -1)
  245. perssionName = strings.Replace(perssionName, "(主观)", "", -1)
  246. mapIsUpgrade[fmt.Sprint(v.CompanyContractId, "perssionName", perssionName)] = true
  247. }
  248. }
  249. } else {
  250. if v.ChartPermissionId == utils.ZHUAN_JIA_ID {
  251. mapContractIdPerssion[(v.CompanyId)] += utils.ZHUAN_JIA_NAME + ","
  252. }
  253. if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  254. if v.ExpensiveYx == 1 {
  255. mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(5w),"
  256. } else if v.ExpensiveYx == 2 {
  257. mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(10w),"
  258. } else {
  259. mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + ","
  260. }
  261. }
  262. if v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  263. mapContractIdPerssion[(v.CompanyId)] += utils.YAN_XUAN_KOU_DIAN_BAO_NAME + ","
  264. }
  265. }
  266. }
  267. //合并客观权限
  268. for k, v := range mapContractIdPerssion {
  269. perssionName := v
  270. if strings.Count(v, utils.YI_YAO_NAME) == 2 {
  271. perssionName = strings.Replace(perssionName, "医药(主观)", "医药", -1)
  272. perssionName = strings.Replace(perssionName, "医药(客观)", "", -1)
  273. }
  274. if strings.Count(v, utils.XIAO_FEI_NAME) == 2 {
  275. perssionName = strings.Replace(perssionName, "消费(主观)", "消费", -1)
  276. perssionName = strings.Replace(perssionName, "消费(客观)", "", -1)
  277. }
  278. if strings.Count(v, utils.KE_JI_NAME) == 2 {
  279. perssionName = strings.Replace(perssionName, "科技(主观)", "科技", -1)
  280. perssionName = strings.Replace(perssionName, "科技(客观)", "", -1)
  281. }
  282. if strings.Count(v, utils.ZHI_ZAO_NAME) == 2 {
  283. perssionName = strings.Replace(perssionName, "智造(主观)", "智造", -1)
  284. perssionName = strings.Replace(perssionName, "智造(客观)", "", -1)
  285. }
  286. perssionName = strings.TrimRight(perssionName, ",")
  287. mapContractIdPerssion[k] = perssionName
  288. }
  289. mapContractResp = make(map[int]string, 0)
  290. //过滤多余的","
  291. for k, v := range mapContractIdPerssion {
  292. sliceName := strings.Split(v, ",")
  293. var nameArr []string
  294. for _, vName := range sliceName {
  295. if vName == "" {
  296. continue
  297. }
  298. if mapIsUpgrade[fmt.Sprint(k, "perssionName", vName)] {
  299. vName += "(升级)"
  300. }
  301. nameArr = append(nameArr, vName)
  302. }
  303. mapContractResp[k] = strings.Join(nameArr, ",")
  304. }
  305. return
  306. }
  307. // GetCompanyPermissionNameStatusMapByCompanyId 通过公司ID,获取公司当下所有权限的状态信息
  308. func GetCompanyPermissionNameStatusMapByCompanyId(companyIds []int) (mapResp map[string]string, err error) {
  309. //return
  310. lenArr := len(companyIds)
  311. if lenArr == 0 {
  312. return
  313. }
  314. var condition string
  315. var pars []interface{}
  316. condition += " AND company_id IN (" + utils.GetOrmInReplace(lenArr) + ") AND product_id = 2 AND status = '正式' "
  317. pars = append(pars, companyIds)
  318. //获取所有开通买方研选正式试用的客户列表
  319. listCompanyPermission, e := company.GetCompanyReportPermissionList(condition, pars, 0, 0)
  320. if e != nil && e.Error() != utils.ErrNoRow() {
  321. err = errors.New("GetCompanyReportPermissionList, Err: " + e.Error())
  322. return
  323. }
  324. //获取行业权限ID与名称的映射关系
  325. permissionList, e := models.GetChartPermissionList()
  326. if e != nil && e.Error() != utils.ErrNoRow() {
  327. err = errors.New("GetChartPermissionList, Err: " + e.Error())
  328. return
  329. }
  330. mapResp = make(map[string]string, 0)
  331. mapChartPermission := make(map[int]string)
  332. for _, v := range permissionList {
  333. mapChartPermission[v.ChartPermissionId] = v.PermissionName
  334. }
  335. for _, v := range listCompanyPermission {
  336. if mapChartPermission[v.ChartPermissionId] == "" {
  337. continue
  338. }
  339. //公司ID与权限名称组成映射关系
  340. mapResp[fmt.Sprint(v.CompanyId, mapChartPermission[v.ChartPermissionId])] = v.Status
  341. }
  342. return
  343. }
  344. // 判断合同审核通过时间是否超过九十天
  345. func GetMapIsGrayByCompanyContractIds(companyContractIds []int) (mapResp map[int]bool, err error) {
  346. lenArr := len(companyContractIds)
  347. if lenArr == 0 {
  348. return
  349. }
  350. var condition string
  351. var pars []interface{}
  352. pars = make([]interface{}, 0)
  353. condition = " AND company_contract_id IN (" + utils.GetOrmInReplace(lenArr) + ") GROUP BY company_contract_id ORDER BY create_time DESC "
  354. pars = append(pars, companyContractIds)
  355. companyContractPermissionList, e := company.GetCompanyContractPermissionList(condition, pars)
  356. if e != nil && e.Error() != utils.ErrNoRow() {
  357. err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
  358. return
  359. }
  360. //超过九十天就置灰
  361. timeInit := time.Now().AddDate(0, 0, -180)
  362. mapResp = make(map[int]bool, 0)
  363. for _, v := range companyContractPermissionList {
  364. if v.CreateTime.Before(timeInit) {
  365. mapResp[v.CompanyContractId] = true
  366. }
  367. }
  368. return
  369. }
  370. //func init3() {
  371. // var condition string
  372. // var pars []interface{}
  373. // //默认只查询权益 2023-06-01 之后的合同
  374. // condition += ` AND c.product_id = ? AND a.start_date > ? `
  375. // pars = append(pars, 2, "2023-06-01")
  376. //
  377. // //列表页数据
  378. // list, err := cygx.GetCompanyContractListJoinCompany(condition, pars, 0, 1000)
  379. // if err != nil {
  380. // fmt.Println(err)
  381. // return
  382. // }
  383. //
  384. // for _, v := range list {
  385. // fmt.Println(v.CompanyContractId)
  386. // HandleAllocationCompanyContractByYanXuan(v.CompanyContractId)
  387. // }
  388. //
  389. // fmt.Println(len(list))
  390. //}
  391. // 如果合同只有研选的时候,自动处理派点
  392. func HandleAllocationCompanyContractByYanXuan(companyContractId int) (err error) {
  393. defer func() {
  394. if err != nil {
  395. fmt.Println(err)
  396. go alarm_msg.SendAlarmMsg(fmt.Sprint("如果合同只有研选的时候,自动处理派点失败,Err:", err.Error(), "companyContractId", companyContractId), 2)
  397. }
  398. }()
  399. var condition string
  400. var pars []interface{}
  401. pars = make([]interface{}, 0)
  402. condition = " AND company_contract_id = ? "
  403. pars = append(pars, companyContractId)
  404. companyContractPermissionList, e := company.GetCompanyContractPermissionList(condition, pars)
  405. if e != nil && e.Error() != utils.ErrNoRow() {
  406. err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
  407. return
  408. }
  409. if e != nil && e.Error() != utils.ErrNoRow() {
  410. err = errors.New("GetCygxAllocationCompanyContractPermissionListById, Err: " + e.Error())
  411. return
  412. }
  413. if len(companyContractPermissionList) > 2 {
  414. return
  415. }
  416. var expensiveYxmoney float64
  417. //for _, v := range companyContractPermissionList {
  418. // if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  419. // err = errors.New("没有发现研选权限: ")
  420. // return
  421. // }
  422. // if v.ExpensiveYx == 1 {
  423. // expensiveYxmoney = 5
  424. // } else if v.ExpensiveYx == 2 {
  425. // expensiveYxmoney = 10
  426. // } else {
  427. // expensiveYxmoney = 3
  428. // }
  429. //}
  430. var items []*cygx.CygxAllocationCompanyContract
  431. var itemsPermission []*cygx.CygxAllocationCompanyContractPermission
  432. for _, v := range companyContractPermissionList {
  433. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  434. return
  435. }
  436. if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  437. expensiveYxmoney = 3
  438. }
  439. if v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  440. expensiveYxmoney = 0.2 * v.Points
  441. }
  442. itemPermission := new(cygx.CygxAllocationCompanyContractPermission)
  443. itemPermission.CompanyContractId = companyContractId
  444. //itemPermission.AdminId = sysUser.AdminId
  445. //itemPermission.AdminName = sysUser.RealName
  446. itemPermission.Proportion = 0
  447. itemPermission.Money = expensiveYxmoney
  448. itemPermission.MoneyAvg = 0
  449. itemPermission.ChartPermissionName = v.PermissionName
  450. itemPermission.CreateTime = time.Now()
  451. itemPermission.ModifyTime = time.Now()
  452. itemsPermission = append(itemsPermission, itemPermission)
  453. item := new(cygx.CygxAllocationCompanyContract)
  454. item.CompanyContractId = companyContractId
  455. //item.AdminId = sysUser.AdminId
  456. //item.AdminName = sysUser.RealName
  457. item.Proportion = 0
  458. item.Money = expensiveYxmoney
  459. item.RealName = v.PermissionName
  460. item.ChartPermissionName = v.PermissionName
  461. item.CreateTime = time.Now()
  462. item.ModifyTime = time.Now()
  463. items = append(items, item)
  464. }
  465. if len(items) == 0 {
  466. return
  467. }
  468. e = cygx.AddAndUpdateCygxAllocationCompanyContract(items, itemsPermission, companyContractId)
  469. if e != nil {
  470. err = errors.New("AddAndUpdateCygxAllocationCompanyContract, Err: " + e.Error())
  471. return
  472. }
  473. return
  474. }
  475. //func init() {
  476. // var condition string
  477. // var pars []interface{}
  478. //
  479. // condition = " AND status = 1 "
  480. //
  481. // list, err := company.GetCompanyContractList(condition, pars)
  482. // if err != nil {
  483. // fmt.Println(err)
  484. // return
  485. // }
  486. // fmt.Println(len(list))
  487. // //return
  488. // for _, v := range list {
  489. // fmt.Println(v.CompanyContractId)
  490. // HandleCompanyContractPackageDifference(v.CompanyContractId)
  491. // }
  492. //
  493. //}
  494. // HandleCompanyContractPackageDifference 更新与上一份合同的金额的对比 '增加套餐','减少套餐','维持套餐'
  495. func HandleCompanyContractPackageDifference(companyContractId int) (err error) {
  496. defer func() {
  497. if err != nil {
  498. fmt.Println(err)
  499. go alarm_msg.SendAlarmMsg(fmt.Sprint("更新与上一份合同的金额的对比 '增加套餐','减少套餐','维持套餐'失败,Err:", err.Error(), "companyContractId", companyContractId), 2)
  500. }
  501. }()
  502. var condition string
  503. var pars []interface{}
  504. condition = " AND company_contract_id = ? "
  505. pars = append(pars, companyContractId)
  506. detail, e := company.GetCompanyContracDetail(condition, pars)
  507. if e != nil {
  508. err = errors.New("GetCompanyContracDetail,detail Err: " + e.Error())
  509. return
  510. }
  511. //如果不是续约合同就不做对比处理
  512. if detail.ContractType != "续约合同" {
  513. return
  514. }
  515. //获取前一份合同的信息
  516. pars = make([]interface{}, 0)
  517. condition = " AND company_id = ? AND company_contract_id < ? AND status = 1 AND product_id = ? ORDER BY company_contract_id DESC LIMIT 1 "
  518. pars = append(pars, detail.CompanyId, companyContractId, detail.ProductId)
  519. detailPrevious, e := company.GetCompanyContracDetail(condition, pars)
  520. if e != nil {
  521. err = errors.New("GetCompanyContracDetail,detailPrevious Err: " + e.Error())
  522. return
  523. }
  524. var packageDifference string
  525. if detail.Money > detailPrevious.Money {
  526. packageDifference = "增加套餐"
  527. } else if detail.Money < detailPrevious.Money {
  528. packageDifference = "减少套餐"
  529. } else {
  530. packageDifference = "维持套餐"
  531. }
  532. e = company.UpdateCompanyContractPackageDifference(packageDifference, companyContractId)
  533. if e != nil {
  534. err = errors.New("UpdateCompanyContractPackageDifference, Err: " + e.Error())
  535. return
  536. }
  537. return
  538. }
  539. // HandleCompanyContractTypeByRaiXClass 所有x类试用转正的合同都记为 :打分派点
  540. func HandleCompanyContractTypeByRaiXClass(companyContractId int) (err error) {
  541. defer func() {
  542. if err != nil {
  543. go alarm_msg.SendAlarmMsg(fmt.Sprint(" 所有x类试用转正的合同都记为 :打分派点失败,HandleCompanyContractTypeByRaiXClass Err:", err.Error(), "companyContractId", companyContractId), 2)
  544. }
  545. }()
  546. var condition string
  547. var pars []interface{}
  548. condition = " AND company_contract_id = ? "
  549. pars = append(pars, companyContractId)
  550. detail, e := company.GetCompanyContracDetail(condition, pars)
  551. if e != nil {
  552. err = errors.New("GetCompanyContracDetail,detail Err: " + e.Error())
  553. return
  554. }
  555. companyProduct, e := company.GetCompanyProductByCompanyIdAndProductId(detail.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
  556. if e != nil {
  557. err = errors.New("GetCompanyProductByCompanyIdAndProductId Err: " + e.Error())
  558. return
  559. }
  560. //权益非永续客户不处理
  561. if companyProduct.Status != utils.COMPANY_STATUS_FOREVER {
  562. return
  563. }
  564. e = company.UpdateCompanyContractType("打分派点", companyContractId)
  565. if e != nil {
  566. err = errors.New("UpdateCompanyContractType, Err: " + e.Error())
  567. return
  568. }
  569. return
  570. }
  571. // HandleCompanyContractPermissionContractType 更新合同权限表中的权限名称,以及对应的行业权限类型(行业新签、行业续约)
  572. func HandleCompanyContractPermissionContractType(companyContractId int) (err error) {
  573. defer func() {
  574. if err != nil {
  575. fmt.Println(err)
  576. go alarm_msg.SendAlarmMsg(fmt.Sprint("更新合同权限表中的权限名称,以及对应的行业权限类型(行业新签、行业续约)失败,HandleCompanyContractPermissionContractType Err:", err.Error(), "companyContractId", companyContractId), 2)
  577. }
  578. }()
  579. var condition string
  580. var pars []interface{}
  581. condition = " AND company_contract_id = ? "
  582. pars = append(pars, companyContractId)
  583. detail, e := company.GetCompanyContracDetail(condition, pars)
  584. if e != nil {
  585. err = errors.New("GetCompanyContracDetail,detail Err: " + e.Error())
  586. return
  587. }
  588. //获取权限ID与名称的map映射
  589. permissionList, e := models.GetChartPermissionList()
  590. if e != nil && e.Error() != utils.ErrNoRow() {
  591. err = errors.New("GetChartPermissionList Err: " + e.Error())
  592. return
  593. }
  594. mapChartPermission := make(map[int]string)
  595. for _, v := range permissionList {
  596. mapChartPermission[v.ChartPermissionId] = v.PermissionName
  597. }
  598. companyId := detail.CompanyId
  599. //如果不是续约合同就不做对比处理
  600. pars = make([]interface{}, 0)
  601. condition = " AND company_contract_id != ? AND company_id = ? "
  602. pars = append(pars, companyContractId, companyId)
  603. //获取历史签约信息
  604. companyContractPermissionListHistory, e := company.GetCompanyContractPermissionList(condition, pars)
  605. if e != nil && e.Error() != utils.ErrNoRow() {
  606. err = errors.New("companyContractPermissionListHistory Err: " + e.Error())
  607. return
  608. }
  609. var mapHistoryPerssionName []string
  610. for _, v := range companyContractPermissionListHistory {
  611. mapHistoryPerssionName = append(mapHistoryPerssionName, mapChartPermission[v.ChartPermissionId])
  612. }
  613. pars = make([]interface{}, 0)
  614. condition = " AND company_contract_id = ? "
  615. pars = append(pars, companyContractId)
  616. //获取当前签约的合同信息
  617. companyContractPermissionLisThis, e := company.GetCompanyContractPermissionList(condition, pars)
  618. if e != nil && e.Error() != utils.ErrNoRow() {
  619. err = errors.New("companyContractPermissionLisThis Err: " + e.Error())
  620. return
  621. }
  622. var items []*company.CompanyContractPermission
  623. for _, v := range companyContractPermissionLisThis {
  624. v.PermissionName = mapChartPermission[v.ChartPermissionId]
  625. if v.PermissionName == "" {
  626. continue
  627. }
  628. //已经存在的属于行业续约、不存在的属于行业新签
  629. if utils.InArrayByStr(mapHistoryPerssionName, v.PermissionName) {
  630. v.ContractType = "行业续约"
  631. } else {
  632. v.ContractType = "行业新签"
  633. }
  634. items = append(items, v)
  635. }
  636. //批量更新合同权限表的权限行业名称,以及签约合同时,当前行业类型(行业续约、行业新签)
  637. e = company.UpdateCompanyContractPermissionMulti(items)
  638. if e != nil {
  639. err = errors.New("UpdateCompanyContractPermissionMulti Err: " + e.Error())
  640. return
  641. }
  642. return
  643. }
  644. func initCRM14_4() {
  645. //func init() {
  646. permissionList, e := models.GetChartPermissionList()
  647. if e != nil && e.Error() != utils.ErrNoRow() {
  648. fmt.Println(permissionList)
  649. return
  650. }
  651. mapChartPermission := make(map[int]string)
  652. for _, v := range permissionList {
  653. mapChartPermission[v.ChartPermissionId] = v.PermissionName
  654. }
  655. var condition string
  656. var pars []interface{}
  657. condition = " AND status = 1 AND product_id = 2 "
  658. companyContractList, e := company.GetCompanyContractList(condition, pars)
  659. if e != nil && e.Error() != utils.ErrNoRow() {
  660. fmt.Println(e)
  661. return
  662. }
  663. fmt.Println(len(companyContractList))
  664. for k, v := range companyContractList {
  665. fmt.Println(k)
  666. HandleCompanyContractPermissionContractType(v.CompanyContractId)
  667. }
  668. //var companyContractIds []int
  669. //for _, v := range companyContractList {
  670. // companyContractIds = append(companyContractIds, v.CompanyContractId)
  671. //}
  672. //condition = " AND company_contract_id IN (" + utils.GetOrmInReplace(len(companyContractIds)) + ") "
  673. //pars = append(pars, companyContractIds)
  674. //
  675. //companyContractPermissionList, e := company.GetCompanyContractPermissionList(condition, pars)
  676. //if e != nil && e.Error() != utils.ErrNoRow() {
  677. // fmt.Println(e)
  678. // return
  679. //}
  680. //
  681. //var items []*company.CompanyContractPermission
  682. //
  683. //for _, v := range companyContractPermissionList {
  684. // v.PermissionName = mapChartPermission[v.ChartPermissionId]
  685. //
  686. // items = append(items, v)
  687. //}
  688. //fmt.Println(len(items))
  689. ////return
  690. //e = company.UpdateCompanyContractPermissionMulti(items)
  691. //if e != nil && e.Error() != utils.ErrNoRow() {
  692. // fmt.Println(e)
  693. // return
  694. //}
  695. }
  696. func initCrm13_2() {
  697. var condition string
  698. var pars []interface{}
  699. condition = " AND chart_permission_id = 31 AND `status` IN ('正式','试用') AND product_id = 2 "
  700. //获取所有开通买方研选正式试用的客户列表
  701. listCompanyPermissionYx, e := company.GetCompanyReportPermissionList(condition, pars, 0, 0)
  702. if e != nil && e.Error() != utils.ErrNoRow() {
  703. fmt.Println(e)
  704. return
  705. }
  706. condition = " AND chart_permission_id = 52 "
  707. listCompanyPermissionKouDian, e := company.GetCompanyReportPermissionList(condition, pars, 0, 0)
  708. if e != nil && e.Error() != utils.ErrNoRow() {
  709. fmt.Println(e)
  710. return
  711. }
  712. mapKoud := make(map[int]bool)
  713. for _, v := range listCompanyPermissionKouDian {
  714. mapKoud[v.CompanyId] = true
  715. }
  716. //var i int
  717. var items []*company.CompanyReportPermission
  718. for k, v := range listCompanyPermissionYx {
  719. if mapKoud[v.CompanyId] {
  720. continue
  721. }
  722. permission := new(company.CompanyReportPermission)
  723. permission.CompanyId = v.CompanyId
  724. permission.ReportPermissionId = v.ReportPermissionId
  725. permission.CreatedTime = time.Now()
  726. permission.LastUpdatedTime = time.Now()
  727. permission.ChartPermissionId = 52
  728. permission.StartDate = v.StartDate
  729. permission.EndDate = v.EndDate
  730. permission.ProductId = 2
  731. permission.ProductName = "权益"
  732. permission.ModifyTime = time.Now()
  733. permission.Status = v.Status
  734. err := company.AddCompanyReportPermission(permission)
  735. if err != nil {
  736. return
  737. }
  738. fmt.Println(k)
  739. items = append(items, permission)
  740. }
  741. fmt.Println(len(items))
  742. }
  743. func initCRM_15_4() {
  744. var conditionAllocation string
  745. var parsAllocation []interface{}
  746. conditionAllocation = " AND company_contract_id IN (SELECT company_contract_id FROM cygx_allocation_company_contract_permission WHERE chart_permission_name LIKE '%研选%') GROUP BY company_contract_id "
  747. allocationCompanyContractPermissionList, err := cygx.GetCygxAllocationCompanyContractPermissionList(conditionAllocation, parsAllocation)
  748. if err != nil {
  749. fmt.Println(err)
  750. return
  751. }
  752. var companyContractIds []int
  753. for _, v := range allocationCompanyContractPermissionList {
  754. companyContractIds = append(companyContractIds, v.CompanyContractId)
  755. }
  756. lenCon := len(companyContractIds)
  757. for _, v := range companyContractIds {
  758. UpdateInitAvg(v)
  759. }
  760. fmt.Println("lenCon", lenCon)
  761. return
  762. }
  763. //func init() {
  764. // UpdateInitAvg(1249)
  765. //}
  766. // 合并研选订阅与研选扣点包,为买方研选
  767. func UpdateInit(companyContractId int) {
  768. fmt.Println(companyContractId)
  769. allocationNames := []string{"董衡", "高亦文", "吴昂迪", "冯柯然", "汪洋"}
  770. fmt.Println(allocationNames)
  771. listPerssion, err := cygx.GetCygxAllocationCompanyContractPermissionListByIdInitYx(companyContractId)
  772. if err != nil {
  773. fmt.Println(err)
  774. return
  775. }
  776. //listUser, err := cygx.GetCygxAllocationCompanyContractListById(companyContractId)
  777. //if err != nil {
  778. // fmt.Println(err)
  779. // return
  780. //}
  781. var totalMoney float64
  782. var items []*cygx.CygxAllocationCompanyContract
  783. var itemsPermission []*cygx.CygxAllocationCompanyContractPermission
  784. //var proportionSum float64 // 校验前端传过来的占比使用
  785. var AdminId int
  786. var AdminName string
  787. for _, v := range listPerssion {
  788. totalMoney += v.Money
  789. AdminId = v.AdminId
  790. AdminName = v.AdminName
  791. }
  792. fmt.Println(totalMoney)
  793. //return
  794. itemPermission := new(cygx.CygxAllocationCompanyContractPermission)
  795. itemPermission.CompanyContractId = companyContractId
  796. itemPermission.AdminId = AdminId
  797. itemPermission.AdminName = AdminName
  798. //itemPermission.Proportion = v.Money / totalMoney * 100
  799. itemPermission.Money = totalMoney
  800. itemPermission.ChartPermissionName = utils.CHART_PERMISSION_NAME_MAI_FANG_YANXUAN
  801. itemPermission.CreateTime = time.Now()
  802. itemPermission.ModifyTime = time.Now()
  803. itemsPermission = append(itemsPermission, itemPermission)
  804. for _, v := range allocationNames {
  805. item := new(cygx.CygxAllocationCompanyContract)
  806. item.CompanyContractId = companyContractId
  807. item.AdminId = AdminId
  808. item.AdminName = AdminName
  809. //item.Proportion =
  810. item.Money = totalMoney / 5
  811. item.RealName = v
  812. item.ChartPermissionName = utils.CHART_PERMISSION_NAME_MAI_FANG_YANXUAN
  813. item.CreateTime = time.Now()
  814. item.ModifyTime = time.Now()
  815. items = append(items, item)
  816. }
  817. fmt.Println(len(items))
  818. fmt.Println(len(itemsPermission))
  819. //return
  820. err = cygx.AddAndUpdateCygxAllocationCompanyContractInit(items, itemsPermission, companyContractId)
  821. fmt.Println(err)
  822. }
  823. func UpdateInitAvg(companyContractId int) {
  824. fmt.Println(companyContractId)
  825. listPerssion, err := cygx.GetCygxAllocationCompanyContractPermissionListByIdInit(companyContractId)
  826. if err != nil {
  827. fmt.Println(err)
  828. return
  829. }
  830. listUser, err := cygx.GetCygxAllocationCompanyContractListById(companyContractId)
  831. if err != nil {
  832. fmt.Println(err)
  833. return
  834. }
  835. var totalMoney float64
  836. var items []*cygx.CygxAllocationCompanyContract
  837. var itemsPermission []*cygx.CygxAllocationCompanyContractPermission
  838. //var proportionSum float64 // 校验前端传过来的占比使用
  839. for _, v := range listPerssion {
  840. totalMoney += v.Money
  841. }
  842. moneyAvg := totalMoney / float64(len(listPerssion))
  843. for _, v := range listPerssion {
  844. itemPermission := new(cygx.CygxAllocationCompanyContractPermission)
  845. itemPermission.CompanyContractId = companyContractId
  846. itemPermission.AdminId = v.AdminId
  847. itemPermission.AdminName = v.AdminName
  848. itemPermission.Proportion = v.Money / totalMoney * 100
  849. itemPermission.Money = v.Money
  850. itemPermission.MoneyAvg = moneyAvg
  851. itemPermission.ChartPermissionName = v.ChartPermissionName
  852. itemPermission.CreateTime = time.Now()
  853. itemPermission.ModifyTime = time.Now()
  854. itemsPermission = append(itemsPermission, itemPermission)
  855. fmt.Println(v.Money, "___", itemPermission.Proportion, "___", v.AllocationCompanyContractId)
  856. err = cygx.Cygx_allocation_company_contract_permissionEdit(itemPermission.Proportion, itemPermission.MoneyAvg, v.AllocationCompanyContractId)
  857. //fmt.Println("AllocationCompanyContractId", v.AllocationCompanyContractId)
  858. if err != nil {
  859. fmt.Println(err)
  860. return
  861. }
  862. }
  863. //return
  864. fmt.Println("研究员修改")
  865. //var userProportionSum float64 // 校验前端传过来的占比使用
  866. for _, v2 := range listUser {
  867. item := new(cygx.CygxAllocationCompanyContract)
  868. item.CompanyContractId = companyContractId
  869. item.AdminId = v2.AdminId
  870. item.AdminName = v2.RealName
  871. item.Proportion = v2.Money / totalMoney * 100
  872. item.Money = v2.Money
  873. item.RealName = v2.RealName
  874. item.ChartPermissionName = v2.ChartPermissionName
  875. item.CreateTime = time.Now()
  876. item.ModifyTime = time.Now()
  877. items = append(items, item)
  878. err = cygx.Cygx_allocation_company_contractEdit(item.Proportion, v2.AllocationCompanyContractId)
  879. fmt.Println("AllocationCompanyContractId", v2.AllocationCompanyContractId)
  880. if err != nil {
  881. fmt.Println(err)
  882. return
  883. }
  884. }
  885. //err = cygx.AddAndUpdateCygxAllocationCompanyContractInit(items, itemsPermission, companyContractId)
  886. //fmt.Println(err)
  887. }
  888. // 权益的合同录分之后自动派点
  889. func UpdateCygxallocationCompanyContractByEnterScore(itemsPermissionEnterScore []*cygx.CygxEnterScorePermission, itemsResearcher []*cygx.CygxEnterScoreResearcher, startDate, endDate string, companyId int, sysUser *system.Admin) {
  890. var err error
  891. defer func() {
  892. if err != nil {
  893. fmt.Println(err)
  894. go alarm_msg.SendAlarmMsg("权益的合同录分之后自动派点失败 UpdateCygxallocationCompanyContractByEnterScore ErrMsg:"+err.Error(), 2)
  895. }
  896. }()
  897. var condition string
  898. var pars []interface{}
  899. condition = " AND status = 1 AND product_id = 2 AND company_id = ? AND start_date <= ? AND end_date <= ? "
  900. pars = append(pars, companyId, startDate, endDate)
  901. companyContractList, e := company.GetCompanyContractList(condition, pars)
  902. if e != nil && e.Error() != utils.ErrNoRow() {
  903. err = errors.New("GetCompanyContractList, Err: " + e.Error())
  904. return
  905. }
  906. if len(companyContractList) == 0 {
  907. err = nil
  908. return
  909. }
  910. var companyContractIds []int
  911. //var companyContractIdMoney []float64 // 合同对应的金额
  912. for _, v := range companyContractList {
  913. companyContractIds = append(companyContractIds, v.CompanyContractId)
  914. }
  915. fmt.Println("companyContractIds", companyContractIds)
  916. var items []*cygx.CygxAllocationCompanyContract
  917. var itemsPermission []*cygx.CygxAllocationCompanyContractPermission
  918. var totalProportionPermission float64 //计算总占比
  919. for _, v := range itemsPermissionEnterScore {
  920. totalProportionPermission += v.Proportion
  921. }
  922. //var totalResearcher float64 //计算研究员的总占比
  923. //for _, v := range itemsResearcher {
  924. // totalResearcher += v.Proportion
  925. //}
  926. for _, vContract := range companyContractList {
  927. for _, v := range itemsPermissionEnterScore {
  928. itemPermission := new(cygx.CygxAllocationCompanyContractPermission)
  929. itemPermission.CompanyContractId = vContract.CompanyContractId
  930. itemPermission.AdminId = sysUser.AdminId
  931. itemPermission.AdminName = sysUser.RealName
  932. itemPermission.Proportion = v.Proportion / totalProportionPermission * 100 // 占比转换
  933. itemPermission.Money = v.Proportion * vContract.Money / 10000 / 100 // 单位转成万
  934. itemPermission.MoneyAvg = vContract.Money / 6 // 目前6个行业
  935. itemPermission.ChartPermissionName = v.ChartPermissionName
  936. itemPermission.CreateTime = time.Now()
  937. itemPermission.ModifyTime = time.Now()
  938. itemsPermission = append(itemsPermission, itemPermission)
  939. }
  940. for _, v := range itemsResearcher {
  941. item := new(cygx.CygxAllocationCompanyContract)
  942. item.CompanyContractId = vContract.CompanyContractId
  943. item.AdminId = sysUser.AdminId
  944. item.AdminName = sysUser.RealName
  945. item.Proportion = v.Proportion / totalProportionPermission * 100 // 占比转换
  946. item.Money = v.Proportion * vContract.Money / 10000 / 100 // 单位转成万
  947. item.RealName = v.RealName
  948. item.ChartPermissionName = v.ChartPermissionName
  949. item.CreateTime = time.Now()
  950. item.ModifyTime = time.Now()
  951. items = append(items, item)
  952. }
  953. }
  954. e = cygx.AddAndUpdateCygxAllocationCompanyContractRai(items, itemsPermission, companyContractIds)
  955. if e != nil {
  956. err = errors.New("AddAndUpdateCygxAllocationCompanyContractRai, Err: " + e.Error())
  957. return
  958. }
  959. return
  960. }
  961. //func init15_4_1() {
  962. // UpdateCygxallocationCompanyContractByEnterScoreInit()
  963. // //"SELECT * FROM company_contract WHERE company_id IN (SELECT company_id FROM company_product WHERE product_id = 2 AND init_status = '永续' ) AND product_id = 2 ;"
  964. //}
  965. func UpdateCygxallocationCompanyContractByEnterScoreInit() {
  966. var condition string
  967. var pars []interface{}
  968. listEnterScore, err := cygx.GetCygxEnterScoreList(condition, pars, 0, 999)
  969. if err != nil {
  970. fmt.Println(err)
  971. return
  972. }
  973. for _, v := range listEnterScore {
  974. fmt.Println("v.EnterScoreId", v.EnterScoreId)
  975. listPermission, err := cygx.GetCygxEnterScorePermissionListById(v.EnterScoreId)
  976. if err != nil {
  977. fmt.Println(err)
  978. return
  979. }
  980. listResearcher, err := cygx.GeCygxEnterScoreResearcherListById(v.EnterScoreId)
  981. if err != nil {
  982. fmt.Println(err)
  983. return
  984. }
  985. sysUser, err := system.GetSysUserById(v.AdminId)
  986. if err != nil {
  987. fmt.Println(err)
  988. return
  989. }
  990. go UpdateCygxallocationCompanyContractByEnterScore(listPermission, listResearcher, v.StartDate, v.EndDate, v.CompanyId, sysUser)
  991. }
  992. fmt.Println("END")
  993. return
  994. }
  995. // 根据公司ID获取近四周之内有决策人互动的客户
  996. func GetCompanyProductIsUserMakerByCompanyIds(companyIds []int) (mapIsUserMakerResp map[int]int) {
  997. var err error
  998. defer func() {
  999. if err != nil {
  1000. go alarm_msg.SendAlarmMsg("根据公司ID获取近四周之内有决策人互动的客户失败 GetCompanyProductIsUserMakerByCompanyIds ErrMsg:"+err.Error(), 2)
  1001. }
  1002. }()
  1003. lenArr := len(companyIds)
  1004. if lenArr == 0 {
  1005. return
  1006. }
  1007. var condition string
  1008. var pars []interface{}
  1009. condition += " AND company_id IN (" + utils.GetOrmInReplace(lenArr) + ") AND product_id = 2 AND status IN ('正式','试用','永续') AND company_id > 1 "
  1010. pars = append(pars, companyIds)
  1011. productList, e := company.GetCompanyProductList(condition, pars)
  1012. if e != nil && e.Error() != utils.ErrNoRow() {
  1013. err = errors.New("GetCompanyProductList, Err: " + e.Error())
  1014. return
  1015. }
  1016. mapIsUserMakerResp = make(map[int]int)
  1017. for _, v := range productList {
  1018. mapIsUserMakerResp[v.CompanyId] = v.IsUserMaker
  1019. }
  1020. return
  1021. }