|
@@ -60,10 +60,7 @@ func OrderList(c *gin.Context) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
state := []map[string]string{ |
|
|
state := []map[string]string{ |
|
|
{"name": "待制作", "value": "0"}, |
|
|
|
|
|
{"name": "制作中", "value": "1"}, |
|
|
{"name": "制作中", "value": "1"}, |
|
|
{"name": "烘焙中", "value": "2"}, |
|
|
|
|
|
{"name": "分拣中", "value": "3"}, |
|
|
|
|
|
{"name": "已完成", "value": "4"}, |
|
|
{"name": "已完成", "value": "4"}, |
|
|
{"name": "已取消", "value": "5"}, |
|
|
{"name": "已取消", "value": "5"}, |
|
|
} |
|
|
} |
|
@@ -264,8 +261,7 @@ func OrderTotal(c *gin.Context) { |
|
|
for _, v := range nativeString { |
|
|
for _, v := range nativeString { |
|
|
res = append(res, "订单总金额(元):"+v["amount"]) |
|
|
res = append(res, "订单总金额(元):"+v["amount"]) |
|
|
res = append(res, "总订单数量:"+v["alls"]) |
|
|
res = append(res, "总订单数量:"+v["alls"]) |
|
|
res = append(res, "待制作订单数:"+v["wait_do"]) |
|
|
|
|
|
res = append(res, "待烘焙订单数:"+v["dos"]) |
|
|
|
|
|
|
|
|
res = append(res, "制作中订单数:"+v["dos"]) |
|
|
res = append(res, "已完成订单数:"+v["success"]) |
|
|
res = append(res, "已完成订单数:"+v["success"]) |
|
|
res = append(res, "已取消订单数:"+v["cancel"]) |
|
|
res = append(res, "已取消订单数:"+v["cancel"]) |
|
|
} |
|
|
} |
|
@@ -634,10 +630,10 @@ func OrderEditNum(c *gin.Context) { |
|
|
e.OutErr(c, 400, e.NewErr(400, "订单已取消,不能修改")) |
|
|
e.OutErr(c, 400, e.NewErr(400, "订单已取消,不能修改")) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if order.State > 0 { |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "订单制作中,不能修改")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//if order.State > 0 { |
|
|
|
|
|
// e.OutErr(c, 400, e.NewErr(400, "订单制作中,不能修改")) |
|
|
|
|
|
// return |
|
|
|
|
|
//} |
|
|
sess := eg.NewSession() |
|
|
sess := eg.NewSession() |
|
|
defer sess.Close() |
|
|
defer sess.Close() |
|
|
sess.Begin() |
|
|
sess.Begin() |
|
@@ -645,6 +641,25 @@ func OrderEditNum(c *gin.Context) { |
|
|
orderGoods := db.GetOrderGoodsByIdSess(sess, args["id"]) |
|
|
orderGoods := db.GetOrderGoodsByIdSess(sess, args["id"]) |
|
|
isHasSku := 0 |
|
|
isHasSku := 0 |
|
|
if orderGoods.SkuId != utils.StrToInt64(args["sku_id"]) { |
|
|
if orderGoods.SkuId != utils.StrToInt64(args["sku_id"]) { |
|
|
|
|
|
//判断有没有的扣 |
|
|
|
|
|
all := db.GetOrderGoodsMakeStockAll(sess, orderGoods.GoodsId, orderGoods.SkuId) |
|
|
|
|
|
if all == nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if all.WaitMakeNum < orderGoods.Num { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "订单已经在制作,取消失败")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
all.WaitBakingNum -= orderGoods.Num |
|
|
|
|
|
_, err := sess.Where("id=?", all.Id).Cols("wait_baking_num").Update(all) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
orderGoodsSku := db.GetOrderGoodsBySkuIdSess(sess, args["oid"], args["sku_id"]) |
|
|
orderGoodsSku := db.GetOrderGoodsBySkuIdSess(sess, args["oid"], args["sku_id"]) |
|
|
if orderGoodsSku != nil { |
|
|
if orderGoodsSku != nil { |
|
|
isHasSku = 1 |
|
|
isHasSku = 1 |
|
@@ -664,14 +679,23 @@ func OrderEditNum(c *gin.Context) { |
|
|
sqlSecond = fmt.Sprintf(sqlSecond, args["num"], orderGoodsSku.GoodsId) |
|
|
sqlSecond = fmt.Sprintf(sqlSecond, args["num"], orderGoodsSku.GoodsId) |
|
|
db.QueryNativeStringSess(sess, sqlSecond) |
|
|
db.QueryNativeStringSess(sess, sqlSecond) |
|
|
//重新计算价格 |
|
|
//重新计算价格 |
|
|
|
|
|
tmp := orderGoodsSku |
|
|
orderGoodsSku.Num += utils.StrToInt(args["num"]) |
|
|
orderGoodsSku.Num += utils.StrToInt(args["num"]) |
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + utils.StrToFloat64(args["num"])*utils.StrToFloat64(orderGoodsSku.Price)) |
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + utils.StrToFloat64(args["num"])*utils.StrToFloat64(orderGoodsSku.Price)) |
|
|
_, err = sess.Where("id=?", orderGoodsSku.Id).Cols("num").Update(orderGoodsSku) |
|
|
|
|
|
|
|
|
orderGoodsSku.DeductMemo = args["memo"] |
|
|
|
|
|
_, err = sess.Where("id=?", orderGoodsSku.Id).Cols("num,memo").Update(orderGoodsSku) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
sess.Rollback() |
|
|
sess.Rollback() |
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
tmp.Num = utils.StrToInt(args["num"]) |
|
|
|
|
|
err = Total(sess, *tmp) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "下单失败")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
orderGoods.SkuId = utils.StrToInt64(args["sku_id"]) |
|
|
orderGoods.SkuId = utils.StrToInt64(args["sku_id"]) |
|
|
_, sku, _ := db.GetMallSkuBySkuId(eg, args["sku_id"], utils.Int64ToStr(orderGoods.GoodsId)) |
|
|
_, sku, _ := db.GetMallSkuBySkuId(eg, args["sku_id"], utils.Int64ToStr(orderGoods.GoodsId)) |
|
@@ -682,23 +706,44 @@ func OrderEditNum(c *gin.Context) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if isHasSku == 0 { |
|
|
if isHasSku == 0 { |
|
|
|
|
|
//判断有没有的扣 |
|
|
|
|
|
all := db.GetOrderGoodsMakeStockAll(sess, orderGoods.GoodsId, orderGoods.SkuId) |
|
|
|
|
|
if all == nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
num := utils.StrToInt(args["num"]) - orderGoods.Num |
|
|
num := utils.StrToInt(args["num"]) - orderGoods.Num |
|
|
if num < 0 { //少要了 就总金额 减少 |
|
|
if num < 0 { //少要了 就总金额 减少 |
|
|
|
|
|
if all.WaitMakeNum < orderGoods.Num { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "订单已经在制作,取消失败")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
num = orderGoods.Num - utils.StrToInt(args["num"]) |
|
|
num = orderGoods.Num - utils.StrToInt(args["num"]) |
|
|
|
|
|
all.WaitBakingNum -= orderGoods.Num |
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) - float64(num)*utils.StrToFloat64(orderGoods.Price)) |
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) - float64(num)*utils.StrToFloat64(orderGoods.Price)) |
|
|
//销量扣除 |
|
|
//销量扣除 |
|
|
sqlSecond := `UPDATE goods SET sale=sale-%d WHERE id=%d` |
|
|
sqlSecond := `UPDATE goods SET sale=sale-%d WHERE id=%d` |
|
|
sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) |
|
|
sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) |
|
|
db.QueryNativeStringSess(sess, sqlSecond) |
|
|
db.QueryNativeStringSess(sess, sqlSecond) |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
all.WaitBakingNum += orderGoods.Num |
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + float64(num)*utils.StrToFloat64(orderGoods.Price)) |
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + float64(num)*utils.StrToFloat64(orderGoods.Price)) |
|
|
//销量增加 |
|
|
//销量增加 |
|
|
sqlSecond := `UPDATE goods SET sale=sale+%d WHERE id=%d` |
|
|
sqlSecond := `UPDATE goods SET sale=sale+%d WHERE id=%d` |
|
|
sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) |
|
|
sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) |
|
|
db.QueryNativeStringSess(sess, sqlSecond) |
|
|
db.QueryNativeStringSess(sess, sqlSecond) |
|
|
} |
|
|
} |
|
|
|
|
|
_, err := sess.Where("id=?", all.Id).Cols("wait_baking_num").Update(all) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
orderGoods.Num = utils.StrToInt(args["num"]) |
|
|
orderGoods.Num = utils.StrToInt(args["num"]) |
|
|
_, err := sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku").Update(orderGoods) |
|
|
|
|
|
|
|
|
orderGoods.DeductMemo = args["memo"] |
|
|
|
|
|
_, err = sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku,memo").Update(orderGoods) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
sess.Rollback() |
|
|
sess.Rollback() |
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|