SOURCE

const saleList = [{ "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "e126071d451c4774bf938a71bfe7fd20", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "1023", "offLineSLSRate": "0.004", "goal": "1500", "customerNum": "14", "storeCustomerRate": "0.010", "singleFlowerB": "0", "saleNum": "27", "singleFlowerA": "24", "pkgsFee": "0", "offLineCustomerRate": "0.012", "mixFlower": "0", "potA": "3", "potRate": "0.114", "goalRate": "0.682", "potB": "0", "storeSLSRate": "0.003", "pricePerCus": "73", "saleDate": "1683475200000", "storeSLS": "318701", "offLineCustomer": "1129", "offLineSLS": "286667", "storeCustomer": "1374" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "f8194fb008504c4aaa0a53267423b860", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "1017", "offLineSLSRate": "0.003", "goal": "1800", "customerNum": "15", "storeCustomerRate": "0.011", "singleFlowerB": "0", "saleNum": "26.5", "singleFlowerA": "23", "pkgsFee": "0", "offLineCustomerRate": "0.013", "mixFlower": "0", "potA": "2", "potRate": "0.134", "goalRate": "0.565", "potB": "1", "storeSLSRate": "0.003", "pricePerCus": "68", "saleDate": "1683561600000", "storeSLS": "345373", "offLineCustomer": "1135", "offLineSLS": "310336", "storeCustomer": "1370" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "958645ba17074cce9fc44fe85729df38", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "1431", "offLineSLSRate": "0.004", "goal": "1600", "customerNum": "27", "storeCustomerRate": "0.018", "singleFlowerB": "0", "saleNum": "37", "singleFlowerA": "33", "pkgsFee": "0", "offLineCustomerRate": "0.021", "mixFlower": "0", "potA": "4", "potRate": "0.109", "goalRate": "0.894", "potB": "0", "storeSLSRate": "0.004", "pricePerCus": "53", "saleDate": "1683648000000", "storeSLS": "383916", "offLineCustomer": "1313", "offLineSLS": "351563", "storeCustomer": "1521" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "2056ec2df8c245f1bcca2d88fc2f60bb", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "1647", "offLineSLSRate": "0.005", "goal": "1500", "customerNum": "27", "storeCustomerRate": "0.019", "singleFlowerB": "0", "saleNum": "42.5", "singleFlowerA": "32", "pkgsFee": "2", "offLineCustomerRate": "0.021", "mixFlower": "0", "potA": "9", "potRate": "0.248", "goalRate": "1.098", "potB": "1", "storeSLSRate": "0.004", "pricePerCus": "61", "saleDate": "1683734400000", "storeSLS": "376871", "offLineCustomer": "1273", "offLineSLS": "362322", "storeCustomer": "1421" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "4797a0942c624318968f5af6d397f9c9", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "3280", "offLineSLSRate": "0.009", "goal": "2500", "customerNum": "54", "storeCustomerRate": "0.034", "singleFlowerB": "0", "saleNum": "86", "singleFlowerA": "78", "pkgsFee": "0", "offLineCustomerRate": "0.037", "mixFlower": "0", "potA": "2", "potRate": "0.095", "goalRate": "1.312", "potB": "4", "storeSLSRate": "0.008", "pricePerCus": "61", "saleDate": "1683820800000", "storeSLS": "412177", "offLineCustomer": "1476", "offLineSLS": "380201", "storeCustomer": "1579" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "3b0983a25c4943e29eee48f1d5fded67", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "5345", "offLineSLSRate": "0.007", "goal": "5000", "customerNum": "74", "storeCustomerRate": "0.024", "singleFlowerB": "0", "saleNum": "140.5", "singleFlowerA": "131", "pkgsFee": "0", "offLineCustomerRate": "0.025", "mixFlower": "0", "potA": "8", "potRate": "0.069", "goalRate": "1.069", "potB": "1", "storeSLSRate": "0.007", "pricePerCus": "72", "saleDate": "1683907200000", "storeSLS": "819351", "offLineCustomer": "2954", "offLineSLS": "803697", "storeCustomer": "3057" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "83807c32058f484191c6e49bcdd368ac", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "8434", "offLineSLSRate": "0.011", "goal": "11000", "customerNum": "136", "storeCustomerRate": "0.051", "singleFlowerB": "0", "saleNum": "220", "singleFlowerA": "207", "pkgsFee": "0", "offLineCustomerRate": "0.052", "mixFlower": "0", "potA": "7", "potRate": "0.060", "goalRate": "0.767", "potB": "4", "storeSLSRate": "0.011", "pricePerCus": "62", "saleDate": "1683993600000", "storeSLS": "748005", "offLineCustomer": "2628", "offLineSLS": "737783", "storeCustomer": "2681" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "0fba5f6b80e6410b8d380f6293dda813", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "819", "offLineSLSRate": "0.002", "goal": "1500", "customerNum": "15", "storeCustomerRate": "0.010", "singleFlowerB": "0", "saleNum": "21", "singleFlowerA": "15", "pkgsFee": "0", "offLineCustomerRate": "0.011", "mixFlower": "0", "potA": "6", "potRate": "0.286", "goalRate": "0.546", "potB": "0", "storeSLSRate": "0.002", "pricePerCus": "55", "saleDate": "1684080000000", "storeSLS": "406463", "offLineCustomer": "1370", "offLineSLS": "379731", "storeCustomer": "1572" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "508be8f0870a49838036c8f786b6e397", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "969", "offLineSLSRate": "0.003", "goal": "1800", "customerNum": "20", "storeCustomerRate": "0.014", "singleFlowerB": "0", "saleNum": "25", "singleFlowerA": "23", "pkgsFee": "0", "offLineCustomerRate": "0.017", "mixFlower": "0", "potA": "2", "potRate": "0.080", "goalRate": "0.538", "potB": "0", "storeSLSRate": "0.003", "pricePerCus": "48", "saleDate": "1684166400000", "storeSLS": "333966", "offLineCustomer": "1210", "offLineSLS": "316119", "storeCustomer": "1408" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "b1e76b6efc014518b9fe66ddf881bd06", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "1421", "offLineSLSRate": "0.004", "goal": "1600", "customerNum": "19", "storeCustomerRate": "0.012", "singleFlowerB": "0", "saleNum": "37.5", "singleFlowerA": "32", "pkgsFee": "0", "offLineCustomerRate": "0.014", "mixFlower": "0", "potA": "1", "potRate": "0.150", "goalRate": "0.888", "potB": "3", "storeSLSRate": "0.004", "pricePerCus": "75", "saleDate": "1684252800000", "storeSLS": "394533", "offLineCustomer": "1356", "offLineSLS": "374801", "storeCustomer": "1560" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "33d341c84f82440bb2afeaf094cc23d9", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "1709", "offLineSLSRate": "0.005", "goal": "1500", "customerNum": "22", "storeCustomerRate": "0.014", "singleFlowerB": "0", "saleNum": "45", "singleFlowerA": "43", "pkgsFee": "0", "offLineCustomerRate": "0.016", "mixFlower": "0", "potA": "2", "potRate": "0.046", "goalRate": "1.139", "potB": "0", "storeSLSRate": "0.005", "pricePerCus": "78", "saleDate": "1684339200000", "storeSLS": "370462", "offLineCustomer": "1368", "offLineSLS": "350928", "storeCustomer": "1573" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "5cfbbafbe062433d8584f680a87a6fa7", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "3268", "offLineSLSRate": "0.010", "goal": "6000", "customerNum": "53", "storeCustomerRate": "0.040", "singleFlowerB": "0", "saleNum": "85.5", "singleFlowerA": "78", "pkgsFee": "0", "offLineCustomerRate": "0.043", "mixFlower": "0", "potA": "6", "potRate": "0.089", "goalRate": "0.545", "potB": "1", "storeSLSRate": "0.009", "pricePerCus": "62", "saleDate": "1684425600000", "storeSLS": "356597", "offLineCustomer": "1219", "offLineSLS": "332160", "storeCustomer": "1337" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "28c06799ad86428fa41390278ba51185", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "9745", "offLineSLSRate": "0.013", "goal": "14000", "customerNum": "161", "storeCustomerRate": "0.057", "singleFlowerB": "0", "saleNum": "255", "singleFlowerA": "249", "pkgsFee": "0", "offLineCustomerRate": "0.057", "mixFlower": "0", "potA": "6", "potRate": "0.024", "goalRate": "0.696", "potB": "0", "storeSLSRate": "0.013", "pricePerCus": "61", "saleDate": "1684512000000", "storeSLS": "745553", "offLineCustomer": "2841", "offLineSLS": "742620", "storeCustomer": "2810" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "5b18dddc2a8c48c0b71f50d18fd845d8", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "4159", "offLineSLSRate": "0.007", "goal": "4000", "customerNum": "67", "storeCustomerRate": "0.028", "singleFlowerB": "0", "saleNum": "108.5", "singleFlowerA": "100", "pkgsFee": "2", "offLineCustomerRate": "0.031", "mixFlower": "0", "potA": "7", "potRate": "0.080", "goalRate": "1.040", "potB": "1", "storeSLSRate": "0.006", "pricePerCus": "62", "saleDate": "1684598400000", "storeSLS": "643269", "offLineCustomer": "2156", "offLineSLS": "598825", "storeCustomer": "2383" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "92683a58d9964d36b605aca4641cf524", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "1335", "offLineSLSRate": "0.005", "goal": "1300", "customerNum": "21", "storeCustomerRate": "0.017", "singleFlowerB": "0", "saleNum": "35", "singleFlowerA": "34", "pkgsFee": "0", "offLineCustomerRate": "0.019", "mixFlower": "0", "potA": "1", "potRate": "0.029", "goalRate": "1.027", "potB": "0", "storeSLSRate": "0.004", "pricePerCus": "64", "saleDate": "1684684800000", "storeSLS": "329780", "offLineCustomer": "1088", "offLineSLS": "293371", "storeCustomer": "1235" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "1fc0088d964e427da9724f6386b168bd", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "1386", "offLineSLSRate": "0.005", "goal": "1500", "customerNum": "25", "storeCustomerRate": "0.020", "singleFlowerB": "0", "saleNum": "36", "singleFlowerA": "29", "pkgsFee": "0", "offLineCustomerRate": "0.022", "mixFlower": "0", "potA": "7", "potRate": "0.197", "goalRate": "0.924", "potB": "0", "storeSLSRate": "0.004", "pricePerCus": "55", "saleDate": "1684771200000", "storeSLS": "312298", "offLineCustomer": "1122", "offLineSLS": "284446", "storeCustomer": "1269" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "c1c5a94b30c64a0db509aeaf6c77bcdc", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "918", "offLineSLSRate": "0.004", "goal": "1300", "customerNum": "17", "storeCustomerRate": "0.014", "singleFlowerB": "0", "saleNum": "24", "singleFlowerA": "24", "pkgsFee": "0", "offLineCustomerRate": "0.017", "mixFlower": "0", "potA": "0", "potRate": "0.000", "goalRate": "0.706", "potB": "0", "storeSLSRate": "0.003", "pricePerCus": "54", "saleDate": "1684857600000", "storeSLS": "283106", "offLineCustomer": "1025", "offLineSLS": "257713", "storeCustomer": "1202" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "fccb2630a7a44a29844b7a6f75139b92", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "1600", "offLineSLSRate": "0.005", "goal": "1300", "customerNum": "25", "storeCustomerRate": "0.020", "singleFlowerB": "0", "saleNum": "42", "singleFlowerA": "38", "pkgsFee": "0", "offLineCustomerRate": "0.023", "mixFlower": "0", "potA": "4", "potRate": "0.098", "goalRate": "1.231", "potB": "0", "storeSLSRate": "0.004", "pricePerCus": "64", "saleDate": "1684944000000", "storeSLS": "358230", "offLineCustomer": "1110", "offLineSLS": "329523", "storeCustomer": "1238" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "c9b4e61973b743edac585ef7a91ba01b", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "1665", "offLineSLSRate": "0.005", "goal": "2000", "customerNum": "28", "storeCustomerRate": "0.019", "singleFlowerB": "0", "saleNum": "43", "singleFlowerA": "38", "pkgsFee": "0", "offLineCustomerRate": "0.022", "mixFlower": "0", "potA": "5", "potRate": "0.117", "goalRate": "0.833", "potB": "0", "storeSLSRate": "0.004", "pricePerCus": "59", "saleDate": "1685030400000", "storeSLS": "372219", "offLineCustomer": "1283", "offLineSLS": "335842", "storeCustomer": "1489" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "78c7e6e26c7c43b4aee4d730ae91ad72", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "3109", "offLineSLSRate": "0.005", "goal": "5500", "customerNum": "55", "storeCustomerRate": "0.023", "singleFlowerB": "0", "saleNum": "81", "singleFlowerA": "75", "pkgsFee": "0", "offLineCustomerRate": "0.024", "mixFlower": "0", "potA": "6", "potRate": "0.075", "goalRate": "0.565", "potB": "0", "storeSLSRate": "0.005", "pricePerCus": "57", "saleDate": "1685116800000", "storeSLS": "639176", "offLineCustomer": "2293", "offLineSLS": "614140", "storeCustomer": "2438" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "cf75b83f9eb74c2dbee9c162cc71d0da", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "2082", "offLineSLSRate": "0.004", "goal": "4300", "customerNum": "34", "storeCustomerRate": "0.014", "singleFlowerB": "0", "saleNum": "54", "singleFlowerA": "46", "pkgsFee": "0", "offLineCustomerRate": "0.016", "mixFlower": "0", "potA": "8", "potRate": "0.150", "goalRate": "0.484", "potB": "0", "storeSLSRate": "0.003", "pricePerCus": "61", "saleDate": "1685203200000", "storeSLS": "629900", "offLineCustomer": "2164", "offLineSLS": "577718", "storeCustomer": "2461" }, { "owner": null, "createdAt": 1685504528542, "createBy": "管理员", "updateBy": "管理员", "_departmentList": null, "_id": "b2be4ea677f34826bc63fac2a6bfff52", "updatedAt": 1685504528542, "storeID": "S1006000888", "saleAt": null, "actuals": "1543", "offLineSLSRate": "0.005", "goal": "1300", "customerNum": "16", "storeCustomerRate": "0.009", "singleFlowerB": "0", "saleNum": "41", "singleFlowerA": "41", "pkgsFee": "0", "offLineCustomerRate": "0.014", "mixFlower": "0", "potA": "0", "potRate": "0.000", "goalRate": "1.187", "potB": "0", "storeSLSRate": "0.003", "pricePerCus": "96", "saleDate": "1685289600000", "storeSLS": "448926", "offLineCustomer": "1137", "offLineSLS": "309619", "storeCustomer": "1806" }]
// 按周分组
const weekList = [{ "monday": 1683475200000, "sunday": 1683993600000, "weekText": "2023-5-8~2023-5-14" }, { "monday": 1684080000000, "sunday": 1684598400000, "weekText": "2023-5-15~2023-5-21" }, { "monday": 1684684800000, "sunday": 1685203200000, "weekText": "2023-5-22~2023-5-28" }, { "monday": 1685289600000, "sunday": 1685808000000, "weekText": "2023-5-29~2023-6-4" }]

// 分组,各周数据归各周
const weekSaleList = weekList.map(item => saleList.filter(subItem => +subItem.saleDate >= item.monday && +subItem.saleDate <= item.sunday))

const weekModel = {
    goal: 0,
    actuals: 0,
    goalRate: 0,
    customerNum: 0,
    pricePerCus: 0,
    singleFlowerA: 0,
    singleFlowerB: 0,
    mixFlower: 0,
    potA: 0,
    potB: 0,
    pkgsFee: 0,
    saleNum: 0,
    storeSLSRate: 0,
    storeCustomerRate: 0,
    offLineSLSRate: 0,
    offLineCustomerRate: 0,
    potRate: 0,
    storeSLS: 0,
    storeCustomer: 0,
    offLineSLS: 0,
    offLineCustomer: 0
}

// 每周的数据进行计算
let records = []
weekSaleList.map(weekArr => {
    let { goal, actuals, goalRate, customerNum, pricePerCus, singleFlowerA, singleFlowerB, mixFlower, potA, potB, pkgsFee, saleNum, storeSLSRate, storeCustomerRate, offLineSLSRate, offLineCustomerRate, potRate, storeSLS, storeCustomer, offLineSLS, offLineCustomer } = weekModel
    weekArr.map(item => {
        singleFlowerA += +item.singleFlowerA
        singleFlowerB += +item.singleFlowerB
        potA += +item.potA
        potB += +item.potB
        pkgsFee += +item.pkgsFee
        saleNum += +item.saleNum
        mixFlower += +item.mixFlower

        goal += (Math.floor(+item.goal)) // 周间目标
        actuals += (Math.floor(+item.actuals)) // 周间实绩
        customerNum += (Math.floor(+item.customerNum)) // 周间花客数
        storeSLS += (Math.floor(+item.storeSLS)) // 周间店铺SLS
        storeCustomer += (Math.floor(+item.storeCustomer)) // 周间店铺客数
        offLineSLS += (Math.floor(+item.offLineSLS)) // 周间线下SLS
        offLineCustomer += (Math.floor(+item.offLineCustomer)) // 周间线下客数
    })

    // 周间目标比(保留一位小数)(actuals / goal) * 100%
    goalRate = ((+actuals / +goal) * 1).toFixed(3)
    // 周间客单价(四舍五入取整)(actuals / customerNum)
    pricePerCus = Math.round((actuals / customerNum))
    // 周间目标比 (保留一位小数)(actuals / goal) * 100%
    goalRate = +((actuals / goal) * 1).toFixed(3)
    // 周间店铺SLS占比 (保留一位小数) 
    storeSLSRate = +(actuals / storeSLS).toFixed(3)
    // 周间店铺客数占比 (保留一位小数)
    storeCustomerRate = +(customerNum / storeCustomer).toFixed(3)
    // 周间线下SLS占比 (保留一位小数)
    offLineSLSRate = +(actuals / offLineSLS).toFixed(3)
    // 周间线下客数占比 (保留一位小数)
    offLineCustomerRate = +(customerNum / offLineCustomer).toFixed(3)
    // 周间盆栽占比 (保留一位小数)
    potRate = +(((potA * 39) + (potB * 58)) / actuals).toFixed(3)



    records.push({
        goal: goal.toString(),
        actuals: actuals.toString(),
        goalRate: goalRate.toString(),
        customerNum: customerNum.toString(),
        pricePerCus: pricePerCus.toString(),
        singleFlowerA: singleFlowerA.toString(),
        singleFlowerB: singleFlowerB.toString(),
        mixFlower: mixFlower.toString(),
        potA: potA.toString(),
        potB: potB.toString(),
        pkgsFee: pkgsFee.toString(),
        saleNum: saleNum.toString(),
        storeSLSRate: storeSLSRate.toString(),
        storeCustomerRate: storeCustomerRate.toString(),
        offLineSLSRate: offLineSLSRate.toString(),
        offLineCustomerRate: offLineCustomerRate.toString(),
        potRate: potRate.toString(),
        storeSLS: storeSLS.toString(),
        storeCustomer: storeCustomer.toString(),
        offLineSLS: offLineSLS.toString(),
        offLineCustomer: offLineCustomer.toString()
    })
})

console.log(records)

console 命令行工具 X clear

                    
>
console