company_share.go 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  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. services.UpdateCompanyContractSellerMove(req.CompanyId, productId) //益客户移动所属销售之后,更新所关联的销售信息
  724. }
  725. //新增操作记录
  726. //{
  727. // remark := "移动到:" + seller.RealName
  728. // operation := "move_seller"
  729. // services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
  730. // cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
  731. //}
  732. //变更销售员与联系人关系
  733. //_ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
  734. br.Ret = 200
  735. br.Success = true
  736. br.Msg = "分配成功"
  737. }
  738. // CompanyShareAddRemark
  739. // @Title 新增客户备注
  740. // @Description 新增客户备注
  741. // @Param request body company.RemarkReq true "type json string"
  742. // @Success 200 编辑成功
  743. // @router /share/remark/add [post]
  744. func (this *CompanyController) CompanyShareAddRemark() {
  745. br := new(models.BaseResponse).Init()
  746. defer func() {
  747. this.Data["json"] = br
  748. this.ServeJSON()
  749. }()
  750. sysUser := this.SysUser
  751. if sysUser == nil {
  752. br.Msg = "请登录"
  753. br.ErrMsg = "请登录,SysUser Is Empty"
  754. br.Ret = 408
  755. return
  756. }
  757. var req company.RemarkReq
  758. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  759. if err != nil {
  760. br.Msg = "参数解析异常!"
  761. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  762. return
  763. }
  764. if req.CompanyId <= 0 {
  765. br.Msg = "参数缺失"
  766. br.ErrMsg = "参数缺失,客户编号未传!"
  767. return
  768. }
  769. if req.Remark == "" {
  770. br.Msg = "参数缺失"
  771. br.ErrMsg = "参数缺失,备注说明未传!"
  772. return
  773. }
  774. var productId int
  775. groupFicc := []string{
  776. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  777. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  778. }
  779. groupRai := []string{
  780. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP,
  781. utils.ROLE_TYPE_CODE_RAI_DEPARTMENT, utils.ROLE_TYPE_CODE_RAI_ADMIN,
  782. }
  783. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  784. productId = 1
  785. }
  786. if utils.InArrayByStr(groupRai, sysUser.RoleTypeCode) {
  787. productId = 2
  788. }
  789. if productId == 0 {
  790. br.Msg = "该角色不可添加备注"
  791. return
  792. }
  793. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  794. if err != nil {
  795. br.Msg = "查询客户异常"
  796. br.ErrMsg = "查询客户异常,Err:" + err.Error()
  797. }
  798. remark := company.CompanyProductRemark{
  799. CompanyId: companyProduct.CompanyId,
  800. ProductId: companyProduct.ProductId,
  801. ProductName: companyProduct.ProductName,
  802. Remark: req.Remark,
  803. CreateTime: time.Now(),
  804. SysUserId: sysUser.AdminId,
  805. SysRealName: sysUser.RealName,
  806. }
  807. var newId int64
  808. newId, err = company.AddCompanyRemark(&remark)
  809. if err != nil {
  810. br.Msg = "操作失败"
  811. br.ErrMsg = "新增共享客户备注失败, Err: " + err.Error()
  812. return
  813. }
  814. go func() {
  815. approveContent := req.Remark
  816. remark := "新增备注"
  817. operation := "add_remark"
  818. _ = services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  819. companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  820. }()
  821. //如果是权益的写入历史备注表
  822. if productId == utils.COMPANY_PRODUCT_RAI_ID {
  823. //权益客户新增历史备注总表
  824. itemRecord := new(company.CompanyHistoryRemark)
  825. itemRecord.CompanyId = req.CompanyId
  826. itemRecord.Content = req.Remark
  827. itemRecord.SysAdminId = sysUser.AdminId
  828. itemRecord.SysAdminName = sysUser.RealName
  829. itemRecord.CreateTime = time.Now().Local()
  830. itemRecord.ModifyTime = time.Now().Local()
  831. itemRecord.ShowTime = time.Now().Local()
  832. itemRecord.ProductId = 2
  833. itemRecord.TableName = "company_product_remark"
  834. itemRecord.TableId = int(newId)
  835. go services.AddCompanyHistoryRemark(itemRecord)
  836. }
  837. br.Ret = 200
  838. br.Success = true
  839. br.Msg = "编辑成功"
  840. }
  841. // CompanyShareMark
  842. // @Title 新增客户标记
  843. // @Description 新增客户标记
  844. // @Param request body company.CompanyMarkReq true "type json string"
  845. // @Success 200 编辑成功
  846. // @router /share/mark [post]
  847. func (this *CompanyController) CompanyShareMark() {
  848. br := new(models.BaseResponse).Init()
  849. defer func() {
  850. this.Data["json"] = br
  851. this.ServeJSON()
  852. }()
  853. sysUser := this.SysUser
  854. if sysUser == nil {
  855. br.Msg = "请登录"
  856. br.ErrMsg = "请登录,SysUser Is Empty"
  857. br.Ret = 408
  858. return
  859. }
  860. var req company.CompanyMarkReq
  861. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  862. if err != nil {
  863. br.Msg = "参数解析异常!"
  864. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  865. return
  866. }
  867. if req.CompanyServiceRecordId <= 0 {
  868. br.Msg = "参数缺失"
  869. br.ErrMsg = "参数缺失,备注ID未传!"
  870. return
  871. }
  872. err = company.UpdateCompanyServiceRecordMark(req.CompanyServiceRecordId, req.Status)
  873. if err != nil {
  874. br.Msg = "操作失败"
  875. br.ErrMsg = "新增共享客户备注失败, Err: " + err.Error()
  876. return
  877. }
  878. br.Ret = 200
  879. br.Success = true
  880. br.Msg = "编辑成功"
  881. }
  882. // @Title 共享客户列表-同城
  883. // @Description 共享客户列表接口
  884. // @Param Keyword query string true "搜索关键词"
  885. // @Param ListParam query int false "筛选字段参数,用来筛选的字段, 枚举值:0:全部 、 1:已分配 、 2:未分配 "
  886. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、`expireDay:到期时间` 、 `createTime:创建时间` 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间 、'tryOutDay':试用天数"
  887. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  888. // @Param PageSize query int true "每页数据条数"
  889. // @Param CurrentIndex query int true "当前页页码,从1开始"
  890. // @Success Ret=200 设置成功
  891. // @router /share/list/city [get]
  892. func (this *CompanyController) CompanyShareListByCity() {
  893. br := new(models.BaseResponse).Init()
  894. defer func() {
  895. this.Data["json"] = br
  896. this.ServeJSON()
  897. }()
  898. sysUser := this.SysUser
  899. if sysUser == nil {
  900. br.Msg = "请登录"
  901. br.ErrMsg = "请登录,SysUser Is Empty"
  902. br.Ret = 408
  903. return
  904. }
  905. pageSize, _ := this.GetInt("PageSize")
  906. currentIndex, _ := this.GetInt("CurrentIndex")
  907. keyword := this.GetString("Keyword")
  908. province := this.GetString("Province")
  909. city := this.GetString("City")
  910. //排序参数
  911. //sortParam := this.GetString("SortParam")
  912. //listParam, _ := this.GetInt("ListParam")
  913. //sortType := this.GetString("SortType")
  914. var total int
  915. page := paging.GetPaging(currentIndex, pageSize, total)
  916. var startSize int
  917. if pageSize <= 0 {
  918. pageSize = utils.PageSize20
  919. }
  920. if currentIndex <= 0 {
  921. currentIndex = 1
  922. }
  923. startSize = paging.StartIndex(currentIndex, pageSize)
  924. var condition string
  925. var pars []interface{}
  926. if keyword != "" {
  927. companyIdStr, err := company.GetCompanyIdByKeyWord(keyword)
  928. if err != nil {
  929. br.Msg = "获取客户信息失败"
  930. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  931. return
  932. }
  933. if companyIdStr != "" {
  934. condition += ` AND (a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%' OR a.company_id IN(` + companyIdStr + `)) `
  935. } else {
  936. condition += ` AND (a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%' ) `
  937. }
  938. }
  939. condition += ` AND b.is_share=1 `
  940. if province != "" {
  941. var provinceSql string
  942. slice := strings.Split(province, ",")
  943. for _, v := range slice {
  944. provinceSql += "'" + v + "'" + ","
  945. }
  946. provinceSql = strings.TrimRight(provinceSql, ",")
  947. condition += ` AND a.province IN (` + provinceSql + `) `
  948. }
  949. if city != "" {
  950. var citySql string
  951. slice := strings.Split(city, ",")
  952. for _, v := range slice {
  953. citySql += "'" + v + "'" + ","
  954. }
  955. citySql = strings.TrimRight(citySql, ",")
  956. condition += ` AND a.city IN (` + citySql + `) `
  957. }
  958. total, err := company.GetShareCompanyListCount(condition, pars)
  959. if err != nil {
  960. br.Msg = "获取失败"
  961. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  962. return
  963. }
  964. sysUserList, err := system.GetAdminList()
  965. if err != nil {
  966. br.Msg = "获取失败"
  967. br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
  968. return
  969. }
  970. adminMap := make(map[int]*system.Admin, 0)
  971. for _, v := range sysUserList {
  972. adminMap[v.AdminId] = v
  973. }
  974. sortStr := ` `
  975. //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  976. // sortStr = " ORDER BY sort_status asc, all_view_total desc, a.created_time "
  977. //} else {
  978. // sortStr = " ORDER BY sort_status asc, b.view_total desc, a.created_time "
  979. //}
  980. list, err := company.GetShareCompanyList(condition, sortStr, pars, startSize, pageSize)
  981. if err != nil {
  982. br.Msg = "获取失败"
  983. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  984. return
  985. }
  986. //企业用户数组切片
  987. companyIds := make([]int, 0)
  988. companyIdSlice := make([]string, 0)
  989. for _, v := range list {
  990. companyIds = append(companyIds, v.CompanyId)
  991. companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  992. }
  993. //企业用户产品开通数
  994. companyIdStr := strings.Join(companyIdSlice, ",")
  995. companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  996. companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  997. for _, companyProductTotal := range companyProductTotalList {
  998. companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  999. }
  1000. // 客户产品详细信息
  1001. companyProductMap := make(map[string]*company.CompanyProduct)
  1002. var companyProductCondition string
  1003. var companyProductPars []interface{}
  1004. companyProductList, err := company.GetCompanyProductsByCompanyIds(companyIdStr, companyProductCondition, companyProductPars)
  1005. if err != nil {
  1006. br.Msg = "获取失败"
  1007. br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
  1008. return
  1009. }
  1010. for _, companyProduct := range companyProductList {
  1011. key := fmt.Sprint(companyProduct.CompanyId, "_", companyProduct.ProductId)
  1012. companyProductMap[key] = companyProduct
  1013. }
  1014. companyLists := make([]*company.CompanyListItem, 0)
  1015. //查询阅读次数
  1016. if list == nil {
  1017. companyLists = make([]*company.CompanyListItem, 0)
  1018. } else {
  1019. for _, v := range list {
  1020. //viewTotal:=GetviewTotal(v.CompanyId)
  1021. //活跃(客户状态)
  1022. if v.IsShare != 1 {
  1023. if v.BtnItem.BtnModifySeller == true {
  1024. v.BtnItem.BtnModifySeller = false
  1025. }
  1026. }
  1027. companyList := &company.CompanyListItem{
  1028. CompanyId: v.CompanyId,
  1029. CompanyName: v.CompanyName,
  1030. CreditCode: v.CreditCode,
  1031. CompanyCode: v.CompanyCode,
  1032. StartDate: v.StartDate,
  1033. EndDate: v.EndDate,
  1034. LoseReason: v.LoseReason,
  1035. RenewalReason: v.RenewalReason,
  1036. FreezeReason: v.FreezeReason,
  1037. LossTime: v.LossTime,
  1038. Status: v.Status,
  1039. CompanyType: v.CompanyType,
  1040. ApproveStatus: v.ApproveStatus,
  1041. SellerName: v.SellerName,
  1042. SellerId: v.SellerId,
  1043. SellerIds: v.SellerIds,
  1044. ExpireDay: v.ExpireDay,
  1045. FreezeTime: v.FreezeTime,
  1046. GroupId: v.GroupId,
  1047. GroupIds: v.GroupIds,
  1048. DepartmentId: v.DepartmentId,
  1049. IndustryName: v.IndustryName,
  1050. IsSuspend: v.IsSuspend,
  1051. CreatedTime: v.CreatedTime,
  1052. Source: v.Source,
  1053. Province: v.Province,
  1054. City: v.City,
  1055. Address: v.Address,
  1056. Reasons: v.Reasons,
  1057. FreezeStartDate: v.FreezeStartDate,
  1058. FreezeEndDate: v.FreezeEndDate,
  1059. FreezeExpireDays: v.FreezeExpireDays,
  1060. BtnItem: v.BtnItem,
  1061. ProductId: v.ProductId,
  1062. FormalTime: v.FormalTime,
  1063. IsShared: v.IsShared,
  1064. RegionType: v.RegionType,
  1065. FiccPackageType: v.FiccPackageType,
  1066. FiccLastViewTime: v.FiccLastViewTime,
  1067. RaiLastViewTime: v.RaiLastViewTime,
  1068. //FiccView: viewTotal[0],
  1069. //RaiView: viewTotal[1],
  1070. //FiccView: ficcViewTotal,
  1071. //RaiView: raiViewTotal,
  1072. FiccView: v.FiccView,
  1073. RaiView: v.RaiView,
  1074. FiccTryOutDay: v.FiccTryOutDay,
  1075. RaiTryOutDay: v.RaiTryOutDay,
  1076. AllViewTotal: v.AllViewTotal,
  1077. RoadShowTotal: v.RoadShowTotal,
  1078. TryStageSlice: v.TryStageSlice,
  1079. Deadline: v.Deadline,
  1080. WeekViewActive: v.WeekViewActive,
  1081. IsShare: v.IsShare,
  1082. ShareSellerId: v.ShareSellerId,
  1083. LastServiceTime: v.LastServiceTime,
  1084. ServiceTimes: v.ServiceTimes,
  1085. }
  1086. if v.ShareSellerIds != "" {
  1087. shareSellerIds := strings.Split(v.ShareSellerIds, ",")
  1088. for _, idStr := range shareSellerIds {
  1089. shareSellerId, e := strconv.Atoi(idStr)
  1090. if e != nil {
  1091. err = e
  1092. return
  1093. }
  1094. shareSeller := adminMap[shareSellerId]
  1095. if shareSeller != nil {
  1096. companyList.ShareSeller += shareSeller.RealName + "(" + shareSeller.GroupName + ")" + "/"
  1097. }
  1098. }
  1099. companyList.ShareSeller = strings.TrimRight(companyList.ShareSeller, "/")
  1100. }
  1101. companyLists = append(companyLists, companyList)
  1102. }
  1103. }
  1104. if companyLists == nil {
  1105. companyLists = make([]*company.CompanyListItem, 0)
  1106. }
  1107. page = paging.GetPaging(currentIndex, pageSize, total)
  1108. resp := new(company.CompanyListResp)
  1109. resp.List = companyLists
  1110. resp.Paging = page
  1111. br.Ret = 200
  1112. br.Success = true
  1113. br.Msg = "获取成功"
  1114. br.Data = resp
  1115. }