Commit bd9f7432 by Joneq

增加发送钉钉消息

parent 5e92a25e
......@@ -4,6 +4,7 @@ import (
"flag"
"context"
"crm-server/internal/service"
"fmt"
"github.com/bilibili/kratos/pkg/conf/paladin"
"github.com/bilibili/kratos/pkg/log"
......@@ -23,9 +24,9 @@ func main() {
defer log.Close()
log.Info("caipu-server start")
//声明service层
//声明service层 测试数据库是否连接
svc := service.New()
ctx := context.Background()
//调用会员服务
svc.GetUserInfoByUserId(ctx,1)
fmt.Println(svc.GetUserInfoByUserId(ctx,1))
}
package main
//用户池中已下单的释放
package main
import (
"crm-server/internal/dao"
"crm-server/internal/model"
"crm-server/internal/service"
"fmt"
"time"
)
func main() {
db := dao.GetDb()
haveDandleUser := make(map[int]int)
var assign_active model.AssignActive
//查找出不再跟随的用户ID,然后不再允许跟进
rows,_ := db.Queryx("select user_id,turn_in_id from lie_assign_active where is_success = ? and change_time < ?",2,(time.Now().Unix()- 86400 * 30))
for rows.Next() {
_ = rows.StructScan(&assign_active)
haveDandleUser[assign_active.User_Id] = assign_active.Turn_In_id
}
//查找出即将释放的用户,然后释放
for k,v := range haveDandleUser{
_,err := db.Exec("INSERT INTO `lie_not_follow_user` (`user_id`, `sale_id`, `stop_time`)VALUES(?, ?,?)",k,v,time.Now().Unix())
if err != nil {
fmt.Println("添加记录失败",k)
}
db.Exec("delete from lie_assign_active where user_id = ? and turn_in_id = ?",k,v)
}
//查找出需要发送通知的用户,发送通知
rows,_ = db.Queryx("select turn_in_id,user_id from lie_assign_active where change_time < ? and change_time > ?",(time.Now().Unix()- 86400 * 23),(time.Now().Unix()- 86400 * 24))
db = dao.GetCmsDb()
var user_info model.UserInfo
var user_company model.UserCompany
for rows.Next() {
_ = rows.StructScan(&assign_active)
//查找手机号
err := db.QueryRowx("select mobile from user_info where userId = ?",assign_active.Turn_In_id).StructScan(&user_info)
if err != nil {
fmt.Println(err)
}
//查找公司名称
err = dao.GetDb().QueryRowx("select com_name from lie_user_company where user_id = ?",assign_active.User_Id).StructScan(&user_company)
if err != nil {
fmt.Println(err)
}
service.SendMessage(user_info.Mobile,"您的客户:"+user_company.Com_name+"在跟进后23天任未下单,还有7天将被转出,请注意查看")
}
}
package main
//用户池中未下单的释放
\ No newline at end of file
......@@ -6,6 +6,8 @@ require (
github.com/bilibili/kratos v0.0.0-20191025092737-e14170de04ba
github.com/gogo/protobuf v1.3.0
github.com/golang/protobuf v1.3.2
github.com/jmoiron/sqlx v1.2.0
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/pkg/errors v0.8.1
golang.org/x/net v0.0.0-20191011234655-491137f69257
google.golang.org/grpc v1.24.0
......
......@@ -48,6 +48,7 @@ github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dT
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
......@@ -83,6 +84,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/influxdata/influxdb1-client v0.0.0-20190809212627-fc22c7df067e/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
......@@ -100,12 +103,16 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
......
package dao
import (
"crm-server/configs"
"fmt"
"log"
"github.com/jmoiron/sqlx"
)
func GetDb()(*sqlx.DB) {
db1 := configs.GetDBOne()
db, err := sqlx.Open(db1.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", db1.User, db1.Pass, db1.Ip, db1.Port, db1.Table))
if err != nil {
log.Fatalln(err)
}
return db
}
func GetCmsDb()(*sqlx.DB) {
db1 := configs.GetDBCms()
db, err := sqlx.Open(db1.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", db1.User, db1.Pass, db1.Ip, db1.Port, db1.Table))
if err != nil {
log.Fatalln(err)
}
return db
}
......@@ -10,7 +10,7 @@ import (
)
const (
_user_Info_One = "SELECT user_id, user_name FROM ys_users WHERE user_id=?"
_user_Info_One = "SELECT user_id FROM lie_user WHERE user_id=?"
)
......@@ -19,7 +19,7 @@ func (d *dao) GetUserInfoByUserId(ctx context.Context, user_id int64) (r *model.
var row *sql.Row
r = new(model.Users)
row = d.db.QueryRow(ctx, _user_Info_One, user_id)
if err = row.Scan(&r.User_id, &r.User_name); err != nil {
if err = row.Scan(&r.User_id); err != nil {
if err == sql.ErrNoRows {
err = nil
r = nil
......
package logic
import (
"crypto/md5"
"encoding/hex"
)
// Md5 md5()
func Md5(str string) string {
hash := md5.New()
hash.Write([]byte(str))
return hex.EncodeToString(hash.Sum(nil))
}
\ No newline at end of file
package model
type AssignActive struct {
Id int `json:"id"`
User_Id int `json:"user_id"`
Turn_Out_id int `json:"turn_out_id"`
Turn_In_id int `json:"turn_in_id"`
Assign_id int `json:"assign_id"`
Is_Success int `json:"is_success"`
Change_Time int `json:"change_time"`
Create_time int `json:"create_time"`
}
/*
CREATE TABLE `lie_assign_active` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '转入接收日志',
`user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
`turn_out_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '转出人ID',
`turn_in_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '转入人ID',
`assign_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '分配人ID',
`is_success` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否成功',
`change_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '变更时间',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COMMENT='转入接收日志表';
*/
\ No newline at end of file
package model
// Kratos hello kratos.
type Kratos struct {
Hello string
}
\ No newline at end of file
package model
type NotFollowUser struct {
Id int `json:"id"`
User_Id int `json:"user_id"`
Sale_Id int `json:"sale_id"`
Stop_Time int `json:"Stop_time"`
Update_Time int `json:"Update_time"`
}
/*
CREATE TABLE `lie_not_follow_user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '客户ID',
`sale_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '交易员ID',
`stop_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '停止时间',
`update_time` int(11) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='客服不能跟进用户表';
*/
\ No newline at end of file
package model
type Salesman struct {
Id int `json:"id"`
User_Id int `json:"user_id"`
Sale_Id int `json:"sale_id"`
Assign_Time int `json:"assign_time"`
Update_Time int `json:"update_time"`
}
/*
CREATE TABLE `lie_salesman` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '客户ID',
`sale_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '交易员ID',
`assign_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '指派时间',
`update_time` int(11) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=69 DEFAULT CHARSET=utf8;
*/
\ No newline at end of file
package model
type UserCompany struct {
Com_name string `json:"com_name"`
}
\ No newline at end of file
package model
type UserInfo struct {
Mobile int64 `json:"mobile"`
}
\ No newline at end of file
......@@ -3,5 +3,4 @@ package model
// Kratos hello kratos.
type Users struct {
User_id int64 `json:"user_id"`
User_name string `json:"user_name"`
}
\ No newline at end of file
package service
import (
"crm-server/internal/logic"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"time"
)
const APIMD5STR string = "fh6y5t4rr351d2c3bryi"
const APIDOMAIN string = "http://api.ichunt.com/msg/sendMessageByAuto"
func SendMessage(mobile int64 , content string){
if mobile != 0 {
timeNow := time.Now().Unix()
requestContent,_ := json.Marshal(map[string]string{"content":content})
requestTel,_ := json.Marshal([]int64{mobile})
resp,err := http.PostForm(APIDOMAIN,url.Values{
"data" : {string(requestContent)},
"touser" : {string(requestTel)},
"keyword" : {"register_nopay_notify"},
"k1" : {strconv.FormatInt(int64(timeNow),10)},
"k2" : {logic.Md5(logic.Md5(strconv.FormatInt(int64(timeNow),10))+APIMD5STR)},
"is_ignore" : {},
})
if err != nil {
fmt.Print(err)
}
defer resp.Body.Close()
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment