增加消费码支付功能、支付逻辑优化、金额问题优化、订单绑定优化
This commit is contained in:
@@ -121,18 +121,18 @@ class MainScreenPresentation(
|
||||
.d("updateWeight lastWeight = $weight, currentStep = $currentStep, isGoStep1 = $isGoStep1")
|
||||
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
if (mealPickupMode == 1 && chargeMode == 0) {
|
||||
//余量计量+计费模式
|
||||
if (isFirstGetWeight && lastWeight > 5) {
|
||||
recognitionWeight = lastWeight
|
||||
isFirstGetWeight = false
|
||||
}
|
||||
if (lastWeight > 5) {
|
||||
//余量计量,有重量的情况下不回到重新识别状态
|
||||
return
|
||||
}
|
||||
isFirstGetWeight = true
|
||||
}
|
||||
// if (mealPickupMode == 1 && chargeMode == 0) {
|
||||
// //余量计量+计费模式
|
||||
// if (isFirstGetWeight && lastWeight > 5) {
|
||||
// recognitionWeight = lastWeight
|
||||
// isFirstGetWeight = false
|
||||
// }
|
||||
// if (lastWeight > 5) {
|
||||
// //余量计量,有重量的情况下不回到重新识别状态
|
||||
// return
|
||||
// }
|
||||
// isFirstGetWeight = true
|
||||
// }
|
||||
if (currentStep == 2 && lastWeight <= 5 && isGoStep1) {
|
||||
//人脸识别过程中,秤上物品拿走
|
||||
isGoStep1 = false
|
||||
@@ -1109,7 +1109,8 @@ class MainScreenPresentation(
|
||||
activity.createOrder(
|
||||
foodInfo = currentFood!!,
|
||||
foodWeight = lastWeight.roundToInt(),
|
||||
eatWeight = eatWeight.roundToInt()
|
||||
eatWeight = eatWeight.roundToInt(),
|
||||
eatNum = activity.getEatNum(eatWeight, currentFood!!.specWeight)
|
||||
) {
|
||||
if (MyApp.DEBUG) {
|
||||
ToastUtils.showToast("订单已生成")
|
||||
|
||||
@@ -4,36 +4,28 @@ import android.Manifest
|
||||
import android.app.Dialog
|
||||
import android.app.Presentation
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Point
|
||||
import android.hardware.Camera
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.Spanned
|
||||
import android.text.SpannedString
|
||||
import android.text.TextUtils
|
||||
import android.text.style.AbsoluteSizeSpan
|
||||
import android.view.Display
|
||||
import android.view.TextureView
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewTreeObserver
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.text.buildSpannedString
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.arcsoft.face.ErrorInfo
|
||||
import com.sw.dualscreen.GlobalKey
|
||||
import com.sw.dualscreen.R
|
||||
import com.sw.dualscreen.activity.PayActivity
|
||||
import com.sw.dualscreen.databinding.PresentationFacePayBinding
|
||||
import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.ext.load
|
||||
import com.sw.dualscreen.model.response.MemberInfo
|
||||
import com.sw.dualscreen.model.response.TextBean
|
||||
import com.sw.dualscreen.utils.GsonUtils
|
||||
import com.sw.dualscreen.utils.SPUtil
|
||||
import com.sw.dualscreen.utils.SpannedUtils
|
||||
import com.sw.dualscreen.view.CustomDialog
|
||||
import com.sw.dualscreen.viewmodel.UserViewModel
|
||||
@@ -248,7 +240,7 @@ class FacePayPresentation(
|
||||
// recognitionWeight = lastWeight
|
||||
lastFaceTrackId = compareResult.trackId
|
||||
val faceEntity = compareResult.faceEntity
|
||||
var userId = faceEntity.userName
|
||||
val userId = faceEntity.userName
|
||||
if (userId == null) return@Observer
|
||||
// TODO: 测试支付用户id
|
||||
// userId = "1987710988425662466"
|
||||
@@ -566,77 +558,66 @@ class FacePayPresentation(
|
||||
}
|
||||
|
||||
private var lastFaceTrackId: Int = -1 // 上一次的人脸信息
|
||||
private var mDialogWaiting: CustomDialog? = null
|
||||
|
||||
/**
|
||||
* 显示等待提示框
|
||||
*/
|
||||
fun showWaitingDialog(tip: String?): Dialog? {
|
||||
hideWaitingDialog()
|
||||
val view = View.inflate(activity, R.layout.dialog_waiting, null)
|
||||
if (!TextUtils.isEmpty(tip)) (view.findViewById<View?>(R.id.tvTip) as TextView).text = tip
|
||||
mDialogWaiting = CustomDialog(activity, view, R.style.MyDialog)
|
||||
mDialogWaiting!!.show()
|
||||
mDialogWaiting!!.setCancelable(true)
|
||||
return mDialogWaiting
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏等待提示框
|
||||
*/
|
||||
fun hideWaitingDialog() {
|
||||
mDialogWaiting?.dismiss()
|
||||
mDialogWaiting = null
|
||||
}
|
||||
|
||||
override fun onDisplayRemoved() {
|
||||
super.onDisplayRemoved()
|
||||
onDismissListener()
|
||||
}
|
||||
|
||||
|
||||
private fun faceRecSuccess(userId: String) {
|
||||
activity.runOnUiThread {
|
||||
showWaitingDialog("加载中,请稍后……")
|
||||
activity.showWaitingDialog("加载中,请稍后……")
|
||||
}
|
||||
getMemberInfo(userId) { memberInfo ->
|
||||
bindOrder(userId) {
|
||||
activity.getMemberInfoById(userId) { memberInfo ->
|
||||
if (memberInfo == null) {
|
||||
activity.hideWaitingDialog()
|
||||
//ToastUtils.showToast("查询会员信息失败,请稍后重试")
|
||||
return@getMemberInfoById
|
||||
}
|
||||
activity.bindOrder(memberInfo.faceUserId?:"") { bindResult ->
|
||||
if (bindResult.not()) {
|
||||
activity.hideWaitingDialog()
|
||||
//ToastUtils.showToast("订单绑定失败")
|
||||
return@bindOrder
|
||||
}
|
||||
binding.root.postDelayed({
|
||||
hideWaitingDialog()
|
||||
activity.hideWaitingDialog()
|
||||
activity.showPayInfo(type = 1, isVip = true, memberInfo = memberInfo)
|
||||
activity.hidePayTab()
|
||||
binding.root.postDelayed({
|
||||
dismiss()
|
||||
}, 500)
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindOrder(userId:String, block:()-> Unit) {
|
||||
userViewModel.bindOrder(userId, activity.foodOrderId) { bindResult ->
|
||||
activity.runOnUiThread {
|
||||
if (bindResult.not()) {
|
||||
hideWaitingDialog()
|
||||
ToastUtils.showToast("订单绑定失败")
|
||||
return@runOnUiThread
|
||||
}
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMemberInfo(userId: String, block:(MemberInfo)-> Unit) {
|
||||
userViewModel.getMemberInfo(memberId = userId) { memberInfo ->
|
||||
activity.runOnUiThread {
|
||||
if (memberInfo == null) {
|
||||
hideWaitingDialog()
|
||||
ToastUtils.showToast("查询会员信息失败,请稍后重试")
|
||||
return@runOnUiThread
|
||||
}
|
||||
block(memberInfo)
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private fun bindOrder(userId: String, block: () -> Unit) {
|
||||
// val pickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0)
|
||||
// val mode = if (pickupMode == 1) 1 else 2
|
||||
// userViewModel.bindOrder(userId, activity.foodOrderId, mode = mode) { bindResult ->
|
||||
// activity.runOnUiThread {
|
||||
// if (bindResult.not()) {
|
||||
// activity.hideWaitingDialog()
|
||||
// //ToastUtils.showToast("订单绑定失败")
|
||||
// return@runOnUiThread
|
||||
// }
|
||||
// block()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// private fun getMemberInfo(userId: String, block:(MemberInfo)-> Unit) {
|
||||
// userViewModel.getMemberInfoById(memberId = userId) { memberInfo ->
|
||||
// activity.runOnUiThread {
|
||||
// if (memberInfo == null) {
|
||||
// activity.hideWaitingDialog()
|
||||
// //ToastUtils.showToast("查询会员信息失败,请稍后重试")
|
||||
// return@runOnUiThread
|
||||
// }
|
||||
// block(memberInfo)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -74,12 +74,11 @@ class ScanQrCodePayPresentation(
|
||||
1 -> {
|
||||
val memberInfo = activity.memberInfo
|
||||
binding.layoutVip.run {
|
||||
if (memberInfo!=null) visible() else gone()
|
||||
if (memberInfo != null) visible() else gone()
|
||||
}
|
||||
binding.layoutPaySuccess.gone()
|
||||
binding.layoutScanQrCode.visible()
|
||||
|
||||
//totalPrice = if (memberInfo != null) activity.foodInfo?.vipPrice else activity.foodInfo?.specPrice
|
||||
balance = (memberInfo?.topUpBalance ?: 0.0) + (memberInfo?.rewardBalance ?: 0.0)
|
||||
realPayPrice = if (balance >= totalPrice) 0.0 else totalPrice - balance
|
||||
expensesBalance = if (balance >= totalPrice) totalPrice else balance
|
||||
@@ -110,13 +109,13 @@ class ScanQrCodePayPresentation(
|
||||
2 -> {
|
||||
val memberInfo = activity.memberInfo
|
||||
binding.layoutVip.run {
|
||||
if (memberInfo!=null) visible() else gone()
|
||||
if (memberInfo != null) visible() else gone()
|
||||
}
|
||||
binding.layoutPaySuccess.visible()
|
||||
binding.layoutScanQrCode.gone()
|
||||
|
||||
//totalPrice = activity.foodInfo?.vipPrice ?: 0.0
|
||||
balance = if (memberInfo != null) (memberInfo.topUpBalance ?: 0.0)+(memberInfo.rewardBalance ?: 0.0) else 0.0
|
||||
balance = if (memberInfo != null) (memberInfo.topUpBalance
|
||||
?: 0.0) + (memberInfo.rewardBalance ?: 0.0) else 0.0
|
||||
realPayPrice = if (balance >= totalPrice) 0.0 else totalPrice - balance
|
||||
expensesBalance = if (balance >= totalPrice) totalPrice else balance
|
||||
|
||||
@@ -136,6 +135,10 @@ class ScanQrCodePayPresentation(
|
||||
}
|
||||
}
|
||||
|
||||
fun loadQrCodeImage(qrCodeUrl: String?) {
|
||||
binding.ivPayQrCode.load(qrCodeUrl)
|
||||
}
|
||||
|
||||
private fun loadUserInfo(item: MemberInfo) {
|
||||
binding.ivHeadPic.load(item.faceUrl?.ifBlank { R.drawable.ic_avatar_default })
|
||||
binding.tvUserName.text = item.name
|
||||
@@ -154,24 +157,37 @@ class ScanQrCodePayPresentation(
|
||||
TextBean(
|
||||
text = "-${expensesBalance.format2String(2)}",
|
||||
textSize = 30,
|
||||
textColor = "#FF0A1428"
|
||||
textColor = "#FF0A1428",
|
||||
isBold = true
|
||||
)
|
||||
)
|
||||
|
||||
if (balance >= totalPrice) {
|
||||
//余额大于等于总价格,使用余额支付
|
||||
TextBean(text = " 元,扣除后可用余额 ", textSize = 30, textColor = "#FF5E7585")
|
||||
list.add(TextBean(text = " 元,扣除后可用余额 ", textSize = 30, textColor = "#FF5E7585"))
|
||||
val remainingBalance = balance - totalPrice
|
||||
TextBean(
|
||||
text = remainingBalance.format2String(2), textSize = 30, textColor = "#FF0A1428"
|
||||
list.add(
|
||||
TextBean(
|
||||
text = remainingBalance.format2String(2),
|
||||
textSize = 30,
|
||||
textColor = "#FF0A1428",
|
||||
isBold = true
|
||||
)
|
||||
)
|
||||
} else {
|
||||
//余额小于总价格,使用余额+扫码支付
|
||||
//实际支付金额
|
||||
TextBean(text = " 元,还需支付 ", textSize = 30, textColor = "#FF5E7585")
|
||||
TextBean(text = realPayPrice.format2String(2), textSize = 30, textColor = "#FF0A1428")
|
||||
TextBean(text = " 元", textSize = 30, textColor = "#FF5E7585")
|
||||
list.add(TextBean(text = " 元,还需支付 ", textSize = 30, textColor = "#FF5E7585"))
|
||||
list.add(
|
||||
TextBean(
|
||||
text = realPayPrice.format2String(2),
|
||||
textSize = 30,
|
||||
textColor = "#FF0A1428",
|
||||
isBold = true
|
||||
)
|
||||
)
|
||||
}
|
||||
list.add(TextBean(text = " 元", textSize = 30, textColor = "#FF5E7585"))
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user