增加消费码支付功能、支付逻辑优化、金额问题优化、订单绑定优化
This commit is contained in:
@@ -63,6 +63,7 @@ import kotlin.math.roundToInt
|
||||
class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "MainActivity"
|
||||
const val TIME_OUT = 5 * 60 * 1000L
|
||||
}
|
||||
|
||||
@@ -237,32 +238,35 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
//计费
|
||||
if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
eatWeight = presentation!!.lastWeight
|
||||
foodWeight = presentation!!.lastWeight
|
||||
eatWeight = lastWeight * 1000
|
||||
foodWeight = lastWeight * 1000
|
||||
} else {
|
||||
//余量计量
|
||||
eatWeight = presentation!!.recognitionWeight - presentation!!.lastWeight
|
||||
foodWeight = presentation!!.recognitionWeight
|
||||
eatWeight = (recognizeWeight - lastWeight) * 1000
|
||||
foodWeight = recognizeWeight * 1000
|
||||
}
|
||||
} else {
|
||||
//不计费
|
||||
foodWeight = presentation!!.recognitionWeight
|
||||
foodWeight = recognizeWeight * 1000
|
||||
eatWeight = if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
presentation!!.recognitionWeight
|
||||
recognizeWeight * 1000
|
||||
} else {
|
||||
//余量计量
|
||||
presentation!!.recognitionWeight - presentation!!.lastWeight
|
||||
(recognizeWeight - lastWeight) * 1000
|
||||
}
|
||||
}
|
||||
val eatNum = getEatNum(eatWeight, checkedItem!!.specWeight)
|
||||
createOrder(
|
||||
foodInfo = checkedItem!!,
|
||||
foodWeight = foodWeight.roundToInt(),
|
||||
eatWeight = eatWeight.roundToInt()
|
||||
eatWeight = eatWeight.roundToInt(),
|
||||
eatNum = eatNum
|
||||
) {
|
||||
presentation?.dismiss()
|
||||
startActivity(Intent(this, PayActivity::class.java).apply {
|
||||
putExtra(PayActivity.FOOD_INFO, checkedItem!!)
|
||||
putExtra(PayActivity.FOOD_EAT_NUM, eatNum)
|
||||
putExtra(PayActivity.FOOD_ORDER_ID, foodOrderId)
|
||||
})
|
||||
}
|
||||
@@ -270,6 +274,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
private var recognizeWeight = 0.0
|
||||
fun updateCurrentFood(foodInfo: FoodInfo?) {
|
||||
if (foodInfo == null) {
|
||||
binding.tvFoodName.text = "-"
|
||||
@@ -280,6 +285,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
return
|
||||
}
|
||||
pauseAnalysis()
|
||||
recognizeWeight = lastWeight
|
||||
presentation?.updateFood(foodInfo)
|
||||
binding.tvFoodName.text = foodInfo.foodName
|
||||
binding.previewView.visibility = View.GONE
|
||||
@@ -393,13 +399,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun updateFoodInfo(list: MutableList<FoodInfo>, scoreList: List<IdNameScore>) {
|
||||
Timber.d(
|
||||
"registerDataChange识别后查询接口数据:${GsonUtils.toJson(list)},识别数据:${
|
||||
GsonUtils.toJson(
|
||||
scoreList
|
||||
)
|
||||
}"
|
||||
)
|
||||
val queryData = GsonUtils.toJson(list)
|
||||
val recData = GsonUtils.toJson(scoreList)
|
||||
Timber.d("registerDataChange识别后查询接口数据:$queryData,识别数据:$recData")
|
||||
list.forEach { foodInfo ->
|
||||
val scoreItem = scoreList.firstOrNull { it.name == foodInfo.foodName }
|
||||
val score = scoreItem?.score ?: 0.0
|
||||
@@ -702,12 +704,20 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
lastTouchTime = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
fun createOrder(foodInfo: FoodInfo, foodWeight: Int, eatWeight: Int, block: () -> Unit) {
|
||||
fun createOrder(
|
||||
foodInfo: FoodInfo,
|
||||
foodWeight: Int,
|
||||
eatWeight: Int,
|
||||
eatNum: Int,
|
||||
block: () -> Unit
|
||||
) {
|
||||
Timber.tag(TAG).d("foodWeight=$foodWeight,eatWeight=$eatWeight")
|
||||
if (foodWeight <= 5 || eatWeight <= 5) {
|
||||
ToastUtils.showToast("请取走餐品")
|
||||
return
|
||||
}
|
||||
val mode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
val pickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
val order = FoodOrder(
|
||||
deviceId = GlobalData.deviceId,
|
||||
foodId = foodInfo.foodId,
|
||||
@@ -717,9 +727,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
foodWeight = foodWeight,
|
||||
eatWeight = eatWeight,
|
||||
//根据specId对应规格重量计算
|
||||
eatNum = getEatNum(foodWeight, foodInfo.specWeight ?: 0.0),
|
||||
eatNum = eatNum,
|
||||
userId = null,
|
||||
notPay = mode != 0,
|
||||
notPay = chargeMode != 0,
|
||||
//即放即取-1,称重-2
|
||||
mode = if (pickupMode == 1) 1 else 2
|
||||
)
|
||||
viewModel.createOrder(order) { orderId ->
|
||||
runOnUiThread {
|
||||
@@ -733,8 +745,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getEatNum(realWeight: Int, specWeight: Double): Int {
|
||||
if (realWeight == 0 || specWeight == 0.0) return 0
|
||||
fun getEatNum(realWeight: Double?, specWeight: Double?): Int {
|
||||
if (realWeight == null || realWeight == 0.0 || specWeight == null || specWeight == 0.0) return 1
|
||||
return (realWeight / specWeight).roundToInt()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user