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