|
|
@ -20,9 +20,9 @@ func init() { |
|
|
|
go loopUnifiedOrder() |
|
|
|
} |
|
|
|
|
|
|
|
var orderDelayQueue = make(chan *orderDelayQueueParam, math.MaxInt8) |
|
|
|
var orderDelayQueue = make(chan *OrderDelayQueueParam, math.MaxInt8) |
|
|
|
|
|
|
|
type orderDelayQueueParam struct { |
|
|
|
type OrderDelayQueueParam struct { |
|
|
|
Order *models.UserOrder |
|
|
|
First bool `json:"first"` |
|
|
|
Expires int64 `json:"expires"` |
|
|
@ -35,10 +35,10 @@ func PutOrderDelayQueue(order *models.UserOrder, expires int64, delay int) { |
|
|
|
} |
|
|
|
|
|
|
|
if delay == 0 { |
|
|
|
delay = 1000 |
|
|
|
delay = 0 |
|
|
|
} |
|
|
|
|
|
|
|
orderDelayQueue <- &orderDelayQueueParam{ |
|
|
|
orderDelayQueue <- &OrderDelayQueueParam{ |
|
|
|
First: true, |
|
|
|
Expires: expires, |
|
|
|
Delay: delay, |
|
|
@ -262,10 +262,13 @@ type NotifyRequest struct { |
|
|
|
TimeEnd string `xml:"time_end,omitempty" json:"time_end,omitempty"` |
|
|
|
} |
|
|
|
|
|
|
|
func NotifyOrder(w io.Reader) (*models.UserOrder, error) { |
|
|
|
func NotifyOrder(w io.Reader) (order *models.UserOrder, err error) { |
|
|
|
var exist bool |
|
|
|
res := new(NotifyRequest) |
|
|
|
if err := xml.NewDecoder(w).Decode(res); err != nil { |
|
|
|
return nil, fmt.Errorf("xml.NewDecoder.Decode:%w", err) |
|
|
|
err = xml.NewDecoder(w).Decode(res) |
|
|
|
if err != nil { |
|
|
|
err = fmt.Errorf("xml.NewDecoder.Decode:%w", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if res.ReturnCode != CODE_SUCCESS { |
|
|
@ -277,12 +280,20 @@ func NotifyOrder(w io.Reader) (*models.UserOrder, error) { |
|
|
|
userOrder.TimeEnd = res.TimeEnd |
|
|
|
userOrder.TransactionId = res.TransactionId |
|
|
|
userOrder.Status = 1 |
|
|
|
if _, err := userOrder.UpdateStatusByOutTradeNo(res.OutTradeNo, 1); err != nil { |
|
|
|
_, err = userOrder.UpdateStatusByOutTradeNo(res.OutTradeNo, 1) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
exist, err = userOrder.GetByOutTradeNo(res.OutTradeNo) |
|
|
|
if err == nil || !exist { |
|
|
|
err = fmt.Errorf("network error, retrun_code: %v and return_msg: %v", res.ReturnCode, res.ReturnMsg) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
return userOrder, nil |
|
|
|
} else { |
|
|
|
return nil, fmt.Errorf("trade error, err_code: %v and err_code_des: %v", res.ErrCode, res.ErrCodeDes) |
|
|
|
err = fmt.Errorf("trade error, err_code: %v and err_code_des: %v", res.ErrCode, res.ErrCodeDes) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|