contant.go 3.1 KB

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