Commit 489ccb9f by Joneq

增加三个脚本

parent 170d329a
......@@ -5,6 +5,7 @@ import (
"crm-server/internal/logic"
"crm-server/internal/model"
"crm-server/internal/service"
"encoding/json"
"strconv"
)
......@@ -37,4 +38,10 @@ func main(){
//处理得到的用户数据
InsertData = logic.HandleData(InsertData)
if !logic.InsertMemberUser(InsertData) {
errSourcedata,_ := json.Marshal(InsertData)
service.WriteErrDetail("插入用户数据错误:"+string(errSourcedata))
}
}
\ No newline at end of file
package main
import (
"crm-server/internal/dao"
"crm-server/internal/model"
)
//向crm中插入数据
const INSERTFEEDBACK = "INSERT INTO `lie_feedback` (`user_id`, `outter_uid`, `ip`, `type`, `mobile`, `content`, `source`, `pf`, `status`, `sale_id`, `bom_url`, `responses`,`create_time`)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)"
//查询主库里面的fb数据
const SELECTFEEDBACK = "select `user_id`, `ip`, `type`, `mobile`, `content`, `create_time`, `source`, `pf`, `status`, `sale_id`, `bom_url`, `responses`, `create_time` from lie_feedback where id = ?"
func main() {
//增加rabbitmq推送过来的数据
var lieXinFeedBack model.Feedback
var lieXinFeedId int = 2
var User_Id int
err := dao.GetLiexinDb().QueryRowx(SELECTFEEDBACK,lieXinFeedId).StructScan(&lieXinFeedBack)
err_two := dao.GetDb().QueryRowx("select user_id from lie_user where outter_uid = ?",lieXinFeedBack.User_Id).Scan(&User_Id)
if err == nil && err_two == nil && User_Id != 0 {
lieXinFeedBack.Outter_Uid = lieXinFeedBack.User_Id
lieXinFeedBack.User_Id = User_Id
row,insertErr := dao.GetDb().Exec(INSERTFEEDBACK,lieXinFeedBack.User_Id,lieXinFeedBack.Outter_Uid,lieXinFeedBack.Ip,lieXinFeedBack.Type,lieXinFeedBack.Mobile,lieXinFeedBack.Content,lieXinFeedBack.Source, lieXinFeedBack.Pf,lieXinFeedBack.Status,lieXinFeedBack.Sale_Id,lieXinFeedBack.Bom_Url,lieXinFeedBack.Responses,lieXinFeedBack.Create_Time)
insertId,_ := row.LastInsertId()
if insertErr == nil {
dao.GetDb().Exec("update lie_user set fkid = ? where user_id = ?",insertId,User_Id)
}
}
}
\ No newline at end of file
package main
import (
"crm-server/internal/dao"
"crm-server/internal/service"
"fmt"
"time"
)
//查询需要发送消息的数据
const USERMESSAGE = "select `lie_l`.`msg_log_id`, `lie_l`.`user_id`, `lie_l`.`fol_id`, `lie_f`.`next_details`, `lie_f`.`remind_type`, `lie_f`.`remind_time`, `lie_l`.`sale_id` from `lie_msg_log` as `lie_l` left join `lie_follow_up` as `lie_f` on `lie_l`.`fol_id` = `lie_f`.`fol_id` where (`lie_l`.`remind_type` = 5) and `lie_l`.`status` <> -1 and `lie_f`.`remind_type` = 'wait_notify' and `lie_f`.`remind_time` <= ? order by `lie_l`.`create_time` desc"
//查找用户手机号
const MOBILEVALUE = "select mobile from user_info where userId = ?"
//修改消息为已经发送
const UPDATEHAVEREAD = "update lie_msg_log set remind_type = ? and create_time = ? where msg_log_id = ? "
type UserMessage struct {
User_Id int `json:"user_id"`
Fol_Id int `json:"fol_id"`
Next_Details string `json:"next_details"`
Remind_Type string `json:"remind_type"`
Remind_Time int `json:"remind_time"`
Sale_Id int `json:"sale_id"`
Msg_Log_id int `json:"msg_log_id"`
}
//给用户发送消息
func main() {
var userMessage []UserMessage
var mobile int64
var timeNow = time.Now().Unix()
//查找出需要发送的数据
err := dao.GetDb().Select(&userMessage,USERMESSAGE,timeNow)
if err != nil{
service.WriteErr(err)
}
if len(userMessage) <= 0 {
panic("暂无需要发送的消息")
}
for _,v := range userMessage{
mobile = 0
err := dao.GetCmsDb().QueryRowx(MOBILEVALUE,v.Sale_Id).Scan(&mobile)
if mobile == 0 {
continue
}
service.SendMessage(mobile,v.Next_Details)
_,err = dao.GetDb().Exec(UPDATEHAVEREAD,1,timeNow,v.Msg_Log_id)
if err != nil {
fmt.Println(err)
}
}
}
\ No newline at end of file
......@@ -7,28 +7,70 @@ import (
)
const INSERTCRMUSER = "INSERT INTO `lie_user` (" +
"`outter_id`, `source`,`adtag`, `mobile`,`email`, `create_time`,`copy_time`, `customer_identity`,`name`, `channel_source`,`remark`, " +
"`adtag`,`ptag`,`customer_identity`,`adtag`,`adtag`,`adtag`," +
")VALUES()"
"`outter_uid`, `source`,`adtag`, `mobile`,`email`, `create_time`,`copy_ctime`, `customer_identity`,`name`, `channel_source`,`remark`,`ptag`,`channel_source_other`" +
")VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)"
const INSERTCOMPANY = "INSERT INTO `lie_user_company` (" +
"`user_id`, `com_name`,`address`, `fixed_tel`,`fax`, `main_brand`,`com_desc`, `create_time`)VALUES(?,?,?,?,?,?,?,?)"
const INSERTISCREATEORDER = "INSERT INTO `lie_user_extend` (`user_id`, `no_create_order`,`outter_uid`)VALUES(?,?,?)"
const INSERTSALES = "INSERT INTO `lie_salesman` (`user_id`, `sale_id`,`assign_time`)VALUES(?,?,?)"
//检测会员用户是否存在
func CheckMemberIdIsHave(memberId int)(returnUserId int){
var userId int = 0
err := dao.GetDb().QueryRowx("select user_id from lie_user where outter_uid = ?",memberId).Scan(&userId)
if err != nil {
service.WriteErr(err)
}
dao.GetDb().QueryRowx("select user_id from lie_user where outter_uid = ?",memberId).Scan(&userId)
return userId
}
//增加从会员系统来的用户
func InsertMemberUser(memberInfo model.MemberAddUserData) {
func InsertMemberUser(memberInfo model.MemberAddUserData)bool {
//开启事务,增加用户数据
dbTran,_ := dao.GetDb().Begin()
insertResult, err := dbTran.Exec(INSERTCRMUSER,memberInfo.User_Id,memberInfo.Source,memberInfo.Adtag,memberInfo.Mobile,memberInfo.Email,memberInfo.Create_Time,memberInfo.Create_Time, memberInfo.Customer_identity,memberInfo.User_Name,memberInfo.Channel_source,memberInfo.Remark,memberInfo.Ptag,"")
if err != nil {
service.WriteErrDetail("插入用户数据错误:增加用户数据"+err.Error())
err = dbTran.Rollback()
return false
}
//开启事务
//dbTran,_ := dao.GetDb().Begin()
//获取插入ID
lastInsertId,err := insertResult.LastInsertId()
if err != nil {
service.WriteErrDetail("插入用户数据错误:获取插入ID"+err.Error())
err = dbTran.Rollback()
return false
}
//插入是否下单
insertResult, err = dbTran.Exec(INSERTISCREATEORDER,lastInsertId,memberInfo.No_Create_Order,memberInfo.User_Id)
if err != nil {
service.WriteErrDetail("插入用户数据错误:插入是否下单"+err.Error())
err = dbTran.Rollback()
return false
}
//插入跟进销售
insertResult, err = dbTran.Exec(INSERTSALES,lastInsertId,memberInfo.Sale_Id,memberInfo.Create_Time)
if err != nil {
service.WriteErrDetail("插入用户数据错误:插入跟进销售"+err.Error())
err = dbTran.Rollback()
return false
}
//插入公司
insertResult, err = dbTran.Exec(INSERTCOMPANY,lastInsertId,memberInfo.Com_Name,memberInfo.Com_Full_addr,memberInfo.Com_Telphone,memberInfo.Com_Fax,"",memberInfo.Com_Desc, memberInfo.Create_Time)
if err != nil {
service.WriteErrDetail("插入用户数据错误:插入公司"+err.Error())
err = dbTran.Rollback()
return false
}
dbTran.Commit()
return true
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import (
"crm-server/internal/dao"
"crm-server/internal/model"
"crm-server/internal/service"
"fmt"
"regexp"
"strconv"
"strings"
......@@ -141,6 +142,29 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{
MemberUserInfo.Com_Full_addr = common.AllCity[strconv.Itoa(MemberUserInfo.Com_Province_Id)] + common.AllCity[strconv.Itoa(MemberUserInfo.Com_City_Id)] + common.AllCity[strconv.Itoa(MemberUserInfo.Com_Area_Id)] + MemberUserInfo.Com_Address
}
//oems信息
var oems model.OemsUserinfo
dao.GetDb().QueryRowx("select contract,contract_name,note,outter_uid from lie_oems_userinfo where outter_uid = ?",&oems.Outter_Uid)
if oems.Outter_Uid != 0 {
fmt.Println(oems)
if MemberUserInfo.Mobile == "" {
MemberUserInfo.Mobile = oems.Contact
}
MemberUserInfo.User_Name = oems.Contact_Name
MemberUserInfo.Channel_source = 8
MemberUserInfo.Remark = oems.Note
}
//判断是否下单
var orderId int
err = dao.GetLiexinDb().QueryRowx("select order_id from lie_order where user_id = ?",MemberUserInfo.User_Id).Scan(orderId);
if orderId != 0 {
MemberUserInfo.No_Create_Order = 2
}else{
MemberUserInfo.No_Create_Order = 1
}
return MemberUserInfo
}
\ No newline at end of file
package model
type Feedback struct {
User_Id int `json:"user_id"`
Outter_Uid int `json:"outter_uid"`
Ip int `json:"ip"`
Type int `json:"type"`
Mobile string `json:"mobile"`
Content string `json:"content"`
Source string `json:"source"`
Pf int `json:"pf"`
Status int `json:"status"`
Sale_Id int `json:"sale_id"`
Bom_Url string `json:"bom_url"`
Responses string `json:"responses"`
Contact_Name string `json:"contact_name"`
Company_Name string `json:"company_name"`
Company_Type int `json:"company_type"`
Note string `json:"note"`
Create_Time int `json:"create_time"`
}
/*
CREATE TABLE `lie_feedback` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT COMMENT '流水id',
`user_id` mediumint(8) unsigned NOT NULL DEFAULT '0' COMMENT '如果用登陆,则记录用户id',
`outter_uid` mediumint(8) unsigned NOT NULL DEFAULT '0' COMMENT 'crm用户ID',
`ip` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'ip',
`type` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '5.搜索无结果 6、多次搜索 7、快速找货 8、SEO落地页面反馈',
`mobile` char(16) NOT NULL DEFAULT '' COMMENT '手机号',
`content` varchar(255) NOT NULL DEFAULT ' ' COMMENT '反馈意见',
`source` varchar(100) NOT NULL DEFAULT ' ' COMMENT '页面来源',
`pf` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '1、pc 2.H5',
`status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '0为未处理,1已处理',
`sale_id` mediumint(8) unsigned NOT NULL DEFAULT '0' COMMENT '客服id',
`bom_url` varchar(255) NOT NULL DEFAULT ' ' COMMENT 'bom单excel存在OSS的地址链接',
`responses` varchar(255) NOT NULL DEFAULT ' ' COMMENT '回复内容',
`contact_name` varchar(80) NOT NULL DEFAULT ' ' COMMENT '联系名称',
`company_name` varchar(50) NOT NULL DEFAULT ' ' COMMENT '公司名称',
`company_type` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '1代工厂 2终端 3代理商 4贸易商 5其它',
`note` varchar(100) NOT NULL DEFAULT ' ' COMMENT '备注',
`create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COMMENT='意见反馈表';
*/
\ No newline at end of file
......@@ -7,6 +7,7 @@ type MemberAddUserData struct {
User_Name string `json:"user_name"`
Email string `json:"email"`
Reg_Remark string `json:"reg_remark"`
Remark string `json:"remark"`
Create_Device int `json:"create_device"`
Create_Time int `json:"create_time"`
Com_Id int `json:"com_id"`
......@@ -30,4 +31,6 @@ type MemberAddUserData struct {
Channel_source int `json:"channel_source"`
Source int `json:"source"`
Customer_identity int `json:"customer_identity"`
No_Create_Order int `json:"no_create_order"`
}
\ No newline at end of file
package model
type OemsUserinfo struct {
Outter_Uid string `json:"outter_uid"`
Contact string `json:"contact"`
Contact_Name string `json:"contact_name"`
Note string `json:"note"`
Outter_Uid int `json:"outter_uid"`
Contact string `json:"contact"`
Contact_Name string `json:"contact_name"`
Note string `json:"note"`
}
\ No newline at end of file
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