|
|
@@ -38,12 +38,33 @@ func OrderList(c *gin.Context) { |
|
|
|
arg["uid"] = utils.IntToStr(user.Info.Uid) |
|
|
|
data := db.GetOrderList(MasterDb(c), arg) |
|
|
|
var state = []string{"待付款", "待提货", "已完成", "已取消"} |
|
|
|
list := make([]map[string]string, 0) |
|
|
|
list := make([]map[string]interface{}, 0) |
|
|
|
if data != nil { |
|
|
|
now := time.Now().Unix() |
|
|
|
for _, v := range *data { |
|
|
|
store := db.GetStoreIdEg(MasterDb(c), utils.IntToStr(v.StoreUid)) |
|
|
|
info := db.GetOrderInfoEg(MasterDb(c), utils.Int64ToStr(v.Oid)) |
|
|
|
info := db.GetOrderInfoAllEg(MasterDb(c), utils.Int64ToStr(v.Oid)) |
|
|
|
goodsInfo := make([]map[string]string, 0) |
|
|
|
if info != nil { |
|
|
|
for _, v1 := range *info { |
|
|
|
tmp := map[string]string{ |
|
|
|
"img": v1.Img, |
|
|
|
"title": v1.Title, |
|
|
|
"sku_str": "", |
|
|
|
} |
|
|
|
skuData := make([]md.Sku, 0) |
|
|
|
json.Unmarshal([]byte(v1.SkuInfo), &skuData) |
|
|
|
skuStr := "" |
|
|
|
for _, v2 := range skuData { |
|
|
|
if skuStr != "" { |
|
|
|
skuStr += ";" |
|
|
|
} |
|
|
|
skuStr += v2.Value |
|
|
|
} |
|
|
|
tmp["sku_str"] = skuStr |
|
|
|
goodsInfo = append(goodsInfo, tmp) |
|
|
|
} |
|
|
|
} |
|
|
|
downTime := "0" |
|
|
|
if v.State == 0 { |
|
|
|
downTime = utils.IntToStr(int(v.CreateAt.Unix() + 15*60 - now)) |
|
|
@@ -54,27 +75,21 @@ func OrderList(c *gin.Context) { |
|
|
|
downTime = "0" |
|
|
|
} |
|
|
|
} |
|
|
|
img := "" |
|
|
|
title := "" |
|
|
|
storeName := "" |
|
|
|
if store != nil { |
|
|
|
storeName = store.Name |
|
|
|
} |
|
|
|
if info != nil { |
|
|
|
img = info.Img |
|
|
|
title = info.Title |
|
|
|
} |
|
|
|
tmp := map[string]string{ |
|
|
|
tmp := map[string]interface{}{ |
|
|
|
"oid": utils.Int64ToStr(v.Oid), |
|
|
|
"label": "自提", |
|
|
|
"state": utils.IntToStr(v.State), |
|
|
|
"state_str": state[v.State], |
|
|
|
"store_name": storeName, |
|
|
|
"img": img, |
|
|
|
"title": title, |
|
|
|
"goods_info": goodsInfo, |
|
|
|
"amount": v.Amount, |
|
|
|
"num": utils.IntToStr(v.Num), |
|
|
|
"timer": "", |
|
|
|
"code": v.Code, |
|
|
|
"down_time": downTime, |
|
|
|
} |
|
|
|
if v.Type == 1 { |
|
|
@@ -111,8 +126,6 @@ func OrderDetail(c *gin.Context) { |
|
|
|
downTime = "0" |
|
|
|
} |
|
|
|
} |
|
|
|
img := "" |
|
|
|
title := "" |
|
|
|
storeName := "" |
|
|
|
storeAddress := "" |
|
|
|
lat := "" |
|
|
@@ -183,8 +196,6 @@ func OrderDetail(c *gin.Context) { |
|
|
|
"lat": lat, |
|
|
|
"lng": lng, |
|
|
|
"km": km, |
|
|
|
"img": img, |
|
|
|
"title": title, |
|
|
|
"amount": data.Amount, |
|
|
|
"num": utils.IntToStr(data.Num), |
|
|
|
"timer": "", |
|
|
@@ -375,6 +386,49 @@ func OrderCancel(c *gin.Context) { |
|
|
|
e.OutSuc(c, "success", nil) |
|
|
|
return |
|
|
|
} |
|
|
|
func OrderConfirm(c *gin.Context) { |
|
|
|
var arg map[string]string |
|
|
|
if err := c.ShouldBindJSON(&arg); err != nil { |
|
|
|
e.OutErr(c, e.ERR_INVALID_ARGS, err) |
|
|
|
return |
|
|
|
} |
|
|
|
// 加锁 防止并发提取 |
|
|
|
mutexKey := fmt.Sprintf("%s:team.OrderConfirm:%s", c.GetString("mid"), arg["oid"]) |
|
|
|
withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 5, "NX") |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR, err) |
|
|
|
return |
|
|
|
} |
|
|
|
if withdrawAvailable != "OK" { |
|
|
|
e.OutErr(c, e.ERR, e.NewErr(400000, "请求过于频繁,请稍后再试")) |
|
|
|
return |
|
|
|
} |
|
|
|
sess := MasterDb(c).NewSession() |
|
|
|
defer sess.Close() |
|
|
|
sess.Begin() |
|
|
|
order := db.GetOrder(sess, arg["oid"]) |
|
|
|
if order == nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "订单不存在")) |
|
|
|
return |
|
|
|
} |
|
|
|
if order.State != 1 { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "订单不能确认收货")) |
|
|
|
return |
|
|
|
} |
|
|
|
order.State = 2 |
|
|
|
order.UpdateAt = time.Now() |
|
|
|
update, err := sess.Where("id=?", order.Id).Cols("state,update_at").Update(order) |
|
|
|
if update == 0 || err != nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "订单取消失败")) |
|
|
|
return |
|
|
|
} |
|
|
|
sess.Commit() |
|
|
|
e.OutSuc(c, "success", nil) |
|
|
|
return |
|
|
|
} |
|
|
|
func OrderCreate(c *gin.Context) { |
|
|
|
var arg md.OrderTotal |
|
|
|
if err := c.ShouldBindJSON(&arg); err != nil { |
|
|
|