company_share.go 39 KB

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