Kaynağa Gözat

收单备注

icole 4 yıl önce
ebeveyn
işleme
0c532c0244

+ 22 - 0
internal/handler/acquirer_student/acquirer_student_remark_handler.go

@@ -0,0 +1,22 @@
+package acquirer_student
+
+import (
+	"net/http"
+
+	"git.i2edu.net/i2/go-zero/rest/httpx"
+	logic "git.i2edu.net/i2/i2-bill-api/internal/logic/acquirer_student"
+	"git.i2edu.net/i2/i2-bill-api/internal/svc"
+)
+
+func AcquirerStudentRemarkHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+
+		l := logic.NewAcquirerStudentRemarkLogic(r.Context(), ctx)
+		resp, err := l.AcquirerStudentRemark(r)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 53 - 0
internal/logic/acquirer_student/acquirer_student_remark_logic.go

@@ -0,0 +1,53 @@
+package acquirer_student
+
+import (
+	"context"
+	"encoding/json"
+	"git.i2edu.net/i2/i2-bill-api/model"
+	"io/ioutil"
+	"net/http"
+
+	"git.i2edu.net/i2/i2-bill-api/internal/svc"
+	"git.i2edu.net/i2/i2-bill-api/internal/types"
+
+	"git.i2edu.net/i2/go-zero/core/logx"
+)
+
+type AcquirerStudentRemarkLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewAcquirerStudentRemarkLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerStudentRemarkLogic {
+	return AcquirerStudentRemarkLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *AcquirerStudentRemarkLogic) AcquirerStudentRemark(r *http.Request) (*types.Response, error) {
+	// todo: add your logic here and delete this line
+	body, err := ioutil.ReadAll(r.Body)
+	if err != nil {
+		logx.Error(err.Error())
+		return &types.Response{500, err.Error(), nil}, nil
+	}
+	userId := l.svcCtx.GetUserIdByJwt(l.ctx)
+	bean := new(model.I2billAcquirerStudentXorm)
+	err = json.Unmarshal(body, bean)
+	if bean.Id == 0 || userId != bean.UserId {
+		return &types.Response{500, "参数错误", nil}, nil
+	}
+	if err != nil {
+		logx.Error(err.Error())
+		return &types.Response{500, err.Error(), nil}, nil
+	}
+	_, err = l.svcCtx.DB.Where("id = ? and user_id = ?", bean.Id).Cols("remark").Update(bean)
+	if err != nil {
+		logx.Error(err.Error())
+		return &types.Response{500, err.Error(), nil}, nil
+	}
+	return &types.Response{200, "", bean}, nil
+}