2023-04-07 23:51:09 +08:00
|
|
|
|
package worker
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"film/base/httputil"
|
|
|
|
|
"film/config"
|
|
|
|
|
"film/model"
|
2023-04-08 20:33:48 +08:00
|
|
|
|
"fmt"
|
2023-04-07 23:51:09 +08:00
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
"github.com/smbrave/goutil"
|
|
|
|
|
"github.com/spf13/cast"
|
|
|
|
|
"gitlab.com/jiangyong27/gobase/wxapi"
|
|
|
|
|
"strings"
|
2023-04-08 01:38:13 +08:00
|
|
|
|
"time"
|
2023-04-07 23:51:09 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Dadi struct {
|
2023-04-08 01:38:13 +08:00
|
|
|
|
Token string
|
2023-04-07 23:51:09 +08:00
|
|
|
|
citys map[string]*DadiCity
|
|
|
|
|
qyClient *wxapi.WxQiye
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *Dadi) Init() error {
|
|
|
|
|
cityUrl := "https://appapi.dadicinema.com/app-web/v1/web/cinema/cbticket/cbase/cityAndCinemaList"
|
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
params := d.getBaseParam(&DadiCinema{
|
2023-04-08 01:38:13 +08:00
|
|
|
|
Name: "大地影院(北京十里河铭泽店)",
|
|
|
|
|
Id: 118,
|
|
|
|
|
UnifiedCode: 11050621,
|
|
|
|
|
})
|
2023-04-08 20:33:48 +08:00
|
|
|
|
body, err := httputil.HttpGet(cityUrl, params, d.getBaseHeader())
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorf(" httputil.HttpGet url : %s error: %s", cityUrl, err.Error())
|
2023-04-07 23:51:09 +08:00
|
|
|
|
return err
|
|
|
|
|
}
|
2023-04-08 20:33:48 +08:00
|
|
|
|
result, err := d.checkError(body)
|
|
|
|
|
if err != nil {
|
2023-04-07 23:51:09 +08:00
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
citys := make(map[string]*DadiCity)
|
2023-04-08 20:33:48 +08:00
|
|
|
|
datas := cast.ToSlice(result)
|
2023-04-07 23:51:09 +08:00
|
|
|
|
|
|
|
|
|
for _, d := range datas {
|
|
|
|
|
data := cast.ToStringMap(d)
|
|
|
|
|
|
|
|
|
|
cinemas := make([]*DadiCinema, 0)
|
|
|
|
|
for _, c := range cast.ToSlice(data["cinemas"]) {
|
|
|
|
|
cin := cast.ToStringMap(c)
|
|
|
|
|
cinema := new(DadiCinema)
|
|
|
|
|
cinema.Name = cast.ToString(cin["name"])
|
|
|
|
|
cinema.Address = cast.ToString(cin["address"])
|
|
|
|
|
cinema.Latitude = cast.ToString(cin["latitude"])
|
|
|
|
|
cinema.Longitude = cast.ToString(cin["longitude"])
|
|
|
|
|
cinema.CityId = cast.ToInt64(cin["cityId"])
|
|
|
|
|
cinema.UnifiedCode = cast.ToInt64(cin["unifiedCode"])
|
|
|
|
|
cinemas = append(cinemas, cinema)
|
|
|
|
|
}
|
|
|
|
|
cityInfo := cast.ToStringMap(data["cityInfo"])
|
|
|
|
|
city := new(DadiCity)
|
|
|
|
|
city.Name = cast.ToString(cityInfo["chName"])
|
|
|
|
|
city.ShortName = cast.ToString(cityInfo["shortName"])
|
|
|
|
|
city.CityId = cast.ToInt64(data["cityId"])
|
|
|
|
|
city.CityCode = cast.ToInt64(data["cityCode"])
|
2023-04-08 01:38:13 +08:00
|
|
|
|
city.Cinemas = cinemas
|
2023-04-07 23:51:09 +08:00
|
|
|
|
|
|
|
|
|
citys[city.ShortName] = city
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d.citys = citys
|
2023-04-08 01:38:13 +08:00
|
|
|
|
log.Infof("load dadi citys : %d", len(d.citys))
|
2023-04-07 23:51:09 +08:00
|
|
|
|
|
|
|
|
|
cfg := config.GetConfig()
|
|
|
|
|
d.qyClient = wxapi.NewQiye(&wxapi.QiyeConfig{
|
|
|
|
|
Corpid: cfg.Weixin.QiyeAppid,
|
|
|
|
|
Secret: cfg.Weixin.Qiyesecret,
|
|
|
|
|
Sender: cfg.Weixin.QiyeAgent,
|
|
|
|
|
})
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
func (d *Dadi) UpdateOrder(order *model.Order) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 23:51:09 +08:00
|
|
|
|
func (d *Dadi) NewOrder(order *model.Order) {
|
2023-04-08 20:33:48 +08:00
|
|
|
|
|
|
|
|
|
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())
|
2023-04-07 23:51:09 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2023-04-08 01:38:13 +08:00
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
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())
|
|
|
|
|
}
|
2023-04-08 01:38:13 +08:00
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
}
|
2023-04-08 01:38:13 +08:00
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
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"]))
|
2023-04-07 23:51:09 +08:00
|
|
|
|
}
|
2023-04-08 20:33:48 +08:00
|
|
|
|
|
|
|
|
|
return result["data"], nil
|
2023-04-07 23:51:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
func (d *Dadi) getBaseHeader() map[string]interface{} {
|
|
|
|
|
return map[string]interface{}{
|
|
|
|
|
"User-Agent": "apifox/1.0.0 (https://www.apifox.cn)",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *Dadi) getBaseParam(cinema *DadiCinema) map[string]interface{} {
|
|
|
|
|
params := map[string]interface{}{
|
2023-04-08 01:38:13 +08:00
|
|
|
|
"channelCode": "SYH-DDZY-DD",
|
|
|
|
|
"channelName": "大地自营-大地",
|
|
|
|
|
"channelNo": "SYH-DDZY-DD",
|
|
|
|
|
"channelUid": "SYH-DDZY-DD",
|
|
|
|
|
"cinema": cast.ToString(cinema.UnifiedCode),
|
|
|
|
|
"cinemaCode": cast.ToString(cinema.UnifiedCode),
|
|
|
|
|
"cinemaUid": cast.ToString(cinema.Id),
|
|
|
|
|
"d": "iPhone14,3",
|
|
|
|
|
"i": "00000000-0000-0000-0000-000000000000",
|
|
|
|
|
"k": d.Token,
|
|
|
|
|
"r": "1",
|
|
|
|
|
"s": "iOS15.2.1",
|
|
|
|
|
"t": "1",
|
|
|
|
|
"tenantId": "321566",
|
|
|
|
|
"unifiedCinemaId": cast.ToString(cinema.Id),
|
|
|
|
|
"unifiedCinemaName": cinema.Name,
|
|
|
|
|
"unifiedCode": cast.ToString(cinema.UnifiedCode),
|
|
|
|
|
"v": "8.7.3",
|
|
|
|
|
}
|
|
|
|
|
return params
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
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)
|
2023-04-07 23:51:09 +08:00
|
|
|
|
}
|
2023-04-08 01:38:13 +08:00
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
func (d *Dadi) getCinemaFilm(order *model.Order, cinema *DadiCinema) (*DadiFilmShowHall, error) {
|
|
|
|
|
baseReq := d.getBaseParam(cinema)
|
2023-04-08 01:38:13 +08:00
|
|
|
|
reqUrl := "https://appapi.dadicinema.com/app-web/v1/web/film/getHitFilmAndFilmSession"
|
2023-04-08 20:33:48 +08:00
|
|
|
|
body, err := httputil.HttpGet(reqUrl, baseReq, d.getBaseHeader())
|
2023-04-08 01:38:13 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
log.Errorf("httpGet[%s] error : %s", reqUrl, err.Error())
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
result, err := d.checkError(body)
|
|
|
|
|
if err != nil {
|
2023-04-08 01:38:13 +08:00
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
orderShowDay := time.Unix(order.ShowTime, 0).Format("2006-01-02")
|
|
|
|
|
var hall *DadiFilmShowHall = nil
|
|
|
|
|
for _, f := range cast.ToSlice(cast.ToStringMap(result)["filmList"]) {
|
2023-04-08 01:38:13 +08:00
|
|
|
|
ff := cast.ToStringMap(f)
|
2023-04-08 20:33:48 +08:00
|
|
|
|
filmName := cast.ToString(ff["name"])
|
|
|
|
|
if filmName != order.MovieName {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2023-04-08 01:38:13 +08:00
|
|
|
|
for _, s := range cast.ToSlice(ff["showList"]) {
|
|
|
|
|
ss := cast.ToStringMap(s)
|
2023-04-08 20:33:48 +08:00
|
|
|
|
showDay := cast.ToString(ss["dayStr"])
|
|
|
|
|
if showDay != orderShowDay {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2023-04-08 01:38:13 +08:00
|
|
|
|
for _, p := range cast.ToSlice(ss["plist"]) {
|
|
|
|
|
pp := cast.ToStringMap(p)
|
2023-04-08 20:33:48 +08:00
|
|
|
|
hallName := cast.ToString(pp["hallName"])
|
|
|
|
|
if hallName != order.Ting {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
hall = new(DadiFilmShowHall)
|
|
|
|
|
hall.FilmName = filmName
|
|
|
|
|
hall.ShowDay = showDay
|
2023-04-08 01:38:13 +08:00
|
|
|
|
hall.HallName = cast.ToString(pp["hallName"])
|
|
|
|
|
hall.SessionId = cast.ToString(pp["sessionId"])
|
|
|
|
|
hall.StartTime = cast.ToString(pp["startTime"])
|
|
|
|
|
hall.EndTime = cast.ToString(pp["endTime"])
|
2023-04-08 20:33:48 +08:00
|
|
|
|
return hall, nil
|
2023-04-08 01:38:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2023-04-08 20:33:48 +08:00
|
|
|
|
return nil, fmt.Errorf("film[%s] day[%s] ting[%s] nohas", order.MovieName, orderShowDay, order.Ting)
|
2023-04-08 01:38:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
//baseReq := d.getBaseParam(cinema)
|
|
|
|
|
}
|
2023-04-08 01:38:13 +08:00
|
|
|
|
|
2023-04-08 20:33:48 +08:00
|
|
|
|
func (d *Dadi) holdSeats(order *model.Order, cinema *DadiCinema, hall *DadiFilmShowHall) (*DadiFilmOrder, error) {
|
|
|
|
|
return &DadiFilmOrder{
|
|
|
|
|
OrderId: "test",
|
|
|
|
|
}, nil
|
2023-04-08 01:38:13 +08:00
|
|
|
|
}
|