Browse Source

Merge branch 'feature/v4.9.71' of https://jygit.jydev.jianyu360.cn/qmx/jy into dev/v4.9.71_wmh

wenmenghao321 8 months ago
parent
commit
6b742fdc1d
1 changed files with 16 additions and 8 deletions
  1. 16 8
      src/jfw/modules/subscribepay/src/entity/equityCode.go

+ 16 - 8
src/jfw/modules/subscribepay/src/entity/equityCode.go

@@ -607,7 +607,7 @@ func (e *EquityCode) Submit(codes []string, giftName, industryCode string, buyNu
 	} else if timeType == 3 {
 		cycleUnit = 1
 	}
-	getEndTime := func(t time.Time) string {
+	getEndTime := func(t time.Time) time.Time {
 		var end time.Time
 		endStart := time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, time.Local)
 		if timeType == 1 {
@@ -618,20 +618,21 @@ func (e *EquityCode) Submit(codes []string, giftName, industryCode string, buyNu
 			end = endStart.AddDate(number, 0, 0)
 		} else if timeType == 4 {
 			end = endStart.AddDate(0, 3*number, 0)
-		} else {
-			return ""
 		}
-		return FormatDate(&end, Date_Full_Layout)
+		return end
 	}
-	insertEndTime := getEndTime(time.Now())
+	now := time.Now()
+	insertEndTime := getEndTime(now)
 	values := []interface{}{}
 	for _, v := range codes {
 		if hasPower[v] {
 			continue
 		}
-		values = append(values, comAccountId, nowFormat, insertEndTime, buyNum, v, nowFormat)
+		values = append(values, comAccountId, nowFormat, FormatDate(&insertEndTime, Date_Full_Layout), buyNum, v, nowFormat)
 	}
 	if util.ActivityMysql.ExecTx("生成权益", func(tx *sql.Tx) bool {
+		orderStartTime := now
+		orderEndTime := insertEndTime
 		if len(values) > 0 {
 			r1, r2 := util.ActivityMysql.InsertBatchByTx(tx, "debris_product.user_power", []string{"account_id", "start_time", "end_time", "buy_num", "miniprogram_code", "create_time"}, values)
 			if r1 <= 0 || r2 <= 0 {
@@ -648,7 +649,14 @@ func (e *EquityCode) Submit(codes []string, giftName, industryCode string, buyNu
 				log.Println(e.Phone, fmt.Sprintf("%+v", v), "更新小程序用户权益", err)
 				continue
 			}
-			updateEndTime := getEndTime(thisT)
+			thisStartTime := thisT.AddDate(0, 0, 1)
+			if thisStartTime.After(orderStartTime) {
+				orderStartTime = thisStartTime
+			}
+			updateEndTime := getEndTime(thisStartTime)
+			if updateEndTime.After(orderEndTime) {
+				orderEndTime = updateEndTime
+			}
 			if util.ActivityMysql.UpdateOrDeleteBySqlByTx(tx, "update debris_product.user_power set end_time=? where id=?", updateEndTime, qu.Int64All(v["id"])) <= 0 {
 				return false
 			}
@@ -660,7 +668,7 @@ func (e *EquityCode) Submit(codes []string, giftName, industryCode string, buyNu
 		}
 		filter := fmt.Sprintf(`{"xcx_account_id":%d,"baseUserId":%d,"area_count":%d,"buyItemCode":["%s"],"industryCode":"%s","fromMiniCode":"%s","cycleCount":%d,"cycleUnit":%d,"originalAmount":0}`, comAccountId, userId, buyNum, strings.Join(codes, `","`), industryCode, codes[0], number, cycleUnit)
 		util.ActivityMysql.InsertBatchByTx(tx, "jianyu.dataexport_order", []string{"order_code", "pay_money", "order_money", "pay_time", "order_status", "create_time", "filter", "original_price", "product_type", "user_phone", "user_id", "vip_starttime", "vip_endtime", "discount_price", "sale_time", "order_channel", "distribution_channel", "audit_status"}, []interface{}{
-			orderCode, 0, 0, nowFormat, 1, nowFormat, filter, 0, giftName, e.Phone, positionId, nowFormat, insertEndTime, 0, nowFormat, "xdqd05", "x014", 3})
+			orderCode, 0, 0, nowFormat, 1, nowFormat, filter, 0, giftName, e.Phone, positionId, FormatDate(&orderStartTime, Date_Full_Layout), FormatDate(&orderEndTime, Date_Full_Layout), 0, nowFormat, "xdqd05", "x014", 3})
 		return true
 	}) {
 		return 1