From 8996e27b7023cb476f3b630b0a0a1d4d2de58109 Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Sun, 9 Apr 2023 13:01:04 +0800 Subject: [PATCH] orderNo --- cmd/film.go | 1 + conf/dadi.json | 4 +++- conf/haha.json | 3 +++ config/config.go | 1 - config/{daid.go => dadi.go} | 8 +++++--- config/haha.go | 29 +++++++++++++++++++++++++++++ worker/worker.go | 19 +++++++++++-------- 7 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 conf/haha.json rename config/{daid.go => dadi.go} (66%) create mode 100644 config/haha.go diff --git a/cmd/film.go b/cmd/film.go index c184bbd..d3101b7 100644 --- a/cmd/film.go +++ b/cmd/film.go @@ -47,6 +47,7 @@ func initLog() { func main() { config.LoadServerConfig() config.LoadDadiConfig() + config.LoadHahaConfig() initLog() cfg := config.GetConfig() dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", cfg.Mysql.User, diff --git a/conf/dadi.json b/conf/dadi.json index 83c3397..e3cbc64 100644 --- a/conf/dadi.json +++ b/conf/dadi.json @@ -1,5 +1,7 @@ { "enable": true, "bidProfit": 50, - "couponCost": 3000 + "couponCost": 3000, + "discount": 1, + "token": "321566:7b84a0b1-832a-4492-a96a-23002d6c8715" } \ No newline at end of file diff --git a/conf/haha.json b/conf/haha.json new file mode 100644 index 0000000..969c017 --- /dev/null +++ b/conf/haha.json @@ -0,0 +1,3 @@ +{ + "token": "d6847dfbd7b79bc18709e0311fd7813b" +} \ No newline at end of file diff --git a/config/config.go b/config/config.go index 9a4ede2..09be9ca 100644 --- a/config/config.go +++ b/config/config.go @@ -53,7 +53,6 @@ type Config struct { Mysql *Mysql `toml:"mysql"` Redis *Redis `toml:"redis"` Weixin *Weixin `toml:"weixin"` - Film *Film `toml:"film"` } func GetEnv() string { diff --git a/config/daid.go b/config/dadi.go similarity index 66% rename from config/daid.go rename to config/dadi.go index 152a463..fd3f90c 100644 --- a/config/daid.go +++ b/config/dadi.go @@ -6,9 +6,11 @@ import ( ) type Dadi struct { - Enable bool `json:"enable"` - BidProfit int64 `json:"bidProfit"` - CouponCost int64 `json:"couponCost"` + Enable bool `json:"enable"` + BidProfit int64 `json:"bidProfit"` + CouponCost int64 `json:"couponCost"` + Discount float64 `json:"discount"` + Token string `json:"token"` } var ( diff --git a/config/haha.go b/config/haha.go new file mode 100644 index 0000000..c383346 --- /dev/null +++ b/config/haha.go @@ -0,0 +1,29 @@ +package config + +import ( + "encoding/json" + "io/ioutil" +) + +type Haha struct { + Token string `json:"token"` +} + +var ( + hahaConfig *Haha = nil +) + +func LoadHahaConfig() { + body, err := ioutil.ReadFile("conf/haha.json") + if err != nil { + panic(err) + } + dadiConfig = new(Dadi) + if err := json.Unmarshal([]byte(body), dadiConfig); err != nil { + panic(err) + } +} + +func GetHahaConfig() *Haha { + return hahaConfig +} diff --git a/worker/worker.go b/worker/worker.go index 40ecdc2..2788f5e 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -65,8 +65,9 @@ func (w *Worker) processorDadi(order *model.Order) { return } + cfg := config.GetDadiConfig() bidStatus := false - realCost := checkInfo.TotalRealPrice + int64(goutil.If(checkInfo.CouponPrice > 0, config.GetDadiConfig().CouponCost, 0)) + realCost := int64(float64(checkInfo.TotalRealPrice)*cfg.Discount) + int64(goutil.If(checkInfo.CouponPrice > 0, cfg.CouponCost, 0)) realUnitCost := realCost / int64(order.SeatNum) bidPrice := realUnitCost + config.GetDadiConfig().BidProfit if bidPrice < order.MaxPrice { @@ -108,11 +109,10 @@ func (w *Worker) processorDadi(order *model.Order) { func (w *Worker) Run() { w.initQyWeixin() - cfg := config.GetConfig() newOrderChan := make(chan *model.Order, 100000) updateOrderChan := make(chan *model.Order, 100000) hahaSyncer := haha.NewSyncOrder(&haha.SyncOrderConfig{ - Token: cfg.Film.HahaToken, + Token: config.GetHahaConfig().Token, NewOrder: newOrderChan, UpdateOrder: updateOrderChan, }) @@ -122,12 +122,15 @@ func (w *Worker) Run() { //order, _ := model.GetOrder(590623) //newOrderChan <- order - w.hahaProcessor = haha.NewProcessor(&haha.ProcessorConfig{Token: cfg.Film.HahaToken}) - dadiProcessor, err := dadi.NewProcessor(&dadi.ProcessorConfig{Token: cfg.Film.DadiToken}) - if err != nil { - panic(err) + w.hahaProcessor = haha.NewProcessor(&haha.ProcessorConfig{Token: config.GetHahaConfig().Token}) + if config.GetDadiConfig().Enable { + dadiProcessor, err := dadi.NewProcessor(&dadi.ProcessorConfig{Token: config.GetDadiConfig().Token}) + if err != nil { + panic(err) + } + w.dadiProcessor = dadiProcessor } - w.dadiProcessor = dadiProcessor + for { select { case order := <-newOrderChan: