From 9a19e96d4ff0ba1a6266a124921b76b130442feb Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Mon, 17 Apr 2023 18:15:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=96=8B=E8=8A=82=E6=B4=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/model/act_m/act_m.go | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 internal/model/act_m/act_m.go diff --git a/internal/model/act_m/act_m.go b/internal/model/act_m/act_m.go new file mode 100644 index 0000000..83db70c --- /dev/null +++ b/internal/model/act_m/act_m.go @@ -0,0 +1,47 @@ +package act_m + +import ( + "fmt" + "git.hilo.cn/hilo-common/domain" +) + +type ActPoint struct { + AcId uint64 `json:"ac_id"` + UserId uint64 `json:"user_id"` + Point uint64 `json:"point"` +} + +type ActPointLog struct { + Id uint64 `json:"id"` + AcId uint64 `json:"ac_id"` + UserId uint64 `json:"user_id"` + Point uint64 `json:"point"` + AddReduce uint8 `json:"add_reduce"` // 1.增加2.减少 + Remark string `json:"remark"` +} + +func (this *ActPoint) Add(model *domain.Model) error { + sql := "insert into hilo.act_point (ac_id,user_id,point) " + + "values(?,?,?) on duplicate key update point = point+values(point);" + return model.DB().Exec(sql, this.AcId, this.UserId, this.Point).Error +} + +func (this *ActPoint) Reduce(model *domain.Model) error { + sql := "update hilo.act_point set point = point - ? where ac_id=? and user_id=? and point >= ?;" + result := model.DB().Exec(sql, this.Point, this.AcId, this.UserId, this.Point) + if result.Error != nil { + return result.Error + } + if result.RowsAffected <= 0 { + return fmt.Errorf("bizerr.TransactionFailed") + } + return nil +} + +func CreateActPointLog(model *domain.Model, info *ActPointLog) error { + err := model.DB().Create(&info).Error + if err != nil { + return err + } + return nil +} -- 2.22.0