调试优化
This commit is contained in:
@@ -230,15 +230,34 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
|
||||
//val realWeight = (lastWeight * 1000).roundToInt()
|
||||
val mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
val eatWeight = if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
presentation!!.recognitionWeight
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0) ?: 0
|
||||
var foodWeight = 0.0
|
||||
var eatWeight = 0.0
|
||||
if (chargeMode == 0) {
|
||||
//计费
|
||||
if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
eatWeight = presentation!!.lastWeight
|
||||
foodWeight = presentation!!.lastWeight
|
||||
} else {
|
||||
//余量计量
|
||||
eatWeight = presentation!!.recognitionWeight - presentation!!.lastWeight
|
||||
foodWeight = presentation!!.recognitionWeight
|
||||
}
|
||||
} else {
|
||||
presentation!!.recognitionWeight - lastWeight
|
||||
//不计费
|
||||
foodWeight = presentation!!.recognitionWeight
|
||||
eatWeight = if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
presentation!!.recognitionWeight
|
||||
} else {
|
||||
//余量计量
|
||||
presentation!!.recognitionWeight - presentation!!.lastWeight
|
||||
}
|
||||
}
|
||||
createOrder(
|
||||
foodInfo = checkedItem!!,
|
||||
foodWeight = presentation?.lastWeight?.roundToInt() ?: 0,
|
||||
foodWeight = foodWeight.roundToInt(),
|
||||
eatWeight = eatWeight.roundToInt()
|
||||
) {
|
||||
presentation?.dismiss()
|
||||
|
||||
@@ -194,8 +194,8 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||
hidePayTab()
|
||||
}
|
||||
|
||||
fun getQrCodeImg(orderId: String, userId: String? = null, block: (String?) -> Unit) {
|
||||
userViewModel.getQrCodeImg(orderId = orderId, userId = userId) { qrCodeImg ->
|
||||
fun getQrCodeImg(orderId: String, userId: String? = null, totalFee: String?=null, block: (String?) -> Unit) {
|
||||
userViewModel.getQrCodeImg(orderId = orderId, userId = userId, totalFee = totalFee) { qrCodeImg ->
|
||||
runOnUiThread {
|
||||
if (qrCodeImg.isNullOrBlank()) {
|
||||
ToastUtils.showToast("获取二维码失败")
|
||||
@@ -226,11 +226,10 @@ class PayActivity : BaseActivity<ActivityPayBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun queryOrderState(isVip: Boolean, block: (Boolean) -> Unit) {
|
||||
suspend fun queryOrderState(block: (Boolean) -> Unit) {
|
||||
userViewModel.queryOrderState(orderId = foodOrderId) { payResult ->
|
||||
runOnUiThread {
|
||||
if (payResult) {
|
||||
showPaySuccess(isVip)
|
||||
block(true)
|
||||
} else {
|
||||
block(false)
|
||||
|
||||
@@ -100,19 +100,36 @@ class PayResultFragment : BaseFragment<FragmentPayResultBinding>() {
|
||||
isEnabled = true
|
||||
//点击支付,接口成功打开成功页面
|
||||
setOnClickListener {
|
||||
memberPay()
|
||||
payActivity?.showWaitingDialog("支付中,请稍后……")
|
||||
memberPay(totalPrice.format2String(2)) {
|
||||
binding.root.postDelayed({
|
||||
payActivity?.hideWaitingDialog()
|
||||
payActivity?.showPaySuccess(true)
|
||||
},1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
binding.ivPayQrCode.visible()
|
||||
binding.btnConfirmPay.isEnabled = false
|
||||
val payAmount = totalPrice - balance
|
||||
payActivity?.getQrCodeImg(
|
||||
orderId = payActivity!!.foodOrderId,
|
||||
userId = memberInfo!!.id
|
||||
userId = memberInfo!!.id,
|
||||
totalFee = payAmount.format2String(2)
|
||||
) { qrCodeImg ->
|
||||
binding.ivPayQrCode.load(qrCodeImg)
|
||||
//扫码成功回调打开成功页面
|
||||
paySuccessCallback(true)
|
||||
}
|
||||
paySuccessCallback {
|
||||
//扫码成功回调打开成功页面,后端处理余额扣除
|
||||
payActivity?.showPaySuccess(true)
|
||||
// if (balance > 0.0) {
|
||||
// memberPay(balance.format2String(2)) {
|
||||
// //扫码成功+会员支付完成后打开成功页面
|
||||
// payActivity?.showPaySuccess(true)
|
||||
// }
|
||||
// } else {
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,24 +204,19 @@ class PayResultFragment : BaseFragment<FragmentPayResultBinding>() {
|
||||
phone
|
||||
}
|
||||
|
||||
private fun memberPay() {
|
||||
private fun memberPay(total: String, callback:()-> Unit) {
|
||||
payActivity?.run {
|
||||
showWaitingDialog("支付中,请稍后……")
|
||||
memberPay(
|
||||
hashMapOf(
|
||||
param = hashMapOf(
|
||||
//支付金额
|
||||
"totalFee" to totalPrice.format2String(2),
|
||||
"totalFee" to total,
|
||||
//订单号
|
||||
"orderNo" to payActivity!!.foodOrderId,
|
||||
//用户id
|
||||
"memberId" to memberInfo!!.id!!
|
||||
)
|
||||
) {
|
||||
binding.root.postDelayed({
|
||||
hideWaitingDialog()
|
||||
showPaySuccess(true)
|
||||
},1000)
|
||||
}
|
||||
),
|
||||
block = callback
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,10 +227,11 @@ class PayResultFragment : BaseFragment<FragmentPayResultBinding>() {
|
||||
|
||||
private val intervalExecutor by lazy { IntervalExecutor() }
|
||||
private var payTaskJob: Job? = null
|
||||
fun paySuccessCallback(isVip: Boolean) {
|
||||
fun paySuccessCallback(callback: () -> Unit) {
|
||||
payTaskJob = intervalExecutor.startIntervalTaskWithInitialDelay(5000, 10000) {
|
||||
payActivity?.queryOrderState(isVip) { paySuccess ->
|
||||
payActivity?.queryOrderState { paySuccess ->
|
||||
if (paySuccess) {
|
||||
callback()
|
||||
payTaskJob?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
+16
-13
@@ -16,7 +16,7 @@ import com.sw.dualscreen.databinding.FragmentScanQrcodePayBinding
|
||||
import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.utils.IntervalExecutor
|
||||
|
||||
class ScanQrCodePayFragment: BaseFragment<FragmentScanQrcodePayBinding>() {
|
||||
class ScanQrCodePayFragment : BaseFragment<FragmentScanQrcodePayBinding>() {
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -26,7 +26,7 @@ class ScanQrCodePayFragment: BaseFragment<FragmentScanQrcodePayBinding>() {
|
||||
private var foodName: String? = null
|
||||
private var payAmount: String? = null
|
||||
private var payQrCodePic: String? = null
|
||||
var presentation: ScanQrCodePayPresentation?=null
|
||||
var presentation: ScanQrCodePayPresentation? = null
|
||||
private var countDownJob: Job? = null
|
||||
|
||||
override fun inflateViewBinding(): FragmentScanQrcodePayBinding {
|
||||
@@ -38,9 +38,9 @@ class ScanQrCodePayFragment: BaseFragment<FragmentScanQrcodePayBinding>() {
|
||||
|
||||
foodName = payActivity.foodInfo?.foodName
|
||||
payAmount = payActivity.foodInfo?.specPrice.format2String(2)
|
||||
binding.tvRealAmount.text = getAmountText(payAmount?:"")
|
||||
binding.tvRealAmount.text = getAmountText(payAmount ?: "")
|
||||
|
||||
payActivity.getQrCodeImg(orderId = payActivity.foodOrderId) {
|
||||
payActivity.getQrCodeImg(orderId = payActivity.foodOrderId, totalFee = payAmount) {
|
||||
payQrCodePic = it
|
||||
binding.ivPayQrCode.load(payQrCodePic)
|
||||
binding.tvPayResult.text = "待支付(60s)..."
|
||||
@@ -79,23 +79,25 @@ class ScanQrCodePayFragment: BaseFragment<FragmentScanQrcodePayBinding>() {
|
||||
private fun showSubScreen() {
|
||||
// 查找副屏(通常索引为1)
|
||||
if (displays.size > 1) {
|
||||
presentation = ScanQrCodePayPresentation(activity = payActivity, type = 0, display = displays[1]) {
|
||||
presentation?.dismiss()
|
||||
}.also {
|
||||
it.foodName = foodName
|
||||
it.totalPrice = payActivity.foodInfo?.specPrice?:0.0
|
||||
it.payQrCodePic = payQrCodePic
|
||||
}
|
||||
presentation =
|
||||
ScanQrCodePayPresentation(activity = payActivity, type = 0, display = displays[1]) {
|
||||
presentation?.dismiss()
|
||||
}.also {
|
||||
it.foodName = foodName
|
||||
it.totalPrice = payActivity.foodInfo?.specPrice ?: 0.0
|
||||
it.payQrCodePic = payQrCodePic
|
||||
}
|
||||
presentation?.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAmountText(amount:String): SpannedString {
|
||||
private fun getAmountText(amount: String): SpannedString {
|
||||
return buildSpannedString {
|
||||
append("¥", AbsoluteSizeSpan(36, true), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
append(amount, AbsoluteSizeSpan(60, true), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
}
|
||||
|
||||
private fun startCountDown() {
|
||||
countDownJob = countDownByFlow(
|
||||
total = 60,
|
||||
@@ -116,8 +118,9 @@ class ScanQrCodePayFragment: BaseFragment<FragmentScanQrcodePayBinding>() {
|
||||
private var payTaskJob: Job? = null
|
||||
fun paySuccessCallback(isVip: Boolean) {
|
||||
payTaskJob = intervalExecutor.startIntervalTaskWithInitialDelay(5000, 10000) {
|
||||
payActivity.queryOrderState(isVip) { paySuccess ->
|
||||
payActivity.queryOrderState { paySuccess ->
|
||||
if (paySuccess) {
|
||||
payActivity.showPaySuccess(isVip)
|
||||
payTaskJob?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,8 @@ class MainScreenPresentation(
|
||||
registerDataChange()
|
||||
}
|
||||
|
||||
private var isFirstGetWeight = true
|
||||
|
||||
fun updateWeight(weight: Double) {
|
||||
lastWeight = weight * 1000 // 将千克转成克
|
||||
Timber.tag(TAG)
|
||||
@@ -121,11 +123,15 @@ class MainScreenPresentation(
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
if (mealPickupMode == 1 && chargeMode == 0) {
|
||||
//余量计量+计费模式
|
||||
recognitionWeight = lastWeight
|
||||
if (weight > 5) {
|
||||
if (isFirstGetWeight && lastWeight > 5) {
|
||||
recognitionWeight = lastWeight
|
||||
isFirstGetWeight = false
|
||||
}
|
||||
if (lastWeight > 5) {
|
||||
//余量计量,有重量的情况下不回到重新识别状态
|
||||
return
|
||||
}
|
||||
isFirstGetWeight = true
|
||||
}
|
||||
if (currentStep == 2 && lastWeight <= 5 && isGoStep1) {
|
||||
//人脸识别过程中,秤上物品拿走
|
||||
@@ -159,7 +165,16 @@ class MainScreenPresentation(
|
||||
Timber.tag(TAG).e("updateWeight dinnerType is null")
|
||||
return
|
||||
}
|
||||
calculateNutrition(recognitionWeight - lastWeight)
|
||||
if (chargeMode == 1) {
|
||||
//不计费
|
||||
if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
calculateNutrition(lastWeight)
|
||||
} else {
|
||||
//余量计量
|
||||
calculateNutrition(recognitionWeight - lastWeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setStepChangeCallback(callback: (Int) -> Unit) {
|
||||
|
||||
@@ -277,10 +277,10 @@ class UserViewModel : BaseViewModel() {
|
||||
/**
|
||||
* 获取支付二维码
|
||||
*/
|
||||
fun getQrCodeImg(orderId: String, userId: String? = null, block: (String?) -> Unit) {
|
||||
fun getQrCodeImg(orderId: String, userId: String? = null, totalFee: String?=null, block: (String?) -> Unit) {
|
||||
Timber.tag(TAG).d("getQrCodeImg orderId = $orderId, userId = $userId")
|
||||
launch {
|
||||
val response = repository.getQrCodeImg(orderNo = orderId, memberId = userId)
|
||||
val response = repository.getQrCodeImg(orderNo = orderId, memberId = userId, totalFee = totalFee)
|
||||
if (parseResponse(response)) {
|
||||
block(response.data)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user