فهرست منبع

feat:初始化

wangchuanjin 9 ماه پیش
والد
کامیت
7023adc272
9فایلهای تغییر یافته به همراه0 افزوده شده و 1228 حذف شده
  1. 0 373
      service/custom.go
  2. 0 80
      service/ent.go
  3. 0 48
      service/file.go
  4. 0 40
      service/group.go
  5. 0 241
      service/sale_chance.go
  6. 0 204
      service/sale_clue.go
  7. 0 64
      service/sendMsg.go
  8. 0 48
      service/user.go
  9. 0 130
      service/util.go

+ 0 - 373
service/custom.go

@@ -1,373 +0,0 @@
-package service
-
-import (
-	"context"
-	"database/sql"
-	"fmt"
-	"log"
-	"strings"
-	"time"
-
-	qu "app.yhyue.com/moapp/jybase/common"
-	"app.yhyue.com/moapp/jybase/date"
-	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
-	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
-	"bp.jydev.jianyu360.cn/CRM/application/entity"
-	baseC "bp.jydev.jianyu360.cn/CRM/baseCenter/rpc/pb"
-	"github.com/gogf/gf/v2/util/gconv"
-)
-
-// 客户相关
-type CustomService struct {
-	BaseUserId           int64
-	PositionId           int64
-	EntUserId            int64
-	EntId                int64
-	AppId                string
-	AccountId            int64
-	EntDeptId            int64
-	CustomType           int64   //客户类型
-	Summary              string  //概要信息
-	CustomAllName        string  //客户全称
-	CustomAbbreviation   string  //客户简称
-	CustomLevel          int64   //客户级别
-	CustomIndustry       int64   //客户行业
-	CustomDetailIndustry int64   //客户细分行业
-	Province             string  //省份
-	City                 string  //城市
-	District             string  //地区
-	Address              string  //详细地址
-	CompanyPhone         string  //公司电话
-	NextfollowUpTime     int64   //下次跟进时间戳
-	Types                int64   //处理方式 1自办;2转办
-	User                 []int64 //转办用户
-	EmployCustomId       int64   //客户收录id
-	EmployInfoId         int64   //资讯收录id
-	Remarks              string  //备注
-	CreateName           string  //创建人
-	Source               string
-	OwnerId              string //潜客收录id(人脉)
-	BusinessId           string //商机收录id(人脉)
-}
-
-// Add 创建客户
-func (this *CustomService) Add(ctx context.Context) (int64, string) {
-	nowtime := time.Now().Format(date.Date_Full_Layout)
-	nextFollowTime := time.Unix(this.NextfollowUpTime, 0).Format(date.Date_Full_Layout)
-
-	args := []interface{}{}
-	argsTask := []interface{}{}
-	argsTaskTeam := []interface{}{}
-	//判断处理方式
-	//转办
-	baseUserIdArr := []int64{}
-	customId, taskId := int64(-1), int64(-1)
-	groupId := ""
-	if this.Types == 2 {
-		transferArr := []int64{}
-		for _, v := range this.User {
-			i_entuserid := v
-			resp, err := cm.UserCenterRpc.IdentityByEntUserId(ctx, &pb.IdentityReq{
-				Id: i_entuserid,
-			})
-			if err != nil {
-				log.Println("获取用户职位id信息出错", i_entuserid, "的信息出错", err)
-				return -1, groupId
-			} else if resp == nil {
-				log.Println("entuser用户", i_entuserid, "没有找到职位信息")
-				return -1, groupId
-			}
-			transferArr = append(transferArr, resp.PositionId)
-			baseUserIdArr = append(baseUserIdArr, resp.UserId)
-		}
-		//客户
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.EmployCustomId, this.CustomType, this.CustomAllName, this.CustomAbbreviation, this.Summary, qu.If(this.CustomLevel == 0, nil, this.CustomLevel), this.CustomIndustry, this.CustomDetailIndustry, qu.If(this.Province == "", nil, this.Province), qu.If(this.City == "", nil, this.City), qu.If(this.District == "", nil, this.District), qu.If(this.Address == "", nil, this.Address), qu.If(this.CompanyPhone == "", nil, this.CompanyPhone), qu.If(this.Remarks == "", nil, this.Remarks), this.CreateName, nowtime, this.Source, this.OwnerId, this.BusinessId)
-		//任务
-		argsTask = append(argsTask, this.EntId, this.CustomAllName+"的跟进任务", 3, this.PositionId, 1, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), nil, nil)
-		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.OwnerId, this.BusinessId, this.PositionId, this.CreateName, transferArr, this.EntId, this.EntUserId, this.EntDeptId)
-		if customId < 0 {
-			return -1, groupId
-		}
-	} else if this.Types == 1 {
-		//客户
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.EmployCustomId, this.CustomType, this.CustomAllName, this.CustomAbbreviation, this.Summary, qu.If(this.CustomLevel == 0, nil, this.CustomLevel), this.CustomIndustry, this.CustomDetailIndustry, qu.If(this.Province == "", nil, this.Province), qu.If(this.City == "", nil, this.City), qu.If(this.District == "", nil, this.District), qu.If(this.Address == "", nil, this.Address), qu.If(this.CompanyPhone == "", nil, this.CompanyPhone), qu.If(this.Remarks == "", nil, this.Remarks), this.CreateName, nowtime, this.Source, this.OwnerId, this.BusinessId)
-		//任务s
-		argsTask = append(argsTask, this.EntId, this.CustomAllName+"的跟进任务", 3, this.PositionId, 2, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), nil, nil)
-		//任务团队
-		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
-		//存库
-		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.OwnerId, this.BusinessId, this.PositionId, this.CreateName, []int64{}, this.EntId, this.EntUserId, this.EntDeptId)
-		if customId < 0 {
-			return -1, groupId
-		}
-		baseUserIdArr = append(baseUserIdArr, this.BaseUserId)
-
-		//自办 创建 群聊
-		// gp := &Group{
-		// 	EntId:      this.EntId,
-		// 	PositionId: this.PositionId,
-		// 	UserIdArr:  []int64{},
-		// 	AppId:      this.AppId,
-		// 	EntUserId:  this.EntUserId,
-		// 	AccountId:  this.AccountId,
-		// }
-		// groupId = gp.GroupAdd()
-	} else if this.Types == 3 {
-		transferArr := []int64{}
-		transferArr = append(transferArr, this.PositionId)
-		//客户
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.EmployCustomId, this.CustomType, this.CustomAllName, this.CustomAbbreviation, this.Summary, qu.If(this.CustomLevel == 0, nil, this.CustomLevel), this.CustomIndustry, this.CustomDetailIndustry, qu.If(this.Province == "", nil, this.Province), qu.If(this.City == "", nil, this.City), qu.If(this.District == "", nil, this.District), qu.If(this.Address == "", nil, this.Address), qu.If(this.CompanyPhone == "", nil, this.CompanyPhone), qu.If(this.Remarks == "", nil, this.Remarks), this.CreateName, nowtime, this.Source, this.OwnerId, this.BusinessId)
-		//任务
-		argsTask = append(argsTask, this.EntId, this.CustomAllName+"的跟进任务", 3, this.PositionId, 1, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), nil, nil)
-		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.OwnerId, this.BusinessId, this.PositionId, this.CreateName, transferArr, this.EntId, this.EntUserId, this.EntDeptId)
-		if customId < 0 {
-			return -1, groupId
-		}
-		baseUserIdArr = append(baseUserIdArr, this.BaseUserId)
-	}
-	u := &User{BaseUserIds: baseUserIdArr}
-
-	if this.Types != 3 {
-		var kb strings.Builder
-		var vb strings.Builder
-		for k, v := range u.GetUserId(this.EntId) {
-			kb.WriteString(k + ",")
-			vb.WriteString(gconv.String(v) + ",")
-			userId := strings.TrimRight(kb.String(), ",")
-			positionId := strings.TrimRight(vb.String(), ",")
-			next := strings.Replace(time.Unix(this.NextfollowUpTime, 0).Format(YYYYMMDDHHMM), " ", "%20", -1)
-			pcHref := ""
-			content := ""
-			if this.Types == 1 {
-				pcHref = fmt.Sprintf(cm.Push.Custom.Create.MyselfPcHref, positionId, taskId, customId)
-				content = fmt.Sprintf(cm.Push.Custom.Create.MySelfContent, this.CreateName, strings.Replace(date.NowFormat(YYYYMMDDHHMM), " ", "%20", -1), next)
-			} else if this.Types == 2 {
-				pcHref = fmt.Sprintf(cm.Push.Custom.Create.TransferPcHref, positionId)
-				content = fmt.Sprintf(cm.Push.Custom.Create.TransferContent, this.CreateName, strings.Replace(date.NowFormat(YYYYMMDDHHMM), " ", "%20", -1), next)
-			}
-			StationMailPush(userId, positionId, cm.Push.Custom.Create.Title, content, pcHref, cm.Push.Custom.Create.MobileHref, "11")
-		}
-	}
-
-	return 1, groupId
-}
-
-func SaleCustomAdd(tx *sql.Tx, args []interface{}) int64 {
-	fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "employ_custom_id", "type", "full_name", "sort_name", "summary", "level", "industry", "subdivision_industry", "province", "city", "county", "address", "phone", "remark", "create_person", "create_time", "source", "connection_owner_id", "connection_business_id"}
-	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.CUSTOM, fields, args)
-	return id
-}
-
-// EmployUpdate 是否创建线索/机会/客户修改
-// return employ_info_id,employ_custom_id
-func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64, key string, entId, entUserId, entDeptId int64) (int64, int64) {
-	tablename := ""
-	id := int64(0)
-	if employ_custom_id > 0 {
-		tablename = entity.EMPLOY_CUSTOM
-		id = employ_custom_id
-	} else if employ_info_id > 0 {
-		tablename = entity.EMPLOY_INFO
-		id = employ_info_id
-	}
-	fmt.Println(tablename, id)
-	if tablename == "" || id == 0 {
-		return employ_info_id, employ_custom_id
-	}
-	//判断该条信息是不是当前资讯分配员的
-	d := cm.CrmMysql.SelectBySqlByTx(tx, fmt.Sprintf(`select * from %v where id = ?`, tablename), id)
-	fmt.Println(d)
-	if d != nil && len(*d) > 0 {
-		data := (*d)[0]
-		position_id := gconv.Int64(data["position_id"])
-		if position_id == positionId {
-			cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{"id": id, "position_id": positionId}, map[string]interface{}{key: 1, "is_handle": 1})
-		} else {
-			//判断是否已创建该条,但是是取消收录状态、如果是则改为已收录,不是则创建一条新的
-			d2 := cm.CrmMysql.SelectBySqlByTx(tx, fmt.Sprintf(`select * from %v where source_id = ? and position_id =?`, tablename), data["source_id"], positionId)
-			if d2 != nil && len(*d2) > 0 {
-				//已创建
-				qwe := cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{
-					"source_id":   data["source_id"],
-					"position_id": positionId,
-				}, map[string]interface{}{
-					key:      1,
-					"status": 1,
-				})
-				log.Println(qwe, data["source_id"], positionId)
-			} else {
-				data["position_id"] = positionId
-				data["ent_id"] = entId
-				data["ent_dept_id"] = entDeptId
-				data["ent_user_id"] = entUserId
-				//当前咨询不是分配员的 创建该条
-				if employ_custom_id > 0 {
-					//
-					data["is_handle"] = 1
-					data["is_ignore"] = 0
-					data["is_create_custom"] = 1
-
-				} else if employ_info_id > 0 {
-					data["is_handle"] = 1
-					data["is_ignore"] = 0
-					data["is_dis"] = 0
-					data[key] = 1
-					for _, v := range GetOtherKey(key) {
-						data[v] = 0
-					}
-				}
-				delete(data, "id")
-				newId := cm.CrmMysql.InsertByTx(tx, tablename, data)
-				if tablename == entity.EMPLOY_INFO {
-					employ_info_id = newId
-				} else if tablename == entity.EMPLOY_CUSTOM {
-					employ_custom_id = newId
-				}
-			}
-		}
-	}
-	return employ_info_id, employ_custom_id
-}
-
-func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id int64, ownerId, connectionBusinessId string, positionId int64, createPerson string, transferArr []int64, entId, entUserId, entDeptId int64) (int64, int64) {
-	customId := int64(-1)
-	taskId := int64(-1)
-	//存库
-	cm.CrmMysql.ExecTx("创建客户", func(tx *sql.Tx) bool {
-		//修改状态
-		employ_info_id_new, employ_custom_id_new := EmployUpdate(tx, employ_info_id, employ_custom_id, positionId, "is_create_custom", entId, entUserId, entDeptId)
-		//插入客户
-
-		//修改客户id、咨询id
-		argsCustom[3] = employ_info_id_new
-		argsCustom[4] = employ_custom_id_new
-
-		customId = SaleCustomAdd(tx, argsCustom)
-		//传过来的argTask没有来源id,需要append
-		argsTask = append(argsTask, customId)
-		//任务车存储
-		taskId = TaskAdd(tx, argsTask, argsTaskTeam, transferArr, positionId)
-		//插入台账
-		ok2 := SaveLedger(ctx, positionId, customId, taskId, "创建客户", fmt.Sprintf("%s创建了客户", createPerson), createPerson)
-		//人脉信息添加
-		if ownerId != "" || connectionBusinessId != "" {
-			SaveConnection(tx, positionId, connectionBusinessId, ownerId, entId, entDeptId, entUserId)
-		}
-		if customId > 0 && taskId > 0 && ok2 {
-			return true
-		}
-		log.Println("SaveCustom err:", customId, taskId)
-		return false
-	})
-	return customId, taskId
-}
-
-// SaveLedger 操作台帐相关
-func SaveLedger(ctx context.Context, positionId, businessId, taskId int64, types, content, createPerson string) bool {
-	//操作台账
-	resp, err := cm.BaseCenterRpc.LedgerAdd(ctx, &baseC.LedgerAddReq{
-		PositionId:   positionId,
-		BusinessId:   businessId, //业务id
-		TaskId:       taskId,     //任务id
-		Types:        types,      //类型
-		Content:      content,    //内容
-		CreateWay:    1,          //创建方式 1:人 2:系统
-		CreatePerson: createPerson,
-	})
-	if err != nil {
-		log.Println("save ledger err:", err)
-		return false
-	}
-	if resp == nil {
-		log.Println("save ledger resp is nil")
-		return false
-	}
-	return resp.State
-}
-
-// 消息漏斗保存
-func saveSalesFunnel(tx *sql.Tx, args []interface{}, tpl_id int64) int64 {
-	fields := []string{`chance_id`, `task_id`, `chance_name`, `outline`, `next_follow_time`, `expected_transaction_amount`, `business_type`, `ent_id`, `employ_info_id`, `current_generation`, `current_generation_progress`, `generation`}
-	//当前阶段
-	stageId := int64(0)
-	stageData := cm.CrmMysql.Find(entity.CONFIG_TPL_STAGE, map[string]interface{}{
-		"tpl_id": tpl_id}, "id, `order`", "", -1, -1)
-	if stageData != nil && len(*stageData) > 0 {
-		var a1 []interface{}
-		for _, m := range *stageData {
-			stageId = gconv.Int64(m["id"])
-			order := gconv.Int(m["order"])
-			a1 = append(a1, args...)
-			if order == 1 {
-				a1 = append(a1, stageId)
-			} else {
-				a1 = append(a1, 0)
-			}
-			a1 = append(a1, 0)
-			a1 = append(a1, stageId)
-			//进度查询
-			/*matterData := cm.CrmMysql.SelectBySql("select COUNT(1) as ratio from config_stage_matter where stage_id=? and is_must == 1", stageId)
-			if matterData != nil && len(*matterData) > 0 {
-				ratio := gconv.Int64((*matterData)[0]["ratio"])
-				a1 = append(a1, ratio)
-			} else {
-				a1 = append(a1, 0)
-			}*/
-		}
-		//当前阶段进展
-		_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALES_FUNNEL, fields, a1)
-		return id
-		/**/
-	}
-	return 0
-}
-func GetOtherKey(key string) []string {
-	parameters := map[string][]string{
-		"is_create_clue":   {"is_create_chance", "is_create_custom"},
-		"is_create_chance": {"is_create_clue", "is_create_custom"},
-		"is_create_custom": {"is_create_chance", "is_create_clue"},
-	}
-	return parameters[key]
-}
-func SaveConnection(tx *sql.Tx, positionId int64, businessId, ownerId string, entId, entDeptId, entUserId int64) bool {
-	if businessId != "" || ownerId != "" {
-		table := entity.CONNECTION_STATUS
-		sourceType := 2
-		if businessId == "" {
-			businessId = ownerId
-			sourceType = 1
-		}
-		if cm.CrmMysql.Count(table, map[string]interface{}{
-			"position_id": positionId,
-			"relate_id":   businessId,
-			"itype":       sourceType,
-		}) > 0 {
-			cm.CrmMysql.UpdateByTx(tx, table, map[string]interface{}{
-				"position_id": positionId,
-				"relate_id":   businessId,
-				"itype":       sourceType,
-			}, map[string]interface{}{
-				"is_handle":   1,
-				"relate_id":   businessId,
-				"update_time": time.Now().Format(date.Date_Full_Layout),
-				"is_create":   1,
-			})
-			return true
-		} else {
-			id := cm.CrmMysql.InsertByTx(tx, table, map[string]interface{}{
-				"position_id": positionId,
-				"ent_id":      entId,
-				"ent_dept_id": entDeptId,
-				"ent_user_id": entUserId,
-				"relate_id":   businessId,
-				"is_handle":   1,
-				"is_create":   1,
-				"itype":       sourceType,
-				"create_time": time.Now().Format(date.Date_Full_Layout),
-				"update_time": time.Now().Format(date.Date_Full_Layout),
-			})
-			return id > 0
-		}
-	}
-	return true
-}

+ 0 - 80
service/ent.go

@@ -1,80 +0,0 @@
-package service
-
-import (
-	"app.yhyue.com/moapp/jybase/common"
-	MC "bp.jydev.jianyu360.cn/CRM/application/api/common"
-	"errors"
-	"log"
-	"strings"
-	"time"
-)
-
-type EntService struct {
-}
-
-const (
-	Date_Full_Layout  = "2006-01-02 15:04:05"
-	Date_Short_Layout = "2006-01-02"
-)
-
-func (in *EntService) EntInfo(entName string) (map[string]interface{}, error) {
-	entinfo, _ := MC.MgoEnt.FindOneByField("qyxy_std", map[string]interface{}{"company_name": entName}, map[string]interface{}{
-		"company_type": 1, //公司类型
-		//"issue_date":          1, //核准日期
-		"operation_startdate": 1, //营业期限开始
-		"operation_enddate":   1, //营业期限结束
-		//"authority":           1, //登记机关
-		"credit_no":       1, //统一社会信用代码
-		"tax_code":        1, //纳税人识别码
-		"capital":         1, //注册资本
-		"establish_date":  1, //成立日期
-		"company_status":  1, //经营状态
-		"employee_no":     1, //员工规模
-		"company_address": 1, //注册地
-		"business_scope":  1, //经营范围
-		"company_code":    1, //工商注册号
-		"org_code":        1, //组织机构代码
-		//"stock_realcapital":   1, //实缴资本
-		"legal_person":  1, //法人姓名
-		"company_phone": 1, //公司电话
-	})
-	if entinfo == nil || len(*entinfo) == 0 {
-		log.Println()
-		return nil, errors.New("未查询到企业相关信息")
-	}
-	rData := map[string]interface{}{
-		"type":         (*entinfo)["company_type"],
-		"status":       (*entinfo)["company_status"],
-		"creditNo":     (*entinfo)["credit_no"],
-		"taxCode":      (*entinfo)["tax_code"],
-		"capital":      (*entinfo)["capital"],
-		"employeeNo":   (*entinfo)["employee_no"],
-		"address":      (*entinfo)["company_address"],
-		"scope":        (*entinfo)["business_scope"],
-		"company_code": (*entinfo)["company_code"],
-		"org_code":     (*entinfo)["org_code"],
-		"operStart":    paseDateToint64(common.ObjToString((*entinfo)["operation_startdate"])),
-		"operEnd":      paseDateToint64(common.ObjToString((*entinfo)["operation_enddate"])),
-		"establish":    paseDateToint64(common.ObjToString((*entinfo)["establish_date"])),
-		"legal":        (*entinfo)["legal_person"],
-		"phone":        (*entinfo)["company_phone"],
-		"entName":      (*entinfo)["company_name"],
-	}
-	return rData, nil
-}
-func paseDateToint64(dateStr string) (timeStamp int64) {
-	timeStamp = -1
-	if dateStr == "" {
-		return
-	}
-	if thisTime, err := time.Parse(Date_Short_Layout, dateStr); err == nil {
-		timeStamp = thisTime.Unix()
-	}
-	//企业变更部分信息时间格式2017-04-18 00:00:00.0
-	if len(strings.Split(dateStr, " ")) == 2 {
-		if thisTime, err := time.Parse(Date_Full_Layout, dateStr); err == nil {
-			timeStamp = thisTime.Unix()
-		}
-	}
-	return
-}

+ 0 - 48
service/file.go

@@ -1,48 +0,0 @@
-package service
-
-import (
-	"database/sql"
-	"time"
-
-	"app.yhyue.com/moapp/jybase/date"
-	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
-	"github.com/zeromicro/go-zero/core/logx"
-)
-
-//文件相关
-
-type File struct {
-	Name       string //附件名称
-	Suffix     string //文件后缀
-	FileType   string //文件类型,产品介绍、项目方案、立项报告、报价文件、招标文件、投标文件、中标通知书、合同、发票、其他文件
-	Size       string //文件大小
-	Oss        string //oss地址
-	BusinessId int64  //业务id
-	Types      int64  //类型;1:跟进记录-线下 2:跟进记录-线上 3:跟进记录-备忘 4:销售机会-项目文档 5:客户-客户档案
-}
-
-//Add 文件上传
-func (this *File) Add() bool {
-	//存库
-	return cm.CrmMysql.ExecTx("上传文件", func(tx *sql.Tx) bool {
-		attachmentId := cm.CrmMysql.InsertByTx(tx, "attachment", map[string]interface{}{
-			"name":        this.Name,
-			"suffix":      this.Suffix,
-			"type":        this.FileType,
-			"size":        this.Size,
-			"oss":         this.Oss,
-			"create_time": time.Now().Format(date.Date_Full_Layout),
-		})
-		pointId := cm.CrmMysql.InsertByTx(tx, "anchor_point", map[string]interface{}{
-			"attachment_id": attachmentId,
-			"business_id":   this.BusinessId,
-			"type":          this.Types,
-		})
-		if attachmentId > 0 && pointId > 0 {
-			return true
-		}
-
-		logx.Info("file add err:", attachmentId, pointId)
-		return false
-	})
-}

+ 0 - 40
service/group.go

@@ -1,40 +0,0 @@
-package service
-
-import (
-	"log"
-
-	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
-	"bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/rpc/social/social"
-	"github.com/gogf/gf/v2/os/gctx"
-)
-
-type Group struct {
-	EntId      int64
-	PositionId int64
-	UserIdArr  []int64
-	AppId      string
-	EntUserId  int64
-	AccountId  int64
-}
-
-//GroupAdd 创建群组
-//return 群组id
-func (this *Group) GroupAdd() string {
-	resp, err := cm.SocialPlatformRpc.ChatGroupAdd(gctx.New(), &social.ChatGroupAddReq{
-		EntId:      this.EntId,
-		PositionId: this.PositionId,
-		UserIdArr:  this.UserIdArr,
-		AppId:      this.AppId,
-		EntUserId:  this.EntUserId,
-		AccountId:  this.AccountId,
-	})
-	if err != nil {
-		log.Println("新建群组出错", this.PositionId, err)
-		return ""
-	} else if resp == nil {
-		log.Println("positionId用户", this.PositionId, "新建群组失败")
-		return ""
-	}
-
-	return resp.Data
-}

+ 0 - 241
service/sale_chance.go

@@ -1,241 +0,0 @@
-package service
-
-import (
-	"context"
-	"database/sql"
-	"fmt"
-	"log"
-	"strings"
-	"time"
-
-	qu "app.yhyue.com/moapp/jybase/common"
-	"app.yhyue.com/moapp/jybase/date"
-	"app.yhyue.com/moapp/jybase/encrypt"
-	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
-	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
-	"bp.jydev.jianyu360.cn/CRM/application/entity"
-	"github.com/gogf/gf/v2/util/gconv"
-)
-
-// 线索相关
-type SaleChanceService struct {
-	BaseUserId        int64
-	PositionId        int64
-	EntUserId         int64
-	EntId             int64
-	AppId             string
-	AccountId         int64
-	EntDeptId         int64
-	ChanceName        string  //机会名称
-	Owner             string  //机会所有者
-	Summary           string  //概要信息
-	ChanceClassify    int64   //机会分类
-	ExpectedOrderTime int64   //最初预计落单段时间 时间戳
-	ExpectedMoney     float64 //最初预计落单金额
-	CustomName        string  //客户全称
-	BusinessType      int64   //业务类型
-	Remarks           string  //备注
-	NextfollowUpTime  int64   //下次跟进时间戳
-	Types             int64   //处理方式 1自办;2转办
-	User              []int64 //企业用户id
-	EmployInfoId      int64   //资讯收录id
-	CustomId          int64   //客户id
-	CreateName        string
-	ChanceSource      int64
-	OwnerId           string //潜客收录id(人脉)
-	BusinessId        string //商机收录id(人脉)
-}
-
-// Add 创建机会
-func (this *SaleChanceService) Add(ctx context.Context) (int64, string) {
-	nowtime := time.Now().Format(date.Date_Full_Layout)
-	args := []interface{}{}
-	argsTask := []interface{}{}
-	argsTaskTeam := []interface{}{}
-	//落单时间戳转时间
-	expect_deal_time := time.Unix(this.ExpectedOrderTime, 0).Format(date.Date_Full_Layout)
-	//下次跟进时间
-	nextFollowTime := time.Unix(this.NextfollowUpTime, 0).Format(date.Date_Full_Layout)
-
-	baseUserIdArr := []int64{}
-	chanceId, taskId := int64(-1), int64(-1)
-	groupId := ""
-	//判断处理方式
-	stageId := 0
-	if stageData := cm.CrmMysql.SelectBySql("select id from  config_tpl_stage where tpl_id =? order by `order` limit 1", this.BusinessType); stageData != nil && len(*stageData) > 0 {
-		stageId = gconv.Int((*stageData)[0]["id"])
-	}
-	//转办
-	if this.Types == 2 {
-		transferArr := []int64{}
-		for _, v := range this.User {
-			i_entuserid := v
-			resp, err := cm.UserCenterRpc.IdentityByEntUserId(ctx, &pb.IdentityReq{
-				Id: i_entuserid,
-			})
-			if err != nil {
-				log.Println("获取用户职位id信息出错", i_entuserid, "的信息出错", err)
-				return -1, groupId
-			} else if resp == nil {
-				log.Println("entuser用户", i_entuserid, "没有找到职位信息")
-				return -1, groupId
-			}
-			transferArr = append(transferArr, resp.PositionId)
-			baseUserIdArr = append(baseUserIdArr, resp.UserId)
-		}
-
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.CustomId, this.BusinessType, this.ChanceName, this.Summary, this.ChanceClassify, qu.If(this.ExpectedOrderTime == 0, nil, expect_deal_time), qu.If(this.ExpectedMoney == 0, nil, this.ExpectedMoney), qu.If(this.Remarks == "", nil, this.Remarks), nowtime, this.CreateName, this.ChanceSource, this.OwnerId, this.BusinessId)
-		//任务
-		argsTask = append(argsTask, this.EntId, this.ChanceName+"的跟进任务", 2, this.PositionId, 1, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), this.BusinessType, stageId)
-
-		chanceId, taskId = this.SaveChange(ctx, args, argsTask, argsTaskTeam, transferArr, this.OwnerId, this.BusinessId)
-
-		if chanceId < 0 {
-			return -1, groupId
-		}
-	} else if this.Types == 1 {
-		//线索机会
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.CustomId, this.BusinessType, this.ChanceName, this.Summary, this.ChanceClassify, qu.If(this.ExpectedOrderTime == 0, nil, expect_deal_time), qu.If(this.ExpectedMoney == 0, nil, this.ExpectedMoney), qu.If(this.Remarks == "", nil, this.Remarks), nowtime, this.CreateName, this.ChanceSource, this.OwnerId, this.BusinessId)
-		//任务
-		argsTask = append(argsTask, this.EntId, this.ChanceName+"的跟进任务", 2, this.PositionId, 2, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), this.BusinessType, stageId)
-		//任务团队
-		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
-		//存库
-		chanceId, taskId = this.SaveChange(ctx, args, argsTask, argsTaskTeam, []int64{}, this.OwnerId, this.BusinessId)
-		if chanceId < 0 {
-			return -1, groupId
-		}
-		baseUserIdArr = append(baseUserIdArr, this.BaseUserId)
-
-		// //自办 创建 群聊
-		// gp := &Group{
-		// 	EntId:      this.EntId,
-		// 	PositionId: this.PositionId,
-		// 	UserIdArr:  []int64{},
-		// 	AppId:      this.AppId,
-		// 	EntUserId:  this.EntUserId,
-		// 	AccountId:  this.AccountId,
-		// }
-		// groupId = gp.GroupAdd()
-	} else if this.Types == 3 {
-		transferArr := []int64{}
-		transferArr = append(transferArr, this.PositionId)
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.CustomId, this.BusinessType, this.ChanceName, this.Summary, this.ChanceClassify, qu.If(this.ExpectedOrderTime == 0, nil, expect_deal_time), qu.If(this.ExpectedMoney == 0, nil, this.ExpectedMoney), qu.If(this.Remarks == "", nil, this.Remarks), nowtime, this.CreateName, this.ChanceSource, this.OwnerId, this.BusinessId)
-		//任务
-		argsTask = append(argsTask, this.EntId, this.ChanceName+"的跟进任务", 2, this.PositionId, 1, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), this.BusinessType, stageId)
-		chanceId, taskId = this.SaveChange(ctx, args, argsTask, argsTaskTeam, transferArr, this.OwnerId, this.BusinessId)
-		if chanceId < 0 {
-			return -1, groupId
-		}
-		baseUserIdArr = append(baseUserIdArr, this.BaseUserId)
-	}
-
-	u := &User{BaseUserIds: baseUserIdArr}
-
-	if this.Types != 3 {
-		var kb strings.Builder
-		var vb strings.Builder
-		for k, v := range u.GetUserId(this.EntId) {
-			kb.WriteString(k + ",")
-			vb.WriteString(gconv.String(v) + ",")
-			userId := strings.TrimRight(kb.String(), ",")
-			positionId := strings.TrimRight(vb.String(), ",")
-
-			next := strings.Replace(time.Unix(this.NextfollowUpTime, 0).Format(YYYYMMDDHHMM), " ", "%20", -1)
-			content := ""
-			pcHref := ""
-			if this.Types == 1 {
-				pcHref = fmt.Sprintf(cm.Push.SaleChance.Create.MyselfPcHref, positionId, taskId, chanceId)
-				content = fmt.Sprintf(cm.Push.SaleChance.Create.MySelfContent, this.CreateName, strings.Replace(date.NowFormat(YYYYMMDDHHMM), " ", "%20", -1), next)
-
-			} else if this.Types == 2 {
-				pcHref = fmt.Sprintf(cm.Push.SaleChance.Create.TransferPcHref, positionId)
-				content = fmt.Sprintf(cm.Push.SaleChance.Create.TransferContent, this.CreateName, strings.Replace(date.NowFormat(YYYYMMDDHHMM), " ", "%20", -1), next)
-			}
-
-			StationMailPush(userId, positionId, cm.Push.SaleChance.Create.Title, content, pcHref, cm.Push.SaleChance.Create.MobileHref, "11")
-
-		}
-	}
-	return 1, groupId
-}
-
-// SaleChangeAdd 机会存储
-func SaleChangeAdd(tx *sql.Tx, args []interface{}) int64 {
-	fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "custom_id", "tpl_id", "name", "summary", "classify", "expect_deal_time", "expect_deal_amount", "remark", "create_time", "create_person", "source", "connection_owner_id", "connection_business_id"}
-
-	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALE_CHANCE, fields, args)
-	//
-
-	return id
-}
-
-// Save 存库
-func (this *SaleChanceService) SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interface{}, transferArr []int64, ownerId, connectionBusinessId string) (int64, int64) {
-	//存库
-	changeId, taskId := int64(-1), int64(-1)
-	cm.CrmMysql.ExecTx("创建机会", func(tx *sql.Tx) bool {
-		//
-		employ_info_id_new, _ := EmployUpdate(tx, this.EmployInfoId, 0, this.PositionId, "is_create_chance", this.EntId, this.EntUserId, this.EntDeptId)
-
-		argsChange[3] = employ_info_id_new
-
-		//插入机会
-		changeId = SaleChangeAdd(tx, argsChange)
-		//传过来的argTask没有来源id,需要append
-		argsTask = append(argsTask, changeId)
-		//任务车存储
-		taskId = TaskAdd(tx, argsTask, argsTaskTeam, transferArr, this.PositionId)
-		//操作台帐
-		ok1 := SaveLedger(ctx, this.PositionId, changeId, taskId, "创建销售机会", fmt.Sprintf("%s创建了销售机会", this.CreateName), this.CreateName)
-		//任务执行计划
-		planId := TaskExecutePlanAdd(tx, this.BusinessType, taskId)
-		//销售漏斗
-		nextFollowTime := time.Unix(this.NextfollowUpTime, 0).Format(date.Date_Full_Layout)
-		argsSalesFunnel := []interface{}{
-			changeId,
-			taskId,
-			this.ChanceName,
-			this.Summary,
-			nextFollowTime,
-			this.ExpectedMoney,
-			this.BusinessType,
-			this.EntId,
-			this.EmployInfoId,
-		}
-		SalesFunnel := saveSalesFunnel(tx, argsSalesFunnel, this.BusinessType)
-		//人脉保存
-		if ownerId != "" || connectionBusinessId != "" {
-			if connectionBusinessId != "" {
-				connectionBusinessId = encrypt.DecodeArticleId2ByCheck(connectionBusinessId)[0]
-			}
-			SaveConnection(tx, this.PositionId, connectionBusinessId, ownerId, this.EntId, this.EntDeptId, this.EntUserId)
-		}
-		if changeId > 0 && taskId > 0 && ok1 && planId > 0 && SalesFunnel > 0 {
-			return true
-		}
-		log.Println("save change err: ", changeId, taskId, ok1, planId, SalesFunnel)
-		return false
-	})
-
-	return changeId, taskId
-}
-
-// TaskExecutePlanAdd 任务执行计划存储
-func TaskExecutePlanAdd(tx *sql.Tx, tplId, taskId int64) int64 {
-	args := []interface{}{}
-	data := cm.CrmMysql.SelectBySqlByTx(tx, `SELECT a.name,b.name,b.id FROM config_tpl_stage a
-											INNER JOIN config_stage_matter b ON (b.stage_id=a.id) 
-											where  a.tpl_id=?
-											order by a.id,b.id `, tplId)
-	if data != nil && len(*data) > 0 {
-		for _, v := range *data {
-			matterId := gconv.Int(v["id"])
-			args = append(args, taskId, matterId)
-		}
-		_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.TASK_EXECUTE_PLAN, []string{"task_id", "matter_id"}, args)
-		return id
-	}
-
-	return 0
-}

+ 0 - 204
service/sale_clue.go

@@ -1,204 +0,0 @@
-package service
-
-import (
-	"context"
-	"database/sql"
-	"fmt"
-	"log"
-	"strings"
-	"time"
-
-	qu "app.yhyue.com/moapp/jybase/common"
-	"app.yhyue.com/moapp/jybase/date"
-	"app.yhyue.com/moapp/jybase/encrypt"
-	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
-	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
-	"bp.jydev.jianyu360.cn/CRM/application/entity"
-	"github.com/gogf/gf/v2/util/gconv"
-)
-
-var Se = encrypt.SimpleEncrypt{Key: "topnet"}
-var YYYYMMDDHHMM = "2006-01-02 15:04" //%20用于转义
-
-// 线索相关
-type SaleClueService struct {
-	AppId        string
-	PositionId   int64
-	EntId        int64
-	EntUserId    int64
-	BaseUserId   int64
-	AccountId    int64
-	EntDeptId    int64
-	ClueName     string
-	CluesSource  string
-	Summary      string
-	EmployInfoId int64
-	Types        int64
-	User         []int64
-	FollowUpTime int64
-	CreateName   string
-	Channel      string
-}
-
-// Add 创建线索
-// return 是否成功,群组id
-func (this *SaleClueService) Add(ctx context.Context) (int64, string) {
-	nowtime := time.Now().Format(date.Date_Full_Layout)
-	nextFollowTime := time.Unix(this.FollowUpTime, 0).Format(date.Date_Full_Layout)
-	groupId := ""
-	args := []interface{}{}
-	argsTask := []interface{}{}
-	argsTaskTeam := []interface{}{}
-	baseUserIdArr := []int64{}
-	clueId, taskId := int64(-1), int64(-1)
-	//判断处理方式
-	//转办
-	if this.Types == 2 {
-		transferArr := []int64{}
-		for _, v := range this.User {
-			i_entuserid := v
-			resp, err := cm.UserCenterRpc.IdentityByEntUserId(ctx, &pb.IdentityReq{
-				Id: i_entuserid,
-			})
-			if err != nil {
-				log.Println("获取用户职位id信息出错", i_entuserid, "的信息出错", err)
-				return -1, groupId
-			} else if resp == nil {
-				log.Println("entuser用户", i_entuserid, "没有找到职位信息")
-				return -1, groupId
-			}
-			transferArr = append(transferArr, resp.PositionId)
-			baseUserIdArr = append(baseUserIdArr, resp.UserId)
-		}
-		//线索
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.ClueName, this.CluesSource, this.Summary, this.EmployInfoId, 0, nowtime, this.CreateName, this.Channel)
-		//任务
-		argsTask = append(argsTask, this.EntId, this.ClueName+"的跟进任务", 1, this.PositionId, 1, nowtime, 1, 0, qu.If(this.FollowUpTime == 0, nil, nextFollowTime), nil, nil)
-		clueId, taskId = Save(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, 0, this.PositionId, this.CreateName, transferArr, this.EntId, this.EntUserId, this.EntDeptId)
-		if clueId < 0 {
-			return -1, groupId
-		}
-	} else if this.Types == 1 {
-		//线索
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.ClueName, this.CluesSource, this.Summary, this.EmployInfoId, 0, time.Now().Format(date.Date_Full_Layout), this.CreateName, this.Channel)
-		//任务
-		argsTask = append(argsTask, this.EntId, this.ClueName+"的跟进任务", 1, this.PositionId, 2, nowtime, 1, 0, qu.If(this.FollowUpTime == 0, nil, nextFollowTime), nil, nil)
-		//任务团队
-		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
-		//存库
-		clueId, taskId = Save(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, 0, this.PositionId, this.CreateName, []int64{}, this.EntId, this.EntUserId, this.EntDeptId)
-		if clueId < 0 {
-			return -1, groupId
-		}
-		baseUserIdArr = append(baseUserIdArr, this.BaseUserId)
-
-		//自办 创建 群聊
-		// gp := &Group{
-		// 	EntId:      this.EntId,
-		// 	PositionId: this.PositionId,
-		// 	UserIdArr:  []int64{},
-		// 	AppId:      this.AppId,
-		// 	EntUserId:  this.EntUserId,
-		// 	AccountId:  this.AccountId,
-		// }
-		// groupId = gp.GroupAdd()
-	} else if this.Types == 3 {
-		transferArr := []int64{}
-		transferArr = append(transferArr, this.PositionId)
-		//线索
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.ClueName, this.CluesSource, this.Summary, this.EmployInfoId, 0, nowtime, this.CreateName, this.Channel)
-		//任务
-		argsTask = append(argsTask, this.EntId, this.ClueName+"的跟进任务", 1, this.PositionId, 1, nowtime, 1, 0, qu.If(this.FollowUpTime == 0, nil, nextFollowTime), nil, nil)
-		clueId, taskId = Save(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, 0, this.PositionId, this.CreateName, transferArr, this.EntId, this.EntUserId, this.EntDeptId)
-		if clueId < 0 {
-			return -1, groupId
-		}
-		baseUserIdArr = append(baseUserIdArr, this.BaseUserId)
-	}
-	u := &User{BaseUserIds: baseUserIdArr}
-
-	if this.Types != 3 {
-		var kb strings.Builder
-		var vb strings.Builder
-		for k, v := range u.GetUserId(this.EntId) {
-			kb.WriteString(k + ",")
-			vb.WriteString(gconv.String(v) + ",")
-			userId := strings.TrimRight(kb.String(), ",")
-			positionId := strings.TrimRight(vb.String(), ",")
-			content, pcHref := "", ""
-			next := strings.Replace(time.Unix(this.FollowUpTime, 0).Format(YYYYMMDDHHMM), " ", "%20", -1)
-
-			if this.Types == 1 {
-				pcHref = fmt.Sprintf(cm.Push.SaleClue.Create.MyselfPcHref, positionId, taskId, clueId)
-				content = fmt.Sprintf(cm.Push.SaleClue.Create.MySelfContent, this.CreateName, strings.Replace(date.NowFormat(YYYYMMDDHHMM), " ", "%20", -1), next)
-			} else if this.Types == 2 {
-				pcHref = fmt.Sprintf(cm.Push.SaleClue.Create.TransferPcHref, positionId)
-				content = fmt.Sprintf(cm.Push.SaleClue.Create.TransferContent, this.CreateName, strings.Replace(date.NowFormat(YYYYMMDDHHMM), " ", "%20", -1), next)
-			}
-			StationMailPush(userId, positionId, cm.Push.SaleClue.Create.Title, content, pcHref, cm.Push.SaleClue.Create.MobileHref, "11")
-		}
-	}
-	return 1, groupId
-}
-
-// SaleClueAdd 线索存储
-func SaleClueAdd(tx *sql.Tx, args []interface{}) int64 {
-	fields := []string{"position_id", "ent_id", "ent_user_id", "name", "source", "summary", "employ_info_id", "is_close", "create_time", "create_person", "channel"}
-	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALE_CLUE, fields, args)
-	return id
-}
-
-//TaskAdd 任务车存储
-/*创建任务
-taskTransferMap 自办的map
-transferArr 转办的用户职位id
-*/
-func TaskAdd(tx *sql.Tx, args, taskTeamArgs []interface{}, transferArr []int64, positionId int64) int64 {
-	fields := []string{"ent_id", "name", "source", "create_person", "status", "create_time", "create_way", "join_task_vehicle", "next_follow_time", "tpl_id", "current_stage", "source_id"}
-	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.TASK, fields, args)
-	teamId, transferId := int64(0), int64(0)
-	if len(taskTeamArgs) > 0 {
-		//自办
-		taskTeamFields := []string{"position_id", "ent_user_id", "name", "role", "create_time", "task_id"}
-		taskTeamArgs = append(taskTeamArgs, id)
-		_, teamId = cm.CrmMysql.InsertBatchByTx(tx, entity.TASK_TEAM, taskTeamFields, taskTeamArgs)
-	} else if len(transferArr) > 0 {
-		//转办
-		taskTransferFields := []string{"transfer_id", "responsible_id", "create_time", "task_id"}
-		taskTransferArgs := []interface{}{}
-		for _, v := range transferArr {
-			taskTransferArgs = append(taskTransferArgs, positionId, v, time.Now().Format(date.Date_Full_Layout), id)
-		}
-		_, transferId = cm.CrmMysql.InsertBatchByTx(tx, entity.TASK_TRANSFER, taskTransferFields, taskTransferArgs)
-	}
-	if transferId > 0 || teamId > 0 {
-		return id
-	}
-	log.Println("task add err :", id, len(taskTeamArgs), teamId, len(transferArr), transferId)
-	return -1
-}
-
-// Save 存库
-func Save(ctx context.Context, argsClue, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId int64, createName string, transferArr []int64, entId, entUserId, entDeptId int64) (int64, int64) {
-	clueId, taskId := int64(-1), int64(-1)
-	//存库
-	cm.CrmMysql.ExecTx("创建线索", func(tx *sql.Tx) bool {
-		//是否创建销售线索
-		employ_info_id_new, _ := EmployUpdate(tx, employ_info_id, employ_custom_id, positionId, "is_create_clue", entId, entUserId, entDeptId)
-		//插入线索
-		argsClue[6] = employ_info_id_new
-		clueId = SaleClueAdd(tx, argsClue)
-		//传过来的argTask没有来源id,需要append
-		argsTask = append(argsTask, clueId)
-		//任务车存储
-		taskId = TaskAdd(tx, argsTask, argsTaskTeam, transferArr, positionId)
-		//操作台帐
-		ok2 := SaveLedger(ctx, positionId, clueId, taskId, "创建销售线索", fmt.Sprintf("%s创建了销售线索", createName), createName)
-		if clueId > 0 && taskId > 0 && ok2 {
-			return true
-		}
-		log.Println("save clue err: ", clueId, taskId, ok2)
-		return false
-	})
-	return clueId, taskId
-}

+ 0 - 64
service/sendMsg.go

@@ -1,64 +0,0 @@
-package service
-
-import (
-	"context"
-	"encoding/json"
-	"fmt"
-	"log"
-	"strconv"
-	"time"
-
-	qu "app.yhyue.com/moapp/jybase/common"
-	"app.yhyue.com/moapp/jybase/date"
-	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
-	"github.com/gogf/gf/v2/frame/g"
-)
-
-//将用户格式化成 123,456 格式
-func FormatUserId(useridArr []string) (userids string) {
-	userids = ""
-	for k, v := range useridArr {
-		userids += v
-		if k+1 != len(useridArr) {
-			userids += ","
-		}
-	}
-	return
-}
-
-//站内信推送 msgType 11待办 2服务通知
-func StationMailPush(userId, positionId, title, content, pcHref, mobileHref string, msgType string) bool {
-	pcLandingPage := "/front/sess/" + Se.EncodeString(positionId+",positionId,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(pcHref)
-	wxLandingPage := "/front/sess/" + Se.EncodeString(positionId+",positionId,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(mobileHref)
-	appLandingPage := "/jyapp/free/sess/" + Se.EncodeString(positionId+",positionId,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(mobileHref)
-	href := fmt.Sprintf("%s?_action=%s&userIds=%s&msgType=%s&title=%s&content=%s&link=%s&sendMode=2&sendTime=%s&androidUrl=%s&iosUrl=%s&weChatUrl=%s&_token=12311&reqSource=1&callPlatform=crm&menuname=message&positionIds=%s",
-		cm.Push.StationMailHref, cm.Push.StationMailAction, userId, msgType, title, content, pcLandingPage, date.NowFormat(date.Date_Short_Layout), appLandingPage, appLandingPage, wxLandingPage, positionId)
-	log.Println(href)
-	resp := Get(href, nil)
-	log.Println("resp:", resp)
-	ret := map[string]interface{}{}
-	err := json.Unmarshal([]byte(resp), &ret)
-	if err != nil {
-		return false
-	}
-	if ret != nil && len(ret) > 0 {
-		if data := qu.ObjToMap(ret["data"]); data != nil && len(*data) > 0 {
-			if qu.Int64All((*data)["status"]) != 1 {
-				return false
-			}
-		}
-	}
-	return true
-}
-
-//公共get方法
-func Get(url string, param map[string]interface{}) (str string) {
-	ctx := context.Background()
-	if r, err := g.Client().Get(ctx, url, param); err != nil {
-		log.Println("get err:", err)
-	} else {
-		defer r.Close()
-		str = r.ReadAllString()
-	}
-	return
-}

+ 0 - 48
service/user.go

@@ -1,48 +0,0 @@
-package service
-
-import (
-	"log"
-
-	"app.yhyue.com/moapp/jybase/mongodb"
-	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
-	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
-	"github.com/gogf/gf/v2/os/gctx"
-	"github.com/gogf/gf/v2/util/gconv"
-)
-
-type User struct {
-	BaseUserIds []int64
-}
-
-func (this *User) GetUserId(entId int64) map[string]int64 {
-	m := map[string]int64{}
-	data, ok := cm.Mgo.Find("user", map[string]interface{}{
-		"base_user_id": map[string]interface{}{
-			"$in": this.BaseUserIds,
-		},
-	}, nil, `{"_id":1,"base_user_id":1}`, false, -1, -1)
-	if ok && data != nil && len(*data) > 0 {
-		for _, v := range *data {
-			mdata := cm.BaseMysql.SelectBySql(`SELECT id FROM base_position WHERE user_id =? AND ent_id =? LIMIT 1`, gconv.Int64(v["base_user_id"]), entId)
-			if mdata != nil && len(*mdata) > 0 {
-				m[mongodb.BsonIdToSId(v["_id"])] = gconv.Int64((*mdata)[0]["id"])
-			}
-		}
-	}
-	return m
-}
-
-func (this *User) IdentityByPositionId(positionId int64) *pb.Identity {
-	resp, err := cm.UserCenterRpc.IdentityByPositionId(gctx.New(), &pb.IdentityReq{
-		Id: positionId,
-	})
-	if err != nil {
-		log.Println("获取用户职位id信息出错", positionId, "的信息出错", err)
-		return nil
-	} else if resp == nil {
-		log.Println("positionId用户", positionId, "没有找到职位信息")
-		return nil
-	}
-
-	return resp
-}

+ 0 - 130
service/util.go

@@ -1,130 +0,0 @@
-package service
-
-import (
-	"fmt"
-	"strings"
-
-	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
-	"github.com/gogf/gf/v2/util/gconv"
-)
-
-// CanAdd 是否允许多人针对一个创建
-func CanAdd(entId int64, key string, employInfoId, employCustomId, positionId int64) (status int64, error_msg string) {
-	if employInfoId <= 0 && employCustomId <= 0 {
-		return 1, ""
-	}
-	accountData := cm.BaseMysql.SelectBySql(`select * from base_service.base_account where ent_id =? and person_id =0 and type =1 limit 1`, entId)
-	if accountData == nil || len(*accountData) <= 0 {
-		return 1, ""
-	}
-	accountId := (*accountData)[0]["id"]
-	//
-	tenantData := cm.BaseMysql.SelectBySql(`select * from crm.config_tenant where account_id =?`, accountId)
-	//不允许
-	if (len(*tenantData) == 0) || (len(*tenantData) > 0 && gconv.Int((*tenantData)[0][key]) == 0) {
-		employInfoIdArr := []int64{}
-		if employInfoId > 0 {
-			employ_info := cm.BaseMysql.SelectBySql(`select id from crm.employ_info where source_id =(SELECT source_id FROM crm.employ_info WHERE id =?) and status=1`, employInfoId)
-			if employ_info != nil && len(*employ_info) > 0 {
-				for _, v := range *employ_info {
-					employInfoIdArr = append(employInfoIdArr, gconv.Int64(v["id"]))
-				}
-			} else {
-				employInfoIdArr = []int64{employInfoId}
-			}
-		} else {
-			employInfoIdArr = []int64{employInfoId}
-		}
-		args, ws := GetInForCommaArr(employInfoIdArr)
-		args = append(args, entId)
-		//判断是否已经创建
-		if strings.Contains(key, "clue") {
-			if hasZero(employInfoIdArr) {
-				return 1, ""
-			}
-			d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.sale_clue where employ_info_id in( `+ws+`) and ent_id =? and is_close=0`, args...)
-			if d != nil && len(*d) > 0 {
-				for _, v := range *d {
-					position_id := gconv.Int64(v["position_id"])
-					if positionId == position_id {
-						return 1, ""
-					}
-					return -1, fmt.Sprintf("%v已经基于该资讯创建了线索", v["create_person"])
-				}
-			}
-		} else if strings.Contains(key, "chance") {
-			if hasZero(employInfoIdArr) {
-				return 1, ""
-			}
-			d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.sale_chance where   employ_info_id in ( `+ws+`) and ent_id =? `, args...)
-			if d != nil && len(*d) > 0 {
-				for _, v := range *d {
-					position_id := gconv.Int64(v["position_id"])
-					if positionId == position_id {
-						return 1, ""
-					}
-					return -1, fmt.Sprintf("%v已经基于该资讯创建了机会", v["create_person"])
-				}
-			}
-
-		} else if strings.Contains(key, "custom") {
-			if employInfoId > 0 {
-				d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where   employ_info_id in( `+ws+`) and ent_id =? `, args...)
-				if d != nil && len(*d) > 0 {
-					for _, v := range *d {
-						position_id := gconv.Int64(v["position_id"])
-						if positionId == position_id {
-							return 1, ""
-						}
-						return -1, fmt.Sprintf("%v已经基于该资讯创建了客户", v["create_person"])
-					}
-				}
-			} else if employCustomId > 0 {
-				employCustomIdArr := []int64{}
-				employ_info := cm.BaseMysql.SelectBySql(`select id from crm.employ_custom where company_id =(SELECT company_id FROM crm.employ_custom WHERE id =?)`, employCustomId)
-				if employ_info != nil && len(*employ_info) > 0 {
-					for _, v := range *employ_info {
-						employCustomIdArr = append(employCustomIdArr, gconv.Int64(v["id"]))
-					}
-				} else {
-					employCustomIdArr = []int64{employCustomId}
-				}
-
-				args, ws := GetInForCommaArr(employCustomIdArr)
-				args = append(args, entId)
-				d := cm.BaseMysql.SelectBySql(`select create_person,position_id from crm.custom where   employ_custom_id in( `+ws+`) and ent_id =? `, args...)
-				if d != nil && len(*d) > 0 {
-					for _, v := range *d {
-						position_id := gconv.Int64(v["position_id"])
-						if positionId == position_id {
-							return 1, ""
-						}
-						return -1, fmt.Sprintf("%v已经基于该候选客户创建了客户", v["create_person"])
-					}
-				}
-			}
-		}
-	}
-
-	return 1, ""
-}
-
-// 获取sql语句的in操作相关参数
-func GetInForCommaArr(ids []int64) ([]interface{}, string) {
-	args := []interface{}{}
-	ws := []string{}
-	for _, v := range ids {
-		args = append(args, v)
-		ws = append(ws, "?")
-	}
-	return args, strings.Join(ws, ",")
-}
-
-func hasZero(arr []int64) bool {
-	for i := 0; i < len(arr); i++ {
-		if arr[i] == int64(0) {
-			return true
-		}
-	}
-	return false
-}