cust_customer.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. package cust
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "math"
  7. "strconv"
  8. "dashoo.cn/opms_libary/myerrors"
  9. "github.com/360EntSecGroup-Skylar/excelize"
  10. "github.com/gogf/gf/frame/g"
  11. "github.com/gogf/gf/os/gtime"
  12. "github.com/gogf/gf/text/gstr"
  13. "github.com/gogf/gf/util/gconv"
  14. "dashoo.cn/micro/app/dao/cust"
  15. platdao "dashoo.cn/micro/app/dao/plat"
  16. model "dashoo.cn/micro/app/model/cust"
  17. "dashoo.cn/micro/app/service"
  18. )
  19. const TIME_LAYOUT = "2006-01-02 15:04:05"
  20. type CustomerService struct {
  21. *service.ContextService
  22. Dao *cust.CustCustomerDao
  23. BelongDao *cust.CustCustomerBelongDao
  24. DynamicsDao *cust.CustCustomerDynamicsDao
  25. ContactDao *cust.CustCustomerContactDao
  26. FollowDao *platdao.PlatFollowupDao
  27. BelongServer *CustomerbelongService
  28. ContanctServer *CustomercontactService
  29. }
  30. var isPublic, noPublic = "10", "20" // 公海,非公海
  31. var isTransfer int8 = 1 //转移
  32. var isAllocation int8 = 2 //分配 Allocation
  33. var AllocaTion, OperaTion, Receive, Merge = "10", "20", "30", "40" // 10分配20转移30领取40合并
  34. type OpnType struct {
  35. OperaTion string
  36. }
  37. func NewCustomerService(ctx context.Context) (svc *CustomerService, err error) {
  38. svc = new(CustomerService)
  39. if svc.ContextService, err = svc.Init(ctx); err != nil {
  40. return nil, err
  41. }
  42. svc.Dao = cust.NewCustCustomerDao(svc.Tenant)
  43. svc.BelongDao = cust.NewCustCustomerBelongDao(svc.Tenant)
  44. svc.DynamicsDao = cust.NewCustCustomerDynamicsDao(svc.Tenant)
  45. svc.ContactDao = cust.NewCustCustomerContactDao(svc.Tenant)
  46. svc.FollowDao = platdao.NewPlatFollowupDao(svc.Tenant)
  47. svc.BelongServer, _ = NewCustomerBelongService(ctx)
  48. svc.ContanctServer, _ = NewCustomerContactService(ctx)
  49. return svc, nil
  50. }
  51. //GetList 客户列表列表
  52. func (s *CustomerService) GetList(req *model.CustCustomerSearchReq) (total int, customerList []*model.CustList, err error) {
  53. Model := s.Dao.M
  54. if req.TargetType == "" {
  55. if !req.IsPublic {
  56. Model = Model.Where(s.Dao.Columns.SalesId, s.CxtUser.Id).Where(s.Dao.Columns.IsPublic, noPublic)
  57. } else {
  58. Model = Model.Where(s.Dao.Columns.IsPublic, isPublic)
  59. }
  60. }
  61. //客户名称
  62. if req.CustName != "" {
  63. Model = Model.Where(s.Dao.Columns.CustName+" like ?", "%"+req.CustName+"%")
  64. }
  65. //客户编码
  66. if req.CustCode != "" {
  67. Model = Model.Where(s.Dao.Columns.CustCode+" like ?", "%"+req.CustCode+"%")
  68. }
  69. //客户行业
  70. if req.CustIndustry != "" {
  71. Model = Model.Where(s.Dao.Columns.CustIndustry+" like ?", "%"+req.CustIndustry+"%")
  72. }
  73. //客户级别
  74. if req.CustLevel != "" {
  75. Model = Model.Where(s.Dao.Columns.CustLevel, req.CustLevel)
  76. }
  77. //
  78. if req.FollowUpDate != "" {
  79. Model = Model.Where(s.Dao.Columns.FollowUpDate+" like ? ", req.FollowUpDate+"%")
  80. }
  81. total, err = Model.Count()
  82. if err != nil {
  83. g.Log().Error(err)
  84. return
  85. }
  86. err = Model.Page(req.GetPage()).Order("id desc").Scan(&customerList)
  87. if err != nil {
  88. g.Log().Error(err)
  89. return
  90. }
  91. return
  92. }
  93. //Create 创建客户
  94. func (s *CustomerService) Create(req *model.CustomerAddSeq) (insertId int64, err error) {
  95. cusTomer := new(model.CustCustomer)
  96. count, err := s.Dao.Where(s.Dao.Columns.CustName, req.CustName).Count()
  97. if err != nil {
  98. g.Log().Error(err)
  99. return
  100. }
  101. if count > 0 {
  102. return 0, myerrors.NewMsgError(nil, "该客户信息已存在,不可重复添加")
  103. }
  104. if err = gconv.Struct(req, cusTomer); err != nil {
  105. return
  106. }
  107. service.SetCreatedInfo(cusTomer, s.GetCxtUserId(), s.GetCxtUserName())
  108. cusTomer.CustCode = "CT" + strconv.Itoa(int(gtime.Timestamp()))
  109. cusTomer.CustStatus = "10"
  110. roles := s.GetCxtUserRoles()
  111. isSales := false
  112. for _, v := range roles {
  113. if v == "Sales" { // 销售角色
  114. isSales = true
  115. }
  116. }
  117. // 销售角色
  118. if isSales {
  119. cusTomer.IsPublic = noPublic
  120. cusTomer.SalesId = s.GetCxtUserId()
  121. cusTomer.SalesName = s.GetCxtUserName()
  122. insertId, err = s.Dao.InsertAndGetId(cusTomer)
  123. if err != nil {
  124. g.Log().Error(err)
  125. return 0, err
  126. }
  127. s.CreateBelong(int(insertId))
  128. } else {
  129. cusTomer.IsPublic = isPublic
  130. insertId, err = s.Dao.InsertAndGetId(cusTomer)
  131. if err != nil {
  132. g.Log().Error(err)
  133. return 0, err
  134. }
  135. }
  136. return insertId, err
  137. }
  138. //CreateBelong 创建客户归属信息
  139. func (s *CustomerService) CreateBelong(custId int) (insertId int64, err error) {
  140. belong := new(model.CustCustomerBelong)
  141. service.SetCreatedInfo(belong, s.GetCxtUserId(), s.GetCxtUserName())
  142. belong.CustId = custId
  143. belong.SaleName = s.GetCxtUserName()
  144. belong.OpnType = AllocaTion
  145. belong.OpnPeople = s.GetCxtUserName()
  146. belong.OpnDatetime = gtime.Now()
  147. insertId, err = s.BelongDao.InsertAndGetId(belong)
  148. if err != nil {
  149. g.Log().Error(err)
  150. return
  151. }
  152. return
  153. }
  154. //删除客户
  155. func (s *CustomerService) DeleteById(id int) error {
  156. Model := s.Dao
  157. ContactModel := s.ContactDao //联系人
  158. BelongModel := s.BelongDao
  159. customerCount, err := Model.Where(s.Dao.Columns.Id, id).Count()
  160. if err != nil {
  161. return myerrors.New(" 删除客户 DeleteById Sql执行异常", err)
  162. }
  163. if customerCount == 0 {
  164. err = myerrors.NewMsgError(nil, "客户信息不存在")
  165. return err
  166. }
  167. //删除客户表
  168. _, err = Model.Where(s.Dao.Columns.Id, id).Delete()
  169. if err == nil {
  170. _, err = ContactModel.Where(s.ContactDao.Columns.CustId, id).Delete()
  171. if err == nil {
  172. _, err = BelongModel.Where(s.BelongDao.Columns.CustId, id).Delete()
  173. if err != nil {
  174. return myerrors.New(" 删除客户 BelongModel Sql执行异常", err)
  175. }
  176. } else {
  177. return myerrors.New(" 删除客户 ContactModel Sql执行异常", err)
  178. }
  179. } else {
  180. return myerrors.New(" 删除客户 ColumnsModel Sql执行异常", err)
  181. }
  182. return nil
  183. }
  184. //UpdateById 修改客户
  185. func (s *CustomerService) UpdateById(req *model.UpdateCustomer) (err error) {
  186. //判断数据是否存在
  187. count, err := s.Dao.Where(s.Dao.Columns.Id, req.Id).Count()
  188. if err != nil {
  189. return
  190. }
  191. if count == 0 {
  192. return
  193. }
  194. //新的客户名字是否存在
  195. num, err := s.Dao.Where(s.Dao.Columns.CustName, req.CustName).WhereNot(s.Dao.Columns.Id, req.Id).Count()
  196. if err != nil {
  197. err = myerrors.New(" Sql执行异常", err)
  198. return
  199. }
  200. if num > 0 {
  201. return myerrors.NewMsgError(nil, fmt.Sprintf("客户名称[%s]已存在", req.CustName))
  202. }
  203. CustomertData := new(model.CustomerAddSeq)
  204. if err = gconv.Struct(req, CustomertData); err != nil {
  205. return
  206. }
  207. service.SetUpdatedInfo(CustomertData, s.GetCxtUserId(), s.GetCxtUserName())
  208. _, err = s.Dao.FieldsEx(s.Dao.Columns.CreatedTime, s.Dao.Columns.CreatedBy, s.Dao.Columns.CreatedName, s.Dao.Columns.Id, s.Dao.Columns.CustCode, s.Dao.Columns.SalesName, s.Dao.Columns.SalesId).
  209. WherePri(s.Dao.Columns.Id, req.Id).Update(CustomertData)
  210. if err != nil {
  211. err = myerrors.New("修改用户信息失败", err)
  212. return
  213. }
  214. return
  215. }
  216. //MoveToPubic 移入公海
  217. func (s *CustomerService) MoveToPubic(ids []int64) (err error) {
  218. count, err := s.Dao.WhereIn(s.Dao.Columns.Id, ids).Count()
  219. if err != nil {
  220. g.Log().Error(err)
  221. return
  222. }
  223. if count == 0 {
  224. err = myerrors.NewMsgError(nil, "没有要移除的数据")
  225. return
  226. }
  227. _, err = s.Dao.Data(g.Map{
  228. "is_public": isPublic,
  229. "sales_id": 0,
  230. "sales_name": "",
  231. "dept_id": 0,
  232. "dept_name": "",
  233. "create_time": gtime.Now(),
  234. "updated_by": s.GetCxtUserId(),
  235. "updated_name": s.GetCxtUserName(),
  236. "updated_time": gtime.Now(),
  237. }).WhereIn(s.ContactDao.Columns.Id, ids).Update()
  238. if err != nil {
  239. g.Log().Error(err)
  240. return
  241. }
  242. return nil
  243. }
  244. //AssignCustomer 分配客户
  245. func (s *CustomerService) AssignCustomer(req *model.AssignCustomerReq) (err error) {
  246. data, err := s.Dao.Where("id in (?)", req.Ids).LockShared().All()
  247. if err != nil {
  248. g.Log().Error(err)
  249. return
  250. }
  251. if len(data) == 0 {
  252. return myerrors.NewMsgError(nil, "无可分配客户")
  253. }
  254. for _, v := range data {
  255. if v.SalesId != 0 {
  256. return myerrors.NewMsgError(nil, fmt.Sprintf("客户名称[%s]已被领取或分配", v.CustName))
  257. }
  258. }
  259. s.ChangeCustBelong(req.Ids, req.SalesId, req.SalesName)
  260. if req.Receive != "" {
  261. req.Receive = Receive
  262. } else {
  263. req.Receive = AllocaTion
  264. }
  265. s.BatchCreatebelong(data, req)
  266. return
  267. }
  268. //GetEntityById 客户详情
  269. func (s *CustomerService) GetEntityById(ids []int64) (entityInfo []*model.CustList, err error) {
  270. Model := s.Dao //
  271. err = Model.Where(cust.CustCustomer.Columns.Id+" in (?)", ids).Scan(&entityInfo)
  272. if err != nil {
  273. return nil, myerrors.New("获取用户数据失败", err)
  274. }
  275. for _, v := range entityInfo {
  276. v.FollowUpDate = gstr.SubStr(v.FollowUpDate, 0, 16)
  277. v.CreatedTime = gstr.SubStr(v.CreatedTime, 0, 16)
  278. }
  279. return
  280. }
  281. //GetCustNameIsExist 获取客户名称
  282. func (s *CustomerService) GetCustNameIsExist(name string) (exist bool, err error) {
  283. count, err := s.Dao.Where(cust.CustCustomer.Columns.CustName, name).Count()
  284. if err != nil {
  285. g.Log().Error(err)
  286. return
  287. }
  288. exist = false
  289. if count > 0 {
  290. exist = true
  291. }
  292. return
  293. }
  294. //CustAbstract 客户摘要
  295. func (s *CustomerService) CustAbstract(id int64) (followInfo *model.Follow, err error) {
  296. custModel := s.Dao //
  297. Model := s.FollowDao
  298. count, err := Model.Where(s.FollowDao.Columns.CustId, id).Count()
  299. if err != nil {
  300. return nil, myerrors.New(" CustAbstract Sql执行异常", err)
  301. }
  302. followInfo = new(model.Follow)
  303. followInfo.FollowCount = count
  304. followTime, err := custModel.Fields(s.Dao.Columns.FollowUpDate, s.Dao.Columns.CreatedTime).FindOne(id)
  305. if err != nil {
  306. err = myerrors.New("CustAbstract Sql执行错误", err)
  307. return
  308. }
  309. now := gtime.Now()
  310. var hours float64
  311. if followTime.FollowUpDate == nil {
  312. poor := now.Sub(gtime.New(followTime.CreatedTime))
  313. hours = float64(poor.Hours() / 24)
  314. } else {
  315. poor := now.Sub(gtime.New(followTime.FollowUpDate))
  316. hours = float64(poor.Hours() / 24)
  317. }
  318. if hours < 0 {
  319. followInfo.NotFollowDay = 0
  320. } else {
  321. followInfo.NotFollowDay = int(math.Floor(hours))
  322. }
  323. return
  324. }
  325. //TransCustomer 转移客户
  326. func (s *CustomerService) TransCustomer(req *model.AssignCustomerReq) (err error) {
  327. data, err := s.Dao.Fields("sales_id,sales_name,id").Where("id in (?)", req.Ids).All()
  328. if err != nil {
  329. g.Log().Error(err)
  330. return err
  331. }
  332. if len(data) == 0 {
  333. err = myerrors.New("该数据不存在", err)
  334. return
  335. }
  336. s.ChangeCustBelong(req.Ids, req.SalesId, req.SalesName)
  337. s.BatchCreatebelong(data, req)
  338. return
  339. }
  340. //ChangeCustBelong 变更客户所属关系
  341. func (s *CustomerService) ChangeCustBelong(ids []int64, salesId int64, salesName string) error {
  342. _, err := s.Dao.Data(g.Map{
  343. "sales_id": salesId,
  344. "is_public": noPublic,
  345. "sales_name": salesName,
  346. "updated_by": s.GetCxtUserId(),
  347. "updated_name": s.GetCxtUserName(),
  348. "updated_time": gtime.Now(),
  349. }).Where("id in (?)", ids).Update()
  350. if err != nil {
  351. g.Log().Error(err)
  352. return err
  353. }
  354. return nil
  355. }
  356. //OperationLog 客户操作日志
  357. func (s *CustomerService) OperationLog(ctx context.Context, ids []int64, req *model.AddCustomerDynameicsReq) (err error) {
  358. cusDynameics := new(model.CustCustomerDynamics)
  359. if err = gconv.Struct(req, cusDynameics); err != nil {
  360. err = myerrors.NewMsgError(nil, "操作日志验证结构体失败")
  361. return
  362. }
  363. maps := []map[string]interface{}{}
  364. for _, v := range ids {
  365. contact := map[string]interface{}{}
  366. contact["cust_id"] = v
  367. contact["opn_people_id"] = s.GetCxtUserId()
  368. contact["opn_people"] = s.GetCxtUserName()
  369. contact["opn_date"] = req.OpnDate
  370. contact["opn_type"] = req.OpnType
  371. contact["remark"] = ""
  372. contact["created_by"] = s.GetCxtUserId()
  373. contact["created_name"] = s.GetCxtUserName()
  374. contact["created_by"] = s.GetCxtUserId()
  375. contact["created_time"] = gtime.Now()
  376. contact["opn_content"] = req.OpnContent
  377. maps = append(maps, contact)
  378. }
  379. lastId, err := s.DynamicsDao.InsertAndGetId(maps)
  380. if err != nil {
  381. err = myerrors.New("OperationLog Sql执行失败", err)
  382. return
  383. }
  384. if lastId == 0 {
  385. err = myerrors.New("客户操作日志失败", err)
  386. return
  387. }
  388. return
  389. }
  390. //GetDynamicsList 客户动态
  391. func (s *CustomerService) GetDynamicsList(req *model.CustomerDynameicsReq) (total int, result []interface{}, err error) {
  392. total, err = s.DynamicsDao.Where("cust_id = ", req.CustId).Count()
  393. if err != nil {
  394. g.Log().Error(err)
  395. return
  396. }
  397. dynamics := []*model.CustomerDynameicsRep{}
  398. err = s.DynamicsDao.Where("CustId = ?", req.CustId).Order("created_time desc").Scan(&dynamics)
  399. dynamicsList := make(map[string][]*model.CustomerDynameicsRep)
  400. for _, v := range dynamics {
  401. gt1 := gtime.New(v.OpnDate)
  402. opnDate := gt1.Format("Y-m-d")
  403. dynamicsList[opnDate] = append(dynamicsList[opnDate], &model.CustomerDynameicsRep{
  404. OpnPeople: v.OpnPeople,
  405. OpnDate: v.OpnDate,
  406. OpnType: v.OpnType,
  407. OpnContent: v.OpnContent,
  408. })
  409. }
  410. result = append(result, dynamicsList)
  411. return
  412. }
  413. //MergeCustomer 合并客户
  414. func (s *CustomerService) MergeCustomer(req *model.MergecustomerRep) (err error) {
  415. Model := s.Dao.M
  416. //ContactModel := s.ContactDao.M
  417. BelongDao := s.BelongDao
  418. //当前目标客户是否存在
  419. customerCount, err := s.Dao.Where(s.Dao.Columns.Id, req.Id).Count()
  420. if err != nil {
  421. g.Log().Error(err)
  422. return
  423. }
  424. if customerCount == 0 {
  425. return myerrors.NewMsgError(nil, "该客户不存在")
  426. }
  427. ContactModel := s.ContactDao
  428. _, err = ContactModel.Where(s.ContactDao.Columns.CustId+" in (?)", req.ChooseId).WhereOr(s.ContactDao.Columns.CustId, req.Id).Delete()
  429. if err != nil {
  430. err = myerrors.New("MergeCustomer 合并联系人 Sql执行异常", err)
  431. return
  432. }
  433. CustomertData := new(model.CustomerAddSeq)
  434. if err = gconv.Struct(req, CustomertData); err != nil {
  435. return
  436. }
  437. service.SetUpdatedInfo(CustomertData, s.GetCxtUserId(), s.GetCxtUserName())
  438. _, err = Model.FieldsEx(s.Dao.Columns.CreatedTime, s.Dao.Columns.CreatedBy,
  439. s.Dao.Columns.CreatedName, s.Dao.Columns.Id,
  440. s.Dao.Columns.CustCode).WherePri(s.Dao.Columns.Id, req.Id).Update(CustomertData)
  441. if err != nil {
  442. err = myerrors.New("MergeCustomer 合并客户 update Sql执行异常", err)
  443. return
  444. }
  445. //删除被合并的客户信息
  446. _, err = Model.Where(s.Dao.Columns.Id+" in (?)", req.ChooseId).Delete()
  447. if err != nil {
  448. err = myerrors.New("MergeCustomer 删除被合并的客户信息 Sql执行异常", err)
  449. return
  450. }
  451. //删除 所选客户销售联系人
  452. _, err = BelongDao.Where(s.BelongDao.Columns.CustId+" in (?)", req.ChooseId).WhereOr(s.BelongDao.Columns.CustId, req.Id).Delete()
  453. if err != nil {
  454. err = myerrors.New("MergeCustomer 删除所选客户销售联系人 Sql执行异常", err)
  455. return
  456. }
  457. //插入一条合并成功的归属记录
  458. belongService := s.BelongServer //
  459. req.AddCustomerBelong.CustId = req.Id
  460. req.AddCustomerBelong.OpnType = Merge
  461. req.AddCustomerBelong.OpnPeople = s.GetCxtUserName()
  462. req.AddCustomerBelong.OpnDatetime = gtime.Now()
  463. req.AddCustomerBelong.SaleName = req.SalesName
  464. belongService.Create(req.AddCustomerBelong)
  465. return
  466. }
  467. //联系人(合并)
  468. func (s *CustomerService) Createcontact(id int, Ids []int64, req *model.CustCustomerContactSeq) (err error) {
  469. ContactModel := s.ContactDao
  470. _, err = ContactModel.Where(s.ContactDao.Columns.CustId+" in (?)", Ids).WhereOr(s.ContactDao.Columns.CustId, id).Delete()
  471. if err != nil {
  472. err = myerrors.New("Createcontact 合并删除联系人 Sql执行异常", err)
  473. return
  474. }
  475. contactService := s.ContanctServer //new(CustomercontactService)
  476. err = contactService.Create(req)
  477. if err != nil {
  478. err = myerrors.New("Createcontact 合并删除并创建联系人 Sql执行异常", err)
  479. return
  480. }
  481. return
  482. }
  483. //BatchCreatebelong 批量插入客户归属记录表//parameter map[string]string
  484. func (s *CustomerService) BatchCreatebelong(rep []*model.CustCustomer, req *model.AssignCustomerReq) (err error) {
  485. var belongData []*model.CustCustomerBelong
  486. userName := s.GetCxtUserName()
  487. for _, v := range rep {
  488. orig_sale_name := v.SalesName
  489. belong := new(model.CustCustomerBelong) //map[string]interface{}{}
  490. belong.CustId = v.Id
  491. belong.SaleName = req.SalesName
  492. belong.OrigSaleName = orig_sale_name
  493. belong.OpnType = req.Receive
  494. belong.OpnPeople = userName
  495. belong.CreatedName = userName
  496. belong.OpnDatetime = gtime.Now()
  497. belong.Remark = req.Remark
  498. belong.CreatedBy = s.GetCxtUserId()
  499. belongData = append(belongData, belong)
  500. }
  501. lastId, err := s.BelongDao.InsertAndGetId(belongData)
  502. if err != nil {
  503. g.Log().Error(err)
  504. return err
  505. }
  506. if lastId == 0 {
  507. err = myerrors.New("BatchCreatebelong 插入", err)
  508. return err
  509. }
  510. return
  511. }
  512. //导出数据
  513. func (s *CustomerService) Export(req *model.CustCustomerExport) (content *model.CustExport, err error) {
  514. var con model.CustExport
  515. total, data, err := s.GetList(&req.CustCustomerSearchReq)
  516. if err != nil {
  517. return
  518. }
  519. f := excelize.NewFile()
  520. index := f.NewSheet("Sheet1")
  521. for index, item := range req.Columns {
  522. sheetPosition := service.Div(index+1) + "1"
  523. f.SetCellValue("Sheet1", sheetPosition, item)
  524. }
  525. if total > 0 {
  526. for ck, item := range data {
  527. for index, v := range req.Columns {
  528. // "CustCode":客户编码
  529. if v == "客户编码" {
  530. f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustCode)
  531. }
  532. if v == "客户名称" {
  533. f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustName)
  534. }
  535. if v == "助记名" {
  536. f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.AbbrName)
  537. }
  538. if v == "助记名" {
  539. f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.AbbrName)
  540. }
  541. if v == "所在地区" {
  542. f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustLocation)
  543. }
  544. if v == "客户行业" {
  545. f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustIndustry)
  546. }
  547. if v == "客户级别" {
  548. f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustLevel)
  549. }
  550. if v == "客户状态" {
  551. var CustStatus string
  552. CustStatus = "正常"
  553. if item.CustStatus != "10" {
  554. CustStatus = "异常"
  555. }
  556. f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), CustStatus)
  557. }
  558. if v == "最后跟进时间" {
  559. f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.FollowUpDate)
  560. }
  561. if v == "创建时间" {
  562. f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CreatedTime)
  563. }
  564. }
  565. }
  566. }
  567. f.SetActiveSheet(index)
  568. var buffer *bytes.Buffer
  569. buffer, _ = f.WriteToBuffer()
  570. con.Content = buffer.Bytes()
  571. return &con, err
  572. }