operateReceiveAddress.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "youngee_b_api/consts"
  6. "youngee_b_api/db"
  7. "youngee_b_api/middleware"
  8. "youngee_b_api/model/http_model"
  9. "youngee_b_api/util"
  10. )
  11. func WrapOperateReceiveAddressHandler(ctx *gin.Context) {
  12. handler := newOperateReceiveAddressHandler(ctx)
  13. baseRun(handler)
  14. }
  15. type OperateReceiveAddress struct {
  16. ctx *gin.Context
  17. req *http_model.OperateReceiveAddressRequest
  18. resp *http_model.CommonResponse
  19. }
  20. func (o OperateReceiveAddress) getContext() *gin.Context {
  21. return o.ctx
  22. }
  23. func (o OperateReceiveAddress) getResponse() interface{} {
  24. return o.resp
  25. }
  26. func (o OperateReceiveAddress) getRequest() interface{} {
  27. return o.req
  28. }
  29. func (o OperateReceiveAddress) run() {
  30. auth := middleware.GetSessionAuth(o.ctx)
  31. enterpriseID := auth.EnterpriseID
  32. err := db.OperateReceiveAddress(o.ctx, enterpriseID, o.req)
  33. if err != nil {
  34. // 数据库查询失败,返回5001
  35. logrus.Errorf("[OperateReceiveAddress] call OperateReceiveAddress err:%+v\n", err)
  36. util.HandlerPackErrorResp(o.resp, consts.ErrorInternal, "")
  37. logrus.Info("OperateReceiveAddress fail,req:%+v", o.req)
  38. return
  39. }
  40. if o.req.OperateType == 2 {
  41. o.resp.Message = "已删除该地址信息"
  42. } else {
  43. o.resp.Message = "修改地址信息成功"
  44. }
  45. }
  46. func (o OperateReceiveAddress) checkParam() error {
  47. return nil
  48. }
  49. func newOperateReceiveAddressHandler(ctx *gin.Context) *OperateReceiveAddress {
  50. return &OperateReceiveAddress{
  51. ctx: ctx,
  52. req: http_model.NewOperateReceiveAddressRequest(),
  53. resp: http_model.NewOperateReceiveAddressResponse(),
  54. }
  55. }