|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- package svc
-
- import (
- md2 "applet/app/admin/md"
- "applet/app/bigData/md"
- "applet/app/db"
- "applet/app/db/model"
- "encoding/json"
- "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
- var orders []model.Order
- err = engine.Where(" state != 4 and state != 5").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)
- }
-
- //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
- }
|