This commit is contained in:
苏尹岚
2020-12-04 18:14:47 +08:00
parent 8836690b1a
commit 3f0dbdcfed

View File

@@ -20,13 +20,31 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
)
func CreateOrder(ctx *jxcontext.Context, orderType int, way string, price int, lng, lat float64) (orderID string, err error) {
func CreateOrder(ctx *jxcontext.Context, orderType int, way string, price int, lng, lat float64) (orderID, errCode string, err error) {
var (
db = dao.GetDB()
order *model.Order
)
if err = auth2.CheckWeixinminiAuthBind(ctx.GetUserID()); err != nil {
return "", err
return "", errCode, err
}
if orderType == model.OrderTypeCash {
//如果用户没有对应账单信息就给他生成一条
userBill, err := dao.GetUserBill(db, ctx.GetUserID(), "")
if userBill == nil {
err = financial.AddUserBill(db, jxutils.GenBillID(), ctx.GetUserID())
}
if userBill.AccountBalance < price {
return "", model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足!")
}
//用户一天只能提现一次
billExpends, err := dao.GetBillExpend(db, ctx.GetUserID(), model.BillTypeCash, DayTimeBegin, DayTimeEnd)
if err != nil {
return "", "", err
}
if len(billExpends) > 0 {
return "", "", fmt.Errorf("抱歉,一天只能提现一次!")
}
}
address, dCode, cCode, err := getAddressInfoFromCoord(db, lng, lat)
order = &model.Order{
@@ -54,7 +72,7 @@ func CreateOrder(ctx *jxcontext.Context, orderType int, way string, price int, l
dao.Rollback(db)
}
dao.Commit(db)
return order.OrderID, err
return order.OrderID, errCode, err
}
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType string) (result *financial.WxPayParam, err error) {
@@ -105,22 +123,6 @@ func Cash(ctx *jxcontext.Context, orderID string, payType int, vendorPayType str
return errCode, fmt.Errorf("未找到此订单!")
}
payHandler.Order = order
//如果用户没有对应账单信息就给他生成一条
userBill, err := dao.GetUserBill(db, order.UserID, "")
if userBill == nil {
err = financial.AddUserBill(db, jxutils.GenBillID(), order.UserID)
}
if userBill.AccountBalance < order.PayPrice {
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足,请充值!")
}
//用户一天只能提现一次
billExpends, err := dao.GetBillExpend(db, order.UserID, model.BillTypeCash, DayTimeBegin, DayTimeEnd)
if err != nil {
return errCode, err
}
if len(billExpends) > 0 {
return errCode, fmt.Errorf("抱歉,一天只能提现一次!")
}
err = payHandler.CreateRefund()
return errCode, err
}