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 (
"crypto/tls"
"fmt"
"github.com/spf13/cast"
"io"
"net/http"
"net/url"
@ -10,7 +11,7 @@ import (
)
// 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}
//忽略https的证书
client.Transport = &http.Transport{
@ -20,7 +21,7 @@ func HttpGet(link string, params map[string]string, header map[string]string) ([
u, _ := url.Parse(link)
if params != nil {
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 {
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 {
panic(err)
}
//
//dadiProcessor.NewOrder(&model.Order{
// CityName: "张家口",
// CinemaName: "大地影院(张家口财富中心店)",
// ShowTime: 1681006500,
// Seats: "3:6|3:5",
// MovieName: "超级马力欧兄弟大电影",
//})
order, _ := model.GetOrder(582589)
dadiProcessor.NewOrder(order)
select {}
}

View File

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

View File

@ -1,7 +1,7 @@
[server]
address = "0.0.0.0:9263"
#0:PAINC 1:FATAL 2:ERROR 3:WARNING 4:INFO 5:DEBUG 6:TRACE
log_level = 6
log_level = 4
[mysql]
@ -13,9 +13,9 @@ db = "film"
[weixin]
qiye_appid = "ww1f9a1f9e96186e4c"
qiye_secret = "G3ITLIrqVDG42jObBgh9XH4G3dcVRguonASJJ0x2YwY"
qiye_agent = "1000005"
qiye_appid = "ww288920bd3e8c92b2"
qiye_secret = "3aqE6LAEKLiGtYBtX7TZm0uY_YD52w3R20AQirSICXY"
qiye_agent = "1000013"
[film]
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 {
log.Errorf("[SQL]sql=%s affect=%d cost=%dms error=%v", sql, affects, time.Since(begin).Milliseconds(), err)
} 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())
} else {
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
TotalPrice int64
PayPrice int64
MinPrice int64
MaxPrice int64
MaoyanPrice int64
SeatNum int
Seats string

View File

@ -5,6 +5,7 @@ import (
"film/base/httputil"
"film/config"
"film/model"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil"
"github.com/spf13/cast"
@ -22,27 +23,23 @@ type Dadi struct {
func (d *Dadi) Init() error {
cityUrl := "https://appapi.dadicinema.com/app-web/v1/web/cinema/cbticket/cbase/cityAndCinemaList"
params := d.getCinemaReq(&DadiCinema{
params := d.getBaseParam(&DadiCinema{
Name: "大地影院(北京十里河铭泽店)",
Id: 118,
UnifiedCode: 11050621,
})
body, err := httputil.HttpGet(cityUrl, params, map[string]string{
"User-Agent": "apifox/1.0.0 (https://www.apifox.cn)",
})
result := make(map[string]interface{})
if err := json.Unmarshal(body, &result); err != nil {
log.Errorf("json.unmarshal [%s] error : %s", string(body), err.Error())
body, err := httputil.HttpGet(cityUrl, params, d.getBaseHeader())
if err != nil {
log.Errorf(" httputil.HttpGet url : %s error: %s", cityUrl, err.Error())
return 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"]))
result, err := d.checkError(body)
if err != nil {
return err
}
citys := make(map[string]*DadiCity)
datas := cast.ToSlice(result["data"])
datas := cast.ToSlice(result)
for _, d := range datas {
data := cast.ToStringMap(d)
@ -82,54 +79,72 @@ func (d *Dadi) Init() error {
return nil
}
func (d *Dadi) UpdateOrder(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
}
hall, err := d.getCinemaFilm(order, cinema)
if err != nil {
log.Errorf("getCinemaFilm order : %s error : %s", goutil.EncodeJSON(order), err.Error())
return
}
dadiOrder, err := d.holdSeats(order, cinema, hall)
if err != nil {
log.Errorf("holdSeats order : %s error : %s", goutil.EncodeJSON(order), err.Error())
return
}
city := d.citys[order.CityName]
for _, cinema := range city.Cinemas {
if cinema.Name != order.CinemaName {
continue
}
films, err := d.getCinemaFilm(cinema)
if err != nil {
log.Errorf("getCinemaFilm cinema : %s error :%s", goutil.EncodeJSON(cinema), err.Error())
continue
}
if _, ok := films[order.MovieName]; !ok {
log.Errorf("cinema[%s] not movie[%s] ", cinema.Name, order.MovieName)
continue
}
film := films[order.MovieName]
message := make([]string, 0)
message = append(message, "【哈哈票订单信息】")
message = append(message, fmt.Sprintf("城市:%s", order.CityName))
message = append(message, fmt.Sprintf("影院:%s", order.CinemaName))
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 {
log.Errorf("send message error : %s", err.Error())
}
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 = append(message, "【匹配成功】")
message = append(message, "订单信息:%s", goutil.EncodeJSON(order))
message = append(message, "影院信息:%s", goutil.EncodeJSON(cinema))
message = append(message, "电影信息:%s", goutil.EncodeJSON(film))
if err := d.qyClient.SendText([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
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 {
params := map[string]string{
func (d *Dadi) getBaseParam(cinema *DadiCinema) map[string]interface{} {
params := map[string]interface{}{
"channelCode": "SYH-DDZY-DD",
"channelName": "大地自营-大地",
"channelNo": "SYH-DDZY-DD",
@ -152,62 +167,90 @@ func (d *Dadi) getCinemaReq(cinema *DadiCinema) map[string]string {
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) {
baseReq := d.getCinemaReq(cinema)
func (d *Dadi) getCinemaFilm(order *model.Order, cinema *DadiCinema) (*DadiFilmShowHall, error) {
baseReq := d.getBaseParam(cinema)
reqUrl := "https://appapi.dadicinema.com/app-web/v1/web/film/getHitFilmAndFilmSession"
body, err := httputil.HttpGet(reqUrl, baseReq, map[string]string{
"User-Agent": "apifox/1.0.0 (https://www.apifox.cn)",
})
body, err := httputil.HttpGet(reqUrl, baseReq, d.getBaseHeader())
if err != nil {
log.Errorf("httpGet[%s] error : %s", reqUrl, err.Error())
return nil, err
}
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"]))
result, err := d.checkError(body)
if err != nil {
return nil, err
}
films := make(map[string]*DadiFilm)
for _, f := range cast.ToSlice(cast.ToStringMap(result["data"])["filmList"]) {
film := new(DadiFilm)
orderShowDay := time.Unix(order.ShowTime, 0).Format("2006-01-02")
var hall *DadiFilmShowHall = nil
for _, f := range cast.ToSlice(cast.ToStringMap(result)["filmList"]) {
ff := cast.ToStringMap(f)
film.Id = cast.ToInt64(ff["id"])
film.Name = cast.ToString(ff["name"])
film.Shows = make([]*DadiFilmShow, 0)
filmName := cast.ToString(ff["name"])
if filmName != order.MovieName {
continue
}
for _, s := range cast.ToSlice(ff["showList"]) {
ss := cast.ToStringMap(s)
show := new(DadiFilmShow)
show.Day = cast.ToString(ss["dayStr"])
show.Halls = make([]*DadiFilmShowHall, 0)
showDay := cast.ToString(ss["dayStr"])
if showDay != orderShowDay {
continue
}
for _, p := range cast.ToSlice(ss["plist"]) {
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.SessionId = cast.ToString(pp["sessionId"])
hall.StartTime = cast.ToString(pp["startTime"])
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.IsSeat = cast.ToInt(data["is_seat"])
order.LoverSeat = cast.ToInt(data["loverSeat"])
order.MinPrice = cast.ToInt64(data["min_price"])
order.MaxPrice = cast.ToInt64(data["max_price"])
if isAdd {
model.AddOrder(order)

View File

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