ziwen 1 year ago
parent
commit
2755c5c5de
2 changed files with 7 additions and 15 deletions
  1. 2 7
      controllers/cygx/activity_special_trip.go
  2. 5 8
      models/cygx/activity_special_trip.go

+ 2 - 7
controllers/cygx/activity_special_trip.go

@@ -182,12 +182,7 @@ func (this *ActivitySpecialTripCoAntroller) AddUser() {
 					}
 					items = append(items, item)
 				} else {
-					updateParams := make(map[string]interface{})
-					updateParams["IsValid"] = 1
-					updateParams["CreateTime"] = time.Now()
-					updateParams["IsCancel"] = 0
-					whereParam := map[string]interface{}{"user_id": uid, "activity_id": activityId}
-					err = cygx.UpdateByExpr(cygx.CygxActivitySpecialTrip{}, whereParam, updateParams)
+					err = cygx.UpdateSpecialTrip(1,0,uid, activityId)
 					if err != nil {
 						br.Msg = "报名失败,"
 						br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
@@ -206,7 +201,7 @@ func (this *ActivitySpecialTripCoAntroller) AddUser() {
 					return
 				}
 				if userType == 2 {
-					tripRemaining = tripRemaining+itemBill.BillDetailed-i
+					tripRemaining = tripRemaining + itemBill.BillDetailed-i
 					itemBill.Total = strconv.Itoa(tripRemaining) + "次"
 				} else {
 					for k, num := range mapChartName {

+ 5 - 8
models/cygx/activity_special_trip.go

@@ -290,13 +290,10 @@ func GetUserActivitySpecialTripCount(uid, activityId int) (count int, err error)
 	return
 }
 
-// 更新
-func UpdateByExpr(ptrStructOrTableName interface{}, where, updateParams map[string]interface{}) error {
+
+func UpdateSpecialTrip(isValid, isCancel, userId, activityId int) (err error) {
 	o := orm.NewOrm()
-	qs := o.QueryTable(ptrStructOrTableName)
-	for expr, exprV := range where {
-		qs = qs.Filter(expr, exprV)
-	}
-	_, err := qs.Update(updateParams)
-	return err
+	sql := `UPDATE cygx_activity_special_trip SET is_valid = ?,create_time=NOW(),is_cancel=?  WHERE user_id=? AND activity_id=? `
+	_, err = o.Raw(sql, isValid, isCancel, userId, activityId).Exec()
+	return
 }