Skip to content

Commit

Permalink
feat: fix error code 35
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpiotzh committed Oct 18, 2022
1 parent edd0569 commit ec663d0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
22 changes: 22 additions & 0 deletions dao/t_das_order_info.go
Expand Up @@ -263,6 +263,28 @@ func (d *DbDao) UpdatePreRegisterStatus(orderId string, oldTxStatus, newTxStatus
}).Error
}

func (d *DbDao) UpdateOrderToClosedAndRefund(orderId string) error {
return d.db.Transaction(func(tx *gorm.DB) error {
if err := tx.Model(tables.TableDasOrderInfo{}).
Where("order_id=? AND order_type=? AND order_status=?",
orderId, tables.OrderTypeSelf, tables.OrderStatusDefault).
Updates(map[string]interface{}{
"order_status": tables.OrderStatusClosed,
}).Error; err != nil {
return err
}
if err := tx.Model(tables.TableDasOrderPayInfo{}).
Where("order_id=? AND `status`=? AND refund_status=?",
orderId, tables.OrderTxStatusConfirm, tables.TxStatusDefault).
Updates(map[string]interface{}{
"refund_status": tables.TxStatusSending,
}).Error; err != nil {
return err
}
return nil
})
}

func (d *DbDao) GetPreRegisteredOrderByAccountId(accountId string) (order tables.TableDasOrderInfo, err error) {
err = d.db.Where("account_id=? AND action=? AND register_status>?",
accountId, common.DasActionApplyRegister, tables.RegisterStatusPreRegister).
Expand Down
22 changes: 17 additions & 5 deletions txtool/pre_register.go
Expand Up @@ -115,12 +115,24 @@ func (t *TxTool) DoOrderPreRegisterTx(order *tables.TableDasOrderInfo) error {
}
//
if hash, err := txBuilder.SendTransaction(); err != nil {
// update order
if err := t.DbDao.UpdatePreRegisterStatus(order.OrderId, tables.TxStatusOk, tables.TxStatusSending); err != nil {
log.Error("UpdatePayStatus err:", err.Error(), order.OrderId)
notify.SendLarkTextNotify(config.Cfg.Notify.LarkErrorKey, common.DasActionPreRegister, notify.GetLarkTextNotifyStr("UpdatePayStatus", order.OrderId, err.Error()))
if strings.Contains(err.Error(), "see the error code 35 in the page") {
log.Error("err see the error code 35:", order.OrderId)
notify.SendLarkTextNotify(config.Cfg.Notify.LarkErrorKey, common.DasActionPreRegister,
notify.GetLarkTextNotifyStr("UpdateOrderToClosedAndRefund", order.OrderId, order.Account))

if err := t.DbDao.UpdateOrderToClosedAndRefund(order.OrderId); err != nil {
log.Error("UpdateOrderToClosed err:", err.Error())
notify.SendLarkTextNotify(config.Cfg.Notify.LarkErrorKey, common.DasActionPreRegister, notify.GetLarkTextNotifyStr("UpdateOrderToClosedAndRefund", order.OrderId, err.Error()))
}

} else {
// update order
if err := t.DbDao.UpdatePreRegisterStatus(order.OrderId, tables.TxStatusOk, tables.TxStatusSending); err != nil {
log.Error("UpdatePayStatus err:", err.Error(), order.OrderId)
notify.SendLarkTextNotify(config.Cfg.Notify.LarkErrorKey, common.DasActionPreRegister, notify.GetLarkTextNotifyStr("UpdatePayStatus", order.OrderId, err.Error()))
}
return fmt.Errorf("SendTransaction err: %s", err.Error())
}
return fmt.Errorf("SendTransaction err: %s", err.Error())
} else {
log.Info("SendTransaction ok:", tables.TxActionPreRegister, hash)
t.DasCache.AddCellInputByAction("", txBuilder.Transaction.Inputs)
Expand Down

0 comments on commit ec663d0

Please sign in to comment.