Compare commits

..

No commits in common. "8ef1e5ba0978434abbe10980d85914933a28897e" and "d9127c550b6fd6d8c885705a9105336e7d38ea6a" have entirely different histories.

5 changed files with 9 additions and 48 deletions

View File

@ -2,40 +2,8 @@ package console
import ( import (
"github.com/qit-team/snow-core/command" "github.com/qit-team/snow-core/command"
"qteam/app/models/ordersmodel"
"strconv"
"strings"
"time"
) )
func RegisterCommand(c *command.Command) { func RegisterCommand(c *command.Command) {
c.AddFunc("test", test) c.AddFunc("test", test)
} }
func ClearUnpayOrder() {
var expire = time.Now().Add(-1 * time.Minute).Format(time.DateTime)
var orders []ordersmodel.Orders
ordersmodel.GetInstance().GetDb().Where("state = 1 and create_time <= ?", expire).Select("id,product_id").Find(&orders)
var ids = make([]int, 0)
var prodIds = make([]string, 0)
for _, v := range orders {
ids = append(ids, v.Id)
prodIds = append(prodIds, strconv.Itoa(v.ProductId))
}
if len(prodIds) > 0 {
var session = ordersmodel.GetInstance().GetDb().NewSession()
session.Begin()
_, err := session.In("id", ids).Update(&ordersmodel.Orders{State: 9})
if err == nil {
_, err = session.Exec("update Products set stock=stock+1 where id in (" + strings.Join(prodIds, ",") + ")")
if err == nil {
session.Commit()
} else {
session.Rollback()
}
} else {
session.Rollback()
}
}
}

View File

@ -9,5 +9,7 @@ import (
* @wiki https://godoc.org/github.com/robfig/cron * @wiki https://godoc.org/github.com/robfig/cron
*/ */
func RegisterSchedule(c *cron.Cron) { func RegisterSchedule(c *cron.Cron) {
c.AddFunc("@every 1m", ClearUnpayOrder) //c.AddFunc("0 30 * * * *", test)
//c.AddFunc("@hourly", test)
c.AddFunc("@every 10s", test)
} }

View File

@ -77,7 +77,7 @@ var MsgZH = map[int]string{
YouChuOrderRefundFail: "邮储服务异常", YouChuOrderRefundFail: "邮储服务异常",
ProductStockFAIL: "库存不足", ProductStockFAIL: "库存不足",
InsertUserFail: "用户新增失败", InsertUserFail: "用户新增失败",
UserNotExist: "产品不存在", UserNotExist: "用户不存在",
Fail: "请求失败", Fail: "请求失败",
YouChuCodeFail: "Code解析失败", YouChuCodeFail: "Code解析失败",
YouChuCustNoEmpty: "客户编号为空", YouChuCustNoEmpty: "客户编号为空",

View File

@ -47,7 +47,6 @@ func OrderQuery(c *gin.Context) {
order := ordersmodel.Orders{} order := ordersmodel.Orders{}
order.Id = orderId order.Id = orderId
order.OrderNo = request.OrderNo order.OrderNo = request.OrderNo
order.UserId = controllers.GetUserId(c)
var OrderQueryResponse front.OrderQueryResponse var OrderQueryResponse front.OrderQueryResponse
has, err := services.OrderDetailService(&order) has, err := services.OrderDetailService(&order)
if err != nil { if err != nil {

View File

@ -42,7 +42,7 @@ func CreateOrderService(userId int, productId int) (code int, data front.InsertO
_ = session.Close() _ = session.Close()
}() }()
var product productsmodel.Products var product productsmodel.Products
has, err := productsmodel.GetInstance().GetDb().Where("id = ? and status = 1", productId).Get(&product) has, err := productsmodel.GetInstance().GetDb().Where("id = ?", productId).Get(&product)
if err != nil { if err != nil {
return errorcode.SystemError, data return errorcode.SystemError, data
} }
@ -76,15 +76,7 @@ func CreateOrderService(userId int, productId int) (code int, data front.InsertO
utils.Log(nil, "CreateOrderService", err.Error()) utils.Log(nil, "CreateOrderService", err.Error())
return errorcode.SystemError, data return errorcode.SystemError, data
} else { } else {
rs, err := session.Exec("update Products set stock = stock-1 where stock >= 1 and id = ?", product.Id) _ = session.Commit()
var affect, _ = rs.RowsAffected()
if err != nil || affect < 1 {
return errorcode.ProductStockFAIL, data
session.Rollback()
} else {
_ = session.Commit()
}
} }
data.OrderNo = order.OrderNo data.OrderNo = order.OrderNo
data.NotifyUrl = config.GetConf().YouChu.NotifyUrl data.NotifyUrl = config.GetConf().YouChu.NotifyUrl
@ -236,8 +228,8 @@ func OrderNotify(request front.YouChuRequest) (NotifyResponse front.YouChuOrderN
} else { } else {
order.State = common.ORDER_STATUS_FINISH order.State = common.ORDER_STATUS_FINISH
order.VoucherLink = send.Data.ShortUrl order.VoucherLink = send.Data.ShortUrl
//Stock, _ := strconv.Atoi(productDetail.Stock) Stock, _ := strconv.Atoi(productDetail.Stock)
//productDetail.Stock = strconv.Itoa(Stock - 1) productDetail.Stock = strconv.Itoa(Stock - 1)
} }
} else { } else {
@ -245,7 +237,7 @@ func OrderNotify(request front.YouChuRequest) (NotifyResponse front.YouChuOrderN
//order.RefundOrderSta = YouChuOrderNotifyRequest.OrderSta //order.RefundOrderSta = YouChuOrderNotifyRequest.OrderSta
return front.YouChuOrderNotifyResponse{RespCode: "000005", RespMsg: "订单标识错误"} return front.YouChuOrderNotifyResponse{RespCode: "000005", RespMsg: "订单标识错误"}
} }
_, err = session.Cols("stock,state").Where("order_no = ?", YouChuOrderNotifyRequest.ReqTraceId).Update(&order) _, err = session.Where("order_no = ?", YouChuOrderNotifyRequest.ReqTraceId).Update(&order)
if err != nil { if err != nil {
utils.Log(nil, "OrderNotify-MarketSend", err.Error()) utils.Log(nil, "OrderNotify-MarketSend", err.Error())
_ = session.Rollback() _ = session.Rollback()