huangjiajun 6 miesięcy temu
rodzic
commit
b836bf0647
5 zmienionych plików z 156 dodań i 0 usunięć
  1. +3
    -0
      app/admin/hdl/order/hdl_order_list.go
  2. +1
    -0
      app/admin/md/goods_pay.go
  3. +143
    -0
      app/admin/svc/order/svc_order_list.go
  4. +8
    -0
      app/db/db_order_goods_list.go
  5. +1
    -0
      app/router/admin_router.go

+ 3
- 0
app/admin/hdl/order/hdl_order_list.go Wyświetl plik

@@ -34,6 +34,9 @@ func OrderEdit(c *gin.Context) {
func OrderEditNum(c *gin.Context) {
order.OrderEditNum(c)
}
func OrderAddSku(c *gin.Context) {
order.OrderAddSku(c)
}
func OrderDel(c *gin.Context) {
order.OrderDel(c)
}


+ 1
- 0
app/admin/md/goods_pay.go Wyświetl plik

@@ -4,6 +4,7 @@ type GoodsPayParam struct {
GoodsInfo []GoodsInfo `json:"goods_info"`
EnterpriseId string `json:"enterprise_id"`
BuyInfo BuyInfo `json:"buy_info"`
Oid string `json:"oid"`
}
type BuyInfo struct {
Name string `json:"name"`


+ 143
- 0
app/admin/svc/order/svc_order_list.go Wyświetl plik

@@ -14,6 +14,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
"strconv"
"xorm.io/xorm"
)

func OrderList(c *gin.Context) {
@@ -851,6 +852,148 @@ func OrderEditNum(c *gin.Context) {
e.OutSuc(c, "success", nil)
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) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {


+ 8
- 0
app/db/db_order_goods_list.go Wyświetl plik

@@ -67,3 +67,11 @@ func GetOrderGoods(sess *xorm.Session, oid, gid, skuId string) *model.OrderGoods
}
return &data
}
func GetOrderGoodsAll(sess *xorm.Session, oid string) *[]model.OrderGoods {
var order []model.OrderGoods
err := sess.Where("oid=? and goods_type=0", oid).Find(&order)
if err != nil {
return nil
}
return &order
}

+ 1
- 0
app/router/admin_router.go Wyświetl plik

@@ -144,6 +144,7 @@ func rOrder(r *gin.RouterGroup) {
r.POST("/del", orderHdl.OrderDel) //用户订单商品删除
r.POST("/edit", orderHdl.OrderEdit) //用户订单修改购买人信息
r.POST("/editNum", orderHdl.OrderEditNum) //用户订单修改订单数
r.POST("/addSku", orderHdl.OrderAddSku) //用户订单修改订单数
r.POST("/addNum", orderHdl.OrderAddNum) //用户订单增加数量
r.POST("/deductNum", orderHdl.OrderDeductNum) //用户订单减少数量
r.POST("/makeRecord", orderHdl.MarkRecord) //制作记录


Ładowanie…
Anuluj
Zapisz