|
@@ -14,6 +14,7 @@ import ( |
|
|
"github.com/gin-gonic/gin" |
|
|
"github.com/gin-gonic/gin" |
|
|
"github.com/tidwall/gjson" |
|
|
"github.com/tidwall/gjson" |
|
|
"strconv" |
|
|
"strconv" |
|
|
|
|
|
"xorm.io/xorm" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func OrderList(c *gin.Context) { |
|
|
func OrderList(c *gin.Context) { |
|
@@ -851,6 +852,148 @@ func OrderEditNum(c *gin.Context) { |
|
|
e.OutSuc(c, "success", nil) |
|
|
e.OutSuc(c, "success", nil) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
func OrderAddSku(c *gin.Context) { |
|
|
|
|
|
var req md.GoodsPayParam |
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_INVALID_ARGS, err) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
eg := db.Db |
|
|
|
|
|
order := db.GetOrderById(eg, req.Oid) |
|
|
|
|
|
if order == nil { |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "订单不存在")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
order = JudgePackageOrdOrdState(order) |
|
|
|
|
|
if order.State == 5 { |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "订单已取消,不能修改")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
_, skuPrice := commCalc(c, req) |
|
|
|
|
|
|
|
|
|
|
|
sess := eg.NewSession() |
|
|
|
|
|
defer sess.Close() |
|
|
|
|
|
sess.Begin() |
|
|
|
|
|
orderGoods := db.GetOrderGoodsAll(sess, req.Oid) |
|
|
|
|
|
if orderGoods == nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "订单不存在")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
var amount float64 = 0 |
|
|
|
|
|
skuIds := make([]int64, 0) |
|
|
|
|
|
gids := make([]int64, 0) |
|
|
|
|
|
for _, v := range req.GoodsInfo { |
|
|
|
|
|
skuIds = append(skuIds, utils.StrToInt64(v.SkuId)) |
|
|
|
|
|
gids = append(gids, utils.StrToInt64(v.GoodsId)) |
|
|
|
|
|
} |
|
|
|
|
|
skuMap := db.GetSkuMore(db.Db, skuIds) |
|
|
|
|
|
goodsMap := db.GetGoodsMore(db.Db, gids) |
|
|
|
|
|
for _, v := range req.GoodsInfo { |
|
|
|
|
|
isHas := 0 |
|
|
|
|
|
for _, v1 := range *orderGoods { |
|
|
|
|
|
if v1.GoodsId == utils.StrToInt64(v.GoodsId) && v1.SkuId == utils.StrToInt64(v.SkuId) { |
|
|
|
|
|
isHas = 1 |
|
|
|
|
|
//修改 |
|
|
|
|
|
amount1, err := commAdd(sess, v.Num, &v1) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "添加失败")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
amount += amount1 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if isHas == 0 { |
|
|
|
|
|
//新增 |
|
|
|
|
|
tmp := model.OrderGoods{ |
|
|
|
|
|
Oid: order.Oid, |
|
|
|
|
|
GoodsId: utils.StrToInt64(v.GoodsId), |
|
|
|
|
|
GoodsTitle: goodsMap[utils.StrToInt64(v.GoodsId)].Title, |
|
|
|
|
|
SkuId: utils.StrToInt64(v.SkuId), |
|
|
|
|
|
SkuCode: skuMap[utils.StrToInt64(v.SkuId)].SkuCode, |
|
|
|
|
|
Sku: skuMap[utils.StrToInt64(v.SkuId)].Sku, |
|
|
|
|
|
Num: utils.StrToInt(v.Num), |
|
|
|
|
|
FirstNum: utils.StrToInt(v.Num), |
|
|
|
|
|
Price: skuPrice[v.SkuId], |
|
|
|
|
|
EnterpriseId: utils.StrToInt(req.EnterpriseId), |
|
|
|
|
|
State: 1, |
|
|
|
|
|
IsNew: 1, |
|
|
|
|
|
OrdNo: order.OrdNo, |
|
|
|
|
|
} |
|
|
|
|
|
err := Total(sess, tmp) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "添加失败")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
sql := `UPDATE goods SET sale=sale-%s WHERE goods_id=%s` |
|
|
|
|
|
sql = fmt.Sprintf(sql, v.Num, v.GoodsId) |
|
|
|
|
|
db.QueryNativeStringSess(sess, sql) |
|
|
|
|
|
one, err := sess.InsertOne(&tmp) |
|
|
|
|
|
if one == 0 || err != nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "添加失败")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
amount += utils.StrToFloat64(v.Num) * utils.StrToFloat64(skuPrice[v.SkuId]) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + amount) |
|
|
|
|
|
_, err := sess.Where("id=?", order.Id).Cols("amount").Update(order) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
sess.Rollback() |
|
|
|
|
|
e.OutErr(c, 400, e.NewErr(400, "添加失败")) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
sess.Commit() |
|
|
|
|
|
e.OutSuc(c, "success", nil) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
func commAdd(sess *xorm.Session, num string, orderGoods *model.OrderGoods) (float64, error) { |
|
|
|
|
|
orderGoods.OldNum = orderGoods.Num |
|
|
|
|
|
orderGoods.Num += utils.StrToInt(num) |
|
|
|
|
|
_, err := sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku,old_num,price").Update(orderGoods) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return 0, e.NewErr(400, "修改失败") |
|
|
|
|
|
} |
|
|
|
|
|
orderGoods1 := orderGoods |
|
|
|
|
|
orderGoods1.Id = 0 |
|
|
|
|
|
orderGoods1.GoodsTitle = "(新增)" + orderGoods1.GoodsTitle |
|
|
|
|
|
orderGoods1.IsNew = 1 |
|
|
|
|
|
orderGoods1.GoodsType = 1 |
|
|
|
|
|
orderGoods1.Num = utils.StrToInt(num) |
|
|
|
|
|
sess.InsertOne(orderGoods1) |
|
|
|
|
|
//判断有没有的扣 |
|
|
|
|
|
all1 := db.GetOrderGoodsMakeStockAll(sess, orderGoods1.GoodsId, orderGoods1.SkuId, 0) |
|
|
|
|
|
if all1 == nil { |
|
|
|
|
|
return 0, e.NewErr(400, "修改失败") |
|
|
|
|
|
} |
|
|
|
|
|
all1.WaitMakeNum += utils.StrToInt(num) |
|
|
|
|
|
_, err = sess.Where("id=?", all1.Id).Cols("wait_make_num").Update(all1) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return 0, e.NewErr(400, "修改失败") |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
all := all1 |
|
|
|
|
|
all.Id = 0 |
|
|
|
|
|
all.WaitBakingNum = 0 |
|
|
|
|
|
all.WaitMakeNum = utils.StrToInt(num) |
|
|
|
|
|
all.WaitSortingNum = 0 |
|
|
|
|
|
all.GoodsTitle = orderGoods1.GoodsTitle |
|
|
|
|
|
all.GoodsType = 1 |
|
|
|
|
|
_, err = sess.InsertOne(all) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return 0, e.NewErr(400, "修改失败") |
|
|
|
|
|
} |
|
|
|
|
|
//销量增加 |
|
|
|
|
|
sqlSecond := `UPDATE goods SET sale=sale+%d WHERE id=%d` |
|
|
|
|
|
sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods1.GoodsId) |
|
|
|
|
|
db.QueryNativeStringSess(sess, sqlSecond) |
|
|
|
|
|
return utils.StrToFloat64(num) * utils.StrToFloat64(orderGoods1.Price), nil |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
func OrderAddNum(c *gin.Context) { |
|
|
func OrderAddNum(c *gin.Context) { |
|
|
var args map[string]string |
|
|
var args map[string]string |
|
|
if err := c.ShouldBindJSON(&args); err != nil { |
|
|
if err := c.ShouldBindJSON(&args); err != nil { |
|
|