huangjiajun 6 mesi fa
parent
commit
e9207284d9
9 ha cambiato i file con 50 aggiunte e 234 eliminazioni
  1. +5
    -2
      app/admin/svc/order/svc_order_list.go
  2. +11
    -35
      app/admin/svc/svc_make_record.go
  3. +13
    -0
      app/db/db_goods_list.go
  4. +5
    -8
      app/db/db_order_goods_doing.go
  5. +2
    -1
      app/db/model/order_goods.go
  6. +2
    -0
      app/db/model/order_goods_doing_flow.go
  7. +0
    -12
      app/ipad/hdl/hdl_order_make.go
  8. +5
    -168
      app/ipad/svc/svc_order_make.go
  9. +7
    -8
      app/router/ipad_router.go

+ 5
- 2
app/admin/svc/order/svc_order_list.go Vedi File

@@ -384,6 +384,7 @@ func OrderDetail(c *gin.Context) {
"spe": "",
"sku_list": skuList,
"goods_title": v.GoodsTitle,
"memo": v.DeductMemo,
}

skuData := make([]md.Sku, 0)
@@ -681,9 +682,10 @@ func OrderEditNum(c *gin.Context) {
//重新计算价格
tmp := orderGoodsSku
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))
orderGoodsSku.DeductMemo = args["memo"]
_, err = sess.Where("id=?", orderGoodsSku.Id).Cols("num,memo").Update(orderGoodsSku)
_, err = sess.Where("id=?", orderGoodsSku.Id).Cols("num,memo,old_num").Update(orderGoodsSku)
if err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "修改失败"))
@@ -741,9 +743,10 @@ func OrderEditNum(c *gin.Context) {
e.OutErr(c, 400, e.NewErr(400, "修改失败"))
return
}
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").Update(orderGoods)
_, err = sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku,memo,old_num").Update(orderGoods)
if err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "修改失败"))


+ 11
- 35
app/admin/svc/svc_make_record.go Vedi File

@@ -20,40 +20,28 @@ func MarkRecord(c *gin.Context) {
data := make([]map[string]string, 0)
if list != nil {
stateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
enterpriseIds := make([]int, 0)
adminIds := make([]int, 0)
for _, v := range *list {
enterpriseIds = append(enterpriseIds, v.EnterpriseId)
adminIds = append(adminIds, v.AdminId)
}
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds)
adminMap := db.GetStaffMore(eg, adminIds)

for _, v := range *list {
enterpriseName := ""
adminName := ""
_, ok := enterpriseMap[v.EnterpriseId]
if ok {
enterpriseName = enterpriseMap[v.EnterpriseId].Name
}
_, ok1 := adminMap[v.AdminId]
if ok1 {
adminName = adminMap[v.AdminId].Name
}

var tmp = map[string]string{
"oid": utils.Int64ToStr(v.Oid),
"id": utils.IntToStr(v.Id),
"state_str": stateArr[v.State],
"state": utils.IntToStr(v.State),
"time": v.Time.Format("2006-01-02 15:04:05"),
"enterprise_name": enterpriseName,
"sku_str": "",
"goods_title": v.GoodsTitle,
"memo": v.Memo,
"admin_name": adminName,
"num": utils.IntToStr(v.Num),
"success_num": utils.IntToStr(v.SuccessNum),
"id": utils.IntToStr(v.Id),
"state_str": stateArr[v.State],
"state": utils.IntToStr(v.State),
"time": v.Time.Format("2006-01-02 15:04:05"),
"sku_str": "",
"goods_title": v.GoodsTitle,
"memo": v.Memo,
"admin_name": adminName,
"success_num": utils.IntToStr(v.SuccessNum),
}
skuData := make([]md.Sku, 0)
json.Unmarshal([]byte(v.Sku), &skuData)
@@ -68,21 +56,9 @@ func MarkRecord(c *gin.Context) {
data = append(data, tmp)
}
}
enterpriseList := db.GetEnterpriseList(eg)
enterpriseData := make([]map[string]string, 0)
if enterpriseList != nil {
for _, v := range *enterpriseList {
var tmp = map[string]string{
"id": utils.IntToStr(v.Id),
"name": v.Name,
}
enterpriseData = append(enterpriseData, tmp)
}
}
res := map[string]interface{}{
"total": total,
"enterprise": enterpriseData,
"list": data,
"total": total,
"list": data,
}
e.OutSuc(c, res, nil)
return


+ 13
- 0
app/db/db_goods_list.go Vedi File

@@ -300,3 +300,16 @@ func GetGoodsMore(engine *xorm.Engine, gids []int64) map[int64]model.Goods {
}
return skuMap
}

func GetGoodsSku(eg *xorm.Engine, gid, skuId string) map[string]string {
var goods model.Goods
eg.Where("goods_id=?", gid).Get(&goods)
var sku model.Sku
eg.Where("goods_id=? and sku_id=?", gid, skuId).Get(&sku)
var data = map[string]string{
"title": goods.Title,
"sku": sku.Sku,
}

return data
}

+ 5
- 8
app/db/db_order_goods_doing.go Vedi File

@@ -6,12 +6,12 @@ import (
"xorm.io/xorm"
)

func GetOrderGoodsDoingList(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoods, int64) {
var order []model.OrderGoods
sess := eg.Where("state!=0 and state!=5")
func GetOrderGoodsDoingList(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoodsDoingFlow, int64) {
var order []model.OrderGoodsDoingFlow
sess := eg.Where("1=1")
if param["admin_name"] != "" {
var data []model.Admin
eg.Where("memo like ?", "%"+param["admin_name"]+"%")
eg.Where("memo like ?", "%"+param["admin_name"]+"%").Find(&data)
ids := []int{-1}
for _, v := range data {
ids = append(ids, v.AdmId)
@@ -20,16 +20,13 @@ func GetOrderGoodsDoingList(eg *xorm.Engine, param map[string]string) (*[]model.
}
if param["enterprise_name"] != "" {
var data []model.Enterprise
eg.Where("name like ?", "%"+param["enterprise_name"]+"%")
eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&data)
ids := []int{-1}
for _, v := range data {
ids = append(ids, v.Id)
}
sess.In("enterprise_id", ids)
}
if param["oid"] != "" {
sess.And("oid like ?", "%"+param["oid"]+"%")
}
if param["state"] != "" {
sess.And("state =?", param["state"])
}


+ 2
- 1
app/db/model/order_goods.go Vedi File

@@ -8,12 +8,13 @@ type OrderGoods struct {
GoodsId int64 `json:"goods_id" xorm:"default 0 comment('商品id') BIGINT(20)"`
SkuId int64 `json:"sku_id" xorm:"default 0 comment('sku') BIGINT(20)"`
Num int `json:"num" xorm:"default 0 comment('购买数量') INT(11)"`
OldNum int `json:"old_num" xorm:"default 0 comment('购买数量') INT(11)"`
Price string `json:"price" xorm:"default 0.00 comment('单价') DECIMAL(20,2)"`
State int `json:"state" xorm:"default 0 comment('状态 0待制作 1制作中 2烘焙中 3分拣中 4已完成 ') INT(11)"`
SkuCode string `json:"sku_code" xorm:"VARCHAR(255)"`
GoodsTitle string `json:"goods_title" xorm:"comment('商品标题') VARCHAR(255)"`
DeductMemo string `json:"deduct_memo" xorm:"comment('商品标题') VARCHAR(255)"`
Sku string `json:"sku" xorm:"comment('规格数据') VARCHAR(1000)"`
GoodsTitle string `json:"goods_title" xorm:"comment('商品标题') VARCHAR(255)"`
SuccessNum int `json:"success_num" xorm:"comment('完成数量') INT(11)"`
Memo string `json:"memo" xorm:"comment('制作完成备注') VARCHAR(255)"`
Time time.Time `json:"time" xorm:"DATETIME"`


+ 2
- 0
app/db/model/order_goods_doing_flow.go Vedi File

@@ -15,4 +15,6 @@ type OrderGoodsDoingFlow struct {
SkuId int64 `json:"sku_id" xorm:"BIGINT(20)"`
SkuCode string `json:"sku_code" xorm:"VARCHAR(255)"`
AdminId int `json:"admin_id" xorm:"default 0 comment('admin 的id') INT(11)"`
Sku string `json:"sku" xorm:"comment('规格数据') VARCHAR(1000)"`
GoodsTitle string `json:"goods_title" xorm:"comment('商品标题') VARCHAR(255)"`
}

+ 0
- 12
app/ipad/hdl/hdl_order_make.go Vedi File

@@ -5,18 +5,6 @@ import (
"github.com/gin-gonic/gin"
)

func OrderMakeBegin(c *gin.Context) {
svc.OrderMakeBegin(c)
}
func OrderMakeEnd(c *gin.Context) {
svc.OrderMakeEnd(c)
}
func OrderBakingEnd(c *gin.Context) {
svc.OrderBakingEnd(c)
}
func OrderSortingEnd(c *gin.Context) {
svc.OrderSortingEnd(c)
}
func NewOrderMakeEnd(c *gin.Context) {
svc.NewOrderMakeEnd(c)
}


+ 5
- 168
app/ipad/svc/svc_order_make.go Vedi File

@@ -10,173 +10,6 @@ import (
"time"
)

func OrderMakeBegin(c *gin.Context) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
args["state"] = "1"
args["str"] = "制作"
commMake(c, args)
}
func OrderMakeEnd(c *gin.Context) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
args["state"] = "2"
args["str"] = "烘焙"
commMake(c, args)
}
func OrderBakingEnd(c *gin.Context) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
args["state"] = "3"
args["str"] = "烘焙"
commMake(c, args)
}
func OrderSortingEnd(c *gin.Context) {
var args md.OrderSorting
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
eg := db.Db
sess := eg.NewSession()
defer sess.Close()
sess.Begin()
order := db.GetOrderByIdSess(sess, args.Oid)
if order == nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单查找失败,请重试"))
return
}
if order.State == 4 {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单已分拣完成"))
return
}
//修改制作记录
for _, v := range args.GoodsInfo {
record := db.GetOrderGoodsByIdSess(sess, v["id"])
record.SuccessNum = utils.StrToInt(v["num"])
record.State = 4
record.AdminId = utils.StrToInt(args.AdminId)
record.Time = time.Now()
_, err := sess.Where("id=?", record.Id).Cols("success_num,state,time").Update(record)
if err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
return
}
//写入流程记录
var recordFlow = &model.OrderGoodsDoingFlow{
Num: record.Num,
State: 4,
Memo: "",
SuccessNum: utils.StrToInt(v["num"]),
Time: time.Now(),
Gid: record.GoodsId,
SkuId: record.SkuId,
SkuCode: record.SkuCode,
AdminId: utils.StrToInt(args.AdminId),
}
one, err := sess.InsertOne(recordFlow)
if one == 0 || err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "开始制作失败,请重试"))
return
}
}
//判断大订单 要不要改状态
count, _ := sess.Where("oid=?", order.Oid).Count(&model.OrderGoods{})
countEnd, _ := sess.Where("oid=? and state=?", order.Oid, 4).Count(&model.OrderGoods{})
if countEnd == count {
_, err := sess.Where("oid=?", order.Oid).Cols("state").Update(&model.Order{State: 4})
if err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
return
}
}
sess.Commit()
e.OutSuc(c, "success", nil)
return
}

func commMake(c *gin.Context, args map[string]string) {
eg := db.Db
sess := eg.NewSession()
defer sess.Close()
sess.Begin()
state := utils.StrToInt(args["state"])

orderGoods := db.GetOrderGoodsByIdSess(sess, args["id"])
if orderGoods == nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单查找失败,请重试"))
return
}
order := db.GetOrderByIdSess(sess, utils.Int64ToStr(orderGoods.Oid))
if order == nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单查找失败,请重试"))
return
}
if orderGoods.State >= state {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "该商品已在"+args["str"]+"中"))
return
}
orderGoods.SuccessNum = utils.StrToInt(args["num"])
orderGoods.Memo = args["memo"]
orderGoods.State = state
orderGoods.AdminId = utils.StrToInt(args["admin_id"])
orderGoods.Time = time.Now()
_, err := sess.Where("id=?", orderGoods.Id).Cols("success_num,memo,state,time").Update(orderGoods)
if err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
return
}
//写入流程记录
var recordFlow = &model.OrderGoodsDoingFlow{
Num: orderGoods.Num,
State: state,
Memo: args["memo"],
SuccessNum: utils.StrToInt(args["num"]),
Time: time.Now(),
Gid: orderGoods.GoodsId,
SkuId: orderGoods.SkuId,
SkuCode: orderGoods.SkuCode,
AdminId: utils.StrToInt(args["admin_id"]),
}
one, err := sess.InsertOne(recordFlow)
if one == 0 || err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "开始制作失败,请重试"))
return
}
//判断大订单 要不要改状态
count, _ := sess.Where("oid=?", orderGoods.Oid).Count(&model.OrderGoods{})
countEnd, _ := sess.Where("oid=? and state=?", orderGoods.Oid, state).Count(&model.OrderGoods{})
if countEnd == count {
_, err = sess.Where("oid=?", orderGoods.Oid).Cols("state").Update(&model.Order{State: state})
if err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
return
}
}
sess.Commit()
e.OutSuc(c, "success", nil)
return
}
func NewOrderMakeEnd(c *gin.Context) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {
@@ -247,6 +80,8 @@ func NewOrderSortingEnd(c *gin.Context) {
SkuId: record.SkuId,
SkuCode: record.SkuCode,
AdminId: utils.StrToInt(args.AdminId),
GoodsTitle: record.GoodsTitle,
Sku: record.Sku,
}
one, err := sess.InsertOne(recordFlow)
if one == 0 || err != nil {
@@ -309,6 +144,7 @@ func commNewMake(c *gin.Context, args map[string]string) {
return
}
//写入流程记录

var recordFlow = &model.OrderGoodsDoingFlow{
Num: WaitMakeNum,
State: state,
@@ -319,6 +155,8 @@ func commNewMake(c *gin.Context, args map[string]string) {
SkuId: orderGoods.SkuId,
SkuCode: orderGoods.SkuCode,
AdminId: utils.StrToInt(args["admin_id"]),
GoodsTitle: orderGoods.GoodsTitle,
Sku: orderGoods.Sku,
}
one, err := sess.InsertOne(recordFlow)
if one == 0 || err != nil {
@@ -326,7 +164,6 @@ func commNewMake(c *gin.Context, args map[string]string) {
e.OutErr(c, 400, e.NewErr(400, "操作失败,请重试"))
return
}

sess.Commit()
e.OutSuc(c, "success", nil)
return


+ 7
- 8
app/router/ipad_router.go Vedi File

@@ -8,14 +8,13 @@ import (

func IpadInit(r *gin.RouterGroup) {
r.POST("/login", hdl.Login)
r.Use(mw.Auth) //检测登录状态
r.GET("order/cate", hdl.OrderCate) //订单类目
r.POST("order/list", hdl.Order) //订单
r.POST("order/state_list", hdl.StateOrder) //订单
r.GET("order/goods/cate", hdl.OrderGoodsCate) //订单商品类目
r.POST("order/goods/list", hdl.OrderGoods) //订单商品
r.GET("responsible", hdl.Responsible) //负责人
r.POST("order/make/begin", hdl.OrderMakeBegin) //订单开始制作
r.Use(mw.Auth) //检测登录状态
r.GET("order/cate", hdl.OrderCate) //订单类目
r.POST("order/list", hdl.Order) //订单
r.POST("order/state_list", hdl.StateOrder) //订单
r.GET("order/goods/cate", hdl.OrderGoodsCate) //订单商品类目
r.POST("order/goods/list", hdl.OrderGoods) //订单商品
r.GET("responsible", hdl.Responsible) //负责人

r.POST("order/make/end", hdl.NewOrderMakeEnd) //订单制作完成
r.POST("order/baking/end", hdl.NewOrderBakingEnd) //订单烘焙完成


Caricamento…
Annulla
Salva