我有6个订单。我循环了6个订单,以获取每个订单的总价。
我要做的是在循环中添加每个订单的总价,然后 然后将其与
authorized amount
进行比较。
让我们说,授权金额为2000 。
会发生什么,它将授权金额与PER ORDER比较 总价,而不是所有订单总价。
这是示例代码:
for (Entity checkout : checkouts) {
List<Entity> selectedJOs = AppUtil.getEntities(AppUtil.getListIds(checkout, "job-orders"), jobOrders);
long finalGrandTotalAmount = 0;
for (Entity job_order : selectedJOs) {
grandTotalAmount = 0;
long totalJobOrderPurchasedAmount = 0;
long totalJobOrderDeliveryFee = 0;
long totalJobOrderShoppingFee = 0;
long totalJobOrderDiscount = 0;
totalJobOrderRecalled = 0;
long totalCampaignDiscount = 0;
if (!job_order.attributes.status.equals("cancelled")) {
totalJobOrderPurchasedAmount += (job_order.attributes.purchased_deliverables_amount_in_cents + job_order.attributes.non_membership_fee_in_cents);
totalJobOrderDeliveryFee += job_order.attributes.delivery_fee_in_cents;
totalJobOrderShoppingFee += job_order.attributes.shopping_fee_in_cents;
totalJobOrderRecalled += job_order.attributes.recalled_deliverables_amount_in_cents;
List<Entity> selectedCampaigns = AppUtil.getEntities(AppUtil.getListIds(job_order, "job-order-fmcg-campaign-vouchers"), campaignDiscounts);
for (Entity campaignDiscount : selectedCampaigns) {
totalCampaignDiscount += campaignDiscount.attributes.discount_in_cents;
}
for (Entity discount : discounts) {
long job_order_discount;
if (discount.relationships.job_order.data.id.equals(job_order.id)) {
long purchase_amount = job_order.attributes.purchased_deliverables_amount_in_cents;
if (discount.attributes.sum_in_cents_off <= 0) {
job_order_discount = Math.round(purchase_amount * discount.attributes.percent_off);
} else {
job_order_discount = discount.attributes.sum_in_cents_off;
}
totalJobOrderDiscount += job_order_discount;
}
}
long discounts_total = totalJobOrderDiscount > 0 ? totalJobOrderDiscount + totalCampaignDiscount : totalCampaignDiscount;
grandTotalAmount = (totalJobOrderPurchasedAmount - discounts_total) + (totalJobOrderShoppingFee + totalJobOrderDeliveryFee) - job_order.attributes.credit_amount_of_cents;
boolean isLoginPrimary = true;
List<Entity> selected_consignments = AppUtil.getEntities(AppUtil.getListIds(job_order, "consignments"), consignments);
for (Entity consignment : selected_consignments) {
if (consignment.attributes.primary) {
Entity user = AppUtil.getEntity(consignment.relationships.user.data.id, users);
isLoginPrimary = user.relationships.profile.data.type.equals("runner-profiles") && user.id.equals(Preferences.getString(Prefkey.session_user_id)) && isLoginPrimary;
}
}
if (job_order.relationships.completed_by_user.data != null) {
if (job_order.relationships.completed_by_user.data.id.equals(Preferences.getString(Prefkey.session_user_id))) {
if (checkout.attributes.payment_mode.equals("credit-card")) {
if (checkout.attributes.authorized_amount_in_cents < grandTotalAmount) {
grandTotalAmountCc += checkout.attributes.authorized_amount_in_cents - totalJobOrderRecalled;
grandTotalAmountCash += checkout.attributes.paid_cash_difference_in_cents;
} else {
grandTotalAmountCc += grandTotalAmount - totalJobOrderRecalled;
grandTotalAmountCash += 0;
}
} else {
grandTotalAmountCash += grandTotalAmount - totalJobOrderRecalled;
}
}
}
}
}
}
答案 0 :(得分:0)
对于每个循环,您都将重置grandTotalAmount。通过使其全球化,可以解决您的问题。