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() {
config.LoadServerConfig()
config.LoadDadiConfig()
config.LoadHahaConfig()
initLog()
cfg := config.GetConfig()
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", cfg.Mysql.User,

View File

@ -1,5 +1,7 @@
{
"enable": true,
"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"`
Redis *Redis `toml:"redis"`
Weixin *Weixin `toml:"weixin"`
Film *Film `toml:"film"`
}
func GetEnv() string {

View File

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

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