cust_customer.go 18 KB

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