Răsfoiți Sursa

即将到期发邮件修改

WH01243 6 luni în urmă
părinte
comite
cc1b750ee6
1 a modificat fișierele cu 50 adăugiri și 44 ștergeri
  1. 50 44
      clueSync/kc.go

+ 50 - 44
clueSync/kc.go

@@ -632,18 +632,22 @@ func refundAuto() {
 			}
 			//查询即将到期数据
 			if isRenewalProtection == 0 {
-				aaa := TiDb.CountBySql(`select count(1) from dwd_f_userbase_order_info where uid=?   and (product_type = "企业商机管理" or product_type = "大会员") and order_status = 1  and  refund_status!=1 and vip_endtime < ? and  vip_endtime > ? `, uid, time.Now().AddDate(0, 0, -db.ExpirationPeriod+1).Format(date.Date_Short_Layout), time.Now().AddDate(0, 0, -db.ExpirationPeriod).Format(date.Date_Short_Layout))
-				log.Println(aaa)
-				if aaa > 0 {
-					//即将到期
-					mailData[name] = append(mailData[name], map[string]interface{}{
-						"company_name": company_name,
-						"phone":        phone,
-						"userName":     userName,
-						"remrk":        "1天后即将移交",
-						"reason":       "成交客户续费失败",
-					})
-					continue
+				orderData := TiDb.SelectBySql(`select * from dwd_f_userbase_order_info where uid=?   and (product_type = "企业商机管理" or product_type = "大会员") and order_status = 1  and  refund_status!=1 ORDER BY   vip_endtime  desc  `, uid)
+				if orderData != nil && len(*orderData) > 0 {
+					endDate := time.Now().AddDate(0, 0, -db.ExpirationPeriod+1).Unix()
+					startDate := time.Now().AddDate(0, 0, -db.ExpirationPeriod).Unix()
+					vipEndDate, _ := time.Parse(time.DateTime, gconv.String((*orderData)[0]["vip_endtime"]))
+					if vipEndDate.Unix() > startDate && vipEndDate.Unix() < endDate {
+						//即将到期
+						mailData[name] = append(mailData[name], map[string]interface{}{
+							"company_name": company_name,
+							"phone":        phone,
+							"userName":     userName,
+							"remrk":        "1天后即将移交",
+							"reason":       "成交客户续费失败",
+						})
+						continue
+					}
 				}
 
 			}
@@ -716,42 +720,44 @@ func refundAuto() {
 				order1 := TiDb.SelectBySql(`select id from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime > ? and order_status = 1 `, uid, findNowTime)
 				if order1 == nil || len(*order1) == 0 {
 					isOk := false
-					order3 := TiDb.SelectBySql(`select vip_endtime from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime < ? and order_status = 1 `, uid, findNowTime)
+					earliestTime := time.Now().AddDate(0, 0, gconv.Int(-db.HandoverCycle)).Format(date.Date_Full_Layout)
+					order3 := TiDb.SelectBySql(`select vip_endtime from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime < ?  and  vip_endtime>? and order_status = 1 ORDER BY   vip_endtime  desc limit 1  `, uid, findNowTime, earliestTime)
 					if order3 != nil && len(*order3) > 0 {
-						for _, vv := range *order3 {
-							if isRenewalProtection == 1 {
-								vip_endtime := common.ObjToString(vv["vip_endtime"])
-								vip_endtimes, _ := time.ParseInLocation(date.Date_Full_Layout, vip_endtime, time.Local)
-								//查询申请保护时间
-								renewalTime := time.Now()
-								timeData := TiDb.SelectBySql(`select  max(createtime) as createtime from   dwd_f_crm_clue_change_record   where   clue_id =  ?  and  change_type="申请续费保护"`, clueId)
-								if timeData != nil && len(*timeData) > 0 {
-									if gconv.String(gconv.String((*timeData)[0]["createtime"])) != "" {
-										renewalTime, _ = time.ParseInLocation(date.Date_Short_Layout, gconv.String((*timeData)[0]["createtime"]), time.Local)
-									}
+						//获取最后一个订单信息
+						vv := (*order3)[0]
+						if isRenewalProtection == 1 {
+							vip_endtime := common.ObjToString(vv["vip_endtime"])
+							vip_endtimes, _ := time.ParseInLocation(date.Date_Full_Layout, vip_endtime, time.Local)
+							//查询申请保护时间
+							renewalTime := time.Now()
+							timeData := TiDb.SelectBySql(`select  max(createtime) as createtime from   dwd_f_crm_clue_change_record   where   clue_id =  ?  and  change_type="申请续费保护"`, clueId)
+							if timeData != nil && len(*timeData) > 0 {
+								if gconv.String(gconv.String((*timeData)[0]["createtime"])) != "" {
+									renewalTime, _ = time.ParseInLocation(date.Date_Short_Layout, gconv.String((*timeData)[0]["createtime"]), time.Local)
 								}
-								renewalInt := renewalTime.Unix()
-								log.Println("申请保护期时间", clueId, renewalInt)
-								log.Println("申请保护期时间222", time.Now().Unix()-vip_endtimes.Unix(), (db.HandoverCycle-1)*86400, (db.HandoverCycle)*86400)
-								log.Println("申请保护期时间333", (db.HandoverCycle-1)*86400 < time.Now().Unix()-vip_endtimes.Unix(), time.Now().Unix()-vip_endtimes.Unix() < (db.HandoverCycle)*86400)
-								//查看服务到期时间
-								if renewalInt != 0 && renewalInt < db.CustomerTime {
-									//三个月
-									if time.Now().Unix()-vip_endtimes.Unix() < 3*30*86400 {
-										isOk = true
-									}
-								} else if (db.HandoverCycle-2)*86400 < time.Now().Unix()-vip_endtimes.Unix() && time.Now().Unix()-vip_endtimes.Unix() < (db.HandoverCycle-1)*86400 {
-									//提前一天提示
-									mailData[name] = append(mailData[name], map[string]interface{}{
-										"company_name": company_name,
-										"phone":        phone,
-										"userName":     userName,
-										"remrk":        "1天后即将移交",
-										"reason":       "成交客户续费失败",
-									})
-								} else if time.Now().Unix()-vip_endtimes.Unix() < db.HandoverCycle*86400 {
+							}
+							renewalInt := renewalTime.Unix()
+							log.Println("申请保护期时间", clueId, renewalInt)
+							log.Println("申请保护期时间222", time.Now().Unix()-vip_endtimes.Unix(), (db.HandoverCycle-1)*86400, (db.HandoverCycle)*86400)
+							log.Println("申请保护期时间333", (db.HandoverCycle-1)*86400 < time.Now().Unix()-vip_endtimes.Unix(), time.Now().Unix()-vip_endtimes.Unix() < (db.HandoverCycle)*86400)
+							//查看服务到期时间
+							if renewalInt != 0 && renewalInt < db.CustomerTime {
+								//三个月
+								if time.Now().Unix()-vip_endtimes.Unix() < 3*30*86400 {
 									isOk = true
 								}
+							} else if (db.HandoverCycle-2)*86400 < time.Now().Unix()-vip_endtimes.Unix() && time.Now().Unix()-vip_endtimes.Unix() < (db.HandoverCycle-1)*86400 {
+								//提前一天提示
+								mailData[name] = append(mailData[name], map[string]interface{}{
+									"company_name": company_name,
+									"phone":        phone,
+									"userName":     userName,
+									"remrk":        "1天后即将移交",
+									"reason":       "成交客户续费失败",
+								})
+								isOk = true
+							} else if time.Now().Unix()-vip_endtimes.Unix() < db.HandoverCycle*86400 {
+								isOk = true
 							}
 						}
 					}