This commit is contained in:
jiangyong27 2023-04-09 13:01:04 +08:00
parent 1a940d590c
commit 8996e27b70
7 changed files with 52 additions and 13 deletions

View File

@ -47,6 +47,7 @@ func initLog() {
func main() { func main() {
config.LoadServerConfig() config.LoadServerConfig()
config.LoadDadiConfig() config.LoadDadiConfig()
config.LoadHahaConfig()
initLog() initLog()
cfg := config.GetConfig() cfg := config.GetConfig()
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", cfg.Mysql.User, dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", cfg.Mysql.User,

View File

@ -1,5 +1,7 @@
{ {
"enable": true, "enable": true,
"bidProfit": 50, "bidProfit": 50,
"couponCost": 3000 "couponCost": 3000,
"discount": 1,
"token": "321566:7b84a0b1-832a-4492-a96a-23002d6c8715"
} }

3
conf/haha.json Normal file
View File

@ -0,0 +1,3 @@
{
"token": "d6847dfbd7b79bc18709e0311fd7813b"
}

View File

@ -53,7 +53,6 @@ type Config struct {
Mysql *Mysql `toml:"mysql"` Mysql *Mysql `toml:"mysql"`
Redis *Redis `toml:"redis"` Redis *Redis `toml:"redis"`
Weixin *Weixin `toml:"weixin"` Weixin *Weixin `toml:"weixin"`
Film *Film `toml:"film"`
} }
func GetEnv() string { func GetEnv() string {

View File

@ -6,9 +6,11 @@ import (
) )
type Dadi struct { type Dadi struct {
Enable bool `json:"enable"` Enable bool `json:"enable"`
BidProfit int64 `json:"bidProfit"` BidProfit int64 `json:"bidProfit"`
CouponCost int64 `json:"couponCost"` CouponCost int64 `json:"couponCost"`
Discount float64 `json:"discount"`
Token string `json:"token"`
} }
var ( var (

29
config/haha.go Normal file
View File

@ -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
}

View File

@ -65,8 +65,9 @@ func (w *Worker) processorDadi(order *model.Order) {
return return
} }
cfg := config.GetDadiConfig()
bidStatus := false 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) realUnitCost := realCost / int64(order.SeatNum)
bidPrice := realUnitCost + config.GetDadiConfig().BidProfit bidPrice := realUnitCost + config.GetDadiConfig().BidProfit
if bidPrice < order.MaxPrice { if bidPrice < order.MaxPrice {
@ -108,11 +109,10 @@ func (w *Worker) processorDadi(order *model.Order) {
func (w *Worker) Run() { func (w *Worker) Run() {
w.initQyWeixin() w.initQyWeixin()
cfg := config.GetConfig()
newOrderChan := make(chan *model.Order, 100000) newOrderChan := make(chan *model.Order, 100000)
updateOrderChan := make(chan *model.Order, 100000) updateOrderChan := make(chan *model.Order, 100000)
hahaSyncer := haha.NewSyncOrder(&haha.SyncOrderConfig{ hahaSyncer := haha.NewSyncOrder(&haha.SyncOrderConfig{
Token: cfg.Film.HahaToken, Token: config.GetHahaConfig().Token,
NewOrder: newOrderChan, NewOrder: newOrderChan,
UpdateOrder: updateOrderChan, UpdateOrder: updateOrderChan,
}) })
@ -122,12 +122,15 @@ func (w *Worker) Run() {
//order, _ := model.GetOrder(590623) //order, _ := model.GetOrder(590623)
//newOrderChan <- order //newOrderChan <- order
w.hahaProcessor = haha.NewProcessor(&haha.ProcessorConfig{Token: cfg.Film.HahaToken}) w.hahaProcessor = haha.NewProcessor(&haha.ProcessorConfig{Token: config.GetHahaConfig().Token})
dadiProcessor, err := dadi.NewProcessor(&dadi.ProcessorConfig{Token: cfg.Film.DadiToken}) if config.GetDadiConfig().Enable {
if err != nil { dadiProcessor, err := dadi.NewProcessor(&dadi.ProcessorConfig{Token: config.GetDadiConfig().Token})
panic(err) if err != nil {
panic(err)
}
w.dadiProcessor = dadiProcessor
} }
w.dadiProcessor = dadiProcessor
for { for {
select { select {
case order := <-newOrderChan: case order := <-newOrderChan: