bidprice5

This commit is contained in:
jiangyong27 2023-04-09 17:48:01 +08:00
parent d53f466e2d
commit a37663a122
1 changed files with 107 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package dadi
import (
"encoding/json"
"errors"
"film/base/httputil"
"film/model"
"film/worker/common"
@ -324,6 +325,72 @@ func (p *Processor) getUserPrice(cinema *Cinema, filmName, showTime string) (*Fi
return nil, fmt.Errorf("[%s][%s][%s][%s] not exist", cinema.Name, cinema.Address, filmName, showTime)
}
func (p *Processor) getUserCard(cinema *Cinema) ([]*UserCard, *UserCard, error) {
reqUrl := "https://appapi.dadicinema.com/app-web/v1/user/cards"
body, err := httputil.HttpPostForm(reqUrl, p.getBaseHeader(), p.getBaseParam(cinema))
if err != nil {
log.Errorf("httpPost url[%s] error : %s", reqUrl, err.Error())
return nil, nil, err
}
data, err := p.checkError(body)
if err != nil {
return nil, nil, err
}
allCards := make([]*UserCard, 0)
maxBlance := int64(-1000000)
var defCard *UserCard = nil
for _, c := range cast.ToSlice(data) {
card := cast.ToStringMap(c)
uCard := new(UserCard)
uCard.CardNo = cast.ToString(card["cardNo"])
uCard.CardName = cast.ToString(card["cardName"])
uCard.Balance = int64(cast.ToFloat64(card["amount"]) * 100)
uCard.Expire = cast.ToInt64(card["cardName"]) / 1000
allCards = append(allCards, uCard)
if uCard.Balance > maxBlance {
defCard = uCard
maxBlance = uCard.Balance
}
}
return allCards, defCard, nil
}
func (p *Processor) payOrder(cinema *Cinema, billCode, cardNo string, amount int64) error {
baseReq := p.getBaseParam(cinema)
baseReq["businessSystemCode"] = "c_app"
baseReq["ip"] = "127.0.0.1"
baseReq["amount"] = fmt.Sprintf("%.2f", float64(amount)/100)
baseReq["orderRemark"] = "{\"saleBillUid\":\"\"}"
baseReq["businessSystemName"] = "C_APP"
baseReq["goodBody"] = "APP"
baseReq["orderType"] = "0"
baseReq["payChannelName"] = "大地自营-大地"
baseReq["payChannel"] = "DDZY-DD"
baseReq["payTerminal"] = "APP"
baseReq["businessSystemMainOrderNumber"] = billCode
baseReq["businessSystemFlowNumber"] = cast.ToString(goutil.GetBigID(0, 0))
baseReq["cardNumber"] = cardNo
baseReq["payWay"] = "MEMBER_CARD_PAY"
reqBody, _ := json.Marshal(baseReq)
reqUrl := "https://appapi.dadicinema.com/app-web/v1/web/order/confirmPay"
body, err := httputil.HttpPostJson(reqUrl, nil, p.getBaseHeader(), reqBody)
if err != nil {
log.Errorf("httpPost url[%s] error : %s", reqUrl, err.Error())
return err
}
_, err = p.checkError(body)
if err != nil {
log.Errorf("request : %s", goutil.EncodeJSON(baseReq))
return err
}
return nil
}
func (p *Processor) CheckOrder(order *model.Order) (*common.CheckInfo, error) {
cinema, err := p.getCinema(order.CityName, order.CinemaName)
if err != nil {
@ -364,10 +431,48 @@ func (p *Processor) CheckOrder(order *model.Order) (*common.CheckInfo, error) {
return result, nil
}
func (p *Processor) CreateOrder(*model.Order) (*common.OrderInfo, error) {
return nil, nil
func (p *Processor) CreateOrder(order *model.Order) (*common.OrderInfo, error) {
cinema, err := p.getCinema(order.CityName, order.CinemaName)
if err != nil {
return nil, err
}
price, err := p.getUserPrice(cinema, order.MovieName, goutil.TimeToDateTime(order.ShowTime))
if err != nil {
return nil, err
}
seatGoods, err := p.getSeatGoods(cinema, price.SessionId, order.Seats)
if err != nil {
return nil, err
}
previewOrder, err := p.prevOrderInfo(cinema, seatGoods)
if err != nil {
return nil, err
}
_, defautCard, err := p.getUserCard(cinema)
if err != nil {
return nil, err
}
if defautCard == nil {
return nil, errors.New("No UserCard")
}
if err := p.payOrder(cinema, previewOrder.BillCode, defautCard.CardNo, previewOrder.TotalRealPrice); err != nil {
return nil, err
}
orderInfo := new(common.OrderInfo)
return orderInfo, nil
}
func (p *Processor) getOrderDetail(cinema *Cinema, orderNo string) {
return
}
func (p *Processor) refundOrder(cinema *Cinema, orderNo string) error {
//baseReq := p.getBaseParam(cinema)
//baseReq["orderNo"] = orderNo
return nil
}
func (p *Processor) CancelOrder(order *model.Order, checkInfo *common.CheckInfo) error {
cinema, err := p.getCinema(order.CityName, order.CinemaName)
if err != nil {