This commit is contained in:
jiangyong27 2023-04-08 20:33:48 +08:00
parent 4085364383
commit 2871ef693c
12 changed files with 6840 additions and 100 deletions

View File

@ -3,6 +3,7 @@ package httputil
import ( import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"github.com/spf13/cast"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
@ -10,7 +11,7 @@ import (
) )
// Get 请求 link请求url // Get 请求 link请求url
func HttpGet(link string, params map[string]string, header map[string]string) ([]byte, error) { func HttpGet(link string, params map[string]interface{}, header map[string]interface{}) ([]byte, error) {
client := &http.Client{Timeout: 20 * time.Second} client := &http.Client{Timeout: 20 * time.Second}
//忽略https的证书 //忽略https的证书
client.Transport = &http.Transport{ client.Transport = &http.Transport{
@ -20,7 +21,7 @@ func HttpGet(link string, params map[string]string, header map[string]string) ([
u, _ := url.Parse(link) u, _ := url.Parse(link)
if params != nil { if params != nil {
for k, v := range params { for k, v := range params {
p.Set(k, v) p.Set(k, cast.ToString(v))
} }
} }
@ -32,7 +33,7 @@ func HttpGet(link string, params map[string]string, header map[string]string) ([
if header != nil { if header != nil {
for k, v := range header { for k, v := range header {
req.Header.Add(k, v) req.Header.Add(k, cast.ToString(v))
} }
} }

1
base/util/util.go Normal file
View File

@ -0,0 +1 @@
package util

View File

@ -70,13 +70,9 @@ func main() {
if err := orderWorker.Init(); err != nil { if err := orderWorker.Init(); err != nil {
panic(err) panic(err)
} }
//
//dadiProcessor.NewOrder(&model.Order{ order, _ := model.GetOrder(582589)
// CityName: "张家口",
// CinemaName: "大地影院(张家口财富中心店)", dadiProcessor.NewOrder(order)
// ShowTime: 1681006500,
// Seats: "3:6|3:5",
// MovieName: "超级马力欧兄弟大电影",
//})
select {} select {}
} }

View File

@ -1,7 +1,7 @@
[server] [server]
address = "0.0.0.0:9263" address = "0.0.0.0:9263"
#0:PAINC 1:FATAL 2:ERROR 3:WARNING 4:INFO 5:DEBUG 6:TRACE #0:PAINC 1:FATAL 2:ERROR 3:WARNING 4:INFO 5:DEBUG 6:TRACE
log_level = 6 log_level = 4
[mysql] [mysql]
@ -13,8 +13,8 @@ db = "film"
[weixin] [weixin]
qiye_appid = "ww288920bd3e8c92b2" qiye_appid = "ww288920bd3e8c92b2"
qiye_secret = "U2kq2Fxe_mwV7t-xYYvZJzmeGqkq2_1PPH-QpVGjWDg" qiye_secret = "3aqE6LAEKLiGtYBtX7TZm0uY_YD52w3R20AQirSICXY"
qiye_agent = "1000012" qiye_agent = "1000013"
[film] [film]
haha_token = "cc5f1d4c36f7e9544d641a174b298f94" haha_token = "cc5f1d4c36f7e9544d641a174b298f94"

View File

@ -1,7 +1,7 @@
[server] [server]
address = "0.0.0.0:9263" address = "0.0.0.0:9263"
#0:PAINC 1:FATAL 2:ERROR 3:WARNING 4:INFO 5:DEBUG 6:TRACE #0:PAINC 1:FATAL 2:ERROR 3:WARNING 4:INFO 5:DEBUG 6:TRACE
log_level = 6 log_level = 4
[mysql] [mysql]
@ -13,9 +13,9 @@ db = "film"
[weixin] [weixin]
qiye_appid = "ww1f9a1f9e96186e4c" qiye_appid = "ww288920bd3e8c92b2"
qiye_secret = "G3ITLIrqVDG42jObBgh9XH4G3dcVRguonASJJ0x2YwY" qiye_secret = "3aqE6LAEKLiGtYBtX7TZm0uY_YD52w3R20AQirSICXY"
qiye_agent = "1000005" qiye_agent = "1000013"
[film] [film]
haha_token = "cc5f1d4c36f7e9544d641a174b298f94" haha_token = "cc5f1d4c36f7e9544d641a174b298f94"

2576
data/dadi_seat.json Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -48,7 +48,7 @@ func (d *DBLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql st
if err != nil && err != gorm.ErrRecordNotFound { if err != nil && err != gorm.ErrRecordNotFound {
log.Errorf("[SQL]sql=%s affect=%d cost=%dms error=%v", sql, affects, time.Since(begin).Milliseconds(), err) log.Errorf("[SQL]sql=%s affect=%d cost=%dms error=%v", sql, affects, time.Since(begin).Milliseconds(), err)
} else { } else {
if time.Since(begin).Milliseconds() > 200 { if time.Since(begin).Milliseconds() > 1000 {
log.Errorf("[SQL]sql=%s affect=%d cost=%dms", sql, affects, time.Since(begin).Milliseconds()) log.Errorf("[SQL]sql=%s affect=%d cost=%dms", sql, affects, time.Since(begin).Milliseconds())
} else { } else {
log.Debugf("[SQL]sql=%s affect=%d cost=%dms", sql, affects, time.Since(begin).Milliseconds()) log.Debugf("[SQL]sql=%s affect=%d cost=%dms", sql, affects, time.Since(begin).Milliseconds())

View File

@ -16,6 +16,8 @@ type Order struct {
StartDate string StartDate string
TotalPrice int64 TotalPrice int64
PayPrice int64 PayPrice int64
MinPrice int64
MaxPrice int64
MaoyanPrice int64 MaoyanPrice int64
SeatNum int SeatNum int
Seats string Seats string

View File

@ -5,6 +5,7 @@ import (
"film/base/httputil" "film/base/httputil"
"film/config" "film/config"
"film/model" "film/model"
"fmt"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil" "github.com/smbrave/goutil"
"github.com/spf13/cast" "github.com/spf13/cast"
@ -22,27 +23,23 @@ type Dadi struct {
func (d *Dadi) Init() error { func (d *Dadi) Init() error {
cityUrl := "https://appapi.dadicinema.com/app-web/v1/web/cinema/cbticket/cbase/cityAndCinemaList" cityUrl := "https://appapi.dadicinema.com/app-web/v1/web/cinema/cbticket/cbase/cityAndCinemaList"
params := d.getCinemaReq(&DadiCinema{ params := d.getBaseParam(&DadiCinema{
Name: "大地影院(北京十里河铭泽店)", Name: "大地影院(北京十里河铭泽店)",
Id: 118, Id: 118,
UnifiedCode: 11050621, UnifiedCode: 11050621,
}) })
body, err := httputil.HttpGet(cityUrl, params, map[string]string{ body, err := httputil.HttpGet(cityUrl, params, d.getBaseHeader())
"User-Agent": "apifox/1.0.0 (https://www.apifox.cn)", if err != nil {
}) log.Errorf(" httputil.HttpGet url : %s error: %s", cityUrl, err.Error())
result := make(map[string]interface{})
if err := json.Unmarshal(body, &result); err != nil {
log.Errorf("json.unmarshal [%s] error : %s", string(body), err.Error())
return err return err
} }
if cast.ToInt(result["code"]) != 200 || cast.ToBool(result["success"]) != true { result, err := d.checkError(body)
log.Errorf("code[%d] message[%s]", cast.ToInt(result["code"]), cast.ToString(result["msg"])) if err != nil {
return err return err
} }
citys := make(map[string]*DadiCity) citys := make(map[string]*DadiCity)
datas := cast.ToSlice(result["data"]) datas := cast.ToSlice(result)
for _, d := range datas { for _, d := range datas {
data := cast.ToStringMap(d) data := cast.ToStringMap(d)
@ -82,54 +79,72 @@ func (d *Dadi) Init() error {
return nil return nil
} }
func (d *Dadi) UpdateOrder(order *model.Order) {
}
func (d *Dadi) NewOrder(order *model.Order) { func (d *Dadi) NewOrder(order *model.Order) {
if _, ok := d.citys[order.CityName]; !ok {
log.Errorf("city[%s] not exist dadi cinema", order.CityName) cinema, err := d.getCinema(order)
if err != nil {
log.Errorf("getcinema order : %s error : %s", goutil.EncodeJSON(order), err.Error())
return return
} }
city := d.citys[order.CityName] hall, err := d.getCinemaFilm(order, cinema)
for _, cinema := range city.Cinemas {
if cinema.Name != order.CinemaName {
continue
}
films, err := d.getCinemaFilm(cinema)
if err != nil { if err != nil {
log.Errorf("getCinemaFilm cinema : %s error :%s", goutil.EncodeJSON(cinema), err.Error()) log.Errorf("getCinemaFilm order : %s error : %s", goutil.EncodeJSON(order), err.Error())
continue return
} }
if _, ok := films[order.MovieName]; !ok { dadiOrder, err := d.holdSeats(order, cinema, hall)
log.Errorf("cinema[%s] not movie[%s] ", cinema.Name, order.MovieName) if err != nil {
continue log.Errorf("holdSeats order : %s error : %s", goutil.EncodeJSON(order), err.Error())
} return
film := films[order.MovieName]
orderShowDay := time.Unix(order.ShowTime, 0).Format("2006-01-02")
var show *DadiFilmShow = nil
for _, sh := range film.Shows {
if sh.Day != orderShowDay {
continue
}
show = sh
}
if show == nil {
log.Errorf("cinema[%s] movie[%s] no day[%s]", cinema.Name, order.MovieName, orderShowDay)
continue
} }
message := make([]string, 0) message := make([]string, 0)
message = append(message, "【匹配成功】") message = append(message, "【哈哈票订单信息】")
message = append(message, "订单信息:%s", goutil.EncodeJSON(order)) message = append(message, fmt.Sprintf("城市:%s", order.CityName))
message = append(message, "影院信息:%s", goutil.EncodeJSON(cinema)) message = append(message, fmt.Sprintf("影院:%s", order.CinemaName))
message = append(message, "电影信息:%s", goutil.EncodeJSON(film)) message = append(message, fmt.Sprintf("影厅:%s", order.Ting))
message = append(message, fmt.Sprintf("座位:%s%s%s", order.Seats,
goutil.If(order.IsSeat == 3, "可以调座", "不可调座"),
goutil.If(order.LoverSeat == 1, "情侣座", "普通座")))
message = append(message, fmt.Sprintf("订单编号:%s", order.OrderId))
message = append(message, fmt.Sprintf("订单金额:%.2f", float64(order.TotalPrice)/100))
message = append(message, fmt.Sprintf("报价范围:%.2f~%.2f", float64(order.MinPrice)/100, float64(order.MaxPrice)/100))
message = append(message, fmt.Sprintf("订单时间:%s", time.Unix(order.PayTime, 0).Format("2006-01-02 15:04")))
message = append(message, fmt.Sprintf("放映时间:%s", time.Unix(order.ShowTime, 0).Format("2006-01-02 15:04")))
message = append(message, "\n")
message = append(message, "【大地订单信息】")
message = append(message, fmt.Sprintf("订单编号:%s", dadiOrder.OrderId))
if err := d.qyClient.SendText([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil { if err := d.qyClient.SendText([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
log.Errorf("send message error : %s", err.Error()) log.Errorf("send message error : %s", err.Error())
} }
}
func (d *Dadi) checkError(body []byte) (interface{}, error) {
result := make(map[string]interface{})
if err := json.Unmarshal(body, &result); err != nil {
log.Errorf("json.unmarshal [%s] error : %s", string(body), err.Error())
return nil, err
}
if cast.ToInt(result["code"]) != 200 || cast.ToBool(result["success"]) != true {
log.Errorf("code[%d] message[%s]", cast.ToInt(result["code"]), cast.ToString(result["msg"]))
return nil, fmt.Errorf("code[%d] message[%s]", cast.ToInt(result["code"]), cast.ToString(result["msg"]))
}
return result["data"], nil
}
func (d *Dadi) getBaseHeader() map[string]interface{} {
return map[string]interface{}{
"User-Agent": "apifox/1.0.0 (https://www.apifox.cn)",
} }
} }
func (d *Dadi) getCinemaReq(cinema *DadiCinema) map[string]string { func (d *Dadi) getBaseParam(cinema *DadiCinema) map[string]interface{} {
params := map[string]string{ params := map[string]interface{}{
"channelCode": "SYH-DDZY-DD", "channelCode": "SYH-DDZY-DD",
"channelName": "大地自营-大地", "channelName": "大地自营-大地",
"channelNo": "SYH-DDZY-DD", "channelNo": "SYH-DDZY-DD",
@ -152,62 +167,90 @@ func (d *Dadi) getCinemaReq(cinema *DadiCinema) map[string]string {
return params return params
} }
func (d *Dadi) UpdateOrder(order *model.Order) { func (d *Dadi) getCinema(order *model.Order) (*DadiCinema, error) {
if _, ok := d.citys[order.CityName]; !ok {
log.Errorf("city[%s] not exist dadi cinema", order.CityName)
return nil, fmt.Errorf("city[%s] not exist dadi cinema", order.CityName)
}
city := d.citys[order.CityName]
for _, cinema := range city.Cinemas {
if cinema.Name != order.CinemaName {
continue
}
return cinema, nil
}
return nil, fmt.Errorf("city[%s] not[%s]", order.CityName, order.CinemaName)
} }
func (d *Dadi) getCinemaFilm(cinema *DadiCinema) (map[string]*DadiFilm, error) { func (d *Dadi) getCinemaFilm(order *model.Order, cinema *DadiCinema) (*DadiFilmShowHall, error) {
baseReq := d.getCinemaReq(cinema) baseReq := d.getBaseParam(cinema)
reqUrl := "https://appapi.dadicinema.com/app-web/v1/web/film/getHitFilmAndFilmSession" reqUrl := "https://appapi.dadicinema.com/app-web/v1/web/film/getHitFilmAndFilmSession"
body, err := httputil.HttpGet(reqUrl, baseReq, map[string]string{ body, err := httputil.HttpGet(reqUrl, baseReq, d.getBaseHeader())
"User-Agent": "apifox/1.0.0 (https://www.apifox.cn)",
})
if err != nil { if err != nil {
log.Errorf("httpGet[%s] error : %s", reqUrl, err.Error()) log.Errorf("httpGet[%s] error : %s", reqUrl, err.Error())
return nil, err return nil, err
} }
result := make(map[string]interface{}) result, err := d.checkError(body)
if err := json.Unmarshal(body, &result); err != nil { if err != nil {
log.Errorf("json.unmarshal [%s] error : %s", string(body), err.Error())
return nil, err
}
if cast.ToInt(result["code"]) != 200 || cast.ToBool(result["success"]) != true {
log.Errorf("code[%d] message[%s]", cast.ToInt(result["code"]), cast.ToString(result["msg"]))
return nil, err return nil, err
} }
films := make(map[string]*DadiFilm) orderShowDay := time.Unix(order.ShowTime, 0).Format("2006-01-02")
var hall *DadiFilmShowHall = nil
for _, f := range cast.ToSlice(cast.ToStringMap(result["data"])["filmList"]) { for _, f := range cast.ToSlice(cast.ToStringMap(result)["filmList"]) {
film := new(DadiFilm)
ff := cast.ToStringMap(f) ff := cast.ToStringMap(f)
film.Id = cast.ToInt64(ff["id"]) filmName := cast.ToString(ff["name"])
film.Name = cast.ToString(ff["name"]) if filmName != order.MovieName {
film.Shows = make([]*DadiFilmShow, 0) continue
}
for _, s := range cast.ToSlice(ff["showList"]) { for _, s := range cast.ToSlice(ff["showList"]) {
ss := cast.ToStringMap(s) ss := cast.ToStringMap(s)
show := new(DadiFilmShow) showDay := cast.ToString(ss["dayStr"])
show.Day = cast.ToString(ss["dayStr"]) if showDay != orderShowDay {
show.Halls = make([]*DadiFilmShowHall, 0) continue
}
for _, p := range cast.ToSlice(ss["plist"]) { for _, p := range cast.ToSlice(ss["plist"]) {
pp := cast.ToStringMap(p) pp := cast.ToStringMap(p)
hall := new(DadiFilmShowHall) hallName := cast.ToString(pp["hallName"])
if hallName != order.Ting {
continue
}
hall = new(DadiFilmShowHall)
hall.FilmName = filmName
hall.ShowDay = showDay
hall.HallName = cast.ToString(pp["hallName"]) hall.HallName = cast.ToString(pp["hallName"])
hall.SessionId = cast.ToString(pp["sessionId"]) hall.SessionId = cast.ToString(pp["sessionId"])
hall.StartTime = cast.ToString(pp["startTime"]) hall.StartTime = cast.ToString(pp["startTime"])
hall.EndTime = cast.ToString(pp["endTime"]) hall.EndTime = cast.ToString(pp["endTime"])
show.Halls = append(show.Halls, hall) return hall, nil
} }
film.Shows = append(film.Shows, show)
} }
films[film.Name] = film
} }
return films, nil return nil, fmt.Errorf("film[%s] day[%s] ting[%s] nohas", order.MovieName, orderShowDay, order.Ting)
} }
func (d *Dadi) checkSeats(cinema *DadiCinema, order *model.Order) { func (d *Dadi) getCinemaSeats(order *model.Order, cinema *DadiCinema, hall *DadiFilmShowHall) error {
baseReq := d.getBaseParam(cinema)
baseReq["sessionId"] = hall.SessionId
reqUrl := "https://appapi.dadicinema.com/app-web/v1/web/cinema/cbticket/cticket/getSessionSeat"
body, err := httputil.HttpGet(reqUrl, baseReq, d.getBaseHeader())
if err != nil {
log.Errorf("http get url: %s, error: %s", reqUrl, err.Error())
return err
}
_, err = d.checkError(body)
if err != nil {
return err
}
//baseReq := d.getCinemaReq(cinema) return nil
//baseReq := d.getBaseParam(cinema)
}
func (d *Dadi) holdSeats(order *model.Order, cinema *DadiCinema, hall *DadiFilmShowHall) (*DadiFilmOrder, error) {
return &DadiFilmOrder{
OrderId: "test",
}, nil
} }

View File

@ -111,6 +111,8 @@ func (w *Orders) syncOrder() {
order.Count = cast.ToInt(data["count"]) order.Count = cast.ToInt(data["count"])
order.IsSeat = cast.ToInt(data["is_seat"]) order.IsSeat = cast.ToInt(data["is_seat"])
order.LoverSeat = cast.ToInt(data["loverSeat"]) order.LoverSeat = cast.ToInt(data["loverSeat"])
order.MinPrice = cast.ToInt64(data["min_price"])
order.MaxPrice = cast.ToInt64(data["max_price"])
if isAdd { if isAdd {
model.AddOrder(order) model.AddOrder(order)

View File

@ -1,6 +1,8 @@
package worker package worker
type DadiFilmShowHall struct { type DadiFilmShowHall struct {
ShowDay string
FilmName string
HallName string HallName string
StartTime string StartTime string
EndTime string EndTime string
@ -12,6 +14,13 @@ type DadiFilmShow struct {
Halls []*DadiFilmShowHall Halls []*DadiFilmShowHall
} }
type DadiFilmOrder struct {
OrderId string
}
type DadiFilmSeat struct {
}
type DadiFilm struct { type DadiFilm struct {
Id int64 Id int64
Name string Name string