Commit 51d62436 by 孙龙

up

parent 6b9cd006
......@@ -7,6 +7,7 @@ webhook="https://oapi.dingtalk.com/robot/send?access_token=ec03b2cba0d62ef0bd7b9
jingDiao="https://oapi.dingtalk.com/robot/send?access_token=eaeae1253e9c125a053bc8a7bcfec5096a23625a98044eaa346591863449ba17"
tuangou_webhook="https://oapi.dingtalk.com/robot/send?access_token=a13d6128de5f918fc0f0a4cef70cab8b1962fca709649f7856aea4b1ca4dddf5"
erpLabel_webhook="https://oapi.dingtalk.com/robot/send?access_token=3966b80b7e56e8ffdff5ed2aefa1ea465c0f944a0db6ec5519eeef8721d1eb43"
yaoHaoYou_hook="https://oapi.dingtalk.com/robot/send?access_token=087c11504fb541d004507f06285da88c2501fc1a4ecacd0216b9da964aa65518"
[Api_domain]
......
......@@ -33,3 +33,11 @@ routing_key="sales_label"
exchange="erp_to_webservice"
type="direct"
dns="amqp://guest:guest@192.168.2.232:5672/"
[rabbitmq_yaohaoyou]
queue_name="ichunt_addorder_yaohaoyou"
routing_key="ichunt_addorder_yaohaoyou"
exchange=""
type="direct"
dns="amqp://guest:guest@192.168.2.232:5672/"
\ No newline at end of file
package YaoHaoYou
import (
"errors"
"fmt"
"github.com/ichunt2019/logger"
"github.com/jmoiron/sqlx"
"go-queue-server/dal/db"
)
type UserInvitefriendModel struct {
ID int64 `json:"id" db:"id"`
UserId int64 `json:"user_id" db:"user_id"`
InviteUserId int64 `json:"invite_user_id" db:"invite_user_id"`
Type int `json:"type" db:"type"`
TypeId int64 `json:"type_id" db:"type_id"`
Status int `json:"status" db:"status"`
GoodsId string `json:"goods_id" db:"goods_id"`
}
type UserInfo struct {
UserId string `json:"user_id" db:"user_id"`
Mobile string `json:"mobile" db:"mobile"`
Email string `json:"email" db:"email"`
}
type OrderItems struct {
OrderId string `json:"order_id" db:"order_id"`
GoodsNumbers int `json:"gnums" db:"gnums"`
}
func UpdateuserInvitefriend (order_id int64) (err error){
userInvitefriendModel := &UserInvitefriendModel{}
tx := db.DB.MustBegin()
//获取该记录信息
sql := "select id,user_id,invite_user_id,type,type_id,status,goods_id from lie_user_invitefriend where type =1 and type_id = ? limit 1"
err = tx.Get(userInvitefriendModel,sql,order_id)
if err != nil{
logger.Info(fmt.Sprintf("没有找到相关的邀请好友订单 订单id: %d error : %s",order_id,err))
return errors.New(fmt.Sprintf("没有找到相关的邀请好友订单信息 订单id: %d error : %s",order_id,err))
}
//更新邀好友活动记录表
updateUserinvitefriendSql := `update lie_user_invitefriend set status = 1 where type = 1 and type_id = ?`
_ = tx.MustExec(updateUserinvitefriendSql,order_id)
//新增邀好友活动推送消息记录表
//下单成功消息
err = add_user_invitefriend_msg(userInvitefriendModel,tx,1)
err = add_user_invitefriend_msg(userInvitefriendModel,tx,2)
err = add_user_invitefriend_msg(userInvitefriendModel,tx,3)
//邀请人消息
err = tx.Commit()
if err != nil{
return err
}
return nil
}
func add_user_invitefriend_msg(uifModel *UserInvitefriendModel,tx *sqlx.Tx ,msg_type int) (err error){
var user_id int64
//判断用户和邀请用户
if msg_type == 1{
user_id = uifModel.UserId
}else if msg_type == 2 || msg_type == 3 {
user_id = uifModel.InviteUserId
}
userInfo,err:= getUserInfo(user_id)
var (
username string
msg_conente string
)
if err != nil{
//没有找到相关的用户信息
logger.Error(fmt.Sprintf("没有相关推送消息的用户信息 用户id %d",uifModel.UserId))
}else{
user_invitefriend_msg := `insert into lie_user_invitefriend_msg (user_id,invite_user_id,type,type_id,msg_type,username,status,goods_num)
values(?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE goods_num= ? ,username=?`
goods_num := 0 //默认为0
//用户名加密132xxxx9723
if userInfo.Mobile != "" && len(userInfo.Mobile) > 4 {
username = fmt.Sprintf("%sxxxx%s",userInfo.Mobile[0:3],userInfo.Mobile[7:11])
}else if userInfo.Email != ""{
username = userInfo.Email
}else{
username = fmt.Sprintf("%s",uifModel.UserId)
}
//消息类型 1用户下单 2邀好友 3返利
if msg_type == 1{
msg_conente = fmt.Sprintf("%s",username)
}else if msg_type == 2{
msg_conente = fmt.Sprintf("%s",username)
}else if msg_type == 3{
msg_conente = fmt.Sprintf("%s",username)
orderItems,err :=getOrderInfo(uifModel.TypeId)
if err != nil{
logger.Error(fmt.Sprintf("没有找到需要推送的奖品信息 订单数量有问题 用户id %d,订单id:%d",uifModel.UserId,uifModel.TypeId))
return nil
}else{
goods_num = orderItems.GoodsNumbers
}
}
_ = tx.MustExec(user_invitefriend_msg,uifModel.UserId,uifModel.InviteUserId,uifModel.Type,
uifModel.TypeId,msg_type,msg_conente,1,goods_num,goods_num,msg_conente)
}
return nil
}
/*
获取用户信息
*/
func getUserInfo(user_id int64) (userInfo *UserInfo,err error) {
userInfo = &UserInfo{}
sql := `select mobile,user_id,email from lie_user_main where user_id = ?`
err = db.DB.Get(userInfo,sql,user_id)
if err != nil{
return nil,err
}
return userInfo,nil
}
/*
获取订单的购买数量
*/
func getOrderInfo(order_id int64) (orderItems *OrderItems,err error){
orderItems = &OrderItems{}
sql := `select sum(goods_number) as gnums from lie_order_items where order_id = ? and status = 1`
err = db.DB.Get(orderItems,sql,order_id)
if err != nil{
return nil,err
}
return orderItems,nil
}
\ No newline at end of file
......@@ -15,4 +15,5 @@ require (
github.com/prometheus/common v0.7.0 // indirect
github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71
github.com/tealeg/xlsx v1.0.5
github.com/tidwall/gjson v1.6.0
)
......@@ -92,6 +92,12 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=
github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM=
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
......
package main
import (
"flag"
"fmt"
"github.com/ichunt2019/golang-rbmq-sl/utils/rabbitmq"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
"go-queue-server/order/yaoHaoYou/services"
"go-queue-server/util"
"go-queue-server/util/ding"
_ "sync"
_ "time"
)
type RecvPro struct {
}
//// 实现消费者 消费消息失败 自动进入延时尝试 尝试3次之后入库db
func (t *RecvPro) Consumer(dataByte []byte) error {
logger.Info(string(dataByte))
fmt.Println(string(dataByte))
services.YaohaoyouOrder(string(dataByte));
return nil
}
//消息已经消费3次 失败了 请进行处理
func (t *RecvPro) FailAction(err error,dataByte []byte) error {
logger.Error("任务处理失败了,我要进入db日志库了")
logger.Error("任务处理失败了,发送钉钉消息通知主人")
logger.Error(string(dataByte))
logger.Error("错误原因:%s",err)
ding.Send(
util.Configs.Ding_msg.YaoHaoYouWebhook,
"@所有人 邀好友下单告警:\n",
fmt.Sprintf("失败原因:%s \n %s",err,string(dataByte)) ,
make([]string,0),
false,
)
return nil
}
func initDb(action string,dns string) (err error) {
err = db.CreateDB(action,dns)
if err != nil {
fmt.Println(err)
panic(err)
return
}
return
}
var ConfigDir string
var LogDir string
// 解析命令行参数
func initArgs() {
// worker -config ./worker.json
// worker -h
flag.StringVar(&ConfigDir, "configDir", "", "配置文件")
flag.StringVar(&LogDir, "logDir", "", "日志目录")
flag.Parse()
}
func main() {
initArgs()
//初始化配置文件
util.Init(ConfigDir)
//
logConfig := make(map[string]string)
logConfig["log_path"] = LogDir+"yaohaoyou/"
logConfig["log_chan_size"] = "1000"
logger.InitLogger("file",logConfig)
logger.Init()
//初始化db
initDb("Init",util.Configs.Liexin_databases.Dns)
//initDb("InitLabelDB",util.Configs.LiexinLabel_databases.Dns)
//initDb("InitCmsDB",util.Configs.Liexincms_databases.Dns)
t := &RecvPro{}
rabbitmq.Recv(rabbitmq.QueueExchange{
util.Configs.Rabbitmq_yaohaoyou.QueueName,
util.Configs.Rabbitmq_yaohaoyou.QueueName,
"",
util.Configs.Rabbitmq_yaohaoyou.Type,
util.Configs.Rabbitmq_yaohaoyou.Dns,
},t,2)
}
\ No newline at end of file
package services
import (
"github.com/tidwall/gjson"
"go-queue-server/dal/order/YaoHaoYou"
)
type OrderYHY struct {
OrderoId int64 `json:"order_id"`
}
/*
邀好友
处理邀好友活动 好友邀请用户 用户下单后续操作
1,修改邀好友活动记录表
2,增加消息
*/
func YaohaoyouOrder(order string){
order_id := gjson.Get(order, "order_id")
//修改记录
YaoHaoYou.UpdateuserInvitefriend(order_id.Int())
}
package util
import (
"fmt"
"github.com/BurntSushi/toml"
)
......@@ -13,6 +12,7 @@ type Config struct{
Rabbitmq_ichunt *RabbitmqIchunt
Rabbitmq_erp_label *RabbitmqErpLabel
Rabbitmq_order_push_stock *RabbitmqOrderPushStock
Rabbitmq_yaohaoyou *RabbitmqYaoHaoYou
Crm_domain *SendMail
Ding_msg *Ding
Api_domain *ApiDomain
......@@ -52,6 +52,12 @@ type RabbitmqOrderPushStock struct {
Dns string `toml:"dns"`
}
type RabbitmqYaoHaoYou struct {
QueueName string `toml:"queue_name"`
Type string `toml:"type"`
Dns string `toml:"dns"`
}
type SendMail struct{
SendMailUrl string `toml:"send_mail"`
}
......@@ -61,6 +67,7 @@ type Ding struct {
JingDiao string `toml:"jingDiao"`
TuangouWebhook string `toml:"tuangou_webhook"`
ErpLabelWebhook string `toml:"erpLabel_webhook"`
YaoHaoYouWebhook string `toml:"yaoHaoYou_hook"`
}
type ApiDomain struct {
......@@ -81,15 +88,6 @@ func Init(ConfigDir string){
_, err = toml.DecodeFile(ConfigDir+"config.toml",Configs)
_, err = toml.DecodeFile(ConfigDir+"db.toml",Configs)
if err!=nil{
fmt.Println(err)
panic(err)
}
//fmt.Printf("%+v",Configs.Liexin_databases)
//fmt.Printf("%+v",Configs.Rabbitmq_ichunt)
//fmt.Printf("%+v",Configs.Crm_domain)
//fmt.Printf("%+v",Configs.Ding_msg)
//
//fmt.Printf("%+v",Configs.Crm_domain)
//fmt.Printf("%+v",Configs.Rabbitmq_ichunt)
//fmt.Printf("%+v",Configs.Redis_config)
//fmt.Printf("%+v",Configs.Rabbitmq_order_push_stock)
}
go run ./order/yaoHaoYou/main.go -configDir=./config/ -logDir=./log/
\ 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