mirror of http://gitlab.batiao8.com/yic/film.git
bidprice
This commit is contained in:
parent
ee962053df
commit
683eeed3c3
|
@ -46,6 +46,7 @@ func initLog() {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config.LoadServerConfig()
|
config.LoadServerConfig()
|
||||||
|
config.LoadDadiConfig()
|
||||||
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,
|
||||||
|
|
|
@ -15,6 +15,7 @@ db = "film"
|
||||||
qiye_appid = "ww288920bd3e8c92b2"
|
qiye_appid = "ww288920bd3e8c92b2"
|
||||||
qiye_secret = "3aqE6LAEKLiGtYBtX7TZm0uY_YD52w3R20AQirSICXY"
|
qiye_secret = "3aqE6LAEKLiGtYBtX7TZm0uY_YD52w3R20AQirSICXY"
|
||||||
qiye_agent = "1000013"
|
qiye_agent = "1000013"
|
||||||
|
receiver = ["jiangyong", "zhangping"]
|
||||||
|
|
||||||
[film]
|
[film]
|
||||||
haha_token = "cc5f1d4c36f7e9544d641a174b298f94"
|
haha_token = "cc5f1d4c36f7e9544d641a174b298f94"
|
||||||
|
|
|
@ -16,6 +16,7 @@ db = "film"
|
||||||
qiye_appid = "ww288920bd3e8c92b2"
|
qiye_appid = "ww288920bd3e8c92b2"
|
||||||
qiye_secret = "3aqE6LAEKLiGtYBtX7TZm0uY_YD52w3R20AQirSICXY"
|
qiye_secret = "3aqE6LAEKLiGtYBtX7TZm0uY_YD52w3R20AQirSICXY"
|
||||||
qiye_agent = "1000013"
|
qiye_agent = "1000013"
|
||||||
|
receiver = ["jiangyong", "zhangping"]
|
||||||
|
|
||||||
[film]
|
[film]
|
||||||
haha_token = "cc5f1d4c36f7e9544d641a174b298f94"
|
haha_token = "cc5f1d4c36f7e9544d641a174b298f94"
|
||||||
|
|
|
@ -37,9 +37,10 @@ type Redis struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Weixin struct {
|
type Weixin struct {
|
||||||
QiyeAppid string `toml:"qiye_appid"`
|
QiyeAppid string `toml:"qiye_appid"`
|
||||||
Qiyesecret string `toml:"qiye_secret"`
|
Qiyesecret string `toml:"qiye_secret"`
|
||||||
QiyeAgent string `toml:"qiye_agent"`
|
QiyeAgent string `toml:"qiye_agent"`
|
||||||
|
Receiver []string `toml:"receiver"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Film struct {
|
type Film struct {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/smbrave/goutil"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -38,6 +40,10 @@ type Order struct {
|
||||||
UpdateTime int64
|
UpdateTime int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Order) String() string {
|
||||||
|
return fmt.Sprintf("{%s|%d} city={%s} cinema={%s} film={%s} ting={%s} show={%s}",
|
||||||
|
o.OrderId, o.Id, o.CityName, o.CinemaName, o.MovieName, o.Ting, goutil.TimeToDateTime(o.ShowTime))
|
||||||
|
}
|
||||||
func AddOrder(o *Order) (int64, error) {
|
func AddOrder(o *Order) (int64, error) {
|
||||||
o.CreateTime = time.Now().Unix()
|
o.CreateTime = time.Now().Unix()
|
||||||
o.CreateDate = time.Now().Format("2006-01-02")
|
o.CreateDate = time.Now().Format("2006-01-02")
|
||||||
|
|
|
@ -5,8 +5,7 @@ import "film/model"
|
||||||
type CheckInfo struct {
|
type CheckInfo struct {
|
||||||
TotalOriginPrice int64
|
TotalOriginPrice int64
|
||||||
TotalRealPrice int64
|
TotalRealPrice int64
|
||||||
TotalCouponPrice int64
|
CouponPrice int64
|
||||||
UnitPrice int64
|
|
||||||
BillCode string
|
BillCode string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -271,7 +271,7 @@ func (p *Processor) prevOrderInfo(cinema *Cinema, seatGoods []*SeatGoods) (*Prev
|
||||||
previewOrder := new(PreviewOrder)
|
previewOrder := new(PreviewOrder)
|
||||||
previewOrder.TotalOriginPrice = int64(cast.ToFloat64(realData["ticketOriginPrice"]) * 100)
|
previewOrder.TotalOriginPrice = int64(cast.ToFloat64(realData["ticketOriginPrice"]) * 100)
|
||||||
previewOrder.TotalRealPrice = int64(cast.ToFloat64(realData["ticketRealPrice"]) * 100)
|
previewOrder.TotalRealPrice = int64(cast.ToFloat64(realData["ticketRealPrice"]) * 100)
|
||||||
previewOrder.TotalCouponPrice = int64(cast.ToFloat64(realData["ticketCouponPrice"]) * 100)
|
previewOrder.CouponPrice = int64(cast.ToFloat64(realData["ticketCouponPrice"]) * 100)
|
||||||
previewOrder.BillCode = billCode
|
previewOrder.BillCode = billCode
|
||||||
|
|
||||||
return previewOrder, nil
|
return previewOrder, nil
|
||||||
|
@ -297,9 +297,8 @@ func (p *Processor) CheckOrder(order *model.Order) (*common.CheckInfo, error) {
|
||||||
|
|
||||||
result := new(common.CheckInfo)
|
result := new(common.CheckInfo)
|
||||||
result.TotalRealPrice = previewOrder.TotalRealPrice
|
result.TotalRealPrice = previewOrder.TotalRealPrice
|
||||||
result.TotalRealPrice = previewOrder.TotalOriginPrice
|
result.TotalOriginPrice = previewOrder.TotalOriginPrice
|
||||||
result.TotalRealPrice = previewOrder.TotalCouponPrice
|
result.CouponPrice = previewOrder.CouponPrice
|
||||||
result.UnitPrice = previewOrder.TotalRealPrice / int64(order.SeatNum)
|
|
||||||
result.BillCode = previewOrder.BillCode
|
result.BillCode = previewOrder.BillCode
|
||||||
log.Infof("check order[%s][%s] previewOrder[%s] [%s][%s][%s] success",
|
log.Infof("check order[%s][%s] previewOrder[%s] [%s][%s][%s] success",
|
||||||
order.OrderId, result.BillCode, goutil.EncodeJSON(previewOrder),
|
order.OrderId, result.BillCode, goutil.EncodeJSON(previewOrder),
|
||||||
|
|
|
@ -3,7 +3,7 @@ package dadi
|
||||||
type PreviewOrder struct {
|
type PreviewOrder struct {
|
||||||
TotalOriginPrice int64
|
TotalOriginPrice int64
|
||||||
TotalRealPrice int64
|
TotalRealPrice int64
|
||||||
TotalCouponPrice int64
|
CouponPrice int64
|
||||||
BillCode string
|
BillCode string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
141
worker/worker.go
141
worker/worker.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"film/base/util"
|
"film/base/util"
|
||||||
"film/config"
|
"film/config"
|
||||||
"film/model"
|
"film/model"
|
||||||
|
"film/worker/common"
|
||||||
"film/worker/dadi"
|
"film/worker/dadi"
|
||||||
"film/worker/haha"
|
"film/worker/haha"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -15,7 +16,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Worker struct {
|
type Worker struct {
|
||||||
qyClient *wxapi.WxQiye
|
qyClient *wxapi.WxQiye
|
||||||
|
dadiProcessor common.Processor
|
||||||
|
hahaProcessor *haha.Processor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Worker) initQyWeixin() {
|
func (w *Worker) initQyWeixin() {
|
||||||
|
@ -26,6 +29,93 @@ func (w *Worker) initQyWeixin() {
|
||||||
Sender: cfg.Weixin.QiyeAgent,
|
Sender: cfg.Weixin.QiyeAgent,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Worker) getOrderMesasge(order *model.Order) []string {
|
||||||
|
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.MovieName))
|
||||||
|
message = append(message, fmt.Sprintf("影厅:%s", order.Ting))
|
||||||
|
message = append(message, fmt.Sprintf("时间:%s", time.Unix(order.ShowTime, 0).Format("2006-01-02 15:04")))
|
||||||
|
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("原价:%.2f", float64(order.MaoyanPrice)/100))
|
||||||
|
message = append(message, fmt.Sprintf("编号:%s", order.OrderId))
|
||||||
|
message = append(message, fmt.Sprintf("总金额:%.2f(%d)", float64(order.TotalPrice)/100, order.SeatNum))
|
||||||
|
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.OrderCreateTime, 0).Format("2006-01-02 15:04")))
|
||||||
|
message = append(message, fmt.Sprintf("入库时间:%s", time.Unix(order.CreateTime, 0).Format("2006-01-02 15:04")))
|
||||||
|
return message
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Worker) sendOrderMessage(order *model.Order, message string) {
|
||||||
|
messages := w.getOrderMesasge(order)
|
||||||
|
messages = append(messages, "\n", message)
|
||||||
|
w.qyClient.SendText(config.GetConfig().Weixin.Receiver, strings.Join(messages, "\n"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Worker) processorDadi(order *model.Order) {
|
||||||
|
checkInfo, err := w.dadiProcessor.CheckOrder(order)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("check orrder[%s] error : %s", order.String(), err.Error())
|
||||||
|
w.sendOrderMessage(order, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//hahaProcessor.BidPrice(order.Id, checkInfo.UnitPrice)
|
||||||
|
go func() {
|
||||||
|
/*
|
||||||
|
time.Sleep(60 * time.Second)
|
||||||
|
if err := dadiProcessor.CancelOrder(order, checkInfo); err != nil {
|
||||||
|
log.Errorf("cancel order[%s] error[%s]", order.OrderId, err.Error())
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}()
|
||||||
|
|
||||||
|
bidStatus := false
|
||||||
|
realCost := checkInfo.TotalRealPrice + int64(goutil.If(checkInfo.CouponPrice > 0, config.GetDadiConfig().CouponCost, 0))
|
||||||
|
realUnitCost := realCost / int64(order.SeatNum)
|
||||||
|
bidPrice := realUnitCost + config.GetDadiConfig().BidProfit
|
||||||
|
if bidPrice < order.MaxPrice {
|
||||||
|
if err := w.hahaProcessor.BidPrice(order.Id, bidPrice); err != nil {
|
||||||
|
log.Errorf("BidPrice order[%s] error[%s]", order.String(), err.Error())
|
||||||
|
if err := w.dadiProcessor.CancelOrder(order, checkInfo); err != nil {
|
||||||
|
log.Errorf("cancel order[%s] error[%s]", order.OrderId, err.Error())
|
||||||
|
}
|
||||||
|
message := w.getOrderMesasge(order)
|
||||||
|
message = append(message, "\n", fmt.Sprintf("竞价失败:%s", err.Error()))
|
||||||
|
w.qyClient.SendText(config.GetConfig().Weixin.Receiver, strings.Join(message, "\n"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
bidStatus = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送信息
|
||||||
|
message := w.getOrderMesasge(order)
|
||||||
|
|
||||||
|
message = append(message, "\n")
|
||||||
|
message = append(message, "【大地订单信息】")
|
||||||
|
message = append(message, fmt.Sprintf("订单原价:%s", util.MoneyFen(checkInfo.TotalOriginPrice)))
|
||||||
|
message = append(message, fmt.Sprintf("优惠金额:%s", util.MoneyFen(checkInfo.CouponPrice)))
|
||||||
|
message = append(message, fmt.Sprintf("应付金额:%s", util.MoneyFen(checkInfo.TotalRealPrice)))
|
||||||
|
message = append(message, fmt.Sprintf("实际成本:%s", util.MoneyFen(realCost)))
|
||||||
|
message = append(message, fmt.Sprintf("实际单价:%s", util.MoneyFen(realUnitCost)))
|
||||||
|
|
||||||
|
message = append(message, "\n")
|
||||||
|
message = append(message, "【竞价信息】")
|
||||||
|
message = append(message, fmt.Sprintf("状态:%s", goutil.If(bidStatus, "竞价中", "不可竞价")))
|
||||||
|
if bidStatus {
|
||||||
|
message = append(message, fmt.Sprintf("出价:%s", util.MoneyFen(bidPrice)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := w.qyClient.SendText([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
||||||
|
log.Errorf("send message error : %s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Worker) Run() {
|
func (w *Worker) Run() {
|
||||||
w.initQyWeixin()
|
w.initQyWeixin()
|
||||||
cfg := config.GetConfig()
|
cfg := config.GetConfig()
|
||||||
|
@ -42,62 +132,19 @@ func (w *Worker) Run() {
|
||||||
//order, _ := model.GetOrder(590623)
|
//order, _ := model.GetOrder(590623)
|
||||||
//newOrderChan <- order
|
//newOrderChan <- order
|
||||||
|
|
||||||
//hahaProcessor := haha.NewProcessor(&haha.ProcessorConfig{Token: cfg.Film.HahaToken})
|
w.hahaProcessor = haha.NewProcessor(&haha.ProcessorConfig{Token: cfg.Film.HahaToken})
|
||||||
dadiProcessor, err := dadi.NewProcessor(&dadi.ProcessorConfig{Token: cfg.Film.DadiToken})
|
dadiProcessor, err := dadi.NewProcessor(&dadi.ProcessorConfig{Token: cfg.Film.DadiToken})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
w.dadiProcessor = dadiProcessor
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case order := <-newOrderChan:
|
case order := <-newOrderChan:
|
||||||
|
|
||||||
if !strings.Contains(order.CinemaName, "大地影院") {
|
if !strings.Contains(order.CinemaName, "大地影院") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
checkInfo, err := dadiProcessor.CheckOrder(order)
|
w.processorDadi(order)
|
||||||
if err != nil {
|
|
||||||
log.Errorf("check orrder[%s] error : %s", order.OrderId, err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
//hahaProcessor.BidPrice(order.Id, checkInfo.UnitPrice)
|
|
||||||
go func() {
|
|
||||||
/*
|
|
||||||
time.Sleep(60 * time.Second)
|
|
||||||
if err := dadiProcessor.CancelOrder(order, checkInfo); err != nil {
|
|
||||||
log.Errorf("cancel order[%s] error[%s]", order.OrderId, err.Error())
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}()
|
|
||||||
|
|
||||||
// 发送信息
|
|
||||||
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.MovieName))
|
|
||||||
message = append(message, fmt.Sprintf("影厅:%s", order.Ting))
|
|
||||||
message = append(message, fmt.Sprintf("时间:%s", time.Unix(order.ShowTime, 0).Format("2006-01-02 15:04")))
|
|
||||||
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("原价:%.2f", float64(order.MaoyanPrice)/100))
|
|
||||||
message = append(message, fmt.Sprintf("编号:%s", order.OrderId))
|
|
||||||
message = append(message, fmt.Sprintf("总金额:%.2f(%d)", float64(order.TotalPrice)/100, order.SeatNum))
|
|
||||||
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.OrderCreateTime, 0).Format("2006-01-02 15:04")))
|
|
||||||
message = append(message, fmt.Sprintf("入库时间:%s", time.Unix(order.CreateTime, 0).Format("2006-01-02 15:04")))
|
|
||||||
|
|
||||||
message = append(message, "\n")
|
|
||||||
message = append(message, "【大地订单信息】")
|
|
||||||
message = append(message, fmt.Sprintf("订单原价:%s", util.MoneyFen(checkInfo.TotalOriginPrice)))
|
|
||||||
message = append(message, fmt.Sprintf("优惠金额:%s", util.MoneyFen(checkInfo.TotalCouponPrice)))
|
|
||||||
message = append(message, fmt.Sprintf("实际总价:%s", util.MoneyFen(checkInfo.TotalRealPrice)))
|
|
||||||
message = append(message, fmt.Sprintf("实际单价:%s", util.MoneyFen(checkInfo.UnitPrice)))
|
|
||||||
if err := w.qyClient.SendText([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
|
||||||
log.Errorf("send message error : %s", err.Error())
|
|
||||||
}
|
|
||||||
case updateOrder := <-updateOrderChan:
|
case updateOrder := <-updateOrderChan:
|
||||||
log.Debugf("update:", goutil.EncodeJSON(updateOrder))
|
log.Debugf("update:", goutil.EncodeJSON(updateOrder))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue