|
|
@@ -45,6 +45,7 @@ func OrderList(c *gin.Context) { |
|
|
|
} |
|
|
|
var tmp = map[string]string{ |
|
|
|
"buy_phone": v1.BuyPhone, |
|
|
|
"ord_no": v1.OrdNo, |
|
|
|
"oid": utils.Int64ToStr(v1.Oid), |
|
|
|
"id": utils.IntToStr(v1.Id), |
|
|
|
"amount": v1.Amount, |
|
|
@@ -105,7 +106,7 @@ func OrderExport(c *gin.Context) { |
|
|
|
} |
|
|
|
//TODO:: 查找 `order_goods` |
|
|
|
var orderGoods []model.OrderGoods |
|
|
|
err := eg.Where("oid = ?", v.Oid).Find(&orderGoods) |
|
|
|
err := eg.Where("oid = ? and goods_type=0", v.Oid).Find(&orderGoods) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err) |
|
|
|
return |
|
|
@@ -113,6 +114,7 @@ func OrderExport(c *gin.Context) { |
|
|
|
for _, vv := range orderGoods { |
|
|
|
data[enterpriseName][v.Oid]["date"] = v.CreateAt.Format("2006-01-02") |
|
|
|
data[enterpriseName][v.Oid]["goods_name"] = vv.GoodsTitle |
|
|
|
data[enterpriseName][v.Oid]["ord_no"] = vv.OrdNo |
|
|
|
skuData := make([]md.Sku, 0) |
|
|
|
json.Unmarshal([]byte(vv.Sku), &skuData) |
|
|
|
skuStr := "" |
|
|
@@ -139,9 +141,12 @@ func OrderExport(c *gin.Context) { |
|
|
|
for k, v := range data { |
|
|
|
var total = 0 |
|
|
|
for kk, vv := range v { |
|
|
|
if vv["ord_no"] == "" { |
|
|
|
vv["ord_no"] = utils.Int64ToStr(kk) |
|
|
|
} |
|
|
|
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ |
|
|
|
vv["date"], |
|
|
|
utils.Int64ToStr(kk), |
|
|
|
vv["ord_no"], |
|
|
|
k, |
|
|
|
vv["goods_name"], |
|
|
|
vv["sku_str"], |
|
|
@@ -190,7 +195,7 @@ func JudgePackageOrdOrdState(ord *model.Order) *model.Order { |
|
|
|
return ord |
|
|
|
} |
|
|
|
//1、判断是否有 `制作中` 有一个就是制作中 |
|
|
|
count1, err := db.Db.Where("oid =?", ord.Oid).And("state =?", 1).Count(&model.OrderGoods{}) |
|
|
|
count1, err := db.Db.Where("oid =?", ord.Oid).And("state =? and goods_type=?", 1, 0).Count(&model.OrderGoods{}) |
|
|
|
if err != nil { |
|
|
|
return ord |
|
|
|
} |
|
|
@@ -214,7 +219,7 @@ func JudgePackageOrdOrdState(ord *model.Order) *model.Order { |
|
|
|
ordState = 3 |
|
|
|
} |
|
|
|
//4、判断是否有 `已完成` 要全部已完成 |
|
|
|
count4, err := db.Db.Where("oid =?", ord.Oid).And("state =?", 4).Count(&model.OrderGoods{}) |
|
|
|
count4, err := db.Db.Where("oid =?", ord.Oid).And("state =? and goods_type=?", 4, 0).Count(&model.OrderGoods{}) |
|
|
|
if err != nil { |
|
|
|
return ord |
|
|
|
} |
|
|
@@ -292,8 +297,11 @@ func OrderCancel(c *gin.Context) { |
|
|
|
goods := db.GetOrderGoodsByIds(sess, args["oid"]) |
|
|
|
if goods != nil { |
|
|
|
for _, v := range *goods { |
|
|
|
if v.GoodsType > 0 { |
|
|
|
continue |
|
|
|
} |
|
|
|
//判断有没有的扣 |
|
|
|
all := db.GetOrderGoodsMakeStockAll(sess, v.GoodsId, v.SkuId) |
|
|
|
all := db.GetOrderGoodsMakeStockAll(sess, v.GoodsId, v.SkuId, 0) |
|
|
|
if all == nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "订单取消失败")) |
|
|
@@ -373,9 +381,15 @@ func OrderDetail(c *gin.Context) { |
|
|
|
skuList = append(skuList, skuItem) |
|
|
|
} |
|
|
|
} |
|
|
|
firstNum := utils.IntToStr(v.FirstNum) |
|
|
|
if v.GoodsType > 0 { |
|
|
|
firstNum = "" |
|
|
|
} |
|
|
|
tmp := map[string]interface{}{ |
|
|
|
"goods_img": "", |
|
|
|
"id": utils.IntToStr(v.Id), |
|
|
|
"goods_type": utils.IntToStr(v.GoodsType), |
|
|
|
"first_num": firstNum, |
|
|
|
"sku_id": utils.Int64ToStr(v.SkuId), |
|
|
|
"goods_id": utils.Int64ToStr(v.GoodsId), |
|
|
|
"num": utils.IntToStr(v.Num), |
|
|
@@ -483,7 +497,7 @@ func OrderOutput(c *gin.Context) { |
|
|
|
} |
|
|
|
//TODO:: 查找 `order_goods` |
|
|
|
var orderGoods []model.OrderGoods |
|
|
|
err := eg.Where("oid = ?", v.Oid).Find(&orderGoods) |
|
|
|
err := eg.Where("oid = ? and goods_type=0", v.Oid).Find(&orderGoods) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err) |
|
|
|
return |
|
|
@@ -492,6 +506,7 @@ func OrderOutput(c *gin.Context) { |
|
|
|
data[enterpriseName][v.Oid]["date"] = v.CreateAt.Format("2006-01-02") |
|
|
|
data[enterpriseName][v.Oid]["send_date"] = gjson.Get(v.BuyInfo, "date").String() |
|
|
|
data[enterpriseName][v.Oid]["goods_name"] = vv.GoodsTitle |
|
|
|
data[enterpriseName][v.Oid]["ord_no"] = vv.OrdNo |
|
|
|
skuData := make([]md.Sku, 0) |
|
|
|
json.Unmarshal([]byte(vv.Sku), &skuData) |
|
|
|
skuStr := "" |
|
|
@@ -518,9 +533,12 @@ func OrderOutput(c *gin.Context) { |
|
|
|
for k, v := range data { |
|
|
|
var total = 0 |
|
|
|
for kk, vv := range v { |
|
|
|
if vv["ord_no"] == "" { |
|
|
|
vv["ord_no"] = utils.Int64ToStr(kk) |
|
|
|
} |
|
|
|
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ |
|
|
|
vv["date"], |
|
|
|
utils.Int64ToStr(kk), |
|
|
|
vv["ord_no"], |
|
|
|
k, |
|
|
|
vv["goods_name"], |
|
|
|
vv["sku_str"], |
|
|
@@ -645,7 +663,7 @@ func OrderEditNum(c *gin.Context) { |
|
|
|
isHasSku := 0 |
|
|
|
if orderGoods.SkuId != utils.StrToInt64(args["sku_id"]) { |
|
|
|
//判断有没有的扣 |
|
|
|
all := db.GetOrderGoodsMakeStockAll(sess, orderGoods.GoodsId, orderGoods.SkuId) |
|
|
|
all := db.GetOrderGoodsMakeStockAll(sess, orderGoods.GoodsId, orderGoods.SkuId, 0) |
|
|
|
if all == nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
@@ -683,11 +701,18 @@ func OrderEditNum(c *gin.Context) { |
|
|
|
db.QueryNativeStringSess(sess, sqlSecond) |
|
|
|
//重新计算价格 |
|
|
|
tmp := orderGoodsSku |
|
|
|
oldNum := orderGoodsSku.Num |
|
|
|
orderGoodsSku.Num += utils.StrToInt(args["num"]) |
|
|
|
orderGoodsSku.OldNum += utils.StrToInt(args["num"]) |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + utils.StrToFloat64(args["num"])*utils.StrToFloat64(orderGoodsSku.Price)) |
|
|
|
if utils.StrToFloat64(args["price"]) > 0 && utils.StrToFloat64(args["price"]) != utils.StrToFloat64(orderGoodsSku.Price) { |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) - float64(oldNum)*utils.StrToFloat64(orderGoodsSku.Price)) |
|
|
|
orderGoodsSku.Price = args["price"] |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + float64(orderGoodsSku.Num)*utils.StrToFloat64(orderGoodsSku.Price)) |
|
|
|
} else { |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + utils.StrToFloat64(args["num"])*utils.StrToFloat64(orderGoodsSku.Price)) |
|
|
|
} |
|
|
|
orderGoodsSku.DeductMemo = args["memo"] |
|
|
|
_, err = sess.Where("id=?", orderGoodsSku.Id).Cols("num,memo,old_num").Update(orderGoodsSku) |
|
|
|
_, err = sess.Where("id=?", orderGoodsSku.Id).Cols("num,memo,old_num,price").Update(orderGoodsSku) |
|
|
|
if err != nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
@@ -711,7 +736,7 @@ func OrderEditNum(c *gin.Context) { |
|
|
|
} |
|
|
|
if isHasSku == 0 { |
|
|
|
//判断有没有的扣 |
|
|
|
all := db.GetOrderGoodsMakeStockAll(sess, orderGoods.GoodsId, orderGoods.SkuId) |
|
|
|
all := db.GetOrderGoodsMakeStockAll(sess, orderGoods.GoodsId, orderGoods.SkuId, 0) |
|
|
|
if all == nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
@@ -725,15 +750,27 @@ func OrderEditNum(c *gin.Context) { |
|
|
|
return |
|
|
|
} |
|
|
|
num = orderGoods.Num - utils.StrToInt(args["num"]) |
|
|
|
all.WaitMakeNum -= orderGoods.Num |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) - float64(num)*utils.StrToFloat64(orderGoods.Price)) |
|
|
|
all.WaitMakeNum -= num |
|
|
|
if utils.StrToFloat64(args["price"]) > 0 && utils.StrToFloat64(args["price"]) != utils.StrToFloat64(orderGoods.Price) { |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) - float64(orderGoods.Num)*utils.StrToFloat64(orderGoods.Price)) |
|
|
|
orderGoods.Price = args["price"] |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + float64(utils.StrToInt(args["num"]))*utils.StrToFloat64(orderGoods.Price)) |
|
|
|
} else { |
|
|
|
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 = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) |
|
|
|
db.QueryNativeStringSess(sess, sqlSecond) |
|
|
|
} else { |
|
|
|
all.WaitMakeNum += orderGoods.Num |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + float64(num)*utils.StrToFloat64(orderGoods.Price)) |
|
|
|
all.WaitMakeNum += num |
|
|
|
if utils.StrToFloat64(args["price"]) > 0 && utils.StrToFloat64(args["price"]) != utils.StrToFloat64(orderGoods.Price) { |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) - float64(orderGoods.Num)*utils.StrToFloat64(orderGoods.Price)) |
|
|
|
orderGoods.Price = args["price"] |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + float64(num)*utils.StrToFloat64(orderGoods.Price)) |
|
|
|
} else { |
|
|
|
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 = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) |
|
|
@@ -748,7 +785,7 @@ func OrderEditNum(c *gin.Context) { |
|
|
|
orderGoods.OldNum = orderGoods.Num |
|
|
|
orderGoods.Num = utils.StrToInt(args["num"]) |
|
|
|
orderGoods.DeductMemo = args["memo"] |
|
|
|
_, err = sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku,memo,old_num").Update(orderGoods) |
|
|
|
_, err = sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku,memo,old_num,price").Update(orderGoods) |
|
|
|
if err != nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
@@ -765,3 +802,174 @@ func OrderEditNum(c *gin.Context) { |
|
|
|
e.OutSuc(c, "success", nil) |
|
|
|
return |
|
|
|
} |
|
|
|
func OrderAddNum(c *gin.Context) { |
|
|
|
var args map[string]string |
|
|
|
if err := c.ShouldBindJSON(&args); err != nil { |
|
|
|
e.OutErr(c, e.ERR_INVALID_ARGS, err) |
|
|
|
return |
|
|
|
} |
|
|
|
eg := db.Db |
|
|
|
order := db.GetOrderById(eg, args["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 |
|
|
|
} |
|
|
|
sess := eg.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
sess.Begin() |
|
|
|
num := utils.StrToInt(args["num"]) |
|
|
|
|
|
|
|
orderGoods := db.GetOrderGoodsByIdSess(sess, args["id"]) |
|
|
|
orderGoods.OldNum = orderGoods.Num |
|
|
|
orderGoods.Num += utils.StrToInt(args["num"]) |
|
|
|
_, err := sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku,old_num,price").Update(orderGoods) |
|
|
|
if err != nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
return |
|
|
|
} |
|
|
|
orderGoods1 := orderGoods |
|
|
|
orderGoods1.Id = 0 |
|
|
|
orderGoods1.GoodsTitle = "(新增)" + orderGoods1.GoodsTitle |
|
|
|
orderGoods1.IsNew = 1 |
|
|
|
orderGoods1.GoodsType = 1 |
|
|
|
orderGoods1.Num = num |
|
|
|
sess.InsertOne(orderGoods1) |
|
|
|
//判断有没有的扣 |
|
|
|
all1 := db.GetOrderGoodsMakeStockAll(sess, orderGoods1.GoodsId, orderGoods1.SkuId, 0) |
|
|
|
if all1 == nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
return |
|
|
|
} |
|
|
|
all1.WaitMakeNum += num |
|
|
|
_, err = sess.Where("id=?", all1.Id).Cols("wait_make_num").Update(all1) |
|
|
|
if err != nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
return |
|
|
|
} |
|
|
|
all := all1 |
|
|
|
all.Id = 0 |
|
|
|
all.WaitBakingNum = 0 |
|
|
|
all.WaitMakeNum = num |
|
|
|
all.WaitSortingNum = 0 |
|
|
|
all.GoodsTitle = orderGoods1.GoodsTitle |
|
|
|
all.GoodsType = 1 |
|
|
|
_, err = sess.InsertOne(all) |
|
|
|
if err != nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
return |
|
|
|
} |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + float64(num)*utils.StrToFloat64(orderGoods1.Price)) |
|
|
|
//销量增加 |
|
|
|
sqlSecond := `UPDATE goods SET sale=sale+%d WHERE id=%d` |
|
|
|
sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods1.GoodsId) |
|
|
|
db.QueryNativeStringSess(sess, sqlSecond) |
|
|
|
_, 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 OrderDeductNum(c *gin.Context) { |
|
|
|
var args map[string]string |
|
|
|
if err := c.ShouldBindJSON(&args); err != nil { |
|
|
|
e.OutErr(c, e.ERR_INVALID_ARGS, err) |
|
|
|
return |
|
|
|
} |
|
|
|
eg := db.Db |
|
|
|
order := db.GetOrderById(eg, args["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 |
|
|
|
} |
|
|
|
sess := eg.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
sess.Begin() |
|
|
|
num := utils.StrToInt(args["num"]) |
|
|
|
orderGoods := db.GetOrderGoodsByIdSess(sess, args["id"]) |
|
|
|
orderGoods.OldNum = orderGoods.Num |
|
|
|
orderGoods.Num -= utils.StrToInt(args["num"]) |
|
|
|
_, err := sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku,old_num,price").Update(orderGoods) |
|
|
|
if err != nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
return |
|
|
|
} |
|
|
|
orderGoods1 := orderGoods |
|
|
|
orderGoods1.Id = 0 |
|
|
|
orderGoods1.GoodsTitle = "(减少)" + orderGoods1.GoodsTitle |
|
|
|
orderGoods1.IsNew = 1 |
|
|
|
orderGoods1.GoodsType = 2 |
|
|
|
orderGoods1.Num = num |
|
|
|
sess.InsertOne(orderGoods1) |
|
|
|
//判断有没有的扣 |
|
|
|
all1 := db.GetOrderGoodsMakeStockAll(sess, orderGoods1.GoodsId, orderGoods1.SkuId, 0) |
|
|
|
if all1 == nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
return |
|
|
|
} |
|
|
|
if all1.WaitMakeNum < num { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "订单已经在制作,减少数量失败")) |
|
|
|
return |
|
|
|
} |
|
|
|
all1.WaitMakeNum -= num |
|
|
|
_, err = sess.Where("id=?", all1.Id).Cols("wait_make_num").Update(all1) |
|
|
|
if err != nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
return |
|
|
|
} |
|
|
|
all := all1 |
|
|
|
all.Id = 0 |
|
|
|
all.WaitBakingNum = 0 |
|
|
|
all.WaitMakeNum = num |
|
|
|
all.WaitSortingNum = 0 |
|
|
|
all.GoodsTitle = orderGoods1.GoodsTitle |
|
|
|
all.GoodsType = 2 |
|
|
|
_, err = sess.InsertOne(all) |
|
|
|
if err != nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
return |
|
|
|
} |
|
|
|
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) - float64(num)*utils.StrToFloat64(orderGoods1.Price)) |
|
|
|
//销量减少 |
|
|
|
sqlSecond := `UPDATE goods SET sale=sale-%d WHERE id=%d` |
|
|
|
sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods1.GoodsId) |
|
|
|
db.QueryNativeStringSess(sess, sqlSecond) |
|
|
|
if err != nil { |
|
|
|
sess.Rollback() |
|
|
|
e.OutErr(c, 400, e.NewErr(400, "修改失败")) |
|
|
|
return |
|
|
|
} |
|
|
|
_, 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 |
|
|
|
} |