feat(business): 增加餐具重量配置及扣减功能
- 在 BusinessFragment 中添加实时秤重读取及餐具重量持久化存储 - 在界面显示餐具重量标签,配置时显示当前保存值 - 定义全局常量 KEY_DISH_WEIGHT 用于存储餐具重量 - 在 MainActivity 内部方法添加获取配置餐具重量接口 - 修改订餐逻辑,取餐提交时自动从就餐重量中扣减餐具重量 - 在主界面相关订单及计价逻辑中扣减餐具重量影响份数和价格 - 调整重量监听及订单添加部分逻辑以应用净重计算 - 更新定时任务延迟时间,提高效率和响应速度
This commit is contained in:
@@ -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"
|
||||
}
|
||||
@@ -963,6 +963,14 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
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<ActivityMainBinding>() {
|
||||
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<ActivityMainBinding>() {
|
||||
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<ActivityMainBinding>() {
|
||||
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() {
|
||||
|
||||
@@ -16,11 +16,18 @@ import kotlin.math.roundToInt
|
||||
|
||||
class BusinessFragment: BaseFragment<FragmentBusinessBinding>() {
|
||||
|
||||
// 当前秤的实时读数(克),作为待保存的餐具重量
|
||||
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<FragmentBusinessBinding>() {
|
||||
|
||||
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<FragmentBusinessBinding>() {
|
||||
}
|
||||
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 "餐具重量(克)"
|
||||
}
|
||||
}
|
||||
@@ -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!!,
|
||||
|
||||
@@ -214,6 +214,7 @@
|
||||
android:background="@drawable/setting_border_gray">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDishWeightLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="120dp"
|
||||
android:layout_marginStart="42dp"
|
||||
|
||||
Reference in New Issue
Block a user