xuzhiheng 1 éve
szülő
commit
be4b55dbb3
2 módosított fájl, 93 hozzáadás és 57 törlés
  1. 90 57
      clueSync/everything.go
  2. 3 0
      clueSync/kc.go

+ 90 - 57
clueSync/everything.go

@@ -433,11 +433,12 @@ func bigCustomer() {
 			}
 		}
 	}
-	orderData := Mysql.SelectBySql(`SELECT * FROM dataexport_order WHERE create_time >= "` + time.Now().AddDate(0, 0, -1).Format(date.Date_Short_Layout) + " 00:00:00" + `" AND create_time < "` + time.Now().Format(date.Date_Short_Layout) + " 00:00:00" + `" AND product_type = '历史数据' AND order_status IN (0,1) AND salesperson IS NULL AND is_backstage_order = 0`)
+	orderData := Mysql.SelectBySql(`SELECT * FROM dataexport_order WHERE create_time >= "` + time.Now().AddDate(0, 0, -5).Format(date.Date_Short_Layout) + " 00:00:00" + `" AND create_time < "` + time.Now().Format(date.Date_Short_Layout) + " 00:00:00" + `" AND (product_type = '历史数据' or product_type = '数据流量包') AND order_status IN (0,1) AND salesperson IS NULL AND is_backstage_order = 0`)
 	if orderData != nil && len(*orderData) > 0 {
 		for _, v := range *orderData {
 			phone := common.ObjToString(v["user_phone"])
 			order_status := common.IntAll(v["order_status"])
+			product_type := common.ObjToString(v["product_type"])
 			userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"phone": phone}, "", "")
 			username, usernickname, userid, uid, source, payorderinfo, unpayorderinfo := "", "", "", "", "", "", ""
 			if userData != nil {
@@ -450,12 +451,22 @@ func bigCustomer() {
 					continue
 				}
 			}
-			if order_status == 0 {
-				source = "线上历史数据导出未支付订单"
-				unpayorderinfo = "历史数据"
+			if product_type == "历史数据" {
+				if order_status == 0 {
+					source = "线上历史数据导出未支付订单"
+					unpayorderinfo = "历史数据"
+				} else {
+					source = "线上历史数据导出已支付订单"
+					payorderinfo = "历史数据" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
+				}
 			} else {
-				source = "线上历史数据导出已支付订单"
-				payorderinfo = "历史数据" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
+				if order_status == 0 {
+					source = "线上数据流量包未支付订单"
+					unpayorderinfo = "数据流量包"
+				} else {
+					source = "线上数据流量包已支付订单"
+					payorderinfo = "数据流量包" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
+				}
 			}
 			dataArr = append(dataArr, map[string]interface{}{
 				"createTime":     nowTime,
@@ -471,63 +482,85 @@ func bigCustomer() {
 				"source":         source,
 				"data_count":     v["data_count"],
 				"unpayorderinfo": unpayorderinfo,
-				"payorderinfo":   payorderinfo,
+				"payorderinfo":   payorderinfo, //增加客户需求
 			})
 		}
 	}
 	xlsxArr := []string{"用户昵称", "姓名", "公司名称", "职位", "联系人电话", "购买条数", "用户邮箱", "已支付订单信息", "未支付订单类型", "销售线索来源", "具体来源", "数据需求"}
-	xf := xlsx.NewFile()
-	style := xlsx.NewStyle()
-	style.Font.Size = 12
-	style.Font.Bold = true
-	style.Alignment.Vertical = "center"
-	style.Alignment.Horizontal = "center"
 	fileName, detailName := time.Now().Format(date.Date_Short_Layout)+"大客户销售线索", ""
 	if len(dataArr) > 0 {
-		detailName = time.Now().Format(date.Date_Short_Layout) + "数据详情请查看附件"
-		sh, _ := xf.AddSheet("线索数据")
-		row1 := sh.AddRow()
-		for _, x := range xlsxArr {
-			cell := row1.AddCell()
-			cell.SetString(x)
-			cell.SetStyle(style)
-		}
-		for _, v := range dataArr {
-			row := sh.AddRow()
-			row.AddCell().SetString(common.ObjToString(v["usernickname"]))
-			row.AddCell().SetString(common.ObjToString(v["username"]))
-			row.AddCell().SetString(common.ObjToString(v["company"]))
-			row.AddCell().SetString(common.ObjToString(v["job"]))
-			row.AddCell().SetString(common.ObjToString(v["phone"]))
-			row.AddCell().SetValue(common.IntAll(v["data_count"]))
-			row.AddCell().SetString(common.ObjToString(v["email"]))
-			row.AddCell().SetString(common.ObjToString(v["payorderinfo"]))
-			row.AddCell().SetString(common.ObjToString(v["unpayorderinfo"]))
-			row.AddCell().SetString(common.ObjToString(v["source"]))
-			row.AddCell().SetString(common.ObjToString(v["interest"]))
-			row.AddCell().SetString(common.ObjToString(v["data_requirement"]))
-		}
-	} else {
-		detailName = time.Now().Format(date.Date_Short_Layout) + "无线索"
-	}
-	email := "xuzhiheng@topnet.net.cn,wenyue@topnet.net.cn,zhangwenfu@topnet.net.cn,zhufengchao@topnet.net.cn,zoushanshan@topnet.net.cn,fanzongdong@topnet.net.cn,sunzhenjie@topnet.net.cn"
-	// email = "xuzhiheng@jianyu360.com"
-	dir := "./xlsx/" + fileName + ".xlsx"
-	err := xf.Save(dir)
-	if err != nil && len(dataArr) > 0 {
-		log.Println("xls error", err, dir)
-	} else if len(dataArr) == 0 {
-		log.Println("xlsx数据量为0不发邮件")
-	} else {
-		gmail := &mail.GmailAuth{
-			SmtpHost: "smtp.exmail.qq.com",
-			SmtpPort: 465,
-			User:     "public03@topnet.net.cn",
-			Pwd:      "ue9Rg9Sf4CVtdm5a",
-		}
-		status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
-		if status {
-			log.Println("send mail success", fileName, email)
+		bigData := TiDb.SelectBySql("select * from dwd_f_crm_clue_big_autodraw_record")
+		if bigData != nil && len(*bigData) > 0 {
+			cdata := *bigData
+			bigArr := map[string][]map[string]interface{}{}
+			for _, v := range dataArr {
+				mincount := common.IntAll(cdata[0]["count"])
+				minindex := 0
+				minemail := ""
+				for kk, vv := range cdata {
+					vcount := common.IntAll(vv["count"])
+					vemail := common.ObjToString(vv["email"])
+					if vcount <= mincount {
+						minindex = kk
+						mincount = vcount
+						minemail = vemail
+					}
+				}
+				bigArr[minemail] = append(bigArr[minemail], v)
+				cdata[minindex]["count"] = mincount + 1
+				name := common.ObjToString(cdata[minindex]["name"])
+				TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_big_autodraw_record set count = count + 1 where name = ?`, name)
+			}
+			for k, vb := range bigArr {
+				xf := xlsx.NewFile()
+				style := xlsx.NewStyle()
+				style.Font.Size = 12
+				style.Font.Bold = true
+				style.Alignment.Vertical = "center"
+				style.Alignment.Horizontal = "center"
+				detailName = time.Now().Format(date.Date_Short_Layout) + "数据详情请查看附件"
+				sh, _ := xf.AddSheet("线索数据")
+				row1 := sh.AddRow()
+				for _, x := range xlsxArr {
+					cell := row1.AddCell()
+					cell.SetString(x)
+					cell.SetStyle(style)
+				}
+				for _, v := range vb {
+					row := sh.AddRow()
+					row.AddCell().SetString(common.ObjToString(v["usernickname"]))
+					row.AddCell().SetString(common.ObjToString(v["username"]))
+					row.AddCell().SetString(common.ObjToString(v["company"]))
+					row.AddCell().SetString(common.ObjToString(v["job"]))
+					row.AddCell().SetString(common.ObjToString(v["phone"]))
+					row.AddCell().SetValue(common.IntAll(v["data_count"]))
+					row.AddCell().SetString(common.ObjToString(v["email"]))
+					row.AddCell().SetString(common.ObjToString(v["payorderinfo"]))
+					row.AddCell().SetString(common.ObjToString(v["unpayorderinfo"]))
+					row.AddCell().SetString(common.ObjToString(v["source"]))
+					row.AddCell().SetString(common.ObjToString(v["interest"]))
+					row.AddCell().SetString(common.ObjToString(v["data_requirement"]))
+					//增加客户需求
+				}
+				email := k
+				// email = "xuzhiheng@jianyu360.com"
+				dir := "./xlsx/" + fileName + ".xlsx"
+				err := xf.Save(dir)
+				if err != nil {
+					log.Println("xls error", err, dir)
+				} else {
+					gmail := &mail.GmailAuth{
+						SmtpHost: "smtp.exmail.qq.com",
+						SmtpPort: 465,
+						User:     "public03@topnet.net.cn",
+						Pwd:      "ue9Rg9Sf4CVtdm5a",
+					}
+					status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
+					if status {
+						log.Println("send mail success", fileName, email)
+					}
+				}
+			}
 		}
 	}
 	log.Println("大客户线索定时任务结束")

+ 3 - 0
clueSync/kc.go

@@ -394,6 +394,7 @@ func ordersClue() {
 						uId = common.ObjToString((*userInfo)["uid"])
 						userId = common.ObjToString((*userInfo)["userid"])
 					} else {
+						log.Println("后台订单--未查询到 ", user_phone)
 						break
 					}
 				} else {
@@ -402,6 +403,7 @@ func ordersClue() {
 						if userMapping != nil && len(*userMapping) > 0 {
 							userId = common.ObjToString((*userMapping)["userid"])
 						} else {
+							log.Println("后台订单--未查询到 ", user_phone)
 							break
 						}
 					}
@@ -410,6 +412,7 @@ func ordersClue() {
 					if userInfo != nil && len(*userInfo) > 0 {
 						uId = common.ObjToString((*userInfo)["uid"])
 					} else {
+						log.Println("后台订单--未查询到 ", query, user_phone)
 						break
 					}
 				}