jianghan hai 5 meses
pai
achega
af88f31a12
Modificáronse 2 ficheiros con 46 adicións e 13 borrados
  1. 43 11
      JySEPlatform/service/private_service.go
  2. 3 2
      JySEPlatform/util/cost_util.go

+ 43 - 11
JySEPlatform/service/private_service.go

@@ -241,14 +241,17 @@ func (f *Private) Keydataoption(world string) {
 	infos, ok := Mgo.Find("tagsdata", bson.M{"s_dataid": world}, `{"publishtime":-1}`, nil, false, -1, -1)
 	if ok && infos != nil && *infos != nil && len(*infos) > 0 {
 		for _, v := range *infos {
-			v["id"] = qu.ObjToString(v["info_id"])
-			v["jybxhref"] = v["s_jyhref"]
-			v["createtime"] = time.Now().Unix()
-			v["phone"] = phone
-			delete(v, "_id")
-			v["datasource"] = "自助导出"
-			v["chargtime"] = time.Now().Unix()
-			infoArr = append(infoArr, v)
+			bid := qu.ObjToString(v["info_id"])
+			if repeatResp[bid] {
+				v["id"] = bid
+				v["jybxhref"] = v["s_jyhref"]
+				v["createtime"] = time.Now().Unix()
+				v["phone"] = phone
+				delete(v, "_id")
+				v["datasource"] = "自助导出"
+				v["chargtime"] = time.Now().Unix()
+				infoArr = append(infoArr, v)
+			}
 		}
 	}
 	log.Println("Keydataoption 数据量", len(newIdArr))
@@ -263,7 +266,21 @@ func (f *Private) Keydataoption(world string) {
 		s_name := qu.ObjToString((*datas)["s_name"])
 		xlsxUrl := GetXlsxfile(infoArr, dataType, s_name, fields)
 		log.Println("生成完成", xlsxUrl)
-		SaveExportLog2(entId, entUserId, len(infoArr), len(newIdArr), xlsxUrl, exportIds)
+		filter := make(map[string]interface{})
+		if qu.ObjToString((*datas)["s_area"]) != "" {
+			filter["Area"] = qu.ObjToString((*datas)["s_area"])
+		}
+		if qu.ObjToString((*datas)["s_city"]) != "" {
+			filter["Area"] = qu.ObjToString((*datas)["s_city"])
+		}
+		if qu.Int64All((*datas)["i_starttime"]) > 0 && qu.Int64All((*datas)["i_endtime"]) > 0 {
+			filter["Time"] = fmt.Sprintf("%d_%d", qu.Int64All((*datas)["i_starttime"]), qu.Int64All((*datas)["i_endtime"]))
+		} else if qu.Int64All((*datas)["i_starttime"]) > 0 {
+			filter["Time"] = fmt.Sprintf("%d_", qu.Int64All((*datas)["i_starttime"]))
+		} else if qu.Int64All((*datas)["i_endtime"]) > 0 {
+			filter["Time"] = fmt.Sprintf("_%d", qu.Int64All((*datas)["i_endtime"]))
+		}
+		SaveExportLog2(entId, entUserId, len(infoArr), len(newIdArr), qu.IntAll(tmp["chargeType"]), xlsxUrl, qu.MapToJson(filter), exportIds)
 		go func() {
 			for k, _ := range infoArr {
 				MgoSave.Save(SaveUserMail, infoArr[k])
@@ -315,6 +332,20 @@ func (f *Private) Keydataaccount(world string) {
 	log.Println("Keydataaccount 数据量", len(newIdArr))
 	log.Println("Keydataaccount 新导出", len(exportIds))
 	if resp.Data.ChargeType == 0 {
+		isExport := true
+		var reason []string
+		if int64(len(newIdArr)) > resp.Data.Num1 {
+			isExport = false
+			reason = append(reason, "企业数据流量包余额不足")
+		}
+		if int64(len(newIdArr)) > resp.Data.Num2 {
+			isExport = false
+			reason = append(reason, "超出您的每日导出限额")
+		}
+		if int64(len(newIdArr)) > resp.Data.Num4 {
+			isExport = false
+			reason = append(reason, "超出您的数据导出总量限额")
+		}
 		res := map[string]interface{}{
 			"count":      len(exportIds),
 			"newCount":   len(newIdArr),
@@ -324,7 +355,8 @@ func (f *Private) Keydataaccount(world string) {
 			"num4":       qu.If(resp.Data.Num4 == 0, nil, resp.Data.Num4), // 导出总限额
 			"num3":       resp.Data.Num3,                                  //当日可导出余额
 			"num5":       resp.Data.Num5,
-			"isExport":   qu.If(int64(len(newIdArr)) <= resp.Data.Num1, true, false),
+			"isExport":   isExport,
+			"reason":     strings.Join(reason, "、"),
 		}
 		f.ServeJson(res)
 	} else {
@@ -515,7 +547,7 @@ func GetXlsxfile(mMap []map[string]interface{}, dataType int, fn string, fields
 	fname := fmt.Sprintf("%s_%s_%s.xlsx", fn, t, qu.GetRandom(4))
 	log.Println("fname", fname)
 	err = xf.Save(dir + fname)
-	xlsxUrls := dir + t + "/" + fname
+	xlsxUrls := fmt.Sprintf("/customizedexport/%s/%s", t, fname)
 	return xlsxUrls
 }
 

+ 3 - 2
JySEPlatform/util/cost_util.go

@@ -63,7 +63,7 @@ func DeductNum2(entId int, newCount int, userId int, exportId int64) bool {
 }
 
 // 存导出日志
-func SaveExportLog2(entId, entUserId, count, newCount int, xlsxUrl string, ids []string) {
+func SaveExportLog2(entId, entUserId, count, newCount, chargeType int, xlsxUrl, filter string, ids []string) {
 	query := map[string]interface{}{
 		"id":     entUserId,
 		"ent_id": entId,
@@ -75,7 +75,7 @@ func SaveExportLog2(entId, entUserId, count, newCount int, xlsxUrl string, ids [
 		now := time.Now()
 		JyMysql.Insert("datapacket_record", map[string]interface{}{
 			"infoids":     strings.Join(ids, ","),
-			"type":        4,
+			"type":        qu.If(chargeType == 0, 3, 2),
 			"master_id":   entId,
 			"useid":       entUserId,
 			"query_id":    "",
@@ -90,6 +90,7 @@ func SaveExportLog2(entId, entUserId, count, newCount int, xlsxUrl string, ids [
 			"ent_user_id": entUserId,
 			"operator":    name,
 			"source":      1,
+			"filter":      filter,
 		})
 	}
 	return