浏览代码

wip:销售业绩刷库程序提交

wangkaiyue 11 月之前
父节点
当前提交
3a8445e95a
共有 3 个文件被更改,包括 50 次插入15 次删除
  1. 1 1
      saleFlush/config.yaml
  2. 39 14
      saleFlush/main.go
  3. 10 0
      zhimaPush/config.yaml

+ 1 - 1
saleFlush/config.yaml

@@ -1,7 +1,7 @@
 database:
   release:
     link: "mysql:readuser:jyTi_R202403@tcp(192.168.3.71:4003)/jianyu"
-    debug: true
+    #debug: true
   default:
     link: "mysql:root:=PDT49#80Z!RVv52_z@tcp(192.168.3.14:4000)/jianyu"
     #debug: true

+ 39 - 14
saleFlush/main.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"context"
+	"fmt"
 	_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/util/gconv"
@@ -36,7 +37,9 @@ var (
 	{"oldCode":"070200","show":"数据事业部/售前与售后组","newId":"59007"}
 	]`
 	codeDeptMapping = map[string]*newDept{}
-	beforeMoneyMap  = map[string]int{}
+	beforeMoneyMap  = map[string]int{}  //红冲单子
+	hasSaleMap      = map[string]bool{} //已存在业绩
+	table           = "order_sale_record_release"
 )
 
 type (
@@ -53,12 +56,14 @@ type (
 )
 
 func init() {
+	//加载历史部门
 	for _, m := range gconv.Maps(deptMapping) {
 		codeDeptMapping[gconv.String(m["oldCode"])] = &newDept{
 			Name: gconv.String(m["show"]),
 			Id:   gconv.Int(m["newId"]),
 		}
 	}
+	//加载红冲记录
 	res, err := g.DB("release").Query(context.TODO(), "SELECT createTime,orderCode,payMoney from moneyCorrection WHERE redType='金额红冲' and payMoney!=0 AND createTime >'2024-01-01 00:00:00' and createTime < '2024-09-10 00:00:00'")
 	if err != nil {
 		panic(err)
@@ -71,15 +76,26 @@ func init() {
 		)
 		beforeMoneyMap[orderCode] = beforeMoneyMap[orderCode] - payMoney
 	}
+	//加载已刷新过的业绩
+	res2, err := g.DB().Query(context.TODO(), fmt.Sprintf("SELECT ordercode from %s ", table))
+	if err != nil {
+		panic(err)
+	}
+	for _, row := range res2.List() {
+		var (
+			orderCode = gconv.String(row["ordercode"])
+		)
+		hasSaleMap[orderCode] = true
+	}
 }
 
 func main() {
 	redRecord(context.TODO())
 	CreateSaleRecord(context.TODO())
-	//fmt.Println(int(time.Now().Month()))
 }
+
 func CreateSaleRecord(ctx context.Context) {
-	res, err := g.DB("release").Query(ctx, "SELECT order_status,order_money,order_code,pay_money,saleDep,salesperson_id,salesperson,saleMoney,is_backstage_order,sale_time,pay_time,refund_status,create_time FROM dataexport_order WHERE create_time >'2024-01-01 00:00:00' and create_time < '2024-09-10 00:00:00'")
+	res, err := g.DB("release").Query(ctx, "SELECT order_status,order_money,order_code,pay_money,saleDep,salesperson_id,salesperson,saleMoney,is_backstage_order,sale_time,pay_time,refund_status,create_time FROM dataexport_order WHERE (create_time >'2024-01-01 00:00:00' and create_time < '2024-09-10 00:00:00') or order_code in ('112519605433','090810057631','104306434632','155349703173','111059225831')")
 	if err != nil {
 		panic(err)
 	}
@@ -105,6 +121,9 @@ func CreateSaleRecord(ctx context.Context) {
 		if _, ok := beforeMoneyMap[order_code]; ok {
 			continue
 		}
+		if _, ok := hasSaleMap[order_code]; ok {
+			continue
+		}
 		if is_backstage_order == 1 {
 			//后台创建订单获取业绩时间
 			if (refund_status == 1 || refund_status == 2 || order_status == 1) && pay_money > 0 {
@@ -113,10 +132,7 @@ func CreateSaleRecord(ctx context.Context) {
 					g.Log().Printf(ctx, "格式化销售时间异常 %s %s", order_code, sale_time)
 					continue
 				}
-				if date.Month() <= 3 {
-					//用录入的业绩统计时间
-					statistics_time = sale_time
-				} else {
+				if date.Month() > 3 && date.Year() == 2024 {
 					//管理后台创建的订单:协议归档时间和首笔回款时间的最小值。
 					res, _ := g.DB("release").GetOne(ctx, "SELECT * FROM (SELECT * FROM(SELECT contract_archive_time as t ,'0' as v  FROM contract WHERE order_code=? and contract_archive_time is NOT NULL) as t1 UNION ALL SELECT * FROM(SELECT return_time as t ,'1' as v FROM return_money_record WHERE order_code=? AND state=1) as t2) as d ORDER BY t asc LIMIT 1", order_code, order_code)
 					if !res.IsEmpty() {
@@ -133,6 +149,8 @@ func CreateSaleRecord(ctx context.Context) {
 							reason = "回款成功"
 						}
 					}
+				} else {
+					statistics_time = sale_time
 				}
 				if statistics_time == "" {
 					statistics_time = sale_time
@@ -234,6 +252,10 @@ func CreateSaleRecord(ctx context.Context) {
 				insertArr = append(insertArr, m)
 			}
 		} else {
+			money := order_money
+			if is_backstage_order == 1 {
+				money = pay_money
+			}
 			m := map[string]interface{}{
 				"state":         2,
 				"ordercode":     order_code,
@@ -241,8 +263,8 @@ func CreateSaleRecord(ctx context.Context) {
 				"saler_name":    "-",
 				"saler_dept":    "运营部",
 				"saler_dept_id": 27103,
-				"change_value":  order_money,
-				"money":         order_money,
+				"change_value":  money,
+				"money":         money,
 				"group_uuid":    uuidStr,
 				"operator":      "系统自动",
 				"create_time":   create_time,
@@ -268,7 +290,7 @@ func CreateSaleRecord(ctx context.Context) {
 }
 
 func SaveDb(ctx context.Context, data []map[string]interface{}) {
-	_, err := g.DB().Save(ctx, "order_sale_record_release1", data, 10)
+	_, err := g.DB().Save(ctx, table, data, 10)
 	if err != nil {
 		g.Log().Errorf(ctx, "插入数据异常 %v", err)
 	}
@@ -277,6 +299,9 @@ func SaveDb(ctx context.Context, data []map[string]interface{}) {
 // redRecord 红冲记录补全
 func redRecord(ctx context.Context) {
 	for orderCode, money := range beforeMoneyMap {
+		if _, ok := hasSaleMap[orderCode]; ok {
+			continue
+		}
 		var insertArr []map[string]interface{}
 		m, err := g.DB("release").GetOne(ctx, "SELECT order_status,order_money,order_code,pay_money,saleDep,salesperson_id,salesperson,saleMoney,is_backstage_order,sale_time,pay_time,refund_status,create_time FROM dataexport_order WHERE order_code=?", orderCode)
 		if err != nil || m.IsEmpty() {
@@ -303,10 +328,7 @@ func redRecord(ctx context.Context) {
 				g.Log().Printf(ctx, "格式化销售时间异常 %s %s", order_code, sale_time)
 				continue
 			}
-			if date.Month() <= 3 {
-				//用录入的业绩统计时间
-				statistics_time = sale_time
-			} else {
+			if date.Month() > 3 && date.Year() == 2024 {
 				//管理后台创建的订单:协议归档时间和首笔回款时间的最小值。
 				res, _ := g.DB("release").GetOne(ctx, "SELECT * FROM (SELECT * FROM(SELECT contract_archive_time as t ,'0' as v  FROM contract WHERE order_code=? and contract_archive_time is NOT NULL) as t1 UNION ALL SELECT * FROM(SELECT return_time as t ,'1' as v FROM return_money_record WHERE order_code=? AND state=1) as t2) as d ORDER BY t asc LIMIT 1", order_code, order_code)
 				if !res.IsEmpty() {
@@ -323,6 +345,9 @@ func redRecord(ctx context.Context) {
 						reason = "回款成功"
 					}
 				}
+			} else {
+				//用录入的业绩统计时间
+				statistics_time = sale_time
 			}
 			if statistics_time == "" {
 				statistics_time = sale_time

+ 10 - 0
zhimaPush/config.yaml

@@ -6,6 +6,16 @@ mongodb:
     replSet: ""
     userName: "admin"
     password: "123456"
+  bidding:
+    "address": "192.168.3.206:27002",
+    "size": 5,
+    "dbName": "qfw_data",
+    "replSet": "",
+    "collection": "bidding",
+    "collection_back": "bidding_back",
+    "userName": "jyDevGroup",
+    "password": "jy@DevGroup"
+
 
 # 每天凌晨2点推送前一天访问数据
 runCron: "# 0 2 * * *"