Commit 66a413bf by 孙龙
parents 2a9ea25c 88943fa6
package OrderActionLog
import (
"database/sql"
"go-queue-server/dal/db"
"go-queue-server/util"
"fmt"
"log"
"time"
)
type ActionLog struct {
LogId int `db:"log_id"`
OrderId int `db:"order_id"`
OperatorId int `db:"operator_id"`
OperatorType int `db:"operator_type"`
Event string `db:"event"`
Ip string `db:"ip"`
CreateTime int `db:"create_time"`
}
func initDb(dns string) (err error) {
err = db.Init(dns)
if err != nil {
return
}
return
}
func AddLog() (err error) {
initDb(util.Configs.Liexin_databases.Dns) //初始化db
// QueryRow()
// Query()
Insert(3340, 1000, 2, "go test")
return
}
// 单行查询
func QueryRow() {
var actionLog ActionLog
err1 := db.DB.Get(&actionLog, "select * from lie_order_action_log where order_id = 3340")
if err1 == sql.ErrNoRows {
log.Printf("not found data of the id:%d", 1)
}
if err1 != nil {
panic(err1)
}
fmt.Printf("actionLog: %v\n", actionLog)
}
// 多行查询
func Query() {
var actionLog2 []*ActionLog
err2 := db.DB.Select(&actionLog2, "select * from lie_order_action_log where order_id = 3340")
if err2 == sql.ErrNoRows {
log.Printf("not found data of the id:%d", 1)
}
if err2 != nil {
panic(err2)
}
for _, v := range actionLog2 {
fmt.Println(v)
}
}
func Insert(order_id int, operator_id int, operator_type int, event string) (err error) {
create_time := time.Now().Unix()
result, err := db.DB.Exec("insert into lie_order_action_log (order_id, operator_id, operator_type, event, create_time) values (?, ?, ?, ?, ?)", order_id, operator_id, operator_type, event, create_time)
if err != nil {
panic(err)
}
id, err := result.LastInsertId()
if err != nil {
panic(err)
}
affected, err := result.RowsAffected()
if err != nil {
panic(err)
}
fmt.Printf("last insert id:%d affect rows:%d\n", id, affected)
return err
}
\ No newline at end of file
......@@ -21,7 +21,6 @@ type RecvPro struct {
//// 实现消费者 消费消息失败 自动进入延时尝试 尝试3次之后入库db
func (t *RecvPro) Consumer(dataByte []byte) error {
//fmt.Println(string(dataByte))
logger.Info(string(dataByte))
err := sendEmail.SendPurchaseEmail(string(dataByte))
////return errors.New("顶顶顶顶")
......
package sendEmail
import "fmt"
import (
"fmt"
"go-queue-server/util"
"net/http"
"encoding/json"
"strings"
"io/ioutil"
"go-queue-server/dal/order/OrderActionLog"
)
func SendPurchaseEmail(data string) (err error){
fmt.Println("555555555555555")
fmt.Println(data)
type JosnResp struct {
Errcode int `json:"err_code"`
Errmsg string `json:"msg"`
}
func SendPurchaseEmail(data string) (err error) {
crm_url := util.Configs.Crm_domain.SendMailUrl // CRM发送邮件接口
client := &http.Client{}
req, _ := http.NewRequest("POST", crm_url, strings.NewReader(string(data)))
req.Header.Set("api-key", "crm a1b2c3d4e5f6g7h8i9jk")
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
defer resp.Body.Close()
if err != nil {
fmt.Println(err.Error())
}
body, _ := ioutil.ReadAll(resp.Body)
res := JosnResp{}
err1 := json.Unmarshal([]byte(body), &res)
if err1 !=nil{
fmt.Println(err1)
}
var data_map map[string]interface{}
json.Unmarshal([]byte(data), &data_map)
order_id := data_map["order_id"];
operator_id := data_map["operator_id"];
operator_event := data_map["operator_event"];
// 添加操作日志
OrderActionLog.Insert(order_id, operator_id, 2, operator_event)
// 推送ERP
return
}
......@@ -36,6 +36,7 @@ func Init(){
if err!=nil{
fmt.Println(err)
}
//fmt.Printf("%+v",Configs.Crm_domain)
//fmt.Printf("%+v",Configs.Rabbitmq_ichunt)
}
package ding
import (
"net/http"
"encoding/json"
)
func send() {
}
\ 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