|
- 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
- }
|