company.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. package statistic_report
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/shopspring/decimal"
  7. "hongze/hz_crm_api/models/company"
  8. statisticModels "hongze/hz_crm_api/models/statistic_report"
  9. "hongze/hz_crm_api/models/system"
  10. "hongze/hz_crm_api/services"
  11. "hongze/hz_crm_api/utils"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. func CompanyList(sysUser *system.Admin, req statisticModels.IncrementalCompanyListReq) (resp CompanyListResp, err error, errMsg string) {
  17. pageSize := req.PageSize
  18. currentIndex := req.CurrentIndex
  19. CompanyIds := req.CompanyIds
  20. //排序参数
  21. sortParam := req.SortParam
  22. sortType := req.SortType
  23. roleTypeCode := sysUser.RoleTypeCode
  24. var total int
  25. page := paging.GetPaging(currentIndex, pageSize, total)
  26. //resp := new(CompanyListResp)
  27. var startSize int
  28. if pageSize <= 0 {
  29. pageSize = utils.PageSize20
  30. }
  31. if currentIndex <= 0 {
  32. currentIndex = 1
  33. }
  34. startSize = paging.StartIndex(currentIndex, pageSize)
  35. var condition string
  36. var pars []interface{}
  37. if CompanyIds != "" {
  38. fmt.Println("CompanyIds:", CompanyIds)
  39. condition += ` AND b.company_id IN (` + strings.Replace(CompanyIds, "\"", "", -1) + `) `
  40. }
  41. productId := services.GetProductId(roleTypeCode)
  42. {
  43. //权限控制
  44. //如果不是超级管理员或者财务
  45. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && roleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  46. //如果是部门管理员
  47. condition += ` AND b.product_id=? `
  48. pars = append(pars, productId)
  49. }
  50. }
  51. total, err = company.GetCompanyListCount(condition, pars)
  52. if err != nil {
  53. errMsg = "获取数据总数失败,Err:" + err.Error()
  54. err = errors.New("获取失败")
  55. return
  56. }
  57. status := `全部`
  58. sortStr := ``
  59. if sortParam != "" && sortType != "" {
  60. if sortParam == "expireDay" {
  61. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  62. if sortType == "asc" {
  63. sortStr = " ORDER BY min_end_date"
  64. } else {
  65. sortStr = " ORDER BY max_end_date"
  66. }
  67. } else {
  68. sortStr = " ORDER BY b.end_date "
  69. }
  70. } else if sortParam == "createTime" {
  71. sortStr = " ORDER BY a.created_time "
  72. } else if sortParam == "viewTotal" {
  73. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  74. sortStr = " ORDER BY all_view_total"
  75. } else {
  76. sortStr = " ORDER BY b.view_total"
  77. }
  78. } else if sortParam == "viewTime" {
  79. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  80. if sortType == "asc" {
  81. sortStr = " ORDER BY min_last_view_time"
  82. } else {
  83. sortStr = " ORDER BY max_last_view_time"
  84. }
  85. } else {
  86. sortStr = " ORDER BY b.last_view_time "
  87. }
  88. } else if sortParam == "roadShowTotal" {
  89. sortStr = " ORDER BY b.road_show_total "
  90. } else if sortParam == "formalTime" {
  91. sortStr = " ORDER BY b.formal_time "
  92. } else if sortParam == "freezeTime" {
  93. sortStr = " ORDER BY b.freeze_time "
  94. } else if sortParam == "lossTime" {
  95. sortStr = " ORDER BY b.loss_time "
  96. } else if sortParam == "deadline" {
  97. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  98. sortStr = " ORDER BY sort_todo_end_time asc, all_view_total desc, a.created_time desc"
  99. } else {
  100. sortStr = " ORDER BY sort_todo_end_time asc, b.view_total desc, a.created_time desc"
  101. }
  102. } else if sortParam == "sellerName" {
  103. sortStr = " ORDER BY CONVERT( b.seller_name USING gbk ) COLLATE gbk_chinese_ci "
  104. } else if sortParam == "shareSellerName" {
  105. sortStr = " ORDER BY CONVERT( b.share_seller USING gbk ) COLLATE gbk_chinese_ci "
  106. } else if sortParam == "status" {
  107. sortStr = " ORDER BY b.status "
  108. } else if sortParam == "serviceYears" {
  109. sortStr = " ORDER BY d.first_date"
  110. } else if sortParam == "latestServiceRecord" {
  111. sortStr = " ORDER BY c.latest_service_record "
  112. }else {
  113. errMsg = "排序字段传入数据异常:" + sortParam
  114. err = errors.New("获取失败")
  115. return
  116. }
  117. if sortParam != "deadline" {
  118. if sortType == "asc" {
  119. sortStr += " ASC "
  120. } else if sortType == "desc" {
  121. sortStr += " DESC "
  122. } else {
  123. errMsg = "排序类型传入数据异常:" + sortType
  124. err = errors.New("获取失败")
  125. return
  126. }
  127. }
  128. } else {
  129. //2、客户列表选择“全部”时,支持按照“创建时间”对“全部”分类下所有客户列表进行升降序排列;选择“正式”时按照“转正时间”、选择“冻结”时按照“冻结时间”、选择“流失”时按照“流失时间”、选择“永续”时按照“创建时间”;
  130. if status == "全部" || status == "永续" {
  131. sortStr = " ORDER BY c.latest_service_record ASC"
  132. } else if status == "正式" {
  133. sortStr = " ORDER BY b.formal_time DESC"
  134. } else if status == "冻结" {
  135. sortStr = " ORDER BY b.freeze_time DESC"
  136. } else if status == "流失" {
  137. sortStr = " ORDER BY b.loss_time DESC"
  138. } else if status == "试用" {
  139. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  140. sortStr = " ORDER BY all_view_total DESC"
  141. } else {
  142. sortStr = " ORDER BY b.view_total DESC"
  143. }
  144. }
  145. }
  146. list, err := company.GetCompanyList(condition, status, sortStr, pars, startSize, pageSize)
  147. if err != nil {
  148. errMsg = "获取数据失败,Err:" + err.Error()
  149. err = errors.New("获取失败")
  150. return
  151. }
  152. //企业用户数组切片
  153. companyIdSlice := make([]string, 0)
  154. for _, v := range list {
  155. companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
  156. }
  157. //企业用户产品开通数
  158. companyIdStr := strings.Join(companyIdSlice, ",")
  159. companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
  160. companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
  161. for _, companyProductTotal := range companyProductTotalList {
  162. companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
  163. }
  164. lenList := len(list)
  165. // 客户产品详细信息
  166. companyProductMap := make(map[string]*company.CompanyProduct)
  167. var companyProductCondition string
  168. var companyProductPars []interface{}
  169. if productId != 0 {
  170. companyProductCondition += ` AND product_id=? `
  171. companyProductPars = append(companyProductPars, productId)
  172. }
  173. companyProductList, err := company.GetCompanyProductsByCompanyIds(companyIdStr, companyProductCondition, companyProductPars)
  174. if err != nil {
  175. errMsg = "获取客户产品数据失败,Err:" + err.Error()
  176. err = errors.New("获取失败")
  177. return
  178. }
  179. for _, companyProduct := range companyProductList {
  180. key := fmt.Sprint(companyProduct.CompanyId, "_", companyProduct.ProductId)
  181. companyProductMap[key] = companyProduct
  182. }
  183. sysUserProductId := 0
  184. //获取名下所有的分组
  185. myChildSysGroupMap := make(map[int]*system.SysGroup)
  186. switch sysUser.RoleTypeCode {
  187. case utils.ROLE_TYPE_CODE_FICC_GROUP: //ficc主管
  188. myChildSysGroupMap, err = services.GetBigGroupByFiccGroupId(sysUser.GroupId)
  189. sysUserProductId = 1
  190. case utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc组长
  191. myChildSysGroupMap, err = services.GetBigGroupAllGroupInfo(sysUser.GroupId)
  192. sysUserProductId = 1
  193. case utils.ROLE_TYPE_CODE_RAI_GROUP: //权益组长
  194. myChildSysGroupMap, err = services.GetBigGroupAllGroupInfo(sysUser.GroupId)
  195. sysUserProductId = 2
  196. case utils.ROLE_TYPE_CODE_RAI_SELLER: //权益销售
  197. myChildSysGroupMap, err = services.GetBigGroupAllGroupInfo(sysUser.GroupId)
  198. sysUserProductId = 2
  199. case utils.ROLE_TYPE_CODE_FICC_SELLER: //ficc销售
  200. myChildSysGroupMap, err = services.GetBigGroupAllGroupInfo(sysUser.GroupId)
  201. sysUserProductId = 1
  202. }
  203. for i := 0; i < lenList; i++ {
  204. item := list[i]
  205. //校验该客户是否存在多个产品,如果是,那么代表是共享客户
  206. if companyProductTotal, ok := companyProductTotalMap[int(item.CompanyId)]; ok {
  207. if companyProductTotal.Total > 1 {
  208. list[i].IsShared = true
  209. }
  210. }
  211. var expireDay string
  212. itemStatus := item.Status
  213. if itemStatus != "" {
  214. if !strings.Contains(item.Status, "/") {
  215. if itemStatus == utils.COMPANY_STATUS_FOREVER { //永续
  216. expireDay = "-"
  217. } else if itemStatus == utils.COMPANY_STATUS_TRY_OUT || itemStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  218. if item.StartDate != "" && item.EndDate != "" {
  219. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  220. endDateTime = endDateTime.AddDate(0, 0, 1)
  221. sub := endDateTime.Sub(time.Now())
  222. if sub < 0 {
  223. sub = 0
  224. }
  225. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  226. } else {
  227. expireDay = "-"
  228. }
  229. } else if itemStatus == utils.COMPANY_STATUS_LOSE {
  230. expireDay = "-"
  231. } else if itemStatus == utils.COMPANY_STATUS_FREEZE {
  232. if item.StartDate != "" && item.EndDate != "" {
  233. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  234. endDateTime = endDateTime.AddDate(0, 0, 0)
  235. sub := endDateTime.Sub(time.Now())
  236. if sub < 0 {
  237. sub = 0
  238. }
  239. expireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  240. } else {
  241. expireDay = "-"
  242. }
  243. } else {
  244. expireDay = "-"
  245. }
  246. } else {
  247. statusArr := strings.Split(item.Status, "/")
  248. ficcStatus := statusArr[0]
  249. raiStatus := statusArr[1]
  250. var ficcEndDate, tryEndDate string
  251. var ficcExpireDay, tryExpireDay string
  252. if item.EndDate != "" {
  253. endDateArr := strings.Split(item.EndDate, "/")
  254. if len(endDateArr) == 1 {
  255. ficcEndDate = endDateArr[0]
  256. } else if len(endDateArr) > 1 {
  257. ficcEndDate = endDateArr[0]
  258. tryEndDate = endDateArr[1]
  259. }
  260. if ficcStatus == utils.COMPANY_STATUS_FOREVER { //永续
  261. ficcExpireDay = "-"
  262. } else if ficcStatus == utils.COMPANY_STATUS_TRY_OUT || ficcStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  263. if ficcEndDate != "" {
  264. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  265. endDateTime = endDateTime.AddDate(0, 0, 1)
  266. sub := endDateTime.Sub(time.Now())
  267. if sub < 0 {
  268. sub = 0
  269. }
  270. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  271. } else {
  272. ficcExpireDay = "-"
  273. }
  274. } else if ficcStatus == utils.COMPANY_STATUS_LOSE { //流失
  275. ficcExpireDay = "-"
  276. } else if ficcStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  277. if item.StartDate != "" && item.EndDate != "" {
  278. endDateTime, _ := time.Parse(utils.FormatDate, ficcEndDate)
  279. endDateTime = endDateTime.AddDate(0, 0, 0)
  280. sub := endDateTime.Sub(time.Now())
  281. if sub < 0 {
  282. sub = 0
  283. }
  284. ficcExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  285. } else {
  286. ficcExpireDay = "-"
  287. }
  288. } else {
  289. ficcExpireDay = "-"
  290. }
  291. if raiStatus == utils.COMPANY_STATUS_FOREVER { //永续
  292. tryExpireDay = "-"
  293. } else if raiStatus == utils.COMPANY_STATUS_TRY_OUT || raiStatus == utils.COMPANY_STATUS_FORMAL { //试用/正式
  294. if tryEndDate != "" {
  295. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  296. endDateTime = endDateTime.AddDate(0, 0, 1)
  297. sub := endDateTime.Sub(time.Now())
  298. if sub < 0 {
  299. sub = 0
  300. }
  301. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  302. } else {
  303. tryExpireDay = "-"
  304. }
  305. } else if raiStatus == utils.COMPANY_STATUS_LOSE { //流失
  306. tryExpireDay = "-"
  307. } else if raiStatus == utils.COMPANY_STATUS_FREEZE { //冻结
  308. if item.StartDate != "" && item.EndDate != "" {
  309. endDateTime, _ := time.Parse(utils.FormatDate, tryEndDate)
  310. endDateTime = endDateTime.AddDate(0, 0, 0)
  311. sub := endDateTime.Sub(time.Now())
  312. if sub < 0 {
  313. sub = 0
  314. }
  315. tryExpireDay = fmt.Sprintf("%v", int(sub.Hours()/24))
  316. } else {
  317. tryExpireDay = "-"
  318. }
  319. } else {
  320. tryExpireDay = "-"
  321. }
  322. }
  323. expireDay = ficcExpireDay + "/" + tryExpireDay
  324. }
  325. }
  326. list[i].ExpireDay = expireDay
  327. ficcKey := fmt.Sprint(item.CompanyId, "_", 1)
  328. //ficc
  329. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok && (productId == 0 || productId == 1) {
  330. //套餐类型
  331. item.FiccPackageType = tmpCompanyProduct.PackageType
  332. //总阅读次数
  333. item.FiccView = tmpCompanyProduct.ViewTotal
  334. if !tmpCompanyProduct.LastViewTime.IsZero() {
  335. //最近一次阅读时间
  336. item.FiccLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  337. }
  338. item.FiccTryOutDay = tmpCompanyProduct.TryOutDayTotal
  339. }
  340. //权益
  341. raiKey := fmt.Sprint(item.CompanyId, "_", 2)
  342. if tmpCompanyProduct, ok := companyProductMap[raiKey]; ok && (productId == 0 || productId == 2) {
  343. //总阅读次数
  344. item.RaiView = tmpCompanyProduct.ViewTotal
  345. if !tmpCompanyProduct.LastViewTime.IsZero() {
  346. //最近一次阅读时间
  347. item.RaiLastViewTime = tmpCompanyProduct.LastViewTime.Format(utils.FormatDateTime)
  348. }
  349. item.RaiTryOutDay = tmpCompanyProduct.TryOutDayTotal
  350. }
  351. }
  352. companyLists := make([]*CompanyListItem, 0)
  353. //查询阅读次数
  354. if list == nil {
  355. companyLists = make([]*CompanyListItem, 0)
  356. } else {
  357. for _, v := range list {
  358. //viewTotal:=GetviewTotal(v.CompanyId)
  359. //活跃(客户状态)
  360. tmpStatus := v.Status
  361. //productIdSlice := strings.Split(v.ProductIds, "/")
  362. //statusSlice := strings.Split(v.Status, "/")
  363. // 试用客户子标签
  364. tryStageSlice := make([]company.TryStageSliceItem, 0)
  365. for _, vProductId := range []int{1, 2} {
  366. ficcKey := fmt.Sprint(v.CompanyId, "_", vProductId)
  367. //ficc
  368. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  369. if tmpCompanyProduct.Status == utils.COMPANY_STATUS_TRY_OUT {
  370. key := fmt.Sprint(v.CompanyId, "_", vProductId)
  371. if pro, ok := companyProductMap[key]; ok {
  372. tryItem := company.TryStageSliceItem{
  373. ProductId: vProductId,
  374. TryStage: pro.TryStage,
  375. }
  376. if pro.SellerId == sysUser.AdminId { //产品销售ID和登录ID相等
  377. tryItem.HasPermission = true
  378. }
  379. tryStageSlice = append(tryStageSlice, tryItem)
  380. }
  381. }
  382. }
  383. }
  384. // 是否存在进行中的任务
  385. var todoStatus bool
  386. //是否支持确认完成待办任务
  387. var canConfirm bool
  388. var hiddenConfirm bool //是否隐藏确定完成按钮
  389. var hiddenCreate bool //是否隐藏新增/编辑按钮
  390. hiddenConfirm = true
  391. hiddenCreate = true
  392. todoButtonColor := `green`
  393. //'无任务','未完成','已完成'
  394. if strings.Contains(v.TodoStatuss, "未完成") {
  395. todoButtonColor = "red"
  396. todoStatus = true
  397. } else if strings.Contains(v.TodoStatuss, "已完成") {
  398. todoButtonColor = "green"
  399. } else if strings.Contains(v.TodoStatuss, "无任务") {
  400. todoButtonColor = "gray"
  401. }
  402. for _, vProductId := range []int{1, 2} {
  403. ficcKey := fmt.Sprint(v.CompanyId, "_", vProductId)
  404. //ficc
  405. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  406. if tmpCompanyProduct.Status != utils.COMPANY_STATUS_LOSE && tmpCompanyProduct.Status != utils.COMPANY_STATUS_CLOSE { //非流失
  407. hiddenCreate = false
  408. switch sysUser.RoleTypeCode {
  409. case utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP:
  410. //部门管理员、ficc主管、权益组长
  411. hiddenConfirm = false //不展示
  412. if todoStatus { //有任务,需要展示
  413. canConfirm = true
  414. }
  415. case utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc组长
  416. if todoStatus { //有任务,需要展示
  417. canConfirm = true
  418. }
  419. if v.SellerId != sysUser.AdminId { //不是自己的客户
  420. hiddenConfirm = false //展示
  421. }
  422. case utils.ROLE_TYPE_CODE_RAI_SELLER: //权益销售
  423. if v.SellerId == sysUser.AdminId { //是自己的客户
  424. has := services.CheckRaiApprovePermission(sysUser.AdminId) //这些个权益销售是有权限的
  425. if has {
  426. if todoStatus { //有任务,需要展示
  427. canConfirm = true
  428. }
  429. hiddenConfirm = false //展示
  430. }
  431. }
  432. }
  433. }
  434. }
  435. }
  436. // To-Do任务状态为未完成的对应任务的截止日期-当前日期;
  437. tmpDeadline := v.Deadline
  438. if strings.Contains(v.TodoStatuss, "未完成") {
  439. if strings.Contains(v.TodoEndTimeStr, "/") {
  440. edtSlice := strings.Split(v.TodoEndTimeStr, "/")
  441. v.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, edtSlice[0], time.Local)
  442. } else {
  443. v.TodoEndTime, _ = time.ParseInLocation(utils.FormatDateTime, v.TodoEndTimeStr, time.Local)
  444. }
  445. tmpEndTime := v.TodoEndTime.Format(utils.FormatDate)
  446. if tmpEndTime == "0001-01-01" {
  447. tmpEndTime = ""
  448. }
  449. if tmpEndTime != "" {
  450. dlTime1 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
  451. dlTime2 := time.Date(v.TodoEndTime.Year(), v.TodoEndTime.Month(), v.TodoEndTime.Day(), 0, 0, 0, 0, time.Local)
  452. dldays := int(dlTime2.Sub(dlTime1).Hours() / 24)
  453. tmpDeadline = strconv.Itoa(dldays)
  454. }
  455. }
  456. var isShow bool //是否可见
  457. {
  458. switch sysUser.RoleTypeCode {
  459. case utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_RAI_ADMIN:
  460. //超管、部门管理员
  461. isShow = true
  462. case utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_RAI_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM: //ficc主管、权益主管、ficc组长
  463. ficcKey := fmt.Sprint(v.CompanyId, "_", sysUserProductId)
  464. if _, ok := companyProductMap[ficcKey]; ok {
  465. if _, ok2 := myChildSysGroupMap[v.GroupId]; ok2 {
  466. isShow = true
  467. }
  468. }
  469. case utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_FICC_SELLER: //权益销售、ficc销售
  470. ficcKey := fmt.Sprint(v.CompanyId, "_", sysUserProductId)
  471. if tmpCompanyProduct, ok := companyProductMap[ficcKey]; ok {
  472. if tmpCompanyProduct.SellerId == sysUser.AdminId { //是自己的客户
  473. isShow = true
  474. }
  475. }
  476. }
  477. }
  478. // 计算合同开始日期和结束日期之间的小时差
  479. duration := time.Since(v.FirstDate).Hours()
  480. hoursDiff := decimal.NewFromFloat(duration)
  481. // 计算总小时数
  482. const hoursPerYear = 24 * 365
  483. totalHours := decimal.NewFromInt(hoursPerYear)
  484. // 计算相差的年数,保留一位小数
  485. numYearDecimal := hoursDiff.Div(totalHours).Round(1)
  486. companyList := &CompanyListItem{
  487. CompanyId: v.CompanyId,
  488. CompanyName: v.CompanyName,
  489. CreditCode: v.CreditCode,
  490. CompanyCode: v.CompanyCode,
  491. StartDate: v.StartDate,
  492. EndDate: v.EndDate,
  493. LoseReason: v.LoseReason,
  494. RenewalReason: v.RenewalReason,
  495. FreezeReason: v.FreezeReason,
  496. LossTime: v.LossTime,
  497. Status: tmpStatus,
  498. CompanyType: v.CompanyType,
  499. ApproveStatus: v.ApproveStatus,
  500. SellerName: v.SellerName,
  501. SellerId: v.SellerId,
  502. SellerIds: v.SellerIds,
  503. ExpireDay: v.ExpireDay,
  504. FreezeTime: v.FreezeTime,
  505. GroupId: v.GroupId,
  506. GroupIds: v.GroupIds,
  507. DepartmentId: v.DepartmentId,
  508. IndustryName: v.IndustryName,
  509. IsSuspend: v.IsSuspend,
  510. CreatedTime: v.CreatedTime,
  511. Source: v.Source,
  512. Province: v.Province,
  513. City: v.City,
  514. Address: v.Address,
  515. Reasons: v.Reasons,
  516. FreezeStartDate: v.FreezeStartDate,
  517. FreezeEndDate: v.FreezeEndDate,
  518. FreezeExpireDays: v.FreezeExpireDays,
  519. ProductId: v.ProductId,
  520. FormalTime: v.FormalTime,
  521. IsShared: v.IsShared,
  522. RegionType: v.RegionType,
  523. FiccPackageType: v.FiccPackageType,
  524. FiccLastViewTime: v.FiccLastViewTime,
  525. RaiLastViewTime: v.RaiLastViewTime,
  526. FiccView: v.FiccView,
  527. RaiView: v.RaiView,
  528. RoadShowTotal: v.RoadShowTotal,
  529. FiccTryOutDay: v.FiccTryOutDay,
  530. RaiTryOutDay: v.RaiTryOutDay,
  531. TodoStatus: todoStatus,
  532. CanConfirm: canConfirm,
  533. HiddenConfirm: hiddenConfirm,
  534. HiddenCreate: hiddenCreate,
  535. TodoButtonColor: todoButtonColor,
  536. AllViewTotal: v.AllViewTotal,
  537. Deadline: tmpDeadline,
  538. IsShow: isShow,
  539. TryStageSlice: tryStageSlice,
  540. ShareSeller: v.ShareSeller,
  541. ShareSellerId: v.ShareSellerId,
  542. LatestServiceRecord: v.LatestServiceRecord.Format(utils.FormatDate2),
  543. ServiceYears: numYearDecimal.String(),
  544. }
  545. if strings.Contains(companyList.ApproveStatus, "已审批") {
  546. companyList.ApproveStatus = ""
  547. }
  548. companyLists = append(companyLists, companyList)
  549. }
  550. }
  551. if companyLists == nil {
  552. companyLists = make([]*CompanyListItem, 0)
  553. }
  554. page = paging.GetPaging(currentIndex, pageSize, total)
  555. resp.List = companyLists
  556. resp.Paging = page
  557. return
  558. }