|
- package hdl
-
- import (
- "applet/app/admin/md"
- "applet/app/bigData/svc"
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/e"
- "applet/app/utils"
- "encoding/json"
- "github.com/gin-gonic/gin"
- "strings"
- )
-
- 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
- cfg.Val = "0"
- db.Db.Where("`key`=?", "has_new_order").Update(cfg)
- }
- e.OutSuc(c, res, nil)
- 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
- }
|