feat(weightBilling): 优化按重量计费逻辑并完善界面展示
- 规格栏显示改为直接展示规格重量,去除单价/100克显示 - 新增最小计费重量常量 MIN_BILLABLE_WEIGHT,净重不足时阻止下单 - 下单时检测净重,低于最小计费重量时弹出提示并拦截 - 计算价格时按净重计算,单价基于规格价与规格重量的比值 - 本地明细中 eatNum 仅用于展示份数,不参与金额计算 - SettlementOrder 用实际食用重量 eatWeight 赋值 num 字段,配合重量栏显示逻辑调整
This commit is contained in:
@@ -107,6 +107,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
|
||||
const val WEIGHT_CHANGE_VALUE = 20
|
||||
const val WEIGHT_RESET_RECOGNIZE = 10
|
||||
// 档口按重量计费的最小计费重量(克),净重超过此值才计费/下单
|
||||
const val MIN_BILLABLE_WEIGHT = 10
|
||||
}
|
||||
|
||||
private val viewModel by viewModels<NetViewModelV2>()
|
||||
@@ -912,8 +914,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
//0-即放即取,1-余量计量
|
||||
val pickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
if (eatNum <= 0) {
|
||||
ToastUtils.showToast("您好,当前重量不足一份")
|
||||
// 按重量计费:净重不足最小计费重量时,提示并拦截下单
|
||||
if (eatWeight < MIN_BILLABLE_WEIGHT) {
|
||||
ToastUtils.showToast("重量不足,无法下单")
|
||||
notEnoughOneBlock()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ class FoodOrderAdapter(list: MutableList<FoodItem>) :
|
||||
if (it.orderFrom == 2) {
|
||||
binding.tvPriceNorm.text = if (it.specName.isNullOrBlank()) "${it.specWeight}克" else "${it.specName}/${it.specWeight}克"
|
||||
} else {
|
||||
val foodPrice = it.foodPrice.format2String(2)
|
||||
binding.tvPriceNorm.text = "${foodPrice}/100克"
|
||||
// 营养秤结算:规格栏显示规格重量 specWeight
|
||||
binding.tvPriceNorm.text = "${it.specWeight}克"
|
||||
}
|
||||
//if (it.specName.isNullOrBlank().not()) {
|
||||
// binding.tvPriceFlag.text = "[${it.specName}]"
|
||||
|
||||
@@ -49,5 +49,7 @@ private fun SettlementFoodItem.toFoodItem() = FoodItem(
|
||||
specName = specName,
|
||||
specWeight = specWeight?.toInt() ?: 0,
|
||||
eatNum = eatNum ?: 0,
|
||||
price = price?.toDouble() ?: 0.0
|
||||
price = price?.toDouble() ?: 0.0,
|
||||
// 重量栏读取 num 字段,这里用实际食用重量 eatWeight 赋值
|
||||
num = eatWeight ?: 0
|
||||
)
|
||||
|
||||
@@ -689,7 +689,7 @@ class MainScreenPresentation(
|
||||
Timber.tag(TAG) .d("addFoodToOrder: ${weight == lastAddWeight}")
|
||||
// if (weight == lastAddWeight) return
|
||||
lastAddWeight = weight
|
||||
if (weight <= 10) {
|
||||
if (weight <= MainActivity.MIN_BILLABLE_WEIGHT) {
|
||||
//0-即放即取,1-余量计量
|
||||
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
if (foodOrderList.isNotEmpty() && mealPickupMode == 1) {
|
||||
@@ -702,10 +702,17 @@ class MainScreenPresentation(
|
||||
}
|
||||
return
|
||||
}
|
||||
//val foodPrice = if (isMember) foodInfo.vipPrice else foodInfo.specPrice
|
||||
val foodPrice = (foodInfo.specPrice ?: 0.0) * memberDiscount
|
||||
// 按重量计价:每克单价 = 规格价 / 规格重量,再按会员折扣折算
|
||||
// 单价 = specPrice / specWeight,金额 = 当前秤上净重 × 单价 × 会员折扣
|
||||
val specWeight = foodInfo.specWeight ?: 0.0
|
||||
val specPrice = foodInfo.specPrice ?: 0.0
|
||||
val price = if (specWeight > 0.0) {
|
||||
weight * (specPrice / specWeight) * memberDiscount
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
// eatNum 仅用于本地明细展示(份数),不再参与金额计算
|
||||
val eatNum = activity.getEatNum(weight.toDouble(), foodInfo.specWeight)
|
||||
val price = eatNum * foodPrice
|
||||
if (foodOrderList.isNotEmpty() && mealPickupMode == 1) {
|
||||
val last = foodOrderList.last()
|
||||
if (last.isLocalData) {
|
||||
|
||||
Reference in New Issue
Block a user