diff --git a/app/src/main/java/com/sw/dualscreen/GlobalData.kt b/app/src/main/java/com/sw/dualscreen/GlobalData.kt index 8ae8cee..623b4b0 100644 --- a/app/src/main/java/com/sw/dualscreen/GlobalData.kt +++ b/app/src/main/java/com/sw/dualscreen/GlobalData.kt @@ -73,6 +73,8 @@ object GlobalKey { const val KEY_USER_INFO = "userInfoKey" const val KEY_PICKUP_MODE = "pickupMode" const val KEY_CHARGE_MODE = "chargeMode" + // 餐具重量(克),取餐提交时用于从就餐重量中扣减,默认 0 表示不扣减 + const val KEY_DISH_WEIGHT = "dishWeight" const val KEY_SETTLEMENT_MODE = "settlementMode" const val KEY_BASE_URL = "baseUrlKey" } \ No newline at end of file diff --git a/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt b/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt index b3335af..1fbf357 100644 --- a/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt +++ b/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt @@ -963,6 +963,14 @@ class MainActivity : BaseActivity() { return eatNum; } + /** + * 读取已配置的餐具重量(克)。 + * 用于取餐提交时从就餐重量中扣减,默认 0 表示未配置、不扣减。 + */ + internal fun getDishWeight(): Int { + return SPUtil.getInstance().get(GlobalKey.KEY_DISH_WEIGHT, 0) ?: 0 + } + private var foodOrderId: String = "" private var isExist = false fun addBackEventListener() { @@ -1039,6 +1047,8 @@ class MainActivity : BaseActivity() { val mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0 //0-计费,1-不计费 val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0) ?: 0 + // 餐具重量(克),提交就餐数据时从就餐重量中扣减 + val dishWeight = getDishWeight() var foodWeight = 0 var eatWeight = 0 if (chargeMode == 0) { @@ -1064,6 +1074,10 @@ class MainActivity : BaseActivity() { recognizeWeight - currentWeight } } + // 扣减餐具重量(仅影响就餐重量与份数,菜品原始重量 foodWeight 保持不变),不足则归零 + val rawEatWeight = eatWeight + eatWeight = (rawEatWeight - dishWeight).coerceAtLeast(0) + log("clickPayButton dishWeight=$dishWeight, rawEatWeight=$rawEatWeight, deductedEatWeight=$eatWeight") val eatNum = getEatNum(eatWeight.toDouble(), checkedItem!!.specWeight) createOrder( foodInfo = checkedItem!!, @@ -1196,10 +1210,8 @@ class MainActivity : BaseActivity() { private val intervalExecutor by lazy { IntervalExecutor() } private var faceTaskJob: Job? = null - // private val initialDelay = 5 * 60 * 1000L -// private val dealyMillis = 10 * 60 * 1000L - private val initialDelay = 10 * 1000L - private val dealyMillis = 5 * 1000L + private val initialDelay = 60 * 1000L + private val dealyMillis = 30 * 1000L // private var taskPageNo = 1 fun startFaceTask() { diff --git a/app/src/main/java/com/sw/dualscreen/activity/fragment/BusinessFragment.kt b/app/src/main/java/com/sw/dualscreen/activity/fragment/BusinessFragment.kt index aeaaafb..4592d98 100644 --- a/app/src/main/java/com/sw/dualscreen/activity/fragment/BusinessFragment.kt +++ b/app/src/main/java/com/sw/dualscreen/activity/fragment/BusinessFragment.kt @@ -16,11 +16,18 @@ import kotlin.math.roundToInt class BusinessFragment: BaseFragment() { + // 当前秤的实时读数(克),作为待保存的餐具重量 + private var dishWeight: Int = 0 + override fun inflateViewBinding(): FragmentBusinessBinding { return FragmentBusinessBinding.inflate(LayoutInflater.from(context)) } override fun initialize() { + // 初始化为已保存的餐具重量,未配置过则为 0 + dishWeight = SPUtil.getInstance().get(GlobalKey.KEY_DISH_WEIGHT, 0) ?: 0 + // 在标题后显示当前已保存的餐具重量 + refreshDishWeightLabel() binding.rgSettlement.let { //val settlementMode = if (binding.rgSettlement.checkedRadioButtonId == R.id.rbJointPayment) 0 else 1 @@ -68,6 +75,10 @@ class BusinessFragment: BaseFragment() { val pickupMode = if (binding.rgTakeFood.checkedRadioButtonId == R.id.rbPickAndPlace) 0 else 1 SPUtil.getInstance().put(GlobalKey.KEY_PICKUP_MODE, pickupMode) + // 持久化餐具重量(克) + SPUtil.getInstance().put(GlobalKey.KEY_DISH_WEIGHT, dishWeight) + // 刷新标签文字,显示当前已保存的餐具重量 + refreshDishWeightLabel() EventBus.getDefault().post(ResetRecognizeEvent()) //ToastUtils.showToast("设置已保存") (activity as SettingActivity).let { @@ -80,7 +91,17 @@ class BusinessFragment: BaseFragment() { } SensorScaleUtils.addWeightListener { value -> //val realWeight = (value * 1000).roundToInt() + // 追踪秤的实时读数(克),作为待保存的餐具重量 + dishWeight = value binding.tvFoodWeight.text = "$value" } } + + /** + * 刷新"餐具重量(克)"标签,在末尾显示当前已保存的配置值。 + * 未配置(0)时只显示原标题。 + */ + private fun refreshDishWeightLabel() { + binding.tvDishWeightLabel.text = if (dishWeight > 0) "餐具重量(克):${dishWeight}g" else "餐具重量(克)" + } } \ No newline at end of file diff --git a/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt b/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt index f48f56c..9c4ac6b 100644 --- a/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt +++ b/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt @@ -689,7 +689,9 @@ class MainScreenPresentation( Timber.tag(TAG) .d("addFoodToOrder: ${weight == lastAddWeight}") // if (weight == lastAddWeight) return lastAddWeight = weight - if (weight <= 10) { + // 扣减餐具重量,后续份数、价格、总重量均以净重计算 + val netWeight = (weight - activity.getDishWeight()).coerceAtLeast(0) + if (netWeight <= 10) { //0-即放即取,1-余量计量 mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0 if (foodOrderList.isNotEmpty() && mealPickupMode == 1) { @@ -704,13 +706,13 @@ class MainScreenPresentation( } //val foodPrice = if (isMember) foodInfo.vipPrice else foodInfo.specPrice val foodPrice = (foodInfo.specPrice ?: 0.0) * memberDiscount - val eatNum = activity.getEatNum(weight.toDouble(), foodInfo.specWeight) + val eatNum = activity.getEatNum(netWeight.toDouble(), foodInfo.specWeight) val price = eatNum * foodPrice if (foodOrderList.isNotEmpty() && mealPickupMode == 1) { val last = foodOrderList.last() if (last.isLocalData) { last.eatNum = eatNum - last.num = weight + last.num = netWeight last.price = price // foodOrderAdapter.submitList(foodOrderList) foodOrderAdapter.notifyItemChanged(foodOrderList.lastIndex) @@ -727,7 +729,7 @@ class MainScreenPresentation( foodMaterialId = foodInfo.foodMaterialId, specWeight = foodInfo.specWeight?.toInt() ?: 0, orderFrom = 2, - num = weight, + num = netWeight, eatNum = eatNum, isLocalData = true ) @@ -1379,17 +1381,22 @@ class MainScreenPresentation( fun createOrder(notEnoughOneBlock: () -> Unit = {}, successBlock: () -> Unit) { //0-即放即取,1-余量计量 mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0 + // 餐具重量(克),从就餐重量中扣减 + val dishWeight = activity.getDishWeight() //if (settlementMode == 0) { // //使用联合支付方式 // ToastUtils.showToast("使用联合支付方式") // return //} - val eatWeight = if (mealPickupMode == 0) { + val rawEatWeight = if (mealPickupMode == 0) { //即放即取 recognitionWeight } else { recognitionWeight - lastWeight } + // 扣减餐具重量(不足则归零),foodWeight 保持不变 + val eatWeight = (rawEatWeight - dishWeight).coerceAtLeast(0) + activity.log("createOrder,rawEatWeight=$rawEatWeight,dishWeight=$dishWeight,eatWeight=$eatWeight") //val userNutritionParam = UserNutritionParam( // userId = userNutritionData?.userId!!, // foodId = currentFood?.foodId!!, diff --git a/app/src/main/res/layout/fragment_business.xml b/app/src/main/res/layout/fragment_business.xml index 96f1290..37af084 100644 --- a/app/src/main/res/layout/fragment_business.xml +++ b/app/src/main/res/layout/fragment_business.xml @@ -214,6 +214,7 @@ android:background="@drawable/setting_border_gray">