acquirer_student_remark_logic.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package acquirer_student
  2. import (
  3. "context"
  4. "encoding/json"
  5. "git.i2edu.net/i2/i2-bill-api/model"
  6. "io/ioutil"
  7. "net/http"
  8. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  9. "git.i2edu.net/i2/i2-bill-api/internal/types"
  10. "git.i2edu.net/i2/go-zero/core/logx"
  11. )
  12. type AcquirerStudentRemarkLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewAcquirerStudentRemarkLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerStudentRemarkLogic {
  18. return AcquirerStudentRemarkLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. func (l *AcquirerStudentRemarkLogic) AcquirerStudentRemark(r *http.Request) (*types.Response, error) {
  25. // todo: add your logic here and delete this line
  26. body, err := ioutil.ReadAll(r.Body)
  27. if err != nil {
  28. logx.Error(err.Error())
  29. return &types.Response{500, err.Error(), nil}, nil
  30. }
  31. userId := l.svcCtx.GetUserIdByJwt(l.ctx)
  32. bean := new(model.I2billAcquirerStudentXorm)
  33. err = json.Unmarshal(body, bean)
  34. if bean.Id == 0 || userId != bean.UserId {
  35. return &types.Response{500, "参数错误", nil}, nil
  36. }
  37. if err != nil {
  38. logx.Error(err.Error())
  39. return &types.Response{500, err.Error(), nil}, nil
  40. }
  41. _, err = l.svcCtx.DB.Where("id = ?", bean.Id).Cols("remark").Update(bean)
  42. if err != nil {
  43. logx.Error(err.Error())
  44. return &types.Response{500, err.Error(), nil}, nil
  45. }
  46. return &types.Response{200, "", bean}, nil
  47. }