zhou.xiaoning 3 роки тому
батько
коміт
38c16341b4
1 змінених файлів з 65 додано та 59 видалено
  1. 65 59
      models/ferroalloy.go

+ 65 - 59
models/ferroalloy.go

@@ -137,38 +137,75 @@ func (r *THJSigninReq) Signin() (rsp *THJSigninRsp, err error) {
 
 	now := time.Now()
 
-	// 判断用户积分表是否已经存在此用户
-	curscore := 0
-	t := Thjuserscore{USERID: r.USERID}
-	has, err := session.Exist(&t)
-	if err != nil {
-		session.Rollback()
-		logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
-		return nil, errors.New("数据错误")
-	}
-	if has {
-		// 更新积分
-		curscore = int(t.CURSCORE)
-		t.CURSCORE += int64(c.PARMA1)
-		t.UPDATETIME = now
-		// _, err = session.Update(&t)
-		sql := fmt.Sprintf(`UPDATE THJ_USERSCORE  
-			SET CURSCORE = %v, UPDATETIME = to_date('%v', 'yyyy-mm-dd hh24:mi:ss') 
-			WHERE USERID = %v`,
-			t.CURSCORE, t.UPDATETIME.Format("2006-01-02 15:04:05"), t.USERID)
-		_, err = session.Exec(sql)
+	// 签到积分配置大于0才记积分和流水
+	if c.PARMA1 > 0 {
+		// 判断用户积分表是否已经存在此用户
+		curscore := 0
+		t := Thjuserscore{USERID: r.USERID}
+		has, err := session.Exist(&t)
 		if err != nil {
 			session.Rollback()
 			logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
 			return nil, errors.New("数据错误")
 		}
-	} else {
-		// 新增用户积分记录
-		t.CURSCORE = int64(c.PARMA1)
-		t.UPDATETIME = now
-		// _, err = session.Insert(&t)
-		sql := fmt.Sprintf(`INSERT INTO THJ_USERSCORE VALUES (%v, %v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'))`,
-			t.USERID, t.CURSCORE, 0, t.UPDATETIME.Format("2006-01-02 15:04:05"))
+		if has {
+			// 更新积分
+			curscore = int(t.CURSCORE)
+			t.CURSCORE += int64(c.PARMA1)
+			t.UPDATETIME = now
+			// _, err = session.Update(&t)
+			sql := fmt.Sprintf(`UPDATE THJ_USERSCORE  
+		SET CURSCORE = %v, UPDATETIME = to_date('%v', 'yyyy-mm-dd hh24:mi:ss') 
+		WHERE USERID = %v`,
+				t.CURSCORE, t.UPDATETIME.Format("2006-01-02 15:04:05"), t.USERID)
+			_, err = session.Exec(sql)
+			if err != nil {
+				session.Rollback()
+				logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
+				return nil, errors.New("数据错误")
+			}
+		} else {
+			// 新增用户积分记录
+			t.CURSCORE = int64(c.PARMA1)
+			t.UPDATETIME = now
+			// _, err = session.Insert(&t)
+			sql := fmt.Sprintf(`INSERT INTO THJ_USERSCORE VALUES (%v, %v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'))`,
+				t.USERID, t.CURSCORE, 0, t.UPDATETIME.Format("2006-01-02 15:04:05"))
+			_, err = session.Exec(sql)
+			if err != nil {
+				session.Rollback()
+				logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
+				return nil, errors.New("数据错误")
+			}
+		}
+
+		// 记录积分流水
+		q := Thjuserscorelog{}
+		seqMap, err := session.QueryString("SELECT SEQ_THJ_USERSCORELOG.nextval SEQID FROM dual")
+		if err != nil {
+			session.Rollback()
+			logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
+			return nil, errors.New("数据错误")
+		}
+		if len(seqMap) <= 0 {
+			session.Rollback()
+			return nil, errors.New("获取自增ID错误")
+		}
+		seqID, _ := strconv.Atoi(seqMap[0]["SEQID"])
+		q.AUTOID = int64(seqID)
+		q.USERID = r.USERID
+		q.SCORECONFIGTYPE = 2 // 2:签到送积分
+		q.SCORE = float64(c.PARMA1)
+		q.ORISCORE = float64(curscore)
+		q.CURSCORE = float64(t.CURSCORE)
+		q.CREATETIME = now
+		q.RELATEDORDERID = r.USERID
+		// _, err = session.Insert(&q)
+		sql := fmt.Sprintf(`INSERT INTO THJ_USERSCORELOG 
+			(AUTOID, USERID, SCORECONFIGTYPE, SCORE, ORISCORE, CURSCORE, CREATETIME)
+			VALUES 
+			(%v, %v, %v, %v, %v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'))`,
+			q.AUTOID, q.USERID, q.SCORECONFIGTYPE, q.SCORE, q.ORISCORE, q.CURSCORE, q.CREATETIME.Format("2006-01-02 15:04:05"))
 		_, err = session.Exec(sql)
 		if err != nil {
 			session.Rollback()
@@ -177,39 +214,8 @@ func (r *THJSigninReq) Signin() (rsp *THJSigninRsp, err error) {
 		}
 	}
 
-	// 记录积分流水
-	q := Thjuserscorelog{}
-	seqMap, err := session.QueryString("SELECT SEQ_THJ_USERSCORELOG.nextval SEQID FROM dual")
-	if err != nil {
-		session.Rollback()
-		logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
-		return nil, errors.New("数据错误")
-	}
-	if len(seqMap) <= 0 {
-		session.Rollback()
-		return nil, errors.New("获取自增ID错误")
-	}
-	seqID, _ := strconv.Atoi(seqMap[0]["SEQID"])
-	q.AUTOID = int64(seqID)
-	q.USERID = r.USERID
-	q.SCORECONFIGTYPE = 2 // 2:签到送积分
-	q.SCORE = float64(c.PARMA1)
-	q.ORISCORE = float64(curscore)
-	q.CURSCORE = float64(t.CURSCORE)
-	q.CREATETIME = now
-	q.RELATEDORDERID = r.USERID
-	// _, err = session.Insert(&q)
-	sql := fmt.Sprintf(`INSERT INTO THJ_USERSCORELOG VALUES (%v, %v, %v, %v, %v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'), '%v', NULL)`,
-		q.AUTOID, q.USERID, q.SCORECONFIGTYPE, q.SCORE, q.ORISCORE, q.CURSCORE, q.CREATETIME.Format("2006-01-02 15:04:05"), "")
-	_, err = session.Exec(sql)
-	if err != nil {
-		session.Rollback()
-		logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
-		return nil, errors.New("数据错误")
-	}
-
 	// 增加签到记录
-	sql = fmt.Sprintf(`INSERT INTO THJ_SIGNIN VALUES (%v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'))`,
+	sql := fmt.Sprintf(`INSERT INTO THJ_SIGNIN VALUES (%v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'))`,
 		r.USERID, now.Format("20060102"), now.Format("2006-01-02 15:04:05"))
 	_, err = session.Exec(sql)
 	if err != nil {