wechat_yxcl/pages/everdayRenven/components/anhuiYestodayRevenueData.js
ylj20011123 42f254afb9 update
2025-09-04 14:32:29 +08:00

383 lines
14 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import request from '@/util/index.js'
const methods = {
async getData(obj, isServerPartDetail) { // 获取远程数据
let _this = this
/* ts 数据类型声明
type serverpartRegion = {
serverpartname:string,
cashpay: string
}
tyepy reginListModel = {
name:string,
cashpay:number,
child: serverpartRegion[]
}
*/
// let regionList = [] // 营收上传列表 reginListModel[]
this.groupType = obj.GroupType
const requestParamas = {
Statistics_Date: obj.time,
Statistics_Month: obj.month,
Province_Code: obj.ProvinceCode,
pushProvinceCode: obj.ProvinceCode,
Serverpart_ID: obj.GroupType != 1020 ? obj.ServerpartIds : '',
SPRegionType_ID: obj.GroupType == 1020 ? obj.ServerpartIds : '',
// Revenue_Include: 1
}
const requestParamasBudget = {
Statistics_Date: obj.time,
Statistics_Month: obj.month,
Province_Code: obj.ProvinceCode,
pushProvinceCode: obj.ProvinceCode,
Serverpart_ID: obj.ServerpartIds ? obj.ServerpartIds : ''
}
this.provinceCode = obj.ProvinceCode
try {
// 并行请求优化同时发起所有API请求减少加载时间
const [data, busniessCounts, tradeData, budgetAmount, mobileShare, mallDeliver, bayonetCount] = await Promise.all([
request.$webGet('CommercialApi/Revenue/GetRevenuePushList', requestParamas),
request.$webGet('CommercialApi/BaseInfo/GetShopCountList', requestParamas),
request.$webGet('CommercialApi/BaseInfo/GetBusinessTradeList', requestParamas),
request.$webGet('CommercialApi/Revenue/GetBudgetExpenseList', requestParamasBudget),
request.$webGet('CommercialApi/Revenue/GetMobileShare', requestParamas),
request.$webGet('CommercialApi/Revenue/GetMallDeliver', requestParamas),
request.$webGet('CommercialApi/Revenue/GetSPBayonetList', requestParamas)
])
// 检查数据有效性
if (data.Result_Code != 100 ||
busniessCounts.Result_Code != 100 ||
tradeData.Result_Code != 100 ||
budgetAmount.Result_Code != 100 ||
mobileShare.Result_Code != 100 ||
mallDeliver.Result_Code != 100 ||
bayonetCount.Result_Code != 100) {
console.error('部分API请求失败', {
data: data.Result_Code,
busniessCounts: busniessCounts.Result_Code,
tradeData: tradeData.Result_Code,
budgetAmount: budgetAmount.Result_Code,
mobileShare: mobileShare.Result_Code,
mallDeliver: mallDeliver.Result_Code,
bayonetCount: bayonetCount.Result_Code
})
// 返回一个默认的空数据结构而不是undefined
return [[], {
cashPay: 0,
ticketCount: 0,
totalCount: 0,
uploadState: '0/0'
}, [], [], [], []]
}
if (isServerPartDetail) { // 是服务区营收推送页面
return _this.getSeverpartReginList(data.Result_Data.List, busniessCounts.Result_Data.List,
tradeData.Result_Data.List, budgetAmount.Result_Data.List)
}
return _this.getReginList(data.Result_Data.List, busniessCounts.Result_Data.List,
tradeData.Result_Data.List, budgetAmount.Result_Data.List,
bayonetCount.Result_Data.List, mobileShare.Result_Data, mallDeliver.Result_Data)
// [reginList, totalData, busniessTypePie, busniessTradePie]
} catch (error) {
console.error('API请求出错:', error)
// 返回默认空数据结构
return [[], {
cashPay: 0,
ticketCount: 0,
totalCount: 0,
uploadState: '0/0'
}, [], [], [], []]
}
},
getTotalShowData(newData, oldData, index) {
// <TotalModel>
/*
type TotalModel = {
ticketCount: number // 客单数量 ,
totalCount: number// 总数量 ,
totalOffAmount: number// 优惠金额 ,
mobilePayment: number// 移动支付金额 ,
cashPay: number// 实收金额 ,
different_Price_Less: number// 短款金额 ,
different_Price_More: number// 长款金额 ,
}
*/
if (index > 0) {
oldData.ticketCount += newData.TicketCount
oldData.totalCount += newData.TotalCount
oldData.totalOffAmount += newData.TotalOffAmount
oldData.mobilePayment += newData.MobilePayment
oldData.cashPay += newData.CashPay
oldData.diffLessPrice += newData.Different_Price_Less
oldData.diffMorePrice += newData.Different_Price_More
if (newData.BusinessType == 1000) { // 商超
oldData.scCount = oldData.scCount ? oldData.scCount + 1 : 1
oldData.scCashPay = oldData.scCashPay ? oldData.scCashPay + newData.CashPay : newData.CashPay
}
if (newData.BusinessType == 3000) { // 餐饮
oldData.cyCount = oldData.cyCount ? oldData.cyCount + 1 : 1
oldData.cyCashPay = oldData.cyCashPay ? oldData.cyCashPay + newData.CashPay : newData.CashPay
}
} else {
oldData.ticketCount = newData.TicketCount
oldData.totalCount = newData.TotalCount
oldData.totalOffAmount = newData.TotalOffAmount
oldData.mobilePayment = newData.MobilePayment
oldData.cashPay = newData.CashPay
oldData.diffLessPrice = newData.Different_Price_Less
oldData.diffMorePrice = newData.Different_Price_More
if (newData.BusinessType == 1000) { // 商超
oldData.scCount = 1
oldData.scCashPay = newData.CashPay
}
if (newData.BusinessType == 3000) { // 餐饮
oldData.cyCount = 1
oldData.cyCashPay = newData.CashPay
}
}
return { ...oldData }
},
getBusniessPie(typeName, item, list) { // 经营模式数据
const oldData = list.find(m => m.name === item[typeName])
if (oldData) {
oldData.data = Number((oldData.data + item.CashPay).toFixed(2))
oldData.value = Number((oldData.value + item.CashPay).toFixed(2))
} else {
list.push({
name: item[typeName],
data: item.CashPay,
value: item.CashPay,
})
}
return [...list]
},
getBayonetPie(typeName, item, list) { // 车流量数据
const regionData = list.find(n => n.name === item["SPRegionType_Name"])
if (regionData) {
const oldData = regionData.spList.find(m => m.name === item[typeName])
if (oldData) {
oldData.Vehicle_Count = Number((oldData.Vehicle_Count + item.Vehicle_Count).toFixed(2))
oldData.SectionFlow_Count = Number((oldData.SectionFlow_Count + item.SectionFlow_Count).toFixed(2))
oldData.MinVehicle_Count = Number((oldData.MinVehicle_Count + item.MinVehicle_Count).toFixed(2))
oldData.MediumVehicle_Count = Number((oldData.MediumVehicle_Count + item.MediumVehicle_Count).toFixed(2))
oldData.LargeVehicle_Count = Number((oldData.LargeVehicle_Count + item.LargeVehicle_Count).toFixed(2))
const oldRegion = oldData.regionList.find(o => o.name === item["Serverpart_Region"])
if (oldRegion) {
oldRegion.Vehicle_Count = Number((oldRegion.Vehicle_Count + item.Vehicle_Count).toFixed(2))
oldRegion.SectionFlow_Count = Number((oldRegion.SectionFlow_Count + item.SectionFlow_Count).toFixed(2))
oldRegion.MinVehicle_Count = Number((oldRegion.MinVehicle_Count + item.MinVehicle_Count).toFixed(2))
oldRegion.MediumVehicle_Count = Number((oldRegion.MediumVehicle_Count + item.MediumVehicle_Count).toFixed(2))
oldRegion.LargeVehicle_Count = Number((oldRegion.LargeVehicle_Count + item.LargeVehicle_Count).toFixed(2))
}
else {
oldData.regionList.push({
name: item["Serverpart_Region"],
Vehicle_Count: item.Vehicle_Count,
SectionFlow_Count: item.SectionFlow_Count,
MinVehicle_Count: item.MinVehicle_Count,
MediumVehicle_Count: item.MediumVehicle_Count,
LargeVehicle_Count: item.LargeVehicle_Count,
})
}
} else {
regionData.spList.push({
name: item[typeName],
Vehicle_Count: item.Vehicle_Count,
SectionFlow_Count: item.SectionFlow_Count,
MinVehicle_Count: item.MinVehicle_Count,
MediumVehicle_Count: item.MediumVehicle_Count,
LargeVehicle_Count: item.LargeVehicle_Count,
regionList: [{
name: item["Serverpart_Region"],
Vehicle_Count: item.Vehicle_Count,
SectionFlow_Count: item.SectionFlow_Count,
MinVehicle_Count: item.MinVehicle_Count,
MediumVehicle_Count: item.MediumVehicle_Count,
LargeVehicle_Count: item.LargeVehicle_Count,
}]
})
}
} else {
list.push({
name: item["SPRegionType_Name"],
index: item["SPRegionType_Index"],
spList: [{
name: item[typeName],
Vehicle_Count: item.Vehicle_Count,
SectionFlow_Count: item.SectionFlow_Count,
MinVehicle_Count: item.MinVehicle_Count,
MediumVehicle_Count: item.MediumVehicle_Count,
LargeVehicle_Count: item.LargeVehicle_Count,
regionList: [{
name: item["Serverpart_Region"],
Vehicle_Count: item.Vehicle_Count,
SectionFlow_Count: item.SectionFlow_Count,
MinVehicle_Count: item.MinVehicle_Count,
MediumVehicle_Count: item.MediumVehicle_Count,
LargeVehicle_Count: item.LargeVehicle_Count,
}],
}]
})
}
return [...list]
},
getSeverpartReginList(data, shopCountList, tradeList, budgetAmount) {
let _this = this
let totalShow = {} // 总营收数据统计
let list = [] // 上传营收列表数据
let busniessTypePie = [] // 经营模式饼图统计数据
let busniessTradePie = [] // 经营业态饼图统计数据
let busniessTradeFathPie = [] // 区域经营饼图统计数据
data.map(async (n, index) => {
n.show = false
totalShow = _this.getTotalShowData(n, totalShow, index); // 总营收数据统计
// 寻找门店父业态
let trade = tradeList.find(t => t.BUSINESSTRADE_NAME == n.BusinessTrade_Name)
if (trade && trade.BUSINESSTRADE_PNAME && trade.BUSINESSTRADE_PNAME.indexOf('其他') == -1) {
n.tradename = trade.BUSINESSTRADE_PNAME
} else {
n.tradename = '其他'
}
busniessTypePie = _this.getBusniessPie('Business_TypeName', n, busniessTypePie)
busniessTradePie = _this.getBusniessPie('BusinessTrade_Name', n, busniessTradePie)
busniessTradeFathPie = _this.getBusniessPie('tradename', n, busniessTradeFathPie)
})
totalShow.serverpartname = data[0].Serverpart_Name
totalShow.uploadState = data.length + '/' + (shopCountList.length ? shopCountList[0].SHOP_BUSINESSCOUNT : 0)
totalShow.uploadCount = data.filter(n => n.Revenue_Upload > 0).length
totalShow.totalUploadCount = shopCountList.length ? shopCountList[0].SHOP_BUSINESSCOUNT : 0
totalShow.budgetAmount = 0
if (budgetAmount.length) {
totalShow.budgetAmount = budgetAmount[0].BUDGET_AMOUNT
}
return [totalShow, busniessTypePie, busniessTradePie, busniessTradeFathPie]
},
getReginList(data, shopCountList, tradeList, budgetAmount, bayonetCount, mobileShare, mallDeliver) {
let _this = this
let totalShow = {} // 总营收数据统计
let list = [] // 上传营收列表数据
let busniessTypePie = [] // 经营模式饼图统计数据
let busniessTradePie = [] // 经营业态饼图统计数据
let busniessAreaPie = [] // 区域经营饼图统计数据
let bayonetPie = [] // 区域车流饼图统计数据
let totalUploadCount = 0
data.map(async (n, index) => {
n.show = false
// 寻找门店父业态
let trade = tradeList.find(t => t.BUSINESSTRADE_NAME == n.BusinessTrade_Name)
if (trade && trade.BUSINESSTRADE_PNAME && trade.BUSINESSTRADE_PNAME.indexOf('其他') == -1) {
n.tradename = trade.BUSINESSTRADE_PNAME
} else {
n.tradename = _this.provinceCode == 340000 ? '其他' : (n.BusinessTrade_Name || '其他')
}
// 上传营收情况
let regin = list.find(m => m.name === n.SPRegionType_Name)
let [reginShopCount, serverpartShopCount] = [0, 0]
shopCountList.forEach(shop => {
if (shop.SPREGIONTYPE_NAME == n.SPRegionType_Name) {
reginShopCount += shop.SHOP_BUSINESSCOUNT
}
if (shop.SERVERPART_ID == n.Serverpart_ID) {
serverpartShopCount = shop.SHOP_BUSINESSCOUNT
}
})
if (!regin) {
totalUploadCount += reginShopCount
list.push({
name: n.SPRegionType_Name, // 区域名称
cashpay: n.CashPay,
uploadcount: n.Revenue_Upload > 0 ? 1 : 0, // 区域上传数量
totalcount: reginShopCount,
child: [{
serverpart_Id: n.Serverpart_ID,
serverpart_Name: n.Serverpart_Name,
cashpay: n.CashPay,
uploadcount: n.Revenue_Upload > 0 ? 1 : 0,
totalcount: serverpartShopCount
}]
})
} else {
regin.cashpay += n.CashPay
regin.uploadcount += n.Revenue_Upload > 0 ? 1 : 0
let serverpart = regin.child.find(m => m.serverpart_Name === n.Serverpart_Name)
if (serverpart) {
serverpart.cashpay += n.CashPay
serverpart.uploadcount += n.Revenue_Upload > 0 ? 1 : 0
} else {
regin.child.push({
serverpart_Id: n.Serverpart_ID,
serverpart_Name: n.Serverpart_Name,
cashpay: n.CashPay,
uploadcount: n.Revenue_Upload > 0 ? 1 : 0,
totalcount: serverpartShopCount
})
}
regin.child.sort((a, b) => b.cashpay - a.cashpay)
}
totalShow = _this.getTotalShowData(n, totalShow, index); // 总营收数据统计
busniessTypePie = _this.getBusniessPie('Business_TypeName', n, busniessTypePie)
busniessTradePie = _this.getBusniessPie('tradename', n, busniessTradePie)
if (this.groupType == 1000) {
busniessAreaPie = _this.getBusniessPie('SPRegionType_Name', n, busniessAreaPie)
}
})
list.sort((a, b) => b.cashpay - a.cashpay)
if (this.groupType == 1000 && _this.provinceCode == 340000) {
// 获取移动支付分账数据
if (mobileShare) {
totalShow.shareShopCount = mobileShare.ShareShop_Count
totalShow.royaltyPrice = mobileShare.Royalty_Price
totalShow.subRoyaltyPrice = mobileShare.SubRoyalty_Price
totalShow.ticketFee = mobileShare.Ticket_Fee
}
// 获取移动支付分账数据
if (mallDeliver) {
totalShow.deliverBillCount = mallDeliver.DeliverBill_Count
totalShow.deliverPrice = mallDeliver.Deliver_Price
totalShow.deliverRate = mallDeliver.Deliver_Rate
}
// 片区车流量数据
bayonetCount.map(async (n, index) => {
bayonetPie = _this.getBayonetPie('Serverpart_Name', n, bayonetPie)
})
}
totalShow.uploadState = data.filter(n => n.Revenue_Upload > 0).length + '/' + totalUploadCount
totalShow.budgetAmount = 0
if (_this.provinceCode == 620000) {
const ele = list.find(n => n.name == "通美公司")
totalShow.tmCrashPay = ele ? ele.cashpay : '0.00'
}
if (budgetAmount.length) {
totalShow.budgetAmount = budgetAmount[0].BUDGET_AMOUNT
}
return [list, totalShow, busniessTypePie, busniessTradePie, busniessAreaPie, bayonetPie]
}
}
export default methods;