Pārlūkot izejas kodu

feat:上周增量客户报表邮件发送

Roc 3 gadi atpakaļ
vecāks
revīzija
6b0e3703ca
4 mainītis faili ar 160 papildinājumiem un 1 dzēšanām
  1. 74 0
      models/company_product_update_log.go
  2. 1 0
      models/db.go
  3. 81 1
      services/company.go
  4. 4 0
      services/task.go

+ 74 - 0
models/company_product_update_log.go

@@ -0,0 +1,74 @@
+package models
+
+import (
+	"github.com/rdlucklib/rdluck_tools/orm"
+	"time"
+)
+
+// CompanyProductUpdateLog 客户产品变更日志表
+type CompanyProductUpdateLog struct {
+	Id         int       `orm:"column(id);pk"`
+	CompanyId  int       `description:"客户id"`
+	ProductId  int       `description:"产品id"`
+	Status     string    `description:"变更后的状态"`
+	Source     string    `description:"来源"`
+	CreateTime time.Time `description:"创建时间"`
+}
+
+// AddCompanyProductUpdateLog 新增客户产品变更日志
+func AddCompanyProductUpdateLog(item *CompanyProductUpdateLog) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// GetCompanyProductUpdateLogList 获取客户产品变更日志列表
+func GetCompanyProductUpdateLogList(createTime string) (total int64, list []*CompanyProductUpdateLog, err error) {
+	o := orm.NewOrm()
+	//那就三种情况了:新增试用、冻结转试用、流失转试用
+	//新增:add
+	//领取:receive
+	//试用转正式:turn_positive
+	//冻结转试用:thaw
+	//试用延期:delay
+	//原销售申请领取流失客户:apply_receive
+	//正式客户申请续约:service_update
+	//正式客户新增补充协议:add_agreement
+	sql := `SELECT * FROM company_product_update_log where create_time >= ? AND source in ("add","receive","thaw","apply_receive") `
+	total, err = o.Raw(sql, createTime).QueryRows(&list)
+	return
+}
+
+// IncrementCompanyProductUpdateLog 增量客户产品变更日志表
+type IncrementCompanyProductUpdateLog struct {
+	Id          int       `orm:"column(id);pk"`
+	CompanyId   int       `description:"客户id"`
+	ProductId   int       `description:"产品id"`
+	Status      string    `description:"变更后的状态"`
+	Source      string    `description:"来源"`
+	CreateTime  time.Time `description:"创建时间"`
+	CompanyName string    `description:"客户名称"`
+	CreditCode  string    `description:"社会信用码"`
+	SellerName  string    `description:"销售名称"`
+	CurrStatus  string    `description:"当前产品状态"`
+}
+
+// GetIncrementCompanyProductUpdateLogList 获取客户产品变更日志列表
+func GetIncrementCompanyProductUpdateLogList(startCreateTime, endCreateTime string) (total int64, list []*IncrementCompanyProductUpdateLog, err error) {
+	o := orm.NewOrm()
+	//那就三种情况了:新增试用、冻结转试用、流失转试用
+	//新增:add
+	//领取:receive
+	//试用转正式:turn_positive
+	//冻结转试用:thaw
+	//试用延期:delay
+	//原销售申请领取流失客户:apply_receive
+	//正式客户申请续约:service_update
+	//正式客户新增补充协议:add_agreement
+	sql := `SELECT a.*,b.company_name,b.credit_code,c.status curr_status,c.seller_name FROM company_product_update_log a 
+join company b on a.company_id=b.company_id
+join company_product c on a.company_id=c.company_id and c.product_id=a.product_id 
+where a.create_time >= ? AND a.create_time < ? AND a.source in ("add","receive","thaw","apply_receive") `
+	total, err = o.Raw(sql, startCreateTime, endCreateTime).QueryRows(&list)
+	return
+}

+ 1 - 0
models/db.go

@@ -93,5 +93,6 @@ func init() {
 		new(yb.ActivityRegister),                 //研报活动报名表
 		new(yb.Speaker),                          //研报主持人表
 		new(data_manage.EdbDataLt),               //路透指标数据表
+		new(CompanyProductUpdateLog),             //客户产品状态变更表
 	)
 }

+ 81 - 1
services/company.go

@@ -1,10 +1,12 @@
 package services
 
 import (
+	"context"
 	"fmt"
 	"github.com/tealeg/xlsx"
 	"hongze/hongze_task/models"
 	"hongze/hongze_task/utils"
+	"os"
 	"strings"
 	"time"
 )
@@ -204,7 +206,7 @@ func ImportCompanyUsers() {
 	fmt.Println("len:", n)
 }
 
-//导入客户信用码
+// 导入客户信用码
 func ImportCompanyCreditCode() {
 	var err error
 	defer func() {
@@ -277,3 +279,81 @@ func ImportCompanyCreditCode() {
 	}
 	fmt.Println("len:", n)
 }
+
+// IncrementCompany 增量客户
+func IncrementCompany(cont context.Context) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("crete IncrementCompany err:", err.Error())
+			utils.FileLog.Info(fmt.Sprintf("crete IncrementCompany err: %s", err.Error()))
+		}
+	}()
+
+	//endTime := time.Now().Format(utils.FormatDateTime)
+	startTime := time.Now().AddDate(0, 0, -7).Format(utils.FormatDate)
+	endTime := time.Now().AddDate(0, 0, 1).Format(utils.FormatDate)
+
+	_, items, err := models.GetIncrementCompanyProductUpdateLogList(startTime, endTime)
+	if err != nil {
+		return
+	}
+	title := "增量客户记录"
+	//创建excel
+	file := xlsx.NewFile()
+	sheet, err := file.AddSheet(title)
+	if err != nil {
+		return err
+	}
+	//标头
+	rowTitle := sheet.AddRow()
+	cellA := rowTitle.AddCell()
+	cellA.Value = "客户名称"
+	cellB := rowTitle.AddCell()
+	cellB.Value = "社会信用码"
+	cellC := rowTitle.AddCell()
+	cellC.Value = "客户类型"
+	cellD := rowTitle.AddCell()
+	cellD.Value = "客户状态"
+	cellE := rowTitle.AddCell()
+	cellE.Value = "所属销售"
+
+	for _, item := range items {
+		row := sheet.AddRow()
+		cellA := row.AddCell()
+		cellA.Value = item.CompanyName
+		cellB := row.AddCell()
+		cellB.Value = item.CreditCode
+		cellC := row.AddCell()
+
+		productName := ``
+		switch item.ProductId {
+		case 1:
+			productName = "ficc"
+		case 2:
+			productName = `权益`
+		}
+		cellC.Value = productName
+
+		cellD := row.AddCell()
+		cellD.Value = item.CurrStatus
+		cellE := row.AddCell()
+		cellE.Value = item.SellerName
+	}
+
+	savePath := "increment_company_" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	err = file.Save("./" + savePath)
+	if err != nil {
+		return
+	}
+	//发送邮件
+	fmt.Println("start send email")
+	//收取邮件的人
+	emailUser := "kwhuang@hzinsights.com;csun@hzinsights.com;pyan@hzinsights.com"
+	sendResult := utils.SendEmailByHongze(title, "增量客户记录',\"你好,上周的增量客户记录列表见附件。", emailUser, savePath, title+".xlsx")
+	if sendResult {
+		os.Remove(savePath)
+	}
+	//fmt.Println("send result:", sendResult)
+	fmt.Println("end send email")
+	return nil
+}

+ 4 - 0
services/task.go

@@ -114,6 +114,10 @@ func releaseTask() {
 	freeViewerDetail := task.NewTask("freeViewerDetail", "0 0 9 * * 1 ", FreeViewerDetail)
 	task.AddTask("潜在客户", freeViewerDetail)
 
+	//上周增量客户列表
+	incrementCompany := task.NewTask("incrementCompany", "0 0 9 * * 1 ", IncrementCompany)
+	task.AddTask("上周增量客户列表", incrementCompany)
+
 	//刷新指标数据
 	refreshData := task.NewTask("refreshData", "0 1 0,19 * * *", RefreshData)
 	task.AddTask("refreshData", refreshData)