|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617 |
- package svc
-
- import (
- md2 "applet/app/admin/md"
- "applet/app/admin/svc/order"
- "applet/app/bigData/md"
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/utils"
- "encoding/json"
- "fmt"
- "github.com/gin-gonic/gin"
- "strings"
- "time"
- )
-
- func LeftDataForMake() (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
- //var enterprise []model.Enterprise
- //err = engine.Where("1=1").Find(&enterprise)
- //if err != nil {
- // return
- //}
- //var enterpriseMap = map[int]model.Enterprise{}
- //for _, v := range enterprise {
- // enterpriseMap[v.Id] = v
- //}
- //
- ////1、查找当天的 order 数据(大于 待制作)
- //var orders []model.Order
- //err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 0).Find(&orders)
- //if err != nil {
- // return
- //}
- //var oIds []int64
- //for _, v := range orders {
- // oIds = append(oIds, v.Oid)
- //}
- //
- ////2、查找对应的订单产品记录
- //var orderGoods []model.OrderGoods
- //err = engine.In("oid", oIds).Find(&orderGoods)
- //if err != nil {
- // return
- //}
- //var orderGoodsMap = map[int64][]model.OrderGoods{}
- //var records []int
- //for _, v := range orderGoods {
- // if orderGoodsMap[v.Oid] == nil {
- // orderGoodsMap[v.Oid] = []model.OrderGoods{}
- // }
- // orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v)
- // 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、整合数据
- //orderStateArr := []string{"待制作", "制作中", "烘焙完成", "分拣完成", "已取消"}
- //for _, v := range orders {
- // var list []md.LeftDataForMakeList
- // if len(orderGoodsMap[v.Oid]) > 0 {
- // orderGoodsStateArr := []string{"待制作", "制作中"}
- // for _, vv := range orderGoodsMap[v.Oid] {
- // skuData := make([]md2.Sku, 0)
- // json.Unmarshal([]byte(vv.Sku), &skuData)
- // skuStr := ""
- // for _, v1 := range skuData {
- // if skuStr != "" {
- // skuStr += ";"
- // }
- // skuStr += v1.Value
- // }
- // var stateZh = "已完成"
- // if vv.State <= 1 {
- // stateZh = orderGoodsStateArr[vv.State]
- // }
- // list = append(list, md.LeftDataForMakeList{
- // GoodsName: vv.GoodsTitle,
- // Sku: skuStr,
- // Num: vv.Num,
- // SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum,
- // StateZh: stateZh,
- // State: vv.State,
- // })
- // }
- //
- // resp = append(resp, md.LeftDataForMakeResp{
- // EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
- // EnterpriseId: v.EnterpriseId,
- // StateZh: orderStateArr[v.State],
- // State: v.State,
- // List: list,
- // })
- // }
- //}
- return
- }
-
- func LeftDataForBaking() (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
- //var enterprise []model.Enterprise
- //err = engine.Where("1=1").Find(&enterprise)
- //if err != nil {
- // return
- //}
- //var enterpriseMap = map[int]model.Enterprise{}
- //for _, v := range enterprise {
- // enterpriseMap[v.Id] = v
- //}
- //
- ////1、查找当天的 order 数据(大于 待制作)
- //var orders []model.Order
- //err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 1).Find(&orders)
- //if err != nil {
- // return
- //}
- //var oIds []int64
- //for _, v := range orders {
- // oIds = append(oIds, v.Oid)
- //}
- //
- ////2、查找对应的订单产品记录
- //var orderGoods []model.OrderGoods
- //err = engine.In("oid", oIds).Find(&orderGoods)
- //if err != nil {
- // return
- //}
- //var orderGoodsMap = map[int64][]model.OrderGoods{}
- //var records []int
- //for _, v := range orderGoods {
- // if orderGoodsMap[v.Oid] == nil {
- // orderGoodsMap[v.Oid] = []model.OrderGoods{}
- // }
- // orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v)
- // 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、整合数据
- //orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
- //for _, v := range orders {
- // var list []md.LeftDataForMakeList
- // if len(orderGoodsMap[v.Oid]) > 0 {
- // for _, vv := range orderGoodsMap[v.Oid] {
- // skuData := make([]md2.Sku, 0)
- // json.Unmarshal([]byte(vv.Sku), &skuData)
- // skuStr := ""
- // for _, v1 := range skuData {
- // if skuStr != "" {
- // skuStr += ";"
- // }
- // skuStr += v1.Value
- // }
- // var stateZh = "已完成"
- // if vv.State == 2 {
- // stateZh = "烘焙中"
- // }
- //
- // list = append(list, md.LeftDataForMakeList{
- // GoodsName: vv.GoodsTitle,
- // Sku: skuStr,
- // Num: vv.Num,
- // SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum,
- // StateZh: stateZh,
- // State: vv.State,
- // })
- // }
- //
- // resp = append(resp, md.LeftDataForMakeResp{
- // EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
- // EnterpriseId: v.EnterpriseId,
- // StateZh: orderStateArr[v.State],
- // State: v.State,
- // List: list,
- // })
- // }
- //}
- return
- }
-
- func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) {
- engine := db.Db
- var enterprise []model.Enterprise
- err = engine.Where("1=1").Find(&enterprise)
- if err != nil {
- return
- }
- var enterpriseMap = map[int]model.Enterprise{}
- for _, v := range enterprise {
- enterpriseMap[v.Id] = v
- }
-
- //1、查找不等于4 5
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- now := CommDate()
-
- var orders []model.Order
- err = engine.Where(" state != 4 and state != 5 and make_date=?", now).Find(&orders)
- if err != nil {
- return
- }
- var oIds []int64
- for _, v := range orders {
- v1 := order.JudgePackageOrdOrdState(&v)
- if v1.State == 4 || v1.State == 5 {
- continue
- }
- oIds = append(oIds, v.Oid)
- }
-
- //2、查找对应的订单产品记录
- var orderGoods []model.OrderGoods
- err = engine.In("oid", oIds).Find(&orderGoods)
- if err != nil {
- return
- }
- var orderGoodsMap = map[int64][]model.OrderGoods{}
- var records []int
- for _, v := range orderGoods {
- if orderGoodsMap[v.Oid] == nil {
- orderGoodsMap[v.Oid] = []model.OrderGoods{}
- }
- orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v)
- records = append(records, v.Id)
- }
-
- //4、整合数据
- orderStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成", "已取消"}
- for _, v := range orders {
- var list []md.LeftDataForMakeList
- if len(orderGoodsMap[v.Oid]) > 0 {
- orderGoodsStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成"}
- for _, vv := range orderGoodsMap[v.Oid] {
- skuData := make([]md2.Sku, 0)
- json.Unmarshal([]byte(vv.Sku), &skuData)
- skuStr := ""
- for _, v1 := range skuData {
- if skuStr != "" {
- skuStr += ";"
- }
- skuStr += v1.Value
- }
- var stateZh = orderGoodsStateArr[vv.State]
- list = append(list, md.LeftDataForMakeList{
- GoodsName: vv.GoodsTitle,
- Sku: skuStr,
- Num: vv.Num,
- SuccessNum: vv.SuccessNum,
- StateZh: stateZh,
- State: vv.State,
- })
- }
- resp = append(resp, md.LeftDataForMakeResp{
- EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
- EnterpriseId: v.EnterpriseId,
- StateZh: orderStateArr[v.State],
- State: v.State,
- List: list,
- })
- }
- }
- return
- }
-
- func RightDataForMake(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, 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
- var enterprise []model.Enterprise
- err = engine.Where("1=1").Find(&enterprise)
- if err != nil {
- return
- }
- var enterpriseMap = map[int]model.Enterprise{}
- for _, v := range enterprise {
- enterpriseMap[v.Id] = v
- }
-
- //1、查找当天的 order 数据(大于 待制作)
- var orders []model.Order
- total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 0).
- Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
- if err != nil {
- return
- }
- var oIds []int64
- for _, v := range orders {
- oIds = append(oIds, v.Oid)
- }
-
- //2、整合数据
- orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
- for _, v := range orders {
- resp = append(resp, md.RightDataForMakeResp{
- EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
- EnterpriseId: v.EnterpriseId,
- StateZh: orderStateArr[v.State],
- State: v.State,
- })
- }
- return
- }
-
- func RightDataForBaking(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, 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
- var enterprise []model.Enterprise
- err = engine.Where("1=1").Find(&enterprise)
- if err != nil {
- return
- }
- var enterpriseMap = map[int]model.Enterprise{}
- for _, v := range enterprise {
- enterpriseMap[v.Id] = v
- }
-
- //1、查找当天的 order 数据(大于 待制作)
- var orders []model.Order
- total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 1).
- Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
- if err != nil {
- return
- }
- var oIds []int64
- for _, v := range orders {
- oIds = append(oIds, v.Oid)
- }
-
- //2、整合数据
- orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
- for _, v := range orders {
- resp = append(resp, md.RightDataForMakeResp{
- EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
- EnterpriseId: v.EnterpriseId,
- StateZh: orderStateArr[v.State],
- State: v.State,
- })
- }
- return
- }
-
- func RightDataForSorting(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, 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
- var enterprise []model.Enterprise
- err = engine.Where("1=1").Find(&enterprise)
- if err != nil {
- return
- }
- var enterpriseMap = map[int]model.Enterprise{}
- for _, v := range enterprise {
- enterpriseMap[v.Id] = v
- }
-
- //1、查找当天的 order 数据(大于 待制作)
- var orders []model.Order
- total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 2).
- Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
- if err != nil {
- return
- }
- var oIds []int64
- for _, v := range orders {
- oIds = append(oIds, v.Oid)
- }
-
- //2、整合数据
- orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
- for _, v := range orders {
- resp = append(resp, md.RightDataForMakeResp{
- EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
- EnterpriseId: v.EnterpriseId,
- StateZh: orderStateArr[v.State],
- State: v.State,
- })
- }
- return
- }
-
- func NewSortingCate() []map[string]string {
- engine := db.Db
- res := make([]map[string]string, 0)
- var enterprise []model.Enterprise
- err := engine.Where("1=1").Find(&enterprise)
- if err != nil {
- return res
- }
- var enterpriseMap = map[int]model.Enterprise{}
- for _, v := range enterprise {
- enterpriseMap[v.Id] = v
- }
-
- //1、查找不等于4 5
- now := CommDate()
- var orders []model.Order
- err = engine.Where(" state != 4 and state != 5 and make_date=?", now).Find(&orders)
- if err != nil {
- return res
- }
- ids := make([]string, 0)
- orderStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成", "已取消"}
- for _, v := range orders {
- if utils.InArr(utils.IntToStr(v.EnterpriseId), ids) {
- continue
- }
- tmp := map[string]string{
- "id": utils.IntToStr(v.EnterpriseId),
- "name": enterpriseMap[v.EnterpriseId].Name,
- "state": utils.IntToStr(v.State),
- "state_str": orderStateArr[v.State],
- }
- ids = append(ids, utils.IntToStr(v.EnterpriseId))
- res = append(res, tmp)
- }
- return res
- }
- func NewSortingData(c *gin.Context) []map[string]string {
- res := make([]map[string]string, 0)
- var args map[string]string
- if err := c.ShouldBindJSON(&args); err != nil {
- return res
- }
- engine := db.Db
- var enterprise []model.Enterprise
- err := engine.Where("1=1").Find(&enterprise)
- if err != nil {
- return res
- }
- var enterpriseMap = map[int]model.Enterprise{}
- for _, v := range enterprise {
- enterpriseMap[v.Id] = v
- }
-
- //1、查找不等于4 5
- now := CommDate()
- var orders []model.Order
- err = engine.Where(" state != 4 and state != 5 and make_date=? and enterprise_id=?", now, args["id"]).Find(&orders)
- if err != nil {
- return res
- }
- var oIds []string
- for _, v := range orders {
- v1 := order.JudgePackageOrdOrdState(&v)
- if v1.State == 4 || v1.State == 5 {
- continue
- }
- oIds = append(oIds, utils.Int64ToStr(v.Oid))
- }
- sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku FROM order_goods WHERE oid in (%s) and goods_type=0 GROUP BY enterprise_id,goods_id,sku_id`
- sql = fmt.Sprintf(sql, strings.Join(oIds, ","))
- nativeString, err := db.QueryNativeString(engine, sql)
- for _, v := range nativeString {
- skuData := make([]md2.Sku, 0)
- json.Unmarshal([]byte(v["sku"]), &skuData)
- skuStr := ""
- for _, v1 := range skuData {
- if skuStr != "" {
- skuStr += ";"
- }
- skuStr += v1.Value
- }
- tmp := map[string]string{
- "goods_name": v["goods_title"],
- "sku": skuStr,
- "num": v["num"],
- "success_num": v["success_num"],
- "state": "1",
- "state_str": "待分拣",
- }
- if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) {
- tmp["state"] = "4"
- tmp["stare_str"] = "分拣完成"
- }
- res = append(res, tmp)
- }
- return res
- }
- func NewSortingGoodsCate() []map[string]string {
- res := make([]map[string]string, 0)
-
- engine := db.Db
- //1、查找不等于4 5
- now := CommDate()
- var orders []model.Order
- err := engine.Where(" state != 4 and state != 5 and make_date=? ", now).Find(&orders)
- if err != nil {
- return res
- }
- var oIds []string
- for _, v := range orders {
- v1 := order.JudgePackageOrdOrdState(&v)
- if v1.State == 4 || v1.State == 5 {
- continue
- }
- oIds = append(oIds, utils.Int64ToStr(v.Oid))
- }
- sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku,goods_id,sku_id FROM order_goods WHERE oid in (%s) and goods_type=0 and make_date=%s GROUP BY goods_id,sku_id`
- sql = fmt.Sprintf(sql, strings.Join(oIds, ","), now)
- nativeString, err := db.QueryNativeString(engine, sql)
- for _, v := range nativeString {
- skuData := make([]md2.Sku, 0)
- json.Unmarshal([]byte(v["sku"]), &skuData)
- skuStr := ""
- for _, v1 := range skuData {
- if skuStr != "" {
- skuStr += ";"
- }
- skuStr += v1.Value
- }
- tmp := map[string]string{
- "goods_id": v["goods_id"],
- "sku_id": v["sku_id"],
- "goods_name": v["goods_title"],
- "sku": skuStr,
- "num": v["num"],
- "success_num": v["success_num"],
- "state": "1",
- "state_str": "待分拣",
- }
- if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) {
- tmp["state"] = "4"
- tmp["stare_str"] = "分拣完成"
- }
- res = append(res, tmp)
- }
- return res
- }
- func NewSortingGoodsData(arg map[string]string) []map[string]string {
-
- engine := db.Db
- res := make([]map[string]string, 0)
- var enterprise []model.Enterprise
- err := engine.Where("1=1").Find(&enterprise)
- if err != nil {
- return res
- }
- var enterpriseMap = map[int]model.Enterprise{}
- for _, v := range enterprise {
- enterpriseMap[v.Id] = v
- }
- //1、查找不等于4 5
- now := CommDate()
-
- var orders []model.Order
- err = engine.Where(" state != 4 and state != 5 and make_date=? ", now).Find(&orders)
- if err != nil {
- return res
- }
- var oIds []string
- for _, v := range orders {
- v1 := order.JudgePackageOrdOrdState(&v)
- if v1.State == 4 || v1.State == 5 {
- continue
- }
- oIds = append(oIds, utils.Int64ToStr(v.Oid))
- }
- sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku,goods_id,sku_id,enterprise_id FROM order_goods WHERE oid in (%s) and goods_id=%s and goods_type=0 and sku_id=%s and make_date=%s GROUP BY enterprise_id`
- sql = fmt.Sprintf(sql, strings.Join(oIds, ","), arg["goods_id"], arg["sku_id"], now)
- nativeString, err := db.QueryNativeString(engine, sql)
- for _, v := range nativeString {
- skuData := make([]md2.Sku, 0)
- json.Unmarshal([]byte(v["sku"]), &skuData)
- skuStr := ""
- for _, v1 := range skuData {
- if skuStr != "" {
- skuStr += ";"
- }
- skuStr += v1.Value
- }
- tmp := map[string]string{
- "enterprise_name": enterpriseMap[utils.StrToInt(v["enterprise_id"])].Name,
- "num": v["num"],
- "success_num": v["success_num"],
- "state": "1",
- "state_str": "待分拣",
- }
- if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) {
- tmp["state"] = "4"
- tmp["stare_str"] = "分拣完成"
- }
- res = append(res, tmp)
- }
- return res
-
- }
|