@@ -60,10 +60,7 @@ func OrderList(c *gin.Context) { | |||||
} | } | ||||
} | } | ||||
state := []map[string]string{ | state := []map[string]string{ | ||||
{"name": "待制作", "value": "0"}, | |||||
{"name": "制作中", "value": "1"}, | {"name": "制作中", "value": "1"}, | ||||
{"name": "烘焙中", "value": "2"}, | |||||
{"name": "分拣中", "value": "3"}, | |||||
{"name": "已完成", "value": "4"}, | {"name": "已完成", "value": "4"}, | ||||
{"name": "已取消", "value": "5"}, | {"name": "已取消", "value": "5"}, | ||||
} | } | ||||
@@ -264,8 +261,7 @@ func OrderTotal(c *gin.Context) { | |||||
for _, v := range nativeString { | for _, v := range nativeString { | ||||
res = append(res, "订单总金额(元):"+v["amount"]) | res = append(res, "订单总金额(元):"+v["amount"]) | ||||
res = append(res, "总订单数量:"+v["alls"]) | res = append(res, "总订单数量:"+v["alls"]) | ||||
res = append(res, "待制作订单数:"+v["wait_do"]) | |||||
res = append(res, "待烘焙订单数:"+v["dos"]) | |||||
res = append(res, "制作中订单数:"+v["dos"]) | |||||
res = append(res, "已完成订单数:"+v["success"]) | res = append(res, "已完成订单数:"+v["success"]) | ||||
res = append(res, "已取消订单数:"+v["cancel"]) | res = append(res, "已取消订单数:"+v["cancel"]) | ||||
} | } | ||||
@@ -384,10 +380,12 @@ func OrderDetail(c *gin.Context) { | |||||
"goods_id": utils.Int64ToStr(v.GoodsId), | "goods_id": utils.Int64ToStr(v.GoodsId), | ||||
"num": utils.IntToStr(v.Num), | "num": utils.IntToStr(v.Num), | ||||
"amount": utils.Float64ToStr(utils.StrToFloat64(v.Price) * float64(v.Num)), | "amount": utils.Float64ToStr(utils.StrToFloat64(v.Price) * float64(v.Num)), | ||||
"price": utils.StrToFloat64(v.Price), | |||||
"sku_str": "", | "sku_str": "", | ||||
"spe": "", | "spe": "", | ||||
"sku_list": skuList, | "sku_list": skuList, | ||||
"goods_title": v.GoodsTitle, | "goods_title": v.GoodsTitle, | ||||
"memo": v.DeductMemo, | |||||
} | } | ||||
skuData := make([]md.Sku, 0) | skuData := make([]md.Sku, 0) | ||||
@@ -492,6 +490,7 @@ func OrderOutput(c *gin.Context) { | |||||
} | } | ||||
for _, vv := range orderGoods { | for _, vv := range orderGoods { | ||||
data[enterpriseName][v.Oid]["date"] = v.CreateAt.Format("2006-01-02") | 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]["goods_name"] = vv.GoodsTitle | ||||
skuData := make([]md.Sku, 0) | skuData := make([]md.Sku, 0) | ||||
json.Unmarshal([]byte(vv.Sku), &skuData) | json.Unmarshal([]byte(vv.Sku), &skuData) | ||||
@@ -634,10 +633,10 @@ func OrderEditNum(c *gin.Context) { | |||||
e.OutErr(c, 400, e.NewErr(400, "订单已取消,不能修改")) | e.OutErr(c, 400, e.NewErr(400, "订单已取消,不能修改")) | ||||
return | return | ||||
} | } | ||||
if order.State > 0 { | |||||
e.OutErr(c, 400, e.NewErr(400, "订单制作中,不能修改")) | |||||
return | |||||
} | |||||
//if order.State > 0 { | |||||
// e.OutErr(c, 400, e.NewErr(400, "订单制作中,不能修改")) | |||||
// return | |||||
//} | |||||
sess := eg.NewSession() | sess := eg.NewSession() | ||||
defer sess.Close() | defer sess.Close() | ||||
sess.Begin() | sess.Begin() | ||||
@@ -645,6 +644,25 @@ func OrderEditNum(c *gin.Context) { | |||||
orderGoods := db.GetOrderGoodsByIdSess(sess, args["id"]) | orderGoods := db.GetOrderGoodsByIdSess(sess, args["id"]) | ||||
isHasSku := 0 | isHasSku := 0 | ||||
if orderGoods.SkuId != utils.StrToInt64(args["sku_id"]) { | if orderGoods.SkuId != utils.StrToInt64(args["sku_id"]) { | ||||
//判断有没有的扣 | |||||
all := db.GetOrderGoodsMakeStockAll(sess, orderGoods.GoodsId, orderGoods.SkuId) | |||||
if all == nil { | |||||
sess.Rollback() | |||||
e.OutErr(c, 400, e.NewErr(400, "修改失败")) | |||||
return | |||||
} | |||||
if all.WaitMakeNum < orderGoods.Num { | |||||
sess.Rollback() | |||||
e.OutErr(c, 400, e.NewErr(400, "订单已经在制作,取消失败")) | |||||
return | |||||
} | |||||
all.WaitBakingNum -= orderGoods.Num | |||||
_, err := sess.Where("id=?", all.Id).Cols("wait_baking_num").Update(all) | |||||
if err != nil { | |||||
sess.Rollback() | |||||
e.OutErr(c, 400, e.NewErr(400, "修改失败")) | |||||
return | |||||
} | |||||
orderGoodsSku := db.GetOrderGoodsBySkuIdSess(sess, args["oid"], args["sku_id"]) | orderGoodsSku := db.GetOrderGoodsBySkuIdSess(sess, args["oid"], args["sku_id"]) | ||||
if orderGoodsSku != nil { | if orderGoodsSku != nil { | ||||
isHasSku = 1 | isHasSku = 1 | ||||
@@ -664,14 +682,24 @@ func OrderEditNum(c *gin.Context) { | |||||
sqlSecond = fmt.Sprintf(sqlSecond, args["num"], orderGoodsSku.GoodsId) | sqlSecond = fmt.Sprintf(sqlSecond, args["num"], orderGoodsSku.GoodsId) | ||||
db.QueryNativeStringSess(sess, sqlSecond) | db.QueryNativeStringSess(sess, sqlSecond) | ||||
//重新计算价格 | //重新计算价格 | ||||
tmp := orderGoodsSku | |||||
orderGoodsSku.Num += utils.StrToInt(args["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)) | order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + utils.StrToFloat64(args["num"])*utils.StrToFloat64(orderGoodsSku.Price)) | ||||
_, err = sess.Where("id=?", orderGoodsSku.Id).Cols("num").Update(orderGoodsSku) | |||||
orderGoodsSku.DeductMemo = args["memo"] | |||||
_, err = sess.Where("id=?", orderGoodsSku.Id).Cols("num,memo,old_num").Update(orderGoodsSku) | |||||
if err != nil { | if err != nil { | ||||
sess.Rollback() | sess.Rollback() | ||||
e.OutErr(c, 400, e.NewErr(400, "修改失败")) | e.OutErr(c, 400, e.NewErr(400, "修改失败")) | ||||
return | return | ||||
} | } | ||||
tmp.Num = utils.StrToInt(args["num"]) | |||||
err = Total(sess, *tmp) | |||||
if err != nil { | |||||
sess.Rollback() | |||||
e.OutErr(c, 400, e.NewErr(400, "下单失败")) | |||||
return | |||||
} | |||||
} else { | } else { | ||||
orderGoods.SkuId = utils.StrToInt64(args["sku_id"]) | orderGoods.SkuId = utils.StrToInt64(args["sku_id"]) | ||||
_, sku, _ := db.GetMallSkuBySkuId(eg, args["sku_id"], utils.Int64ToStr(orderGoods.GoodsId)) | _, sku, _ := db.GetMallSkuBySkuId(eg, args["sku_id"], utils.Int64ToStr(orderGoods.GoodsId)) | ||||
@@ -682,23 +710,45 @@ func OrderEditNum(c *gin.Context) { | |||||
} | } | ||||
} | } | ||||
if isHasSku == 0 { | if isHasSku == 0 { | ||||
//判断有没有的扣 | |||||
all := db.GetOrderGoodsMakeStockAll(sess, orderGoods.GoodsId, orderGoods.SkuId) | |||||
if all == nil { | |||||
sess.Rollback() | |||||
e.OutErr(c, 400, e.NewErr(400, "修改失败")) | |||||
return | |||||
} | |||||
num := utils.StrToInt(args["num"]) - orderGoods.Num | num := utils.StrToInt(args["num"]) - orderGoods.Num | ||||
if num < 0 { //少要了 就总金额 减少 | if num < 0 { //少要了 就总金额 减少 | ||||
if all.WaitMakeNum < orderGoods.Num { | |||||
sess.Rollback() | |||||
e.OutErr(c, 400, e.NewErr(400, "订单已经在制作,取消失败")) | |||||
return | |||||
} | |||||
num = orderGoods.Num - utils.StrToInt(args["num"]) | num = orderGoods.Num - utils.StrToInt(args["num"]) | ||||
all.WaitBakingNum -= orderGoods.Num | |||||
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) - float64(num)*utils.StrToFloat64(orderGoods.Price)) | 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 := `UPDATE goods SET sale=sale-%d WHERE id=%d` | ||||
sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) | sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) | ||||
db.QueryNativeStringSess(sess, sqlSecond) | db.QueryNativeStringSess(sess, sqlSecond) | ||||
} else { | } else { | ||||
all.WaitBakingNum += orderGoods.Num | |||||
order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + float64(num)*utils.StrToFloat64(orderGoods.Price)) | 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 := `UPDATE goods SET sale=sale+%d WHERE id=%d` | ||||
sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) | sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) | ||||
db.QueryNativeStringSess(sess, sqlSecond) | db.QueryNativeStringSess(sess, sqlSecond) | ||||
} | } | ||||
_, err := sess.Where("id=?", all.Id).Cols("wait_baking_num").Update(all) | |||||
if err != nil { | |||||
sess.Rollback() | |||||
e.OutErr(c, 400, e.NewErr(400, "修改失败")) | |||||
return | |||||
} | |||||
orderGoods.OldNum = orderGoods.Num | |||||
orderGoods.Num = utils.StrToInt(args["num"]) | orderGoods.Num = utils.StrToInt(args["num"]) | ||||
_, err := sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku").Update(orderGoods) | |||||
orderGoods.DeductMemo = args["memo"] | |||||
_, err = sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku,memo,old_num").Update(orderGoods) | |||||
if err != nil { | if err != nil { | ||||
sess.Rollback() | sess.Rollback() | ||||
e.OutErr(c, 400, e.NewErr(400, "修改失败")) | e.OutErr(c, 400, e.NewErr(400, "修改失败")) | ||||
@@ -11,6 +11,7 @@ import ( | |||||
"errors" | "errors" | ||||
"fmt" | "fmt" | ||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
"strings" | |||||
"time" | "time" | ||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
@@ -51,6 +52,7 @@ func GoodsPayCreate(c *gin.Context) { | |||||
BuyPhone: req.BuyInfo.Phone, | BuyPhone: req.BuyInfo.Phone, | ||||
Amount: utils.Float64ToStr(amount), | Amount: utils.Float64ToStr(amount), | ||||
State: 1, | State: 1, | ||||
Date: utils.StrToInt(strings.ReplaceAll(req.BuyInfo.Date, "-", "")), | |||||
} | } | ||||
one, err := sess.InsertOne(&order) | one, err := sess.InsertOne(&order) | ||||
if one == 0 || err != nil { | if one == 0 || err != nil { | ||||
@@ -81,6 +83,7 @@ func GoodsPayCreate(c *gin.Context) { | |||||
Price: skuPrice[v.SkuId], | Price: skuPrice[v.SkuId], | ||||
EnterpriseId: utils.StrToInt(req.EnterpriseId), | EnterpriseId: utils.StrToInt(req.EnterpriseId), | ||||
State: 1, | State: 1, | ||||
IsNew: 1, | |||||
} | } | ||||
goodsTotal[tmp.GoodsId] += tmp.Num | goodsTotal[tmp.GoodsId] += tmp.Num | ||||
orderGoods = append(orderGoods, tmp) | orderGoods = append(orderGoods, tmp) | ||||
@@ -20,40 +20,28 @@ func MarkRecord(c *gin.Context) { | |||||
data := make([]map[string]string, 0) | data := make([]map[string]string, 0) | ||||
if list != nil { | if list != nil { | ||||
stateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"} | stateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"} | ||||
enterpriseIds := make([]int, 0) | |||||
adminIds := make([]int, 0) | adminIds := make([]int, 0) | ||||
for _, v := range *list { | for _, v := range *list { | ||||
enterpriseIds = append(enterpriseIds, v.EnterpriseId) | |||||
adminIds = append(adminIds, v.AdminId) | adminIds = append(adminIds, v.AdminId) | ||||
} | } | ||||
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds) | |||||
adminMap := db.GetStaffMore(eg, adminIds) | adminMap := db.GetStaffMore(eg, adminIds) | ||||
for _, v := range *list { | for _, v := range *list { | ||||
enterpriseName := "" | |||||
adminName := "" | adminName := "" | ||||
_, ok := enterpriseMap[v.EnterpriseId] | |||||
if ok { | |||||
enterpriseName = enterpriseMap[v.EnterpriseId].Name | |||||
} | |||||
_, ok1 := adminMap[v.AdminId] | _, ok1 := adminMap[v.AdminId] | ||||
if ok1 { | if ok1 { | ||||
adminName = adminMap[v.AdminId].Name | adminName = adminMap[v.AdminId].Name | ||||
} | } | ||||
var tmp = map[string]string{ | 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) | skuData := make([]md.Sku, 0) | ||||
json.Unmarshal([]byte(v.Sku), &skuData) | json.Unmarshal([]byte(v.Sku), &skuData) | ||||
@@ -68,21 +56,9 @@ func MarkRecord(c *gin.Context) { | |||||
data = append(data, tmp) | 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{}{ | res := map[string]interface{}{ | ||||
"total": total, | |||||
"enterprise": enterpriseData, | |||||
"list": data, | |||||
"total": total, | |||||
"list": data, | |||||
} | } | ||||
e.OutSuc(c, res, nil) | e.OutSuc(c, res, nil) | ||||
return | return | ||||
@@ -1,10 +1,15 @@ | |||||
package hdl | package hdl | ||||
import ( | import ( | ||||
"applet/app/admin/md" | |||||
"applet/app/bigData/svc" | "applet/app/bigData/svc" | ||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/db/model" | |||||
"applet/app/e" | "applet/app/e" | ||||
"applet/app/utils" | |||||
"encoding/json" | |||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
"strings" | |||||
) | ) | ||||
func MakingData(c *gin.Context) { | func MakingData(c *gin.Context) { | ||||
@@ -43,3 +48,50 @@ func NewOrderNotice(c *gin.Context) { | |||||
e.OutSuc(c, res, nil) | e.OutSuc(c, res, nil) | ||||
return | return | ||||
} | } | ||||
func NewOrderInfoNotice(c *gin.Context) { | |||||
var data []model.OrderGoods | |||||
db.Db.Where("is_new=1").Find(&data) | |||||
sysCfgDb := db.SysCfgDb{} | |||||
sysCfgDb.Set() | |||||
cfg, _ := sysCfgDb.SysCfgGetOne("new_order_notice") | |||||
str := "" | |||||
if cfg != nil { | |||||
str = cfg.Val | |||||
} | |||||
skuDatas := make(map[int64]map[string]string, 0) | |||||
for _, v := range data { | |||||
_, ok := skuDatas[v.SkuId] | |||||
if ok == false { | |||||
skuDatas[v.SkuId] = make(map[string]string) | |||||
} | |||||
skuDatas[v.SkuId]["goods_title"] = v.GoodsTitle | |||||
skuDatas[v.SkuId]["sku"] = v.Sku | |||||
skuDatas[v.SkuId]["count"] = utils.IntToStr(utils.StrToInt(skuDatas[v.SkuId]["count"]) + v.Num) | |||||
} | |||||
res := make([]map[string]string, 0) | |||||
for _, v := range skuDatas { | |||||
skuData := make([]md.Sku, 0) | |||||
json.Unmarshal([]byte(v["sku"]), &skuData) | |||||
skuStr := "" | |||||
for _, v1 := range skuData { | |||||
if skuStr != "" { | |||||
skuStr += ";" | |||||
} | |||||
skuStr += v1.Value | |||||
} | |||||
tip := str | |||||
tip = strings.ReplaceAll(tip, "[商品名称]", v["goods_title"]) | |||||
tip = strings.ReplaceAll(tip, "[规格]", skuStr) | |||||
tip = strings.ReplaceAll(tip, "[数量]", v["count"]) | |||||
tmp := map[string]string{ | |||||
"str": tip, | |||||
} | |||||
res = append(res, tmp) | |||||
} | |||||
for _, v := range data { | |||||
v.IsNew = 0 | |||||
db.Db.Where("id=?", v.Id).Cols("is_new").Update(&v) | |||||
} | |||||
e.OutSuc(c, res, nil) | |||||
return | |||||
} |
@@ -300,3 +300,16 @@ func GetGoodsMore(engine *xorm.Engine, gids []int64) map[int64]model.Goods { | |||||
} | } | ||||
return skuMap | 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 | |||||
} |
@@ -6,12 +6,12 @@ import ( | |||||
"xorm.io/xorm" | "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"] != "" { | if param["admin_name"] != "" { | ||||
var data []model.Admin | var data []model.Admin | ||||
eg.Where("memo like ?", "%"+param["admin_name"]+"%") | |||||
eg.Where("memo like ?", "%"+param["admin_name"]+"%").Find(&data) | |||||
ids := []int{-1} | ids := []int{-1} | ||||
for _, v := range data { | for _, v := range data { | ||||
ids = append(ids, v.AdmId) | ids = append(ids, v.AdmId) | ||||
@@ -20,16 +20,13 @@ func GetOrderGoodsDoingList(eg *xorm.Engine, param map[string]string) (*[]model. | |||||
} | } | ||||
if param["enterprise_name"] != "" { | if param["enterprise_name"] != "" { | ||||
var data []model.Enterprise | var data []model.Enterprise | ||||
eg.Where("name like ?", "%"+param["enterprise_name"]+"%") | |||||
eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&data) | |||||
ids := []int{-1} | ids := []int{-1} | ||||
for _, v := range data { | for _, v := range data { | ||||
ids = append(ids, v.Id) | ids = append(ids, v.Id) | ||||
} | } | ||||
sess.In("enterprise_id", ids) | sess.In("enterprise_id", ids) | ||||
} | } | ||||
if param["oid"] != "" { | |||||
sess.And("oid like ?", "%"+param["oid"]+"%") | |||||
} | |||||
if param["state"] != "" { | if param["state"] != "" { | ||||
sess.And("state =?", param["state"]) | sess.And("state =?", param["state"]) | ||||
} | } | ||||
@@ -60,6 +60,10 @@ func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int | |||||
if param["end_at"] != "" { | if param["end_at"] != "" { | ||||
sess.And("create_at <= ?", param["end_at"]) | sess.And("create_at <= ?", param["end_at"]) | ||||
} | } | ||||
if param["date"] != "" { | |||||
param["date"] = strings.ReplaceAll(param["date"], "-", "") | |||||
sess.And("date = ?", param["date"]) | |||||
} | |||||
if param["enterprise_name"] != "" { | if param["enterprise_name"] != "" { | ||||
var enterprise []model.Enterprise | var enterprise []model.Enterprise | ||||
eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise) | eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise) | ||||
@@ -142,6 +146,10 @@ func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order | |||||
if param["end_at"] != "" { | if param["end_at"] != "" { | ||||
sess.And("create_at <= ?", param["end_at"]) | sess.And("create_at <= ?", param["end_at"]) | ||||
} | } | ||||
if param["date"] != "" { | |||||
param["date"] = strings.ReplaceAll(param["date"], "-", "") | |||||
sess.And("date = ?", param["date"]) | |||||
} | |||||
if param["enterprise_name"] != "" { | if param["enterprise_name"] != "" { | ||||
var enterprise []model.Enterprise | var enterprise []model.Enterprise | ||||
eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise) | eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise) | ||||
@@ -11,6 +11,7 @@ type Order struct { | |||||
CreateAt time.Time `json:"create_at" xorm:"comment('下单时间') DATETIME"` | CreateAt time.Time `json:"create_at" xorm:"comment('下单时间') DATETIME"` | ||||
CancelAt time.Time `json:"cancel_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)"` | EnterpriseId int `json:"enterprise_id" xorm:"default 0 comment('校企id') INT(11)"` | ||||
Date int `json:"date" xorm:"default 0 comment('校企id') INT(11)"` | |||||
BuyInfo string `json:"buy_info" xorm:"comment('购买人信息 json') VARCHAR(2000)"` | BuyInfo string `json:"buy_info" xorm:"comment('购买人信息 json') VARCHAR(2000)"` | ||||
Amount string `json:"amount" xorm:"default 0.00 comment('付款金额') DECIMAL(20,2)"` | Amount string `json:"amount" xorm:"default 0.00 comment('付款金额') DECIMAL(20,2)"` | ||||
BuyPhone string `json:"buy_phone" xorm:"comment('购买人手机') VARCHAR(20)"` | BuyPhone string `json:"buy_phone" xorm:"comment('购买人手机') VARCHAR(20)"` | ||||
@@ -8,11 +8,14 @@ type OrderGoods struct { | |||||
GoodsId int64 `json:"goods_id" xorm:"default 0 comment('商品id') BIGINT(20)"` | GoodsId int64 `json:"goods_id" xorm:"default 0 comment('商品id') BIGINT(20)"` | ||||
SkuId int64 `json:"sku_id" xorm:"default 0 comment('sku') BIGINT(20)"` | SkuId int64 `json:"sku_id" xorm:"default 0 comment('sku') BIGINT(20)"` | ||||
Num int `json:"num" xorm:"default 0 comment('购买数量') INT(11)"` | Num int `json:"num" xorm:"default 0 comment('购买数量') INT(11)"` | ||||
OldNum int `json:"old_num" xorm:"default 0 comment('购买数量') INT(11)"` | |||||
IsNew int `json:"is_new" xorm:"default 0 comment('购买数量') INT(11)"` | |||||
Price string `json:"price" xorm:"default 0.00 comment('单价') DECIMAL(20,2)"` | 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)"` | State int `json:"state" xorm:"default 0 comment('状态 0待制作 1制作中 2烘焙中 3分拣中 4已完成 ') INT(11)"` | ||||
SkuCode string `json:"sku_code" xorm:"VARCHAR(255)"` | 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)"` | 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)"` | SuccessNum int `json:"success_num" xorm:"comment('完成数量') INT(11)"` | ||||
Memo string `json:"memo" xorm:"comment('制作完成备注') VARCHAR(255)"` | Memo string `json:"memo" xorm:"comment('制作完成备注') VARCHAR(255)"` | ||||
Time time.Time `json:"time" xorm:"DATETIME"` | Time time.Time `json:"time" xorm:"DATETIME"` | ||||
@@ -15,4 +15,6 @@ type OrderGoodsDoingFlow struct { | |||||
SkuId int64 `json:"sku_id" xorm:"BIGINT(20)"` | SkuId int64 `json:"sku_id" xorm:"BIGINT(20)"` | ||||
SkuCode string `json:"sku_code" xorm:"VARCHAR(255)"` | SkuCode string `json:"sku_code" xorm:"VARCHAR(255)"` | ||||
AdminId int `json:"admin_id" xorm:"default 0 comment('admin 的id') INT(11)"` | 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)"` | |||||
} | } |
@@ -5,18 +5,6 @@ import ( | |||||
"github.com/gin-gonic/gin" | "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) { | func NewOrderMakeEnd(c *gin.Context) { | ||||
svc.NewOrderMakeEnd(c) | svc.NewOrderMakeEnd(c) | ||||
} | } | ||||
@@ -10,173 +10,6 @@ import ( | |||||
"time" | "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) { | func NewOrderMakeEnd(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 { | ||||
@@ -247,6 +80,8 @@ func NewOrderSortingEnd(c *gin.Context) { | |||||
SkuId: record.SkuId, | SkuId: record.SkuId, | ||||
SkuCode: record.SkuCode, | SkuCode: record.SkuCode, | ||||
AdminId: utils.StrToInt(args.AdminId), | AdminId: utils.StrToInt(args.AdminId), | ||||
GoodsTitle: record.GoodsTitle, | |||||
Sku: record.Sku, | |||||
} | } | ||||
one, err := sess.InsertOne(recordFlow) | one, err := sess.InsertOne(recordFlow) | ||||
if one == 0 || err != nil { | if one == 0 || err != nil { | ||||
@@ -309,6 +144,7 @@ func commNewMake(c *gin.Context, args map[string]string) { | |||||
return | return | ||||
} | } | ||||
//写入流程记录 | //写入流程记录 | ||||
var recordFlow = &model.OrderGoodsDoingFlow{ | var recordFlow = &model.OrderGoodsDoingFlow{ | ||||
Num: WaitMakeNum, | Num: WaitMakeNum, | ||||
State: state, | State: state, | ||||
@@ -319,6 +155,8 @@ func commNewMake(c *gin.Context, args map[string]string) { | |||||
SkuId: orderGoods.SkuId, | SkuId: orderGoods.SkuId, | ||||
SkuCode: orderGoods.SkuCode, | SkuCode: orderGoods.SkuCode, | ||||
AdminId: utils.StrToInt(args["admin_id"]), | AdminId: utils.StrToInt(args["admin_id"]), | ||||
GoodsTitle: orderGoods.GoodsTitle, | |||||
Sku: orderGoods.Sku, | |||||
} | } | ||||
one, err := sess.InsertOne(recordFlow) | one, err := sess.InsertOne(recordFlow) | ||||
if one == 0 || err != nil { | 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, "操作失败,请重试")) | e.OutErr(c, 400, e.NewErr(400, "操作失败,请重试")) | ||||
return | return | ||||
} | } | ||||
sess.Commit() | sess.Commit() | ||||
e.OutSuc(c, "success", nil) | e.OutSuc(c, "success", nil) | ||||
return | return | ||||
@@ -19,9 +19,10 @@ 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) //新订单提醒 | |||||
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) //新订单提醒 | |||||
r.GET("/new_order_info_notice", hdl.NewOrderInfoNotice) //新订单提醒 | |||||
} | } |
@@ -8,14 +8,13 @@ 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.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/make/end", hdl.NewOrderMakeEnd) //订单制作完成 | ||||
r.POST("order/baking/end", hdl.NewOrderBakingEnd) //订单烘焙完成 | r.POST("order/baking/end", hdl.NewOrderBakingEnd) //订单烘焙完成 | ||||