company_share.go 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/company"
  8. "hongze/hz_crm_api/models/system"
  9. "hongze/hz_crm_api/services"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. // @Title 设置共享客户
  16. // @Description 设置共享客户接口
  17. // @Param request body company.CompanyShareReq true "type json string"
  18. // @Success Ret=200 设置成功
  19. // @router /share [post]
  20. func (this *CompanyController) CompanyShare() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. sysUser := this.SysUser
  27. if sysUser == nil {
  28. br.Msg = "请登录"
  29. br.ErrMsg = "请登录,SysUser Is Empty"
  30. br.Ret = 408
  31. return
  32. }
  33. var req company.CompanyShareReq
  34. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  35. if err != nil {
  36. br.Msg = "参数解析异常!"
  37. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  38. return
  39. }
  40. if req.CompanyId <= 0 {
  41. br.Msg = "参数异常!"
  42. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  43. return
  44. }
  45. if req.IsShare < 0 {
  46. br.Msg = "参数异常!"
  47. br.ErrMsg = "IsShare:" + strconv.Itoa(req.IsShare)
  48. return
  49. }
  50. productId := services.GetProductId(sysUser.RoleTypeCode)
  51. //查询该客户
  52. companyProductItem, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  53. if err != nil {
  54. br.Msg = "查找客户失败"
  55. br.ErrMsg = "查找客户失败,Err:" + err.Error()
  56. return
  57. }
  58. //待更新字段
  59. updateCol := make([]string, 0)
  60. companyProductItem.IsShare = req.IsShare
  61. updateCol = append(updateCol, "IsShare")
  62. if req.IsShare == 0 {
  63. companyProductItem.ShareSeller = ""
  64. companyProductItem.ShareSellerId = 0
  65. companyProductItem.ShareGroupId = 0
  66. updateCol = append(updateCol, "ShareSeller", "ShareSellerId", "ShareGroupId")
  67. }
  68. err = companyProductItem.Update(updateCol)
  69. if err != nil {
  70. br.Msg = "修改客户信息失败"
  71. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  72. return
  73. }
  74. //新增操作记录
  75. //{
  76. // remark := "移动到:" + seller.RealName
  77. // operation := "move_seller"
  78. // services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  79. // cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  80. //}
  81. br.Ret = 200
  82. br.Success = true
  83. br.Msg = "设置成功"
  84. }
  85. // CompanyShareList
  86. // @Title 共享客户列表
  87. // @Description 共享客户列表接口
  88. // @Param SellerId query string false "选择的销售id"
  89. // @Param OriginalSellerId query string false "选择的原销售id"
  90. // @Param Keyword query string true "搜索关键词"
  91. // @Param ListParam query int false "筛选字段参数,用来筛选的字段, 枚举值:0:全部 、 1:已分配 、 2:未分配 、 3:未共享 "
  92. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、`expireDay:到期时间` 、 `createTime:创建时间` 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间 、'tryOutDay':试用天数"
  93. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  94. // @Param PageSize query int true "每页数据条数"
  95. // @Param CurrentIndex query int true "当前页页码,从1开始"
  96. // @Success Ret=200 设置成功
  97. // @router /share/list [get]
  98. func (this *CompanyController) CompanyShareList() {
  99. br := new(models.BaseResponse).Init()
  100. defer func() {
  101. this.Data["json"] = br
  102. this.ServeJSON()
  103. }()
  104. sysUser := this.SysUser
  105. if sysUser == nil {
  106. br.Msg = "请登录"
  107. br.ErrMsg = "请登录,SysUser Is Empty"
  108. br.Ret = 408
  109. return
  110. }
  111. pageSize, _ := this.GetInt("PageSize")
  112. currentIndex, _ := this.GetInt("CurrentIndex")
  113. sellerIds := this.GetString("SellerId")
  114. originalSellerIds := this.GetString("OriginalSellerId")
  115. keyword := this.GetString("Keyword")
  116. //排序参数
  117. sortParam := this.GetString("SortParam")
  118. listParam, _ := this.GetInt("ListParam")
  119. sortType := this.GetString("SortType")
  120. var total int
  121. page := paging.GetPaging(currentIndex, pageSize, total)
  122. var startSize int
  123. if pageSize <= 0 {
  124. pageSize = utils.PageSize20
  125. }
  126. if currentIndex <= 0 {
  127. currentIndex = 1
  128. }
  129. startSize = paging.StartIndex(currentIndex, pageSize)
  130. var condition string
  131. var pars []interface{}
  132. if keyword != "" {
  133. companyIdStr, err := company.GetCompanyIdByKeyWord(keyword)
  134. if err != nil {
  135. br.Msg = "获取客户信息失败"
  136. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  137. return
  138. }
  139. if companyIdStr != "" {
  140. condition += ` AND (a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%' OR a.company_id IN(` + companyIdStr + `)) `
  141. } else {
  142. condition += ` AND (a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%' ) `
  143. }
  144. }
  145. // 咨询组的分组id
  146. groupId := 0
  147. if utils.RunMode == "release" {
  148. groupId = 37
  149. } else {
  150. groupId = 61
  151. }
  152. roleTypeCode := sysUser.RoleTypeCode
  153. productId := services.GetProductId(roleTypeCode)
  154. //权限控制
  155. {
  156. //如果不是超级管理员或者财务
  157. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  158. //如果是部门管理员
  159. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  160. condition += ` AND b.product_id=? `
  161. pars = append(pars, productId)
  162. } else {
  163. condition += ` AND b.product_id=? `
  164. pars = append(pars, productId)
  165. }
  166. if sysUser.Authority == 2 && roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  167. groupIdStr, sellerIdStr, err := services.GetFiccChildGroupIdsByGroupIds(sysUser.GroupId)
  168. if err != nil {
  169. br.Msg = "获取销售分组信息失败!"
  170. br.ErrMsg = "获取销售分组信息失败!Err:" + err.Error()
  171. return
  172. }
  173. if sysUser.GroupId == groupId {
  174. if sellerIdStr != "" {
  175. condition += ` AND b.share_seller_id IN (` + sellerIdStr + `) `
  176. }
  177. } else {
  178. if groupIdStr != "" {
  179. condition += ` AND b.group_id IN (` + groupIdStr + `) `
  180. }
  181. }
  182. } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  183. //if sysUser.GroupId == groupId {
  184. sellerIdStr, err := services.GetFiccSellerIdsByGroupId(sysUser.GroupId)
  185. if err != nil {
  186. br.Msg = "获取销售分组信息失败!"
  187. br.ErrMsg = "获取销售分组信息失败!Err:" + err.Error()
  188. return
  189. }
  190. //权益销售组长可以查看自己的组员以及共享给组员的客户
  191. if sellerIdStr != "" {
  192. condition += ` AND ( b.share_seller_id IN (` + sellerIdStr + `) OR b.group_id= ? )`
  193. pars = append(pars, sysUser.GroupId)
  194. } else {
  195. condition += ` AND b.group_id=? `
  196. pars = append(pars, sysUser.GroupId)
  197. }
  198. } else if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.AdminId != 66 && sysUser.AdminId != 15 && roleTypeCode != utils.ROLE_TYPE_CODE_FICC_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN {
  199. if sysUser.GroupId == groupId {
  200. condition += ` AND b.share_seller_id=? `
  201. pars = append(pars, sysUser.AdminId)
  202. } else {
  203. // 在此页面销售只能看分配给自己的客户
  204. condition += ` AND (b.seller_id =? OR b.share_seller_id =? )`
  205. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  206. }
  207. }
  208. }
  209. }
  210. if listParam == 0 {
  211. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  212. sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  213. sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  214. //非咨询组销售,那么默认查看“未共享”的客户
  215. if sysUser.GroupId != groupId {
  216. listParam = 3
  217. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  218. condition += ` AND b.seller_id = ? `
  219. pars = append(pars, sysUser.AdminId)
  220. }
  221. } else {
  222. condition += ` AND b.is_share=1 `
  223. }
  224. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  225. // 管理员,默认查看“待分配”客户
  226. listParam = 2
  227. }
  228. }
  229. if listParam == 1 {
  230. condition += ` AND b.share_seller_id > 0 AND b.is_share=1 `
  231. } else if listParam == 2 {
  232. condition += ` AND b.share_seller_id = 0 AND b.is_share=1 `
  233. } else if listParam == 3 { // 未共享
  234. if productId == 1 {
  235. condition += ` AND b.is_share=0 and (b.status="正式" AND b.product_id = 1) `
  236. } else if productId == 2 {
  237. condition += ` AND b.is_share=0 and (b.status IN ("正式","试用","永续") AND b.product_id = 2) `
  238. } else {
  239. condition += ` AND b.is_share=0 and ((b.status="正式" AND b.product_id = 1) OR (b.status IN ("正式","试用") AND b.product_id = 2))`
  240. }
  241. }
  242. if sellerIds != "" {
  243. condition += ` AND b.share_seller_id IN (` + sellerIds + `) `
  244. }
  245. if originalSellerIds != "" {
  246. condition += ` AND b.seller_id IN (` + originalSellerIds + `) `
  247. }
  248. total, err := company.GetShareCompanyListCount(condition, pars)
  249. if err != nil {
  250. br.Msg = "获取失败"
  251. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  252. return
  253. }
  254. sortStr := ``
  255. if sortParam != "" && sortType != "" {
  256. if sortParam == "expireDay" {
  257. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  258. if sortType == "asc" {
  259. sortStr = " ORDER BY min_end_date"
  260. } else {
  261. sortStr = " ORDER BY max_end_date"
  262. }
  263. } else {
  264. sortStr = " ORDER BY b.end_date "
  265. }
  266. } else if sortParam == "createTime" {
  267. sortStr = " ORDER BY a.created_time "
  268. } else if sortParam == "viewTotal" {
  269. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  270. sortStr = " ORDER BY all_view_total"
  271. } else {
  272. sortStr = " ORDER BY b.view_total "
  273. }
  274. } else if sortParam == "viewTime" {
  275. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  276. if sortType == "asc" {
  277. sortStr = " ORDER BY min_last_view_time"
  278. } else {
  279. sortStr = " ORDER BY max_last_view_time"
  280. }
  281. } else {
  282. sortStr = " ORDER BY b.last_view_time "
  283. }
  284. } else if sortParam == "roadShowTotal" {
  285. sortStr = " ORDER BY b.road_show_total "
  286. } else if sortParam == "formalTime" {
  287. sortStr = " ORDER BY b.formal_time "
  288. } else if sortParam == "freezeTime" {
  289. sortStr = " ORDER BY b.freeze_time "
  290. } else if sortParam == "lossTime" {
  291. sortStr = " ORDER BY b.loss_time "
  292. } else if sortParam == "todoCreateTime" {
  293. sortStr = " ORDER BY b.todo_create_time "
  294. } else if sortParam == "todoApproveTime" {
  295. sortStr = " ORDER BY b.todo_approve_time "
  296. } else if sortParam == "tryOutDay" {
  297. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  298. sortStr = " ORDER BY all_try_out_day_total "
  299. } else {
  300. sortStr = " ORDER BY b.try_out_day_total "
  301. }
  302. } else if sortParam == "lastServiceTime" {
  303. // 最新服务时间
  304. sortStr = ` ORDER BY last_service_time `
  305. } else if sortParam == "serviceTimes" {
  306. // 服务次数
  307. sortStr = ` ORDER BY service_times `
  308. } else {
  309. br.Msg = "获取失败"
  310. br.ErrMsg = "排序字段传入数据异常:" + sortParam
  311. return
  312. }
  313. sortStr += fmt.Sprintf(` %s`, sortType)
  314. } else {
  315. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  316. //sortStr = " ORDER BY sort_status asc, all_view_total desc, a.created_time "
  317. sortStr = " ORDER BY start_date DESC, all_view_total desc, a.created_time "
  318. } else {
  319. //sortStr = " ORDER BY sort_status asc, b.view_total desc, a.created_time "
  320. sortStr = " ORDER BY start_date DESC, b.view_total desc, a.created_time "
  321. }
  322. sortStr += " DESC "
  323. }
  324. sysUserList, err := system.GetAdminList()
  325. if err != nil {
  326. br.Msg = "获取失败"
  327. br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
  328. return
  329. }
  330. adminMap := make(map[int]*system.Admin, 0)
  331. for _, v := range sysUserList {
  332. adminMap[v.AdminId] = v
  333. }
  334. list, err := company.GetShareCompanyList(condition, sortStr, pars, startSize, pageSize)
  335. if err != nil {
  336. br.Msg = "获取失败"
  337. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  338. return
  339. }
  340. //企业用户数组切片
  341. companyIds := make([]int, 0)
  342. companyIdSlice := make([]string, 0)
  343. for _, v := range list {
  344. companyIds = append(companyIds, v.CompanyId)
  345. companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  346. }
  347. //企业用户产品开通数
  348. companyIdStr := strings.Join(companyIdSlice, ",")
  349. companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  350. companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  351. for _, companyProductTotal := range companyProductTotalList {
  352. companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  353. }
  354. lenList := len(list)
  355. // 客户产品详细信息
  356. companyProductMap := make(map[string]*company.CompanyProduct)
  357. var companyProductCondition string
  358. var companyProductPars []interface{}
  359. companyProductList, err := company.GetCompanyProductsByCompanyIds(companyIdStr, companyProductCondition, companyProductPars)
  360. if err != nil {
  361. br.Msg = "获取失败"
  362. br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
  363. return
  364. }
  365. for _, companyProduct := range companyProductList {
  366. key := fmt.Sprint(companyProduct.CompanyId, "_", companyProduct.ProductId)
  367. companyProductMap[key] = companyProduct
  368. }
  369. // 查询当前销售是否有领取客户的权限
  370. //receiveEnabled, _ := services.CheckCompanyReceiveButton(sysUser.AdminId)
  371. for i := 0; i < lenList; i++ {
  372. item := list[i]
  373. //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  374. if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  375. if companyProductTotal.Total > 1 {
  376. list[i].IsShared = true
  377. }
  378. }
  379. var expireDay string
  380. itemStatus := item.Status
  381. if itemStatus != "" {
  382. if !strings.Contains(item.Status, "/") {
  383. if strings.Contains(itemStatus, utils.COMPANY_STATUS_FOREVER) { //永续
  384. expireDay = "-"
  385. } else if strings.Contains(itemStatus, utils.COMPANY_STATUS_TRY_OUT) || strings.Contains(itemStatus, utils.COMPANY_STATUS_FORMAL) { //试用/正式
  386. if item.StartDate != "" && item.EndDate != "" {
  387. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  388. endDateTime = endDateTime.AddDate(0, 0, 1)
  389. sub := endDateTime.Sub(time.Now())
  390. if sub < 0 {
  391. sub = 0
  392. }
  393. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  394. } else {
  395. expireDay = "-"
  396. }
  397. } else if strings.Contains(itemStatus, utils.COMPANY_STATUS_LOSE) {
  398. expireDay = "-"
  399. } else if strings.Contains(itemStatus, utils.COMPANY_STATUS_FREEZE) {
  400. if item.StartDate != "" && item.EndDate != "" {
  401. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  402. endDateTime = endDateTime.AddDate(0, 0, 0)
  403. sub := endDateTime.Sub(time.Now())
  404. if sub < 0 {
  405. sub = 0
  406. }
  407. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  408. } else {
  409. expireDay = "-"
  410. }
  411. } else {
  412. expireDay = "-"
  413. }
  414. } else {
  415. tmpStatusArr := strings.Split(item.Status, "/")
  416. ficcStatus := tmpStatusArr[0]
  417. raiStatus := tmpStatusArr[1]
  418. var ficcEndDate, tryEndDate string
  419. var ficcExpireDay, tryExpireDay string
  420. if item.EndDate != "" {
  421. endDateArr := strings.Split(item.EndDate, "/")
  422. if len(endDateArr) == 1 {
  423. ficcEndDate = endDateArr[0]
  424. } else if len(endDateArr) > 1 {
  425. ficcEndDate = endDateArr[0]
  426. tryEndDate = endDateArr[1]
  427. }
  428. if strings.Contains(ficcStatus, utils.COMPANY_STATUS_FOREVER) { //永续
  429. ficcExpireDay = "-"
  430. } else if strings.Contains(ficcStatus, utils.COMPANY_STATUS_X_CLASS_TRY_OUT) || strings.Contains(ficcStatus, utils.COMPANY_STATUS_FORMAL) { //试用/正式
  431. if ficcEndDate != "" {
  432. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  433. endDateTime = endDateTime.AddDate(0, 0, 1)
  434. sub := endDateTime.Sub(time.Now())
  435. if sub < 0 {
  436. sub = 0
  437. }
  438. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  439. } else {
  440. ficcExpireDay = "-"
  441. }
  442. } else if strings.Contains(ficcStatus, utils.COMPANY_STATUS_LOSE) { //流失
  443. ficcExpireDay = "-"
  444. } else if strings.Contains(ficcStatus, utils.COMPANY_STATUS_FREEZE) { //冻结
  445. if item.StartDate != "" && item.EndDate != "" {
  446. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  447. endDateTime = endDateTime.AddDate(0, 0, 0)
  448. sub := endDateTime.Sub(time.Now())
  449. if sub < 0 {
  450. sub = 0
  451. }
  452. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  453. } else {
  454. ficcExpireDay = "-"
  455. }
  456. } else {
  457. ficcExpireDay = "-"
  458. }
  459. if strings.Contains(raiStatus, utils.COMPANY_STATUS_FOREVER) { //永续
  460. tryExpireDay = "-"
  461. } else if strings.Contains(raiStatus, utils.COMPANY_STATUS_X_CLASS_TRY_OUT) || strings.Contains(raiStatus, utils.COMPANY_STATUS_FORMAL) { //试用/正式
  462. if tryEndDate != "" {
  463. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  464. endDateTime = endDateTime.AddDate(0, 0, 1)
  465. sub := endDateTime.Sub(time.Now())
  466. if sub < 0 {
  467. sub = 0
  468. }
  469. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  470. } else {
  471. tryExpireDay = "-"
  472. }
  473. } else if strings.Contains(raiStatus, utils.COMPANY_STATUS_LOSE) { //流失
  474. tryExpireDay = "-"
  475. } else if strings.Contains(raiStatus, utils.COMPANY_STATUS_FREEZE) { //冻结
  476. if item.StartDate != "" && item.EndDate != "" {
  477. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  478. endDateTime = endDateTime.AddDate(0, 0, 0)
  479. sub := endDateTime.Sub(time.Now())
  480. if sub < 0 {
  481. sub = 0
  482. }
  483. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  484. } else {
  485. tryExpireDay = "-"
  486. }
  487. } else {
  488. tryExpireDay = "-"
  489. }
  490. }
  491. expireDay = ficcExpireDay + "/" + tryExpireDay
  492. }
  493. }
  494. list[i].ExpireDay = expireDay
  495. //按钮显示控制
  496. btnItem := new(company.ButtonPermission)
  497. if item.CompanyId != 1 {
  498. //*btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId)
  499. //根据销售"领取客户"的权限对部分按钮做限制
  500. //btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
  501. // 13.6正式客户共享按钮显示控制
  502. btnItem = services.GetShareCompanyPermissionButton(roleTypeCode, itemStatus, item.ProductId, item, sysUser)
  503. }
  504. list[i].BtnItem = btnItem
  505. if item.FreezeStartDate != "" && item.FreezeEndDate != "" && strings.Contains(item.Status, utils.COMPANY_STATUS_FREEZE) {
  506. freezeEndDate, _ := time.Parse(utils.FormatDate, item.FreezeEndDate)
  507. if time.Now().Before(freezeEndDate) {
  508. expireDays := freezeEndDate.Sub(time.Now()).Hours() / 24
  509. list[i].FreezeExpireDays = int(expireDays) + 1
  510. }
  511. }
  512. ficcKey := fmt.Sprint(item.CompanyId, "_", 1)
  513. //ficc
  514. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  515. //套餐类型
  516. item.FiccPackageType = tmpCompanyProduct.PackageType
  517. //总试用天数
  518. item.FiccTryOutDay = tmpCompanyProduct.TryOutDayTotal
  519. //总阅读次数
  520. item.FiccView = tmpCompanyProduct.ViewTotal
  521. if !tmpCompanyProduct.LastViewTime.IsZero() {
  522. //最近一次阅读时间
  523. item.FiccLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  524. }
  525. }
  526. //权益
  527. raiKey := fmt.Sprint(item.CompanyId, "_", 2)
  528. if tmpCompanyProduct, ok := companyProductMap[raiKey]; ok {
  529. //总阅读次数
  530. item.RaiView = tmpCompanyProduct.ViewTotal
  531. //总试用天数
  532. item.RaiTryOutDay = tmpCompanyProduct.TryOutDayTotal
  533. if !tmpCompanyProduct.LastViewTime.IsZero() {
  534. //最近一次阅读时间
  535. item.RaiLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  536. }
  537. }
  538. }
  539. companyLists := make([]*company.CompanyListItem, 0)
  540. //查询阅读次数
  541. if list == nil {
  542. companyLists = make([]*company.CompanyListItem, 0)
  543. } else {
  544. for _, v := range list {
  545. //viewTotal:=GetviewTotal(v.CompanyId)
  546. //活跃(客户状态)
  547. if v.IsShare != 1 {
  548. if v.BtnItem.BtnModifySeller == true {
  549. v.BtnItem.BtnModifySeller = false
  550. }
  551. }
  552. if v.IsShare == 1 && v.BtnItem.BtnModifySeller == true && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  553. //如果已经是共享客户了,取消共享按钮全都显示,和修改销售权限一样
  554. v.BtnItem.BtnShare = true
  555. }
  556. //解决共享客户正式筛选下是否标红的问题
  557. if v.WeekViewActive == 0 && v.IsUserMaker == 1 {
  558. v.WeekViewActive = 1
  559. }
  560. companyList := &company.CompanyListItem{
  561. CompanyId: v.CompanyId,
  562. CompanyName: v.CompanyName,
  563. CreditCode: v.CreditCode,
  564. CompanyCode: v.CompanyCode,
  565. StartDate: v.StartDate,
  566. EndDate: v.EndDate,
  567. LoseReason: v.LoseReason,
  568. RenewalReason: v.RenewalReason,
  569. FreezeReason: v.FreezeReason,
  570. LossTime: v.LossTime,
  571. Status: v.Status,
  572. CompanyType: v.CompanyType,
  573. ApproveStatus: v.ApproveStatus,
  574. SellerName: v.SellerName,
  575. SellerId: v.SellerId,
  576. SellerIds: v.SellerIds,
  577. ExpireDay: v.ExpireDay,
  578. FreezeTime: v.FreezeTime,
  579. GroupId: v.GroupId,
  580. GroupIds: v.GroupIds,
  581. DepartmentId: v.DepartmentId,
  582. IndustryName: v.IndustryName,
  583. IsSuspend: v.IsSuspend,
  584. CreatedTime: v.CreatedTime,
  585. Source: v.Source,
  586. Province: v.Province,
  587. City: v.City,
  588. Address: v.Address,
  589. Reasons: v.Reasons,
  590. FreezeStartDate: v.FreezeStartDate,
  591. FreezeEndDate: v.FreezeEndDate,
  592. FreezeExpireDays: v.FreezeExpireDays,
  593. BtnItem: v.BtnItem,
  594. ProductId: v.ProductId,
  595. FormalTime: v.FormalTime,
  596. IsShared: v.IsShared,
  597. RegionType: v.RegionType,
  598. FiccPackageType: v.FiccPackageType,
  599. FiccLastViewTime: v.FiccLastViewTime,
  600. RaiLastViewTime: v.RaiLastViewTime,
  601. //FiccView: viewTotal[0],
  602. //RaiView: viewTotal[1],
  603. //FiccView: ficcViewTotal,
  604. //RaiView: raiViewTotal,
  605. FiccView: v.FiccView,
  606. RaiView: v.RaiView,
  607. FiccTryOutDay: v.FiccTryOutDay,
  608. RaiTryOutDay: v.RaiTryOutDay,
  609. AllViewTotal: v.AllViewTotal,
  610. RoadShowTotal: v.RoadShowTotal,
  611. TryStageSlice: v.TryStageSlice,
  612. Deadline: v.Deadline,
  613. WeekViewActive: v.WeekViewActive,
  614. IsShare: v.IsShare,
  615. ShareSellerId: v.ShareSellerId,
  616. LastServiceTime: v.LastServiceTime,
  617. ServiceTimes: v.ServiceTimes,
  618. IsUserMaker: v.IsUserMaker,
  619. }
  620. if v.ShareSellerIds != "" {
  621. shareSellerIds := strings.Split(v.ShareSellerIds, ",")
  622. for _, idStr := range shareSellerIds {
  623. shareSellerId, e := strconv.Atoi(idStr)
  624. if e != nil {
  625. err = e
  626. return
  627. }
  628. shareSeller := adminMap[shareSellerId]
  629. if shareSeller != nil {
  630. companyList.ShareSeller += shareSeller.RealName + "(" + shareSeller.GroupName + ")" + "/"
  631. }
  632. }
  633. companyList.ShareSeller = strings.TrimRight(companyList.ShareSeller, "/")
  634. }
  635. companyLists = append(companyLists, companyList)
  636. }
  637. }
  638. if companyLists == nil {
  639. companyLists = make([]*company.CompanyListItem, 0)
  640. }
  641. var isShareGroup bool
  642. if sysUser.GroupId == groupId {
  643. isShareGroup = true
  644. }
  645. page = paging.GetPaging(currentIndex, pageSize, total)
  646. resp := new(company.CompanyListResp)
  647. resp.List = companyLists
  648. resp.IsShareGroup = isShareGroup
  649. resp.Status = listParam
  650. resp.Paging = page
  651. br.Ret = 200
  652. br.Success = true
  653. br.Msg = "获取成功"
  654. br.Data = resp
  655. }
  656. // @Title 分配共享销售
  657. // @Description 分配共享销售接口
  658. // @Param request body company.MoveShareSellerReq true "type json string"
  659. // @Success Ret=200 分配成功
  660. // @router /share/moveSeller [post]
  661. func (this *CompanyController) MoveShareSeller() {
  662. br := new(models.BaseResponse).Init()
  663. defer func() {
  664. this.Data["json"] = br
  665. this.ServeJSON()
  666. }()
  667. sysUser := this.SysUser
  668. if sysUser == nil {
  669. br.Msg = "请登录"
  670. br.ErrMsg = "请登录,SysUser Is Empty"
  671. br.Ret = 408
  672. return
  673. }
  674. var req company.MoveShareSellerReq
  675. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  676. if err != nil {
  677. br.Msg = "参数解析异常!"
  678. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  679. return
  680. }
  681. if req.CompanyId <= 0 {
  682. br.Msg = "参数异常!"
  683. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  684. return
  685. }
  686. if req.SellsId <= 0 {
  687. br.Msg = "参数异常!"
  688. br.ErrMsg = "SellsId:" + strconv.Itoa(req.SellsId)
  689. return
  690. }
  691. seller, err := system.GetSysAdminById(req.SellsId)
  692. if err != nil {
  693. br.Msg = "获取销售信息失败"
  694. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  695. return
  696. }
  697. productId := services.GetProductId(sysUser.RoleTypeCode)
  698. if productId == 0 {
  699. br.Msg = "该角色非ficc或权益角色"
  700. br.ErrMsg = "该角色非ficc或权益角色"
  701. return
  702. }
  703. //查询该客户
  704. companyProductItem, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  705. if err != nil {
  706. br.Msg = "查找客户失败"
  707. br.ErrMsg = "查找客户失败,Err:" + err.Error()
  708. return
  709. }
  710. //待更新字段
  711. updateCol := make([]string, 0)
  712. companyProductItem.ShareSeller = seller.RealName
  713. companyProductItem.ShareSellerId = seller.AdminId
  714. companyProductItem.ShareGroupId = seller.GroupId
  715. updateCol = append(updateCol, "ShareSeller", "ShareSellerId", "ShareGroupId")
  716. err = companyProductItem.Update(updateCol)
  717. if err != nil {
  718. br.Msg = "修改客户信息失败"
  719. br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
  720. return
  721. }
  722. //新增操作记录
  723. //{
  724. // remark := "移动到:" + seller.RealName
  725. // operation := "move_seller"
  726. // services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  727. // cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  728. //}
  729. //变更销售员与联系人关系
  730. //_ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
  731. br.Ret = 200
  732. br.Success = true
  733. br.Msg = "分配成功"
  734. }
  735. // CompanyShareAddRemark
  736. // @Title 新增客户备注
  737. // @Description 新增客户备注
  738. // @Param request body company.RemarkReq true "type json string"
  739. // @Success 200 编辑成功
  740. // @router /share/remark/add [post]
  741. func (this *CompanyController) CompanyShareAddRemark() {
  742. br := new(models.BaseResponse).Init()
  743. defer func() {
  744. this.Data["json"] = br
  745. this.ServeJSON()
  746. }()
  747. sysUser := this.SysUser
  748. if sysUser == nil {
  749. br.Msg = "请登录"
  750. br.ErrMsg = "请登录,SysUser Is Empty"
  751. br.Ret = 408
  752. return
  753. }
  754. var req company.RemarkReq
  755. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  756. if err != nil {
  757. br.Msg = "参数解析异常!"
  758. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  759. return
  760. }
  761. if req.CompanyId <= 0 {
  762. br.Msg = "参数缺失"
  763. br.ErrMsg = "参数缺失,客户编号未传!"
  764. return
  765. }
  766. if req.Remark == "" {
  767. br.Msg = "参数缺失"
  768. br.ErrMsg = "参数缺失,备注说明未传!"
  769. return
  770. }
  771. var productId int
  772. groupFicc := []string{
  773. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  774. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  775. }
  776. groupRai := []string{
  777. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP,
  778. utils.ROLE_TYPE_CODE_RAI_DEPARTMENT, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  779. }
  780. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  781. productId = 1
  782. }
  783. if utils.InArrayByStr(groupRai, sysUser.RoleTypeCode) {
  784. productId = 2
  785. }
  786. if productId == 0 {
  787. br.Msg = "该角色不可添加备注"
  788. return
  789. }
  790. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  791. if err != nil {
  792. br.Msg = "查询客户异常"
  793. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  794. }
  795. remark := company.CompanyProductRemark{
  796. CompanyId: companyProduct.CompanyId,
  797. ProductId: companyProduct.ProductId,
  798. ProductName: companyProduct.ProductName,
  799. Remark: req.Remark,
  800. CreateTime: time.Now(),
  801. SysUserId: sysUser.AdminId,
  802. SysRealName: sysUser.RealName,
  803. }
  804. var newId int64
  805. newId, err = company.AddCompanyRemark(&remark)
  806. if err != nil {
  807. br.Msg = "操作失败"
  808. br.ErrMsg = "新增共享客户备注失败, Err: " + err.Error()
  809. return
  810. }
  811. go func() {
  812. approveContent := req.Remark
  813. remark := "新增备注"
  814. operation := "add_remark"
  815. _ = services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  816. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  817. }()
  818. //如果是权益的写入历史备注表
  819. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  820. //权益客户新增历史备注总表
  821. itemRecord := new(company.CompanyHistoryRemark)
  822. itemRecord.CompanyId = req.CompanyId
  823. itemRecord.Content = req.Remark
  824. itemRecord.SysAdminId = sysUser.AdminId
  825. itemRecord.SysAdminName = sysUser.RealName
  826. itemRecord.CreateTime = time.Now().Local()
  827. itemRecord.ModifyTime = time.Now().Local()
  828. itemRecord.ShowTime = time.Now().Local()
  829. itemRecord.ProductId = 2
  830. itemRecord.TableName = "company_product_remark"
  831. itemRecord.TableId = int(newId)
  832. go services.AddCompanyHistoryRemark(itemRecord)
  833. }
  834. br.Ret = 200
  835. br.Success = true
  836. br.Msg = "编辑成功"
  837. }
  838. // CompanyShareMark
  839. // @Title 新增客户标记
  840. // @Description 新增客户标记
  841. // @Param request body company.CompanyMarkReq true "type json string"
  842. // @Success 200 编辑成功
  843. // @router /share/mark [post]
  844. func (this *CompanyController) CompanyShareMark() {
  845. br := new(models.BaseResponse).Init()
  846. defer func() {
  847. this.Data["json"] = br
  848. this.ServeJSON()
  849. }()
  850. sysUser := this.SysUser
  851. if sysUser == nil {
  852. br.Msg = "请登录"
  853. br.ErrMsg = "请登录,SysUser Is Empty"
  854. br.Ret = 408
  855. return
  856. }
  857. var req company.CompanyMarkReq
  858. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  859. if err != nil {
  860. br.Msg = "参数解析异常!"
  861. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  862. return
  863. }
  864. if req.CompanyServiceRecordId <= 0 {
  865. br.Msg = "参数缺失"
  866. br.ErrMsg = "参数缺失,备注ID未传!"
  867. return
  868. }
  869. err = company.UpdateCompanyServiceRecordMark(req.CompanyServiceRecordId, req.Status)
  870. if err != nil {
  871. br.Msg = "操作失败"
  872. br.ErrMsg = "新增共享客户备注失败, Err: " + err.Error()
  873. return
  874. }
  875. br.Ret = 200
  876. br.Success = true
  877. br.Msg = "编辑成功"
  878. }
  879. // @Title 共享客户列表-同城
  880. // @Description 共享客户列表接口
  881. // @Param Keyword query string true "搜索关键词"
  882. // @Param ListParam query int false "筛选字段参数,用来筛选的字段, 枚举值:0:全部 、 1:已分配 、 2:未分配 "
  883. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、`expireDay:到期时间` 、 `createTime:创建时间` 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间 、'tryOutDay':试用天数"
  884. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  885. // @Param PageSize query int true "每页数据条数"
  886. // @Param CurrentIndex query int true "当前页页码,从1开始"
  887. // @Success Ret=200 设置成功
  888. // @router /share/list/city [get]
  889. func (this *CompanyController) CompanyShareListByCity() {
  890. br := new(models.BaseResponse).Init()
  891. defer func() {
  892. this.Data["json"] = br
  893. this.ServeJSON()
  894. }()
  895. sysUser := this.SysUser
  896. if sysUser == nil {
  897. br.Msg = "请登录"
  898. br.ErrMsg = "请登录,SysUser Is Empty"
  899. br.Ret = 408
  900. return
  901. }
  902. pageSize, _ := this.GetInt("PageSize")
  903. currentIndex, _ := this.GetInt("CurrentIndex")
  904. keyword := this.GetString("Keyword")
  905. province := this.GetString("Province")
  906. city := this.GetString("City")
  907. //排序参数
  908. //sortParam := this.GetString("SortParam")
  909. //listParam, _ := this.GetInt("ListParam")
  910. //sortType := this.GetString("SortType")
  911. var total int
  912. page := paging.GetPaging(currentIndex, pageSize, total)
  913. var startSize int
  914. if pageSize <= 0 {
  915. pageSize = utils.PageSize20
  916. }
  917. if currentIndex <= 0 {
  918. currentIndex = 1
  919. }
  920. startSize = paging.StartIndex(currentIndex, pageSize)
  921. var condition string
  922. var pars []interface{}
  923. if keyword != "" {
  924. companyIdStr, err := company.GetCompanyIdByKeyWord(keyword)
  925. if err != nil {
  926. br.Msg = "获取客户信息失败"
  927. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  928. return
  929. }
  930. if companyIdStr != "" {
  931. condition += ` AND (a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%' OR a.company_id IN(` + companyIdStr + `)) `
  932. } else {
  933. condition += ` AND (a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%' ) `
  934. }
  935. }
  936. condition += ` AND b.is_share=1 `
  937. if province != "" {
  938. var provinceSql string
  939. slice := strings.Split(province, ",")
  940. for _, v := range slice {
  941. provinceSql += "'" + v + "'" + ","
  942. }
  943. provinceSql = strings.TrimRight(provinceSql, ",")
  944. condition += ` AND a.province IN (` + provinceSql + `) `
  945. }
  946. if city != "" {
  947. var citySql string
  948. slice := strings.Split(city, ",")
  949. for _, v := range slice {
  950. citySql += "'" + v + "'" + ","
  951. }
  952. citySql = strings.TrimRight(citySql, ",")
  953. condition += ` AND a.city IN (` + citySql + `) `
  954. }
  955. total, err := company.GetShareCompanyListCount(condition, pars)
  956. if err != nil {
  957. br.Msg = "获取失败"
  958. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  959. return
  960. }
  961. sysUserList, err := system.GetAdminList()
  962. if err != nil {
  963. br.Msg = "获取失败"
  964. br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
  965. return
  966. }
  967. adminMap := make(map[int]*system.Admin, 0)
  968. for _, v := range sysUserList {
  969. adminMap[v.AdminId] = v
  970. }
  971. sortStr := ` `
  972. //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  973. // sortStr = " ORDER BY sort_status asc, all_view_total desc, a.created_time "
  974. //} else {
  975. // sortStr = " ORDER BY sort_status asc, b.view_total desc, a.created_time "
  976. //}
  977. list, err := company.GetShareCompanyList(condition, sortStr, pars, startSize, pageSize)
  978. if err != nil {
  979. br.Msg = "获取失败"
  980. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  981. return
  982. }
  983. //企业用户数组切片
  984. companyIds := make([]int, 0)
  985. companyIdSlice := make([]string, 0)
  986. for _, v := range list {
  987. companyIds = append(companyIds, v.CompanyId)
  988. companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  989. }
  990. //企业用户产品开通数
  991. companyIdStr := strings.Join(companyIdSlice, ",")
  992. companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  993. companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  994. for _, companyProductTotal := range companyProductTotalList {
  995. companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  996. }
  997. // 客户产品详细信息
  998. companyProductMap := make(map[string]*company.CompanyProduct)
  999. var companyProductCondition string
  1000. var companyProductPars []interface{}
  1001. companyProductList, err := company.GetCompanyProductsByCompanyIds(companyIdStr, companyProductCondition, companyProductPars)
  1002. if err != nil {
  1003. br.Msg = "获取失败"
  1004. br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
  1005. return
  1006. }
  1007. for _, companyProduct := range companyProductList {
  1008. key := fmt.Sprint(companyProduct.CompanyId, "_", companyProduct.ProductId)
  1009. companyProductMap[key] = companyProduct
  1010. }
  1011. companyLists := make([]*company.CompanyListItem, 0)
  1012. //查询阅读次数
  1013. if list == nil {
  1014. companyLists = make([]*company.CompanyListItem, 0)
  1015. } else {
  1016. for _, v := range list {
  1017. //viewTotal:=GetviewTotal(v.CompanyId)
  1018. //活跃(客户状态)
  1019. if v.IsShare != 1 {
  1020. if v.BtnItem.BtnModifySeller == true {
  1021. v.BtnItem.BtnModifySeller = false
  1022. }
  1023. }
  1024. companyList := &company.CompanyListItem{
  1025. CompanyId: v.CompanyId,
  1026. CompanyName: v.CompanyName,
  1027. CreditCode: v.CreditCode,
  1028. CompanyCode: v.CompanyCode,
  1029. StartDate: v.StartDate,
  1030. EndDate: v.EndDate,
  1031. LoseReason: v.LoseReason,
  1032. RenewalReason: v.RenewalReason,
  1033. FreezeReason: v.FreezeReason,
  1034. LossTime: v.LossTime,
  1035. Status: v.Status,
  1036. CompanyType: v.CompanyType,
  1037. ApproveStatus: v.ApproveStatus,
  1038. SellerName: v.SellerName,
  1039. SellerId: v.SellerId,
  1040. SellerIds: v.SellerIds,
  1041. ExpireDay: v.ExpireDay,
  1042. FreezeTime: v.FreezeTime,
  1043. GroupId: v.GroupId,
  1044. GroupIds: v.GroupIds,
  1045. DepartmentId: v.DepartmentId,
  1046. IndustryName: v.IndustryName,
  1047. IsSuspend: v.IsSuspend,
  1048. CreatedTime: v.CreatedTime,
  1049. Source: v.Source,
  1050. Province: v.Province,
  1051. City: v.City,
  1052. Address: v.Address,
  1053. Reasons: v.Reasons,
  1054. FreezeStartDate: v.FreezeStartDate,
  1055. FreezeEndDate: v.FreezeEndDate,
  1056. FreezeExpireDays: v.FreezeExpireDays,
  1057. BtnItem: v.BtnItem,
  1058. ProductId: v.ProductId,
  1059. FormalTime: v.FormalTime,
  1060. IsShared: v.IsShared,
  1061. RegionType: v.RegionType,
  1062. FiccPackageType: v.FiccPackageType,
  1063. FiccLastViewTime: v.FiccLastViewTime,
  1064. RaiLastViewTime: v.RaiLastViewTime,
  1065. //FiccView: viewTotal[0],
  1066. //RaiView: viewTotal[1],
  1067. //FiccView: ficcViewTotal,
  1068. //RaiView: raiViewTotal,
  1069. FiccView: v.FiccView,
  1070. RaiView: v.RaiView,
  1071. FiccTryOutDay: v.FiccTryOutDay,
  1072. RaiTryOutDay: v.RaiTryOutDay,
  1073. AllViewTotal: v.AllViewTotal,
  1074. RoadShowTotal: v.RoadShowTotal,
  1075. TryStageSlice: v.TryStageSlice,
  1076. Deadline: v.Deadline,
  1077. WeekViewActive: v.WeekViewActive,
  1078. IsShare: v.IsShare,
  1079. ShareSellerId: v.ShareSellerId,
  1080. LastServiceTime: v.LastServiceTime,
  1081. ServiceTimes: v.ServiceTimes,
  1082. }
  1083. if v.ShareSellerIds != "" {
  1084. shareSellerIds := strings.Split(v.ShareSellerIds, ",")
  1085. for _, idStr := range shareSellerIds {
  1086. shareSellerId, e := strconv.Atoi(idStr)
  1087. if e != nil {
  1088. err = e
  1089. return
  1090. }
  1091. shareSeller := adminMap[shareSellerId]
  1092. if shareSeller != nil {
  1093. companyList.ShareSeller += shareSeller.RealName + "(" + shareSeller.GroupName + ")" + "/"
  1094. }
  1095. }
  1096. companyList.ShareSeller = strings.TrimRight(companyList.ShareSeller, "/")
  1097. }
  1098. companyLists = append(companyLists, companyList)
  1099. }
  1100. }
  1101. if companyLists == nil {
  1102. companyLists = make([]*company.CompanyListItem, 0)
  1103. }
  1104. page = paging.GetPaging(currentIndex, pageSize, total)
  1105. resp := new(company.CompanyListResp)
  1106. resp.List = companyLists
  1107. resp.Paging = page
  1108. br.Ret = 200
  1109. br.Success = true
  1110. br.Msg = "获取成功"
  1111. br.Data = resp
  1112. }