소스 검색

充值修改

jiaojiao7 4 년 전
부모
커밋
89100fce6d
4개의 변경된 파일19개의 추가작업 그리고 13개의 파일을 삭제
  1. 5 3
      manage/user/userRecharge.go
  2. 5 5
      service/userRecharge.go
  3. 2 0
      static/templates/moneyRecharge.html
  4. 7 5
      utils/api_util.go

+ 5 - 3
manage/user/userRecharge.go

@@ -13,16 +13,18 @@ import (
 func moneyRecharge(c *gin.Context) {
 	appid := c.PostForm("appid")
 	money, err := strconv.Atoi(c.PostForm("money"))
+	remark := c.PostForm("remark")
 	if err != nil {
 		response.FailWithDetailed(response.ParamError, nil, "参数错误", c)
 		return
 	}
 	p := gin.H{
-		"appid": appid,
-		"money": money,
+		"appid":  appid,
+		"money":  money,
+		"remark": remark,
 	}
 	global.Logger.Info("api moneyRecharge:", zap.Any("param:", p))
-	errs := service.MoneyRecharge(appid, money, c)
+	errs := service.MoneyRecharge(appid, money, remark)
 	if errs == nil {
 		response.Ok(c)
 	} else {

+ 5 - 5
service/userRecharge.go

@@ -12,7 +12,7 @@ import (
 	"time"
 )
 
-func MoneyRecharge(appid string, money int, context *gin.Context) error {
+func MoneyRecharge(appid string, money int, remark string) error {
 	//取出用户锁
 	lock.MainLock.Lock()
 	userLock := lock.UserLockMap[appid]
@@ -33,7 +33,7 @@ func MoneyRecharge(appid string, money int, context *gin.Context) error {
 			return err
 		}
 		//生充值记录
-		err = tx.Exec("insert into user_money_record (app_id,`before`,`after`,trade_money) values (?,?,?,?)", appid, moneyBefore, moneyAfter, money).Error
+		err = tx.Exec("insert into user_money_record (app_id,`before`,`after`,trade_money,remark) values (?,?,?,?,?)", appid, moneyBefore, moneyAfter, money, remark).Error
 		if err != nil {
 			log.Printf("appID:[%s],trade_money:[%d] execute insert into user_money_record error:[%v]", appid, money, err)
 			tx.Rollback()
@@ -69,14 +69,14 @@ func ProductRecharge(appid string, productId, rechargeNum int, startTime string,
 		//充值
 		var err error
 		if endTime != "" && startTime != "" {
-			err = tx.Exec("update user_product set left_num = ?,start_at=?,end_at = ? ,update_at = ? WHERE `app_id` = ? and product_id = ?", after, startTime, endTime,nowStr, appid, productId).Error
+			err = tx.Exec("update user_product set left_num = ?,start_at=?,end_at = ? ,update_at = ? WHERE `app_id` = ? and product_id = ?", after, startTime, endTime, nowStr, appid, productId).Error
 			if err != nil {
 				log.Printf("appID:[%s],left_num:[%d],endtime:[%s],starttime:[%s]  execute cost user_product error:[%v]", appid, after, endTime, startTime, err)
 				tx.Rollback()
 				return err
 			}
 		} else {
-			err = tx.Exec("update user_product set left_num = ?,update_at = ? WHERE `app_id` = ? and product_id = ?", after,nowStr, appid, productId).Error
+			err = tx.Exec("update user_product set left_num = ?,update_at = ? WHERE `app_id` = ? and product_id = ?", after, nowStr, appid, productId).Error
 			if err != nil {
 				log.Printf("appID:[%s],left_num:[%d] execute cost user_product error:[%v]", appid, after, err)
 				tx.Rollback()
@@ -84,7 +84,7 @@ func ProductRecharge(appid string, productId, rechargeNum int, startTime string,
 			}
 		}
 		//生购买记录
-		err = tx.Exec("insert into user_buy_record (app_id,product_id,user_product_id,`before`,`after`,trade_money,buy_type,history_unit_price,create_at) values (?,?,?,?,?,?,?,?,?)", appid, productId, userProduct.ID, before, after, tradeMoney, 1, product.UnitPrice,nowStr).Error
+		err = tx.Exec("insert into user_buy_record (app_id,product_id,user_product_id,`before`,`after`,trade_money,buy_type,history_unit_price,create_at) values (?,?,?,?,?,?,?,?,?)", appid, productId, userProduct.ID, before, after, tradeMoney, 1, product.UnitPrice, nowStr).Error
 		if err != nil {
 			log.Printf("appID:[%s],product_id:[%d],user_product_id:[%d],after:[%d],trade_money:[%d] execute insert into user_buy_record error:[%v]", appid, productId, userProduct.ID, after, tradeMoney, err)
 			tx.Rollback()

+ 2 - 0
static/templates/moneyRecharge.html

@@ -10,6 +10,7 @@
     <h3>余额充值</h3>
     <div id="money">
         <input type="number" id="moneys" placeholder="请输入充值金额">
+        <input type="text" id="remark" placeholder="请输入备注信息">
         <button type="button" id="moneyBtn">提交</button>
     </div>
     <div id="resultContent"></div>
@@ -50,6 +51,7 @@
             var param = {
                 "appid": appid,
                 "money": Math.round($("#moneys").val() * 100),
+                "remark":$("#remark").val(),
             };
             var url = "/manage/user/moneyRecharge";
             var rType = "post";

+ 7 - 5
utils/api_util.go

@@ -43,11 +43,13 @@ func Check(appID string, productID int, c *gin.Context, getData func() ([]map[st
 		return
 	}
 	//校验是否过期
-	now := time.Now().Unix()
-	end := userProduct.EndAt
-	if now > end.Unix() {
-		response.FailWithDetailed(response.InterfaceExpired, nil, "剩余量已过期", c)
-		return
+	if userProduct.CostModel != 1 {
+		now := time.Now().Unix()
+		end := userProduct.EndAt
+		if now > end.Unix() {
+			response.FailWithDetailed(response.InterfaceExpired, nil, "剩余量已过期", c)
+			return
+		}
 	}
 	//校验每日调用上限
 	limittodaykey := fmt.Sprintf("limittoday_%d_%d_%s", time.Now().Day(), productID, appID)