Browse Source

Merge branch 'fix/company_product_update_log' into debug

# Conflicts:
#	services/task.go
Roc 3 years ago
parent
commit
3fdbca6eda

+ 2 - 0
models/company_product_update_log.go

@@ -11,6 +11,8 @@ type CompanyProductUpdateLog struct {
 	CompanyId  int       `description:"客户id"`
 	ProductId  int       `description:"产品id"`
 	Status     string    `description:"变更后的状态"`
+	SellerId   int       `description:"销售id"`
+	SellerName string    `description:"销售名称"`
 	Source     string    `description:"来源"`
 	CreateTime time.Time `description:"创建时间"`
 }

+ 10 - 1
models/free_viewer.go

@@ -3,6 +3,7 @@ package models
 import "github.com/rdlucklib/rdluck_tools/orm"
 
 type FreeViewerDetails struct {
+	UserId         int
 	RealName       string
 	Mobile         string
 	Note           string
@@ -12,7 +13,7 @@ type FreeViewerDetails struct {
 }
 
 func GetFreeViewerDetails(startTime, endTime string) (items []*FreeViewerDetails, err error) {
-	sql := `select u.real_name,u.mobile,u.note,u.created_time,max(uvh.created_time) as max_created_time,u.email
+	sql := `select u.user_id,u.real_name,u.mobile,u.note,u.created_time,max(uvh.created_time) as max_created_time,u.email
 	from wx_user u
 	LEFT JOIN user_view_history uvh on u.user_id = uvh.user_id
     INNER JOIN user_record AS c ON u.user_id=c.user_id
@@ -24,7 +25,15 @@ func GetFreeViewerDetails(startTime, endTime string) (items []*FreeViewerDetails
 	and u.created_time > ?
 	and u.created_time <= ?
 	AND c.create_platform<>4
+    AND u.is_deal = 0
 	group by u.user_id`
 	_, err = orm.NewOrm().Raw(sql, startTime, endTime).QueryRows(&items)
 	return
 }
+
+// DealWxUser 处理用户标记状态
+func DealWxUser(userId int) (err error) {
+	sql := `update wx_user set is_deal = 1 where user_id=?`
+	_, err = orm.NewOrm().Raw(sql, userId).Exec()
+	return
+}

+ 42 - 5
services/company_contract/company_contract.go

@@ -4,11 +4,13 @@ import (
 	"context"
 	"errors"
 	"fmt"
+	"hongze/hongze_task/models"
 	"hongze/hongze_task/models/company"
 	"hongze/hongze_task/models/company_approval"
 	"hongze/hongze_task/models/company_contract"
 	"hongze/hongze_task/utils"
 	"strings"
+	"time"
 )
 
 //合同处理
@@ -41,11 +43,17 @@ func HandleCompanyContract(cont context.Context) (err error) {
 			continue
 		}
 
-		//companyProduct, err := models.GetCompanyProduct(v.CompanyId, v.ProductId)
-		//if err != nil {
-		//	errorList = append(errorList, fmt.Sprint("合同id:", v.CompanyContractId, ";寻找客户产品时异常 err:", err))
-		//	continue
-		//}
+		//客户产品信息
+		companyProduct, err := models.GetCompanyProduct(v.CompanyId, v.ProductId)
+		if err != nil {
+			errorList = append(errorList, fmt.Sprint("合同id:", v.CompanyContractId, ";寻找客户产品时异常", ";Err:"+err.Error()))
+			continue
+		}
+		if companyProduct == nil {
+			errorList = append(errorList, fmt.Sprint("合同id:", v.CompanyContractId, ";寻找客户产品时异常2", ";Err:"+err.Error()))
+			continue
+		}
+
 		//companyProduct.EndDate
 		//格式化客户当前产品结束日期
 		//companyProductEndDate, err := time.Parse(utils.FormatDate, companyProduct.EndDate)
@@ -74,6 +82,35 @@ func HandleCompanyContract(cont context.Context) (err error) {
 			errorList = append(errorList, fmt.Sprint("合同id:", v.CompanyContractId, ";审批单类型异常"))
 			continue
 		}
+
+		{
+			updateSource := ``
+			switch companyApproval.ApplyMethod {
+			case 1: //试用转正式
+				updateSource = `turn_positive`
+			case 2: //冻结->试用
+				updateSource = "thaw"
+			case 3: //试用延期
+				updateSource = "delay"
+			case 4: //原销售申请领取流失客户
+				updateSource = "apply_receive"
+			case 5: //正式客户申请续约
+				updateSource = "service_update"
+			case 6: //正式客户新增补充协议
+				updateSource = "add_agreement"
+			}
+			companyProductUpdateLog := &models.CompanyProductUpdateLog{
+				Id:         0,
+				CompanyId:  companyProduct.CompanyId,
+				ProductId:  companyProduct.ProductId,
+				Status:     companyProduct.Status,
+				SellerId:   companyProduct.SellerId,
+				SellerName: companyProduct.SellerName,
+				Source:     updateSource,
+				CreateTime: time.Now(),
+			}
+			go models.AddCompanyProductUpdateLog(companyProductUpdateLog)
+		}
 	}
 
 	//错误信息,批量返回错误信息

+ 12 - 5
services/data_source_longzhong.go

@@ -1034,6 +1034,8 @@ func GetLzSurveyProduct(cont context.Context) (err error) {
 					models.ModifLongzhongSurveyProductCode(lzCode, surveyProductId)
 				}
 			} else {
+				item.StartDate = "2018-01-01"
+				item.EndDate = "2018-01-01"
 				lastId, err := models.AddLongzhongSurveyProduct(item)
 				if err != nil {
 					msg = "新增隆众价格指标失败:err " + err.Error()
@@ -1085,9 +1087,9 @@ func GetLzSurveyProductData(cont context.Context) (err error) {
 	paramMap["passWord"] = password
 	paramMap["pageSize"] = 100
 
-	//startDate := time.Now().AddDate(-4, 0, 0).UnixNano() / 1e6
-	startDateTime, _ := time.Parse(utils.FormatDate, "2021-12-01")
-	startDate := startDateTime.UnixNano() / 1e6
+	startDate := time.Now().AddDate(-4, 0, 0).UnixNano() / 1e6
+	//startDateTime, _ := time.Parse(utils.FormatDate, "2021-12-01")
+	//startDate := startDateTime.UnixNano() / 1e6
 	endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).UnixNano() / 1e6
 
 	for k, v := range priceInfoList {
@@ -1102,10 +1104,15 @@ func GetLzSurveyProductData(cont context.Context) (err error) {
 		//	endDateTime, _ := time.Parse(utils.FormatDate, v.EndDate)
 		//	startDate = endDateTime.UnixNano() / 1e6
 		//}
+		if v.EndDate != "" {
+			endDateTime, _ := time.Parse(utils.FormatDate, v.EndDate)
+			startDate = endDateTime.AddDate(0, -8, 0).UnixNano() / 1e6
+		}
+
 		if startDate < 0 {
-			startDate = time.Now().AddDate(0, -4, 0).UnixNano() / 1e6
+			startDate = time.Now().AddDate(0, -8, 0).UnixNano() / 1e6
 		}
-		fmt.Println("startDate:" + time.Now().AddDate(0, -4, 0).Format(utils.FormatDate))
+
 		fmt.Println("endDate:" + time.Now().Format(utils.FormatDate))
 
 		for {

+ 11 - 10
services/free_viewer.go

@@ -1,13 +1,13 @@
 package services
 
 import (
+	"context"
 	"fmt"
 	"github.com/tealeg/xlsx"
 	"hongze/hongze_task/models"
 	"hongze/hongze_task/utils"
 	"os"
 	"time"
-	"context"
 )
 
 //潜在客户回访记录
@@ -19,16 +19,15 @@ func FreeViewerDetail(cont context.Context) (err error) {
 		}
 	}()
 
-
 	//endTime := time.Now().Format(utils.FormatDateTime)
 	startTime := time.Now().AddDate(0, 0, -7).Format(utils.FormatDateTime)
-	endTime :=time.Now().Format(utils.FormatDateTime)
+	endTime := time.Now().Format(utils.FormatDateTime)
 
-	items,err:=models.GetFreeViewerDetails(startTime,endTime)
-	if err!=nil {
+	items, err := models.GetFreeViewerDetails(startTime, endTime)
+	if err != nil {
 		return
 	}
-	title:="潜在客户回访记录"
+	title := "潜在客户回访记录"
 	//创建excel
 	file := xlsx.NewFile()
 	sheet, err := file.AddSheet(title)
@@ -55,21 +54,23 @@ func FreeViewerDetail(cont context.Context) (err error) {
 		cellB := row.AddCell()
 		cellB.Value = item.Mobile
 		cellC := row.AddCell()
-		cellC.Value=item.Note
+		cellC.Value = item.Note
 		cellD := row.AddCell()
 		cellD.Value = item.CreatedTime
 		cellE := row.AddCell()
 		cellE.Value = item.Email
+
+		models.DealWxUser(item.UserId)
 	}
 
-	savePath := "free_viewer_details"+ time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	savePath := "free_viewer_details" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
 	err = file.Save("./" + savePath)
 	if err != nil {
 		return
 	}
 	//发送邮件
 	fmt.Println("start send email")
-	sendResult := utils.SendEmailByHongze(title, "潜在客户回访记录',\"你好,上周潜在客户回访记录见附件。", utils.EmailSendToHzUsers, savePath,title+".xlsx")
+	sendResult := utils.SendEmailByHongze(title, "潜在客户回访记录',\"你好,上周潜在客户回访记录见附件。", utils.EmailSendToHzUsers, savePath, title+".xlsx")
 	//sendResult:=utils.SendEmailByHongze(title,"你好,上周研报阅读统计见附件。",utils.EmailSendToMe,savePath)
 	if sendResult {
 		os.Remove(savePath)
@@ -77,4 +78,4 @@ func FreeViewerDetail(cont context.Context) (err error) {
 	//fmt.Println("send result:", sendResult)
 	fmt.Println("end send email")
 	return nil
-}
+}

+ 47 - 0
services/roadshow/company_product.go

@@ -0,0 +1,47 @@
+package roadshow
+
+import (
+	"context"
+	"github.com/rdlucklib/rdluck_tools/orm"
+)
+
+func RoadShow(cont context.Context) (err error) {
+	roadShowTotalList, _ := GetRoadShowTotal()
+	for _, roadShowTotal := range roadShowTotalList {
+		err := updateProduct(roadShowTotal.Total, roadShowTotal.CompanyId)
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+func GetRoadShowTotal() (items []*RoadShowTotalSlice, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	a.company_id,
+	COUNT(DISTINCT a.rs_calendar_id) total 
+FROM
+	rs_calendar AS a
+	INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id = b.rs_calendar_id 
+WHERE
+	a.source = 0 
+	AND a.company_id > 0 
+	AND b.status = 2 
+	AND NOW()> DATE_FORMAT( CONCAT( end_date, " ", end_time ), '%Y-%m-%d %H:%i:%S' ) 
+GROUP BY
+	a.company_id `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+func updateProduct(total, companyId int) (err error){
+	o := orm.NewOrm()
+	sql := `UPDATE company_product SET road_show_total=? WHERE company_id=? AND product_name="ficc" `
+	_, err = o.Raw(sql,total, companyId).Exec()
+	return
+}
+type RoadShowTotalSlice struct {
+	Total     int `description:"总路演数"`
+	CompanyId int `description:"用户id"`
+}

+ 4 - 0
services/task.go

@@ -97,6 +97,10 @@ func Task() {
 	addReportRecord := task.NewTask("addReportRecord", "0 0 */1 * * *", roadshow.AddReportRecord)
 	task.AddTask("addReportRecord", addReportRecord)
 
+	//CRM 6.3 客户列表路演次数统计
+	roadShowTotal := task.NewTask("roadShowTotal", "0 */30 * * * *", roadshow.RoadShow)
+	task.AddTask("roadShowTotal", roadShowTotal)
+
 	task.StartTask()
 	fmt.Println("task end")
 }