|
@@ -1,8 +1,13 @@
|
|
|
package cust
|
|
package cust
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "bytes"
|
|
|
"context"
|
|
"context"
|
|
|
|
|
+ "encoding/csv"
|
|
|
|
|
+ "math"
|
|
|
|
|
+ "sort"
|
|
|
"strconv"
|
|
"strconv"
|
|
|
|
|
+ "time"
|
|
|
|
|
|
|
|
"github.com/gogf/gf/errors/gerror"
|
|
"github.com/gogf/gf/errors/gerror"
|
|
|
"github.com/gogf/gf/frame/g"
|
|
"github.com/gogf/gf/frame/g"
|
|
@@ -10,16 +15,22 @@ import (
|
|
|
"github.com/gogf/gf/util/gconv"
|
|
"github.com/gogf/gf/util/gconv"
|
|
|
|
|
|
|
|
"dashoo.cn/micro/app/dao/cust"
|
|
"dashoo.cn/micro/app/dao/cust"
|
|
|
|
|
+ platdao "dashoo.cn/micro/app/dao/plat"
|
|
|
model "dashoo.cn/micro/app/model/cust"
|
|
model "dashoo.cn/micro/app/model/cust"
|
|
|
"dashoo.cn/micro/app/service"
|
|
"dashoo.cn/micro/app/service"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+const TIME_LAYOUT = "2006-01-02 15:04:05"
|
|
|
|
|
+
|
|
|
|
|
+var derivetable = []string{"客户编码", "客户名称", "助记名", "所在地区", "客户行业", "客户行业", "客户状态", "最后跟进时间", "创建人", "创建时间"}
|
|
|
|
|
+
|
|
|
type CustomerService struct {
|
|
type CustomerService struct {
|
|
|
*service.ContextService
|
|
*service.ContextService
|
|
|
Dao *cust.CustCustomerDao
|
|
Dao *cust.CustCustomerDao
|
|
|
BelongDao *cust.CustCustomerBelongDao
|
|
BelongDao *cust.CustCustomerBelongDao
|
|
|
DynamicsDao *cust.CustCustomerDynamicsDao
|
|
DynamicsDao *cust.CustCustomerDynamicsDao
|
|
|
ContactDao *cust.CustCustomerContactDao
|
|
ContactDao *cust.CustCustomerContactDao
|
|
|
|
|
+ FollowDao *platdao.PlatFollowupDao
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var isPublic, noPublic = "10", "20" // 公海,非公海
|
|
var isPublic, noPublic = "10", "20" // 公海,非公海
|
|
@@ -40,9 +51,51 @@ func NewCustomerService(ctx context.Context) (svc *CustomerService, err error) {
|
|
|
svc.BelongDao = cust.NewCustCustomerBelongDao(svc.Tenant)
|
|
svc.BelongDao = cust.NewCustCustomerBelongDao(svc.Tenant)
|
|
|
svc.DynamicsDao = cust.NewCustCustomerDynamicsDao(svc.Tenant)
|
|
svc.DynamicsDao = cust.NewCustCustomerDynamicsDao(svc.Tenant)
|
|
|
svc.ContactDao = cust.NewCustCustomerContactDao(svc.Tenant)
|
|
svc.ContactDao = cust.NewCustCustomerContactDao(svc.Tenant)
|
|
|
|
|
+ svc.FollowDao = platdao.NewPlatFollowupDao(svc.Tenant)
|
|
|
return svc, nil
|
|
return svc, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+//导出数据
|
|
|
|
|
+func (c *CustomerService) Derive(req *model.CustCustomerSearchReq) (bytesBuffer *bytes.Buffer, err error) {
|
|
|
|
|
+ //file, err := os.Create("cust_list.csv")
|
|
|
|
|
+ //g.Log().Info("xxxx", "cust_list")
|
|
|
|
|
+ //if err != nil {
|
|
|
|
|
+ // fmt.Println("open file is failed, err: ", err)
|
|
|
|
|
+ //}
|
|
|
|
|
+ req.TargetType = "11"
|
|
|
|
|
+ _, data, _ := c.GetList(req)
|
|
|
|
|
+ // 延迟关闭
|
|
|
|
|
+ //buffer := &bytes.Buffer{}
|
|
|
|
|
+ bytesBuffer = &bytes.Buffer{}
|
|
|
|
|
+ bytesBuffer.WriteString("xEFxBBxBF")
|
|
|
|
|
+ //defer file.Close()
|
|
|
|
|
+ //// 写入UTF-8 BOM,防止中文乱码
|
|
|
|
|
+ // buffer.WriteString("\xEF\xBB\xBF")
|
|
|
|
|
+ w := csv.NewWriter(bytesBuffer)
|
|
|
|
|
+ // 写入数据
|
|
|
|
|
+ w.Write(derivetable)
|
|
|
|
|
+ w.Flush()
|
|
|
|
|
+ // Map写入
|
|
|
|
|
+ m := make(map[int][]string)
|
|
|
|
|
+ for k, v := range data {
|
|
|
|
|
+ m[k] = []string{v.CustCode, v.CustName, v.AbbrName, v.CustLocation, v.CustIndustry, v.CustLevel, v.CustStatus,
|
|
|
|
|
+ gconv.String(v.FollowUpDate), v.CreatedName, gconv.String(v.CreatedTime)}
|
|
|
|
|
+ }
|
|
|
|
|
+ // 按照key排序
|
|
|
|
|
+ var keys []int
|
|
|
|
|
+ for k := range m {
|
|
|
|
|
+ keys = append(keys, k)
|
|
|
|
|
+ }
|
|
|
|
|
+ sort.Ints(keys)
|
|
|
|
|
+ for _, key := range keys {
|
|
|
|
|
+ w.Write(m[key])
|
|
|
|
|
+ // 刷新缓冲
|
|
|
|
|
+ }
|
|
|
|
|
+ w.Flush()
|
|
|
|
|
+
|
|
|
|
|
+ return
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
//创建客户
|
|
//创建客户
|
|
|
func (c *CustomerService) Create(req *model.Customer) (insertId int64, err error) {
|
|
func (c *CustomerService) Create(req *model.Customer) (insertId int64, err error) {
|
|
|
cusTomer := new(model.CustCustomer)
|
|
cusTomer := new(model.CustCustomer)
|
|
@@ -123,8 +176,9 @@ func (c *CustomerService) GetList(req *model.CustCustomerSearchReq) (total int,
|
|
|
g.Log().Info("serverS", req)
|
|
g.Log().Info("serverS", req)
|
|
|
Model := c.Dao.M
|
|
Model := c.Dao.M
|
|
|
Model = Model.Where(c.Dao.Columns.DeletedTime + " is null")
|
|
Model = Model.Where(c.Dao.Columns.DeletedTime + " is null")
|
|
|
- if req.TargetType != "" {
|
|
|
|
|
|
|
+ if req.TargetType == "" {
|
|
|
if !req.IsPublic {
|
|
if !req.IsPublic {
|
|
|
|
|
+ g.Log().Info("ISPUblic", "xxxxxx")
|
|
|
Model = Model.Where(c.Dao.Columns.SalesId, c.CxtUser.Id).Where(c.Dao.Columns.IsPublic, noPublic)
|
|
Model = Model.Where(c.Dao.Columns.SalesId, c.CxtUser.Id).Where(c.Dao.Columns.IsPublic, noPublic)
|
|
|
} else {
|
|
} else {
|
|
|
g.Log().Info("serverS", req)
|
|
g.Log().Info("serverS", req)
|
|
@@ -282,7 +336,8 @@ func (c *CustomerService) DistriCustomer(req *model.DistriCustomer) error {
|
|
|
|
|
|
|
|
//客户详情
|
|
//客户详情
|
|
|
func (c *CustomerService) GetEntityById(ids []int64) (entityInfo []*model.CustList, err error) {
|
|
func (c *CustomerService) GetEntityById(ids []int64) (entityInfo []*model.CustList, err error) {
|
|
|
- Model := c.Dao.M
|
|
|
|
|
|
|
+ Model := c.Dao.M //
|
|
|
|
|
+ //FollowModel := c.FollowDao.M
|
|
|
|
|
|
|
|
err = Model.Where(cust.CustCustomer.Columns.Id+" in (?)", ids).Scan(&entityInfo)
|
|
err = Model.Where(cust.CustCustomer.Columns.Id+" in (?)", ids).Scan(&entityInfo)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -292,6 +347,59 @@ func (c *CustomerService) GetEntityById(ids []int64) (entityInfo []*model.CustLi
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+//客户摘要
|
|
|
|
|
+func (c *CustomerService) CustAbstract(id int64) (followInfo *model.Follow, err error) {
|
|
|
|
|
+ custModel := c.Dao.M //
|
|
|
|
|
+ Model := c.FollowDao.M
|
|
|
|
|
+
|
|
|
|
|
+ count, err := Model.Where(c.FollowDao.Columns.CustId, id).Count()
|
|
|
|
|
+ g.Log().Info("count", count)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ return nil, gerror.New("获取用户数据失败")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ followInfo = new(model.Follow)
|
|
|
|
|
+ followInfo.FollowCount = count
|
|
|
|
|
+ //
|
|
|
|
|
+ find, err := custModel.Fields(c.Dao.Columns.FollowUpDate).Where(c.Dao.Columns.Id, id).FindOne()
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ return nil, gerror.New("获取用户数据失败")
|
|
|
|
|
+ }
|
|
|
|
|
+ if find.IsEmpty() {
|
|
|
|
|
+ followInfo.NotFollowDay = 0
|
|
|
|
|
+ }
|
|
|
|
|
+ findOne := find.Map()
|
|
|
|
|
+ //followDate, err := Model.Fields("max(next_time) as next_time").Where(c.FollowDao.Columns.CustId, id).Where(c.FollowDao.Columns.FollowDate, findOne["follow_up_date"]).FindOne()
|
|
|
|
|
+ //if followDate.IsEmpty() {
|
|
|
|
|
+ // followInfo.NotFollowDay = 0
|
|
|
|
|
+ //}
|
|
|
|
|
+ //followNextTime := followDate.Map()
|
|
|
|
|
+ //next_time := gconv.String(followNextTime["next_time"])
|
|
|
|
|
+ upDate := gconv.String(findOne["follow_up_date"])
|
|
|
|
|
+ follow_up, err1 := time.Parse(TIME_LAYOUT, upDate)
|
|
|
|
|
+ now := gtime.Now()
|
|
|
|
|
+ follow_next, err2 := time.Parse(TIME_LAYOUT, gconv.String(now))
|
|
|
|
|
+ if err1 != nil || err2 != nil {
|
|
|
|
|
+ followInfo.NotFollowDay = 0
|
|
|
|
|
+ }
|
|
|
|
|
+ poor := follow_next.Sub(follow_up)
|
|
|
|
|
+ g.Log().Info("xxxxfdsaf", poor)
|
|
|
|
|
+ hours := float64(poor.Hours() / 24)
|
|
|
|
|
+ if hours < 0 {
|
|
|
|
|
+ followInfo.NotFollowDay = 0
|
|
|
|
|
+ } else {
|
|
|
|
|
+ followInfo.NotFollowDay = int(math.Floor(hours))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //g.Log().Info("findOne_time", findOne["follow_up_date"])
|
|
|
|
|
+ //g.Log().Info("next_time", next_time)
|
|
|
|
|
+ //g.Log().Info("ceil", math.Ceil(hours))
|
|
|
|
|
+ return
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
//转移客户
|
|
//转移客户
|
|
|
func (c *CustomerService) UpdateBytransfer(req *model.CustSalesReq) (entityInfo []*model.CustCustomer, err error) {
|
|
func (c *CustomerService) UpdateBytransfer(req *model.CustSalesReq) (entityInfo []*model.CustCustomer, err error) {
|
|
|
custModel := c.Dao.M
|
|
custModel := c.Dao.M
|