@@ -6,10 +6,13 @@ import ( | |||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/db/model" | "applet/app/db/model" | ||||
"applet/app/e" | "applet/app/e" | ||||
"applet/app/svc" | |||||
"applet/app/utils" | "applet/app/utils" | ||||
"errors" | |||||
"fmt" | "fmt" | ||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
"time" | "time" | ||||
"xorm.io/xorm" | |||||
) | ) | ||||
func GoodsPayCalcAmount(c *gin.Context) { | func GoodsPayCalcAmount(c *gin.Context) { | ||||
@@ -39,7 +42,7 @@ func GoodsPayCreate(c *gin.Context) { | |||||
sess := db.Db.NewSession() | sess := db.Db.NewSession() | ||||
defer sess.Close() | defer sess.Close() | ||||
sess.Begin() | sess.Begin() | ||||
sess.Commit() | |||||
var order = model.Order{ | var order = model.Order{ | ||||
Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(req.EnterpriseId))), | Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(req.EnterpriseId))), | ||||
CreateAt: time.Now(), | CreateAt: time.Now(), | ||||
@@ -79,6 +82,12 @@ func GoodsPayCreate(c *gin.Context) { | |||||
} | } | ||||
goodsTotal[tmp.GoodsId] += tmp.Num | goodsTotal[tmp.GoodsId] += tmp.Num | ||||
orderGoods = append(orderGoods, tmp) | orderGoods = append(orderGoods, tmp) | ||||
err = Total(sess, tmp) | |||||
if err != nil { | |||||
sess.Rollback() | |||||
e.OutErr(c, 400, e.NewErr(400, "下单失败")) | |||||
return | |||||
} | |||||
} | } | ||||
for k, v := range goodsTotal { | for k, v := range goodsTotal { | ||||
sql := `UPDATE goods SET sale=sale-%d WHERE goods_id=%d` | sql := `UPDATE goods SET sale=sale-%d WHERE goods_id=%d` | ||||
@@ -91,6 +100,8 @@ func GoodsPayCreate(c *gin.Context) { | |||||
e.OutErr(c, 400, e.NewErr(400, "下单失败")) | e.OutErr(c, 400, e.NewErr(400, "下单失败")) | ||||
return | return | ||||
} | } | ||||
sess.Commit() | |||||
svc.SysCfgSet(c, "has_new_order", "1", "") | |||||
e.OutSuc(c, "success", nil) | e.OutSuc(c, "success", nil) | ||||
return | return | ||||
} | } | ||||
@@ -128,3 +139,20 @@ func commCalc(c *gin.Context, req md.GoodsPayParam) (float64, map[string]string) | |||||
return amount, skuPrice | return amount, skuPrice | ||||
} | } | ||||
// 统计数量 | |||||
func Total(sess *xorm.Session, tmp model.OrderGoods) error { | |||||
stock := db.GetOrderGoodsMakeStock(sess, tmp.GoodsId, tmp.SkuId) | |||||
if stock == nil { | |||||
return errors.New("下单失败") | |||||
} | |||||
stock.Sku = tmp.Sku | |||||
stock.SkuCode = tmp.SkuCode | |||||
stock.GoodsTitle = tmp.GoodsTitle | |||||
stock.WaitMakeNum += tmp.Num | |||||
update, err := sess.Where("id=?", stock.Id).Cols("sku,sku_code,goods_title,wait_make_num").Update(stock) | |||||
if update == 0 || err != nil { | |||||
return errors.New("下单失败") | |||||
} | |||||
return nil | |||||
} |
@@ -0,0 +1,43 @@ | |||||
package hdl | |||||
import ( | |||||
"applet/app/bigData/svc" | |||||
"applet/app/db" | |||||
"applet/app/e" | |||||
"github.com/gin-gonic/gin" | |||||
) | |||||
func MakingData(c *gin.Context) { | |||||
args := map[string]string{ | |||||
"state": "1", | |||||
} | |||||
svc.CommMakingData(c, args) | |||||
} | |||||
func BakingData(c *gin.Context) { | |||||
args := map[string]string{ | |||||
"state": "2", | |||||
} | |||||
svc.CommMakingData(c, args) | |||||
} | |||||
func SortingData(c *gin.Context) { | |||||
result, err := svc.LeftDataForSorting() | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR, err.Error()) | |||||
return | |||||
} | |||||
e.OutSuc(c, result, nil) | |||||
return | |||||
} | |||||
func NewOrderNotice(c *gin.Context) { | |||||
sysCfgDb := db.SysCfgDb{} | |||||
sysCfgDb.Set() | |||||
cfg, _ := sysCfgDb.SysCfgGetOne("has_new_order") | |||||
res := map[string]string{ | |||||
"has_new_order": "0", | |||||
} | |||||
if cfg != nil { | |||||
res["has_new_order"] = cfg.Val | |||||
} | |||||
e.OutSuc(c, res, nil) | |||||
return | |||||
} |
@@ -200,9 +200,6 @@ func LeftDataForBaking() (resp []md.LeftDataForMakeResp, err error) { | |||||
} | } | ||||
func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) { | func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) { | ||||
now := time.Now() | |||||
startDate := now.Format("2006-01-02") + " 00:00:00" | |||||
endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00" | |||||
engine := db.Db | engine := db.Db | ||||
var enterprise []model.Enterprise | var enterprise []model.Enterprise | ||||
err = engine.Where("1=1").Find(&enterprise) | err = engine.Where("1=1").Find(&enterprise) | ||||
@@ -214,9 +211,9 @@ func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) { | |||||
enterpriseMap[v.Id] = v | enterpriseMap[v.Id] = v | ||||
} | } | ||||
//1、查找当天的 order 数据(大于 待制作) | |||||
//1、查找不等于4 5 | |||||
var orders []model.Order | var orders []model.Order | ||||
err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 2).Find(&orders) | |||||
err = engine.Where(" state != 4 and state != 5").Find(&orders) | |||||
if err != nil { | if err != nil { | ||||
return | return | ||||
} | } | ||||
@@ -241,23 +238,12 @@ func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) { | |||||
records = append(records, v.Id) | records = append(records, v.Id) | ||||
} | } | ||||
//3、用户订单商品操作流程 | |||||
var orderGoodsDoingFlows []model.OrderGoodsDoingFlow | |||||
err = engine.Where("state = 2").In("record_id", records).Find(&orderGoodsDoingFlows) | |||||
if err != nil { | |||||
return | |||||
} | |||||
var orderGoodsDoingFlowsMap = map[int]model.OrderGoodsDoingFlow{} | |||||
for _, v := range orderGoodsDoingFlows { | |||||
orderGoodsDoingFlowsMap[v.RecordId] = v | |||||
} | |||||
//4、整合数据 | //4、整合数据 | ||||
orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"} | |||||
orderStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成", "已取消"} | |||||
for _, v := range orders { | for _, v := range orders { | ||||
var list []md.LeftDataForMakeList | var list []md.LeftDataForMakeList | ||||
if len(orderGoodsMap[v.Oid]) > 0 { | if len(orderGoodsMap[v.Oid]) > 0 { | ||||
orderGoodsStateArr := []string{"待制作", "制作中", "烘焙中", "分拣中", "已完成"} | |||||
orderGoodsStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成"} | |||||
for _, vv := range orderGoodsMap[v.Oid] { | for _, vv := range orderGoodsMap[v.Oid] { | ||||
skuData := make([]md2.Sku, 0) | skuData := make([]md2.Sku, 0) | ||||
json.Unmarshal([]byte(vv.Sku), &skuData) | json.Unmarshal([]byte(vv.Sku), &skuData) | ||||
@@ -273,12 +259,11 @@ func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) { | |||||
GoodsName: vv.GoodsTitle, | GoodsName: vv.GoodsTitle, | ||||
Sku: skuStr, | Sku: skuStr, | ||||
Num: vv.Num, | Num: vv.Num, | ||||
SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum, | |||||
SuccessNum: vv.SuccessNum, | |||||
StateZh: stateZh, | StateZh: stateZh, | ||||
State: vv.State, | State: vv.State, | ||||
}) | }) | ||||
} | } | ||||
resp = append(resp, md.LeftDataForMakeResp{ | resp = append(resp, md.LeftDataForMakeResp{ | ||||
EnterpriseName: enterpriseMap[v.EnterpriseId].Name, | EnterpriseName: enterpriseMap[v.EnterpriseId].Name, | ||||
EnterpriseId: v.EnterpriseId, | EnterpriseId: v.EnterpriseId, | ||||
@@ -0,0 +1,54 @@ | |||||
package svc | |||||
import ( | |||||
"applet/app/admin/md" | |||||
"applet/app/db" | |||||
"applet/app/e" | |||||
"applet/app/utils" | |||||
"encoding/json" | |||||
"github.com/gin-gonic/gin" | |||||
) | |||||
func CommMakingData(c *gin.Context, args map[string]string) { | |||||
eg := db.Db | |||||
data, _ := db.GetOrderGoodsMakeStockByBigData(eg, args) | |||||
list := make([]map[string]string, 0) | |||||
if data != nil { | |||||
for _, v := range *data { | |||||
var tmp = map[string]string{ | |||||
"num": "", | |||||
"state_str": "", | |||||
"goods_title": v.GoodsTitle, | |||||
"state": "", | |||||
} | |||||
if args["state"] == "1" { | |||||
tmp["num"] = utils.IntToStr(v.WaitMakeNum) | |||||
tmp["state_str"] = "制作中" | |||||
tmp["state"] = "1" | |||||
} | |||||
if args["state"] == "2" { | |||||
tmp["num"] = utils.IntToStr(v.WaitBakingNum) | |||||
tmp["state_str"] = "烘焙中" | |||||
tmp["state"] = "2" | |||||
} | |||||
if args["state"] == "3" { | |||||
tmp["num"] = utils.IntToStr(v.WaitSortingNum) | |||||
tmp["state_str"] = "分拣中" | |||||
tmp["state"] = "3" | |||||
} | |||||
skuData := make([]md.Sku, 0) | |||||
json.Unmarshal([]byte(v.Sku), &skuData) | |||||
skuStr := "" | |||||
for _, v1 := range skuData { | |||||
if skuStr != "" { | |||||
skuStr += ";" | |||||
} | |||||
skuStr += v1.Value | |||||
} | |||||
tmp["sku_str"] = skuStr | |||||
list = append(list, tmp) | |||||
} | |||||
} | |||||
e.OutSuc(c, list, nil) | |||||
return | |||||
} |
@@ -13,6 +13,12 @@ func GetOrderGoodsListByIpad(eg *xorm.Engine, param map[string]string) (*[]model | |||||
if param["oid"] != "" { | if param["oid"] != "" { | ||||
sess.And("oid = ?", param["oid"]) | sess.And("oid = ?", param["oid"]) | ||||
} | } | ||||
if param["gid"] != "" { | |||||
sess.And("goods_id = ?", param["gid"]) | |||||
} | |||||
if param["sku_id"] != "" { | |||||
sess.And("sku_id = ?", param["sku_id"]) | |||||
} | |||||
if param["state"] != "" { | if param["state"] != "" { | ||||
sess.And("state =?", param["state"]) | sess.And("state =?", param["state"]) | ||||
} | } | ||||
@@ -43,3 +49,11 @@ func GetOrderGoodsByIdSess(sess *xorm.Session, id string) *model.OrderGoods { | |||||
} | } | ||||
return &order | return &order | ||||
} | } | ||||
func GetOrderGoods(sess *xorm.Session, oid, gid, skuId string) *model.OrderGoods { | |||||
var data model.OrderGoods | |||||
get, err := sess.Where("oid=? and goods_id=? and sku_id=?", oid, gid, skuId).Get(&data) | |||||
if err != nil || get == false { | |||||
return nil | |||||
} | |||||
return &data | |||||
} |
@@ -0,0 +1,73 @@ | |||||
package db | |||||
import ( | |||||
"applet/app/db/model" | |||||
"applet/app/utils" | |||||
"xorm.io/xorm" | |||||
) | |||||
func GetOrderGoodsMakeStockByIpad(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoodsMakeStock, int64) { | |||||
var order []model.OrderGoodsMakeStock | |||||
sess := eg.Where("1=1") | |||||
if param["state"] == "1" { | |||||
sess.And("wait_make_num >0") | |||||
} | |||||
if param["state"] == "2" { | |||||
sess.And("wait_baking_num >0") | |||||
} | |||||
if param["state"] == "3" { | |||||
sess.And("wait_sorting_num >0") | |||||
} | |||||
if param["keyword"] != "" { | |||||
sess.And("goods_title like ?", "%"+param["keyword"]+"%") | |||||
} | |||||
size := utils.StrToInt(param["limit"]) | |||||
start := (utils.StrToInt(param["page"]) - 1) * size | |||||
count, err := sess.Limit(size, start).OrderBy("id asc").FindAndCount(&order) | |||||
if err != nil { | |||||
return nil, count | |||||
} | |||||
return &order, count | |||||
} | |||||
func GetOrderGoodsMakeStockByBigData(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoodsMakeStock, int64) { | |||||
var order []model.OrderGoodsMakeStock | |||||
sess := eg.Where("1=1") | |||||
if param["state"] == "1" { | |||||
sess.And("wait_make_num >0") | |||||
} | |||||
if param["state"] == "2" { | |||||
sess.And("wait_baking_num >0") | |||||
} | |||||
if param["state"] == "3" { | |||||
sess.And("wait_sorting_num >0") | |||||
} | |||||
if param["keyword"] != "" { | |||||
sess.And("goods_title like ?", "%"+param["keyword"]+"%") | |||||
} | |||||
count, err := sess.OrderBy("id asc").FindAndCount(&order) | |||||
if err != nil { | |||||
return nil, count | |||||
} | |||||
return &order, count | |||||
} | |||||
func GetOrderGoodsMakeStock(sess *xorm.Session, gid, skuId int64) *model.OrderGoodsMakeStock { | |||||
var data model.OrderGoodsMakeStock | |||||
get, err := sess.Where("gid=? and sku_id=?", gid, skuId).Get(&data) | |||||
if err != nil { | |||||
return nil | |||||
} | |||||
if get == false { | |||||
data = model.OrderGoodsMakeStock{ | |||||
Gid: gid, | |||||
SkuId: skuId, | |||||
} | |||||
insert, err := sess.Insert(&data) | |||||
if insert == 0 || err != nil { | |||||
return nil | |||||
} | |||||
} | |||||
return &data | |||||
} |
@@ -5,13 +5,14 @@ import ( | |||||
) | ) | ||||
type Order struct { | type Order struct { | ||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Oid int64 `json:"oid" xorm:"comment('订单号') BIGINT(20)"` | |||||
State int `json:"state" xorm:"default 0 comment('状态 0待制作 1制作中 2烘焙中 3分拣中 4已完成 5已取消') INT(11)"` | |||||
CreateAt time.Time `json:"create_at" xorm:"comment('下单时间') DATETIME"` | |||||
CancelAt time.Time `json:"cancel_at" xorm:"comment('取消时间') DATETIME"` | |||||
EnterpriseId int `json:"enterprise_id" xorm:"default 0 comment('校企id') INT(11)"` | |||||
BuyInfo string `json:"buy_info" xorm:"comment('购买人信息 json') VARCHAR(2000)"` | |||||
Amount string `json:"amount" xorm:"default 0.00 comment('付款金额') DECIMAL(20,2)"` | |||||
BuyPhone string `json:"buy_phone" xorm:"comment('购买人手机') VARCHAR(20)"` | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Oid int64 `json:"oid" xorm:"comment('订单号') BIGINT(20)"` | |||||
State int `json:"state" xorm:"default 0 comment('状态 0待制作 1制作中 2烘焙中 3分拣中 4已完成 5已取消') INT(11)"` | |||||
CreateAt time.Time `json:"create_at" xorm:"comment('下单时间') DATETIME"` | |||||
CancelAt time.Time `json:"cancel_at" xorm:"comment('取消时间') DATETIME"` | |||||
EnterpriseId int `json:"enterprise_id" xorm:"default 0 comment('校企id') INT(11)"` | |||||
BuyInfo string `json:"buy_info" xorm:"comment('购买人信息 json') VARCHAR(2000)"` | |||||
Amount string `json:"amount" xorm:"default 0.00 comment('付款金额') DECIMAL(20,2)"` | |||||
BuyPhone string `json:"buy_phone" xorm:"comment('购买人手机') VARCHAR(20)"` | |||||
EnterpriseName string `json:"enterprise_name" xorm:"comment('校企名称') VARCHAR(20)"` | |||||
} | } |
@@ -0,0 +1,14 @@ | |||||
package model | |||||
type OrderGoodsMakeStock struct { | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Gid int64 `json:"gid" xorm:"BIGINT(20)"` | |||||
SkuId int64 `json:"sku_id" xorm:"BIGINT(20)"` | |||||
SkuCode string `json:"sku_code" xorm:"VARCHAR(255)"` | |||||
GoodsTitle string `json:"goods_title" xorm:"comment('商品标题') VARCHAR(255)"` | |||||
Sku string `json:"sku" xorm:"comment('规格数据') VARCHAR(1000)"` | |||||
WaitMakeNum int `json:"wait_make_num" xorm:"default 0 comment('待制作') INT(11)"` | |||||
WaitBakingNum int `json:"wait_baking_num" xorm:"comment('待烘焙') INT(11)"` | |||||
WaitSortingNum int `json:"wait_sorting_num" xorm:"default 0 comment('待分拣') INT(11)"` | |||||
SuccessNum int `json:"success_num" xorm:"default 0 comment('已分拣') INT(11)"` | |||||
} |
@@ -8,11 +8,10 @@ import ( | |||||
func OrderCate(c *gin.Context) { | func OrderCate(c *gin.Context) { | ||||
var res = []map[string]string{ | var res = []map[string]string{ | ||||
{"name": "全部", "id": ""}, | |||||
{"name": "待制作", "id": "0"}, | |||||
{"name": "全部订单", "id": ""}, | |||||
{"name": "制作中", "id": "1"}, | {"name": "制作中", "id": "1"}, | ||||
{"name": "待分拣", "id": "3"}, | |||||
{"name": "已完成", "id": "4"}, | |||||
{"name": "烘焙中", "id": "2"}, | |||||
{"name": "分拣中", "id": "3"}, | |||||
} | } | ||||
e.OutSuc(c, res, nil) | e.OutSuc(c, res, nil) | ||||
return | return | ||||
@@ -20,3 +19,6 @@ func OrderCate(c *gin.Context) { | |||||
func Order(c *gin.Context) { | func Order(c *gin.Context) { | ||||
svc.Order(c) | svc.Order(c) | ||||
} | } | ||||
func StateOrder(c *gin.Context) { | |||||
svc.StateOrder(c) | |||||
} |
@@ -45,6 +45,7 @@ func OrderGoods(c *gin.Context) { | |||||
"oid": utils.Int64ToStr(v.Oid), | "oid": utils.Int64ToStr(v.Oid), | ||||
"id": utils.IntToStr(v.Id), | "id": utils.IntToStr(v.Id), | ||||
"num": utils.IntToStr(v.Num), | "num": utils.IntToStr(v.Num), | ||||
"success_num": utils.IntToStr(v.SuccessNum), | |||||
"state_str": stateArr[v.State], | "state_str": stateArr[v.State], | ||||
"btn_str": btnArr[v.State], | "btn_str": btnArr[v.State], | ||||
"goods_title": v.GoodsTitle, | "goods_title": v.GoodsTitle, | ||||
@@ -79,3 +80,43 @@ func OrderGoods(c *gin.Context) { | |||||
e.OutSuc(c, list, nil) | e.OutSuc(c, list, nil) | ||||
return | return | ||||
} | } | ||||
func SortingOrderGoods(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 | |||||
data, _ := db.GetOrderGoodsListByIpad(eg, args) | |||||
list := make([]map[string]string, 0) | |||||
if data != nil { | |||||
enterpriseIds := make([]int, 0) | |||||
for _, v := range *data { | |||||
enterpriseIds = append(enterpriseIds, v.EnterpriseId) | |||||
} | |||||
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds) | |||||
gids := make([]int64, 0) | |||||
for _, v := range *data { | |||||
gids = append(gids, v.GoodsId) | |||||
} | |||||
for _, v := range *data { | |||||
enterpriseName := "" | |||||
_, ok := enterpriseMap[v.EnterpriseId] | |||||
if ok { | |||||
enterpriseName = enterpriseMap[v.EnterpriseId].Name | |||||
} | |||||
var tmp = map[string]string{ | |||||
"oid": utils.Int64ToStr(v.Oid), | |||||
"id": utils.IntToStr(v.Id), | |||||
"num": utils.IntToStr(v.Num), | |||||
"success_num": utils.IntToStr(v.SuccessNum), | |||||
"need_num": utils.IntToStr(v.Num - v.SuccessNum), | |||||
"enterprise_name": enterpriseName, | |||||
} | |||||
list = append(list, tmp) | |||||
} | |||||
} | |||||
e.OutSuc(c, list, nil) | |||||
return | |||||
} |
@@ -17,3 +17,12 @@ func OrderBakingEnd(c *gin.Context) { | |||||
func OrderSortingEnd(c *gin.Context) { | func OrderSortingEnd(c *gin.Context) { | ||||
svc.OrderSortingEnd(c) | svc.OrderSortingEnd(c) | ||||
} | } | ||||
func NewOrderMakeEnd(c *gin.Context) { | |||||
svc.NewOrderMakeEnd(c) | |||||
} | |||||
func NewOrderBakingEnd(c *gin.Context) { | |||||
svc.NewOrderBakingEnd(c) | |||||
} | |||||
func NewOrderSortingEnd(c *gin.Context) { | |||||
svc.NewOrderSortingEnd(c) | |||||
} |
@@ -5,3 +5,9 @@ type OrderSorting struct { | |||||
AdminId string `json:"admin_id"` | AdminId string `json:"admin_id"` | ||||
GoodsInfo []map[string]string `json:"goods_info"` | GoodsInfo []map[string]string `json:"goods_info"` | ||||
} | } | ||||
type NewOrderSorting struct { | |||||
Gid string `json:"gid"` | |||||
SkuId string `json:"sku_id"` | |||||
AdminId string `json:"admin_id"` | |||||
OrderInfo []map[string]string `json:"order_info"` | |||||
} |
@@ -1,9 +1,12 @@ | |||||
package svc | package svc | ||||
import ( | import ( | ||||
"applet/app/admin/md" | |||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/e" | "applet/app/e" | ||||
"applet/app/svc" | |||||
"applet/app/utils" | "applet/app/utils" | ||||
"encoding/json" | |||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
) | ) | ||||
@@ -45,3 +48,78 @@ func Order(c *gin.Context) { | |||||
e.OutSuc(c, list, nil) | e.OutSuc(c, list, nil) | ||||
return | return | ||||
} | } | ||||
func StateOrder(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 | |||||
data, _ := db.GetOrderGoodsMakeStockByIpad(eg, args) | |||||
list := make([]map[string]string, 0) | |||||
if data != nil { | |||||
gids := make([]int64, 0) | |||||
for _, v := range *data { | |||||
gids = append(gids, v.Gid) | |||||
} | |||||
goodsMap := db.GetGoodsMore(eg, gids) | |||||
scheme, host, subDomain, moreSubDomain := svc.ImageBucketNew(c) | |||||
var tmpMap interface{} | |||||
for _, v := range *data { | |||||
var tmp = map[string]string{ | |||||
"id": utils.IntToStr(v.Id), | |||||
"gid": utils.Int64ToStr(v.Gid), | |||||
"sku_id": utils.Int64ToStr(v.SkuId), | |||||
"num": "", | |||||
"state_str": "", | |||||
"btn_str": "", | |||||
"goods_title": v.GoodsTitle, | |||||
"goods_img": "", | |||||
"state": "", | |||||
} | |||||
if args["state"] == "1" { | |||||
tmp["num"] = utils.IntToStr(v.WaitMakeNum) | |||||
tmp["state_str"] = "制作中" | |||||
tmp["btn_str"] = "制作完成" | |||||
tmp["state"] = "1" | |||||
} | |||||
if args["state"] == "2" { | |||||
tmp["num"] = utils.IntToStr(v.WaitBakingNum) | |||||
tmp["state_str"] = "烘焙中" | |||||
tmp["btn_str"] = "烘焙完成" | |||||
tmp["state"] = "2" | |||||
} | |||||
if args["state"] == "3" { | |||||
tmp["num"] = utils.IntToStr(v.WaitSortingNum) | |||||
tmp["state_str"] = "分拣中" | |||||
tmp["btn_str"] = "分拣完成" | |||||
tmp["state"] = "3" | |||||
} | |||||
// 商品主图 | |||||
if goodsMap[v.Gid].ImageList != "" { | |||||
utils.Unserialize([]byte(goodsMap[v.Gid].ImageList), &tmpMap) | |||||
var imageListUrlTmp []string | |||||
for _, v := range tmpMap.([]interface{}) { | |||||
imageListUrlTmp = append(imageListUrlTmp, svc.ImageFormatWithBucketNew(scheme, host, subDomain, moreSubDomain, v.(string))) | |||||
} | |||||
if imageListUrlTmp != nil { | |||||
tmp["goods_img"] = imageListUrlTmp[0] | |||||
} | |||||
} | |||||
skuData := make([]md.Sku, 0) | |||||
json.Unmarshal([]byte(v.Sku), &skuData) | |||||
skuStr := "" | |||||
for _, v1 := range skuData { | |||||
if skuStr != "" { | |||||
skuStr += ";" | |||||
} | |||||
skuStr += v1.Value | |||||
} | |||||
tmp["sku_str"] = skuStr | |||||
list = append(list, tmp) | |||||
} | |||||
} | |||||
e.OutSuc(c, list, nil) | |||||
return | |||||
} |
@@ -30,7 +30,6 @@ func OrderMakeEnd(c *gin.Context) { | |||||
args["str"] = "烘焙" | args["str"] = "烘焙" | ||||
commMake(c, args) | commMake(c, args) | ||||
} | } | ||||
func OrderBakingEnd(c *gin.Context) { | func OrderBakingEnd(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 { | ||||
@@ -174,3 +173,129 @@ func commMake(c *gin.Context, args map[string]string) { | |||||
e.OutSuc(c, "success", nil) | e.OutSuc(c, "success", nil) | ||||
return | return | ||||
} | } | ||||
func NewOrderMakeEnd(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"] = "烘焙" | |||||
commNewMake(c, args) | |||||
} | |||||
func NewOrderBakingEnd(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"] = "烘焙" | |||||
commNewMake(c, args) | |||||
} | |||||
func NewOrderSortingEnd(c *gin.Context) { | |||||
var args md.NewOrderSorting | |||||
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() | |||||
//修改制作记录 | |||||
for _, v := range args.OrderInfo { | |||||
record := db.GetOrderGoods(sess, v["oid"], args.Gid, args.SkuId) | |||||
record.SuccessNum = utils.StrToInt(v["num"]) | |||||
if utils.StrToInt(v["num"]) == record.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(), | |||||
RecordId: record.Id, | |||||
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 | |||||
} | |||||
} | |||||
sess.Commit() | |||||
e.OutSuc(c, "success", nil) | |||||
return | |||||
} | |||||
func commNewMake(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.GetOrderGoodsMakeStock(sess, utils.StrToInt64(args["gid"]), utils.StrToInt64(args["sku_id"])) | |||||
if orderGoods == nil { | |||||
sess.Rollback() | |||||
e.OutErr(c, 400, e.NewErr(400, "订单查找失败,请重试")) | |||||
return | |||||
} | |||||
WaitMakeNum := orderGoods.WaitMakeNum | |||||
if state == 2 { //制作完成 | |||||
orderGoods.WaitMakeNum -= utils.StrToInt(args["num"]) | |||||
orderGoods.WaitBakingNum += utils.StrToInt(args["num"]) | |||||
if orderGoods.WaitMakeNum < 0 { | |||||
orderGoods.WaitMakeNum = 0 | |||||
} | |||||
} | |||||
if state == 3 { //烘焙完成 | |||||
WaitMakeNum = orderGoods.WaitBakingNum | |||||
orderGoods.WaitBakingNum -= utils.StrToInt(args["num"]) | |||||
orderGoods.WaitSortingNum += utils.StrToInt(args["num"]) | |||||
if orderGoods.WaitBakingNum < 0 { | |||||
orderGoods.WaitBakingNum = 0 | |||||
} | |||||
} | |||||
_, err := sess.Where("id=?", orderGoods.Id).Cols("wait_make_num,wait_baking_num,wait_sorting_num").Update(orderGoods) | |||||
if err != nil { | |||||
sess.Rollback() | |||||
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试")) | |||||
return | |||||
} | |||||
//写入流程记录 | |||||
var recordFlow = &model.OrderGoodsDoingFlow{ | |||||
Num: WaitMakeNum, | |||||
State: state, | |||||
Memo: args["memo"], | |||||
SuccessNum: utils.StrToInt(args["num"]), | |||||
Time: time.Now(), | |||||
RecordId: orderGoods.Id, | |||||
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 | |||||
} | |||||
sess.Commit() | |||||
e.OutSuc(c, "success", nil) | |||||
return | |||||
} |
@@ -18,4 +18,10 @@ func BigDataInit(r *gin.RouterGroup) { | |||||
func rData(r *gin.RouterGroup) { | func rData(r *gin.RouterGroup) { | ||||
r.GET("/leftData", hdl.LeftData) //左侧数据 | r.GET("/leftData", hdl.LeftData) //左侧数据 | ||||
r.POST("/rightData", hdl.RightData) //右侧数据 | r.POST("/rightData", hdl.RightData) //右侧数据 | ||||
r.GET("/making_data", hdl.MakingData) //制作区数据 | |||||
r.GET("/baking_data", hdl.BakingData) //烘焙区数据 | |||||
r.GET("/sorting_data", hdl.SortingData) //分拣区数据 | |||||
r.GET("/new_order_notice", hdl.NewOrderNotice) //新订单提醒 | |||||
} | } |
@@ -8,15 +8,18 @@ import ( | |||||
func IpadInit(r *gin.RouterGroup) { | func IpadInit(r *gin.RouterGroup) { | ||||
r.POST("/login", hdl.Login) | r.POST("/login", hdl.Login) | ||||
r.Use(mw.Auth) //检测登录状态 | |||||
r.GET("order/cate", hdl.OrderCate) //订单类目 | |||||
r.POST("order/list", hdl.Order) //订单 | |||||
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.POST("order/make/end", hdl.OrderMakeEnd) //订单制作完成 | |||||
r.POST("order/baking/end", hdl.OrderBakingEnd) //订单烘焙完成 | |||||
r.POST("order/sorting/end", hdl.OrderSortingEnd) //订单分拣完成 | |||||
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.POST("order/make/end", hdl.NewOrderMakeEnd) //订单制作完成 | |||||
r.POST("order/baking/end", hdl.NewOrderBakingEnd) //订单烘焙完成 | |||||
r.POST("order/sorting/end", hdl.NewOrderSortingEnd) //订单分拣完成 | |||||
r.POST("order/goods/sorting_list", hdl.SortingOrderGoods) //订单商品 | |||||
} | } |