contant.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package cust
  2. import (
  3. "context"
  4. "dashoo.cn/common_definition/comm_def"
  5. "dashoo.cn/opms_libary/myerrors"
  6. "github.com/gogf/gf/errors/gerror"
  7. "github.com/gogf/gf/frame/g"
  8. "github.com/gogf/gf/os/gtime"
  9. "github.com/gogf/gf/util/gconv"
  10. "github.com/gogf/gf/util/gvalid"
  11. model "dashoo.cn/micro/app/model/cust"
  12. server "dashoo.cn/micro/app/service/cust"
  13. )
  14. type CustomerContantHeader struct{}
  15. const (
  16. ContantCreate = "创建联系人"
  17. ContantUpdateById = "修改联系人"
  18. ContantDeleteById = "删除联系人"
  19. )
  20. //创建客户联系人
  21. func (c *CustomerContantHeader) Create(ctx context.Context, req *model.CustCustomerContactSeq, rsp *comm_def.CommonMsg) error {
  22. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  23. return err
  24. }
  25. contactService, err := server.NewCustomerContactService(ctx)
  26. if err != nil {
  27. return myerrors.New("系统异常,请重新尝试", err)
  28. }
  29. err = contactService.Create(req)
  30. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  31. if err != nil {
  32. g.Log().Error(err)
  33. return err
  34. }
  35. var Ids []int64
  36. Ids = append(Ids, gconv.Int64(req.CustId))
  37. c.WriteCustLog(ctx, ContantCreate, Ids, req)
  38. return nil
  39. }
  40. //修改联系人
  41. func (c *CustomerContantHeader) UpdateById(ctx context.Context, req *model.UpdateCustCustomerContactSeq, rsp *comm_def.CommonMsg) error {
  42. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  43. return err
  44. }
  45. customerServer, err := server.NewCustomerContactService(ctx)
  46. if err != nil {
  47. return myerrors.New("系统异常,请重新尝试", err)
  48. }
  49. err = customerServer.UpdateById(req)
  50. var Ids []int64
  51. Ids = append(Ids, gconv.Int64(req.CustId))
  52. c.WriteCustLog(ctx, ContantUpdateById, Ids, req)
  53. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  54. if err != nil {
  55. g.Log().Error(err)
  56. return err
  57. }
  58. return nil
  59. }
  60. //客户联系人详情 //GetEntityById
  61. func (c *CustomerContantHeader) GetList(ctx context.Context, req *model.ContactSeq, rsp *comm_def.CommonMsg) error {
  62. if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
  63. return err
  64. }
  65. customerServer, err := server.NewCustomerContactService(ctx)
  66. if err != nil {
  67. return myerrors.New("系统异常,请重新尝试", err)
  68. }
  69. list, err := customerServer.GetList(req.CustId)
  70. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  71. if err != nil {
  72. return err
  73. }
  74. rsp.Data = g.Map{"list": list}
  75. return nil
  76. }
  77. //删除联系人
  78. func (c *CustomerContantHeader) DeleteById(ctx context.Context, req *model.DelCustomerContact, rsp *comm_def.CommonMsg) error {
  79. if req.Id == 0 {
  80. return gerror.New("参数有误!")
  81. }
  82. customerServer, err := server.NewCustomerContactService(ctx)
  83. if err != nil {
  84. return myerrors.New("系统异常,请重新尝试", err)
  85. }
  86. err = customerServer.DeleteById(req.Id)
  87. _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
  88. if err != nil {
  89. return err
  90. }
  91. var Ids []int64
  92. Ids = append(Ids, gconv.Int64(req.CustId))
  93. c.WriteCustLog(ctx, ContantDeleteById, Ids, req)
  94. return nil
  95. }
  96. //DeleteById
  97. //操作日志
  98. func (c *CustomerContantHeader) WriteCustLog(ctx context.Context, custType string, Id []int64, req interface{}) {
  99. CustomerService, _ := server.NewCustomerService(ctx)
  100. custDynameics := new(model.AddCustomerDynameicsReq)
  101. custDynameics.OpnType = custType
  102. custDynameics.OpnDate = gtime.Now()
  103. custDynameics.OpnContent = req
  104. CustomerService.OperationLog(ctx, Id, custDynameics)
  105. }