Commit d305d8d5 authored by 赵鹏翔's avatar 赵鹏翔

支付流程日志完善

parent 92d28b09
......@@ -10,6 +10,7 @@ import com.fastcashier.lib_common.function.account.AccountService
import com.fastcashier.lib_common.function.pay.PayRepository
import com.fastcashier.lib_common.function.print.PrintService
import com.miya.fastcashier.dao.ViewPayOrderData
import com.sdy.miya.moblie.component.pay.core.utils.PayLogFileUtils
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
......@@ -66,8 +67,8 @@ class PayViewModel : ViewModel() {
}
} catch (e: Exception) {
e.printStackTrace()
XLog.d("退款打印异常${e.message}")
refundLiveData.postValue(Result.failure(e))
XLog.d("退款打印异常${e.message}")
}
}
......@@ -77,7 +78,8 @@ class PayViewModel : ViewModel() {
* 退款固定数额
*/
fun refund(payServiceResponse: PayServiceResponse, refundPrice: String) {
XLog.d("开始退款:${GsonUtils.toJson(payServiceResponse)}")
XLog.d("退款:参数${GsonUtils.toJson(payServiceResponse)}")
PayLogFileUtils.writeLog("退款:参数${GsonUtils.toJson(payServiceResponse)}")
viewModelScope.launch(Dispatchers.IO) {
//退款
var refundPayServiceResponse: PayServiceResponse? = null
......@@ -89,20 +91,22 @@ class PayViewModel : ViewModel() {
refundParams["refundOrderNo"] = refundOrderNo
refundParams["refundPrice"] = refundPrice
refundPayServiceResponse = PayRepository.refundByOrderNo(refundParams)
XLog.d("退款成功:${GsonUtils.toJson(refundPayServiceResponse)}")
//保存到数据库
ViewPayOrderData.insert(refundPayServiceResponse)
refundLiveData.postValue(Result.success(refundPayServiceResponse))
XLog.d("退款成功:${GsonUtils.toJson(refundPayServiceResponse)}")
PayLogFileUtils.writeLog("退款成功:${GsonUtils.toJson(refundPayServiceResponse)}")
} catch (e: Exception) {
e.printStackTrace()
XLog.d("退款异常:${e.message}")
refundLiveData.postValue(Result.failure(e))
XLog.d("退款异常:${e.message}")
}
//退款打印
try {
XLog.d("开始退款打印")
XLog.d("退款打印")
PayLogFileUtils.writeLog("退款打印")
AccountService.getAccountInfo()
?.let {
refundPayServiceResponse?.let { it1 ->
......@@ -114,8 +118,10 @@ class PayViewModel : ViewModel() {
}
} catch (e: Exception) {
e.printStackTrace()
XLog.d("退款打印异常${e.message}")
refundLiveData.postValue(Result.failure(e))
XLog.d("退款打印异常${e.message}")
PayLogFileUtils.writeLog("退款打印异常${e.message}")
}
}
......@@ -129,7 +135,7 @@ class PayViewModel : ViewModel() {
* price 传进来要是分,整数
*/
fun generatePayCode(price: String, payType: String) {
XLog.d("开始生成主扫码")
XLog.d("主扫码:开始生成")
if (TextUtils.isEmpty(price)) {
payServiceResponseLiveData.value = Result.failure(RuntimeException("请输入金额!"))
return
......@@ -147,16 +153,18 @@ class PayViewModel : ViewModel() {
val sassid = AccountService.getAccountInfo()?.shopInfo?.saasid
val orderNo = sassid + System.currentTimeMillis()
XLog.d("主扫码订单号${orderNo}")
XLog.d("主扫码:订单号${orderNo},类型${payType}")
PayLogFileUtils.writeLog("主扫:主扫码订单号${orderNo},类型${payType}")
viewModelScope.launch(Dispatchers.IO) {
try {
val payServiceResponse = PayRepository.generatePayCode(orderNo, priceFen, payType)
payServiceResponseLiveData.postValue(Result.success(payServiceResponse))
XLog.d("生成付款码成功${GsonUtils.toJson(payServiceResponse)}")
PayLogFileUtils.writeLog("主扫:生成付款码成功${GsonUtils.toJson(payServiceResponse)}")
} catch (e: Exception) {
e.printStackTrace()
XLog.d("生成付款码异常${e.message}")
payServiceResponseLiveData.postValue(Result.failure(e))
XLog.d("生成付款码异常${e.message}")
}
}
}
......@@ -166,16 +174,19 @@ class PayViewModel : ViewModel() {
* 订单查询
*/
fun payResultQuery(payServiceResponse: PayServiceResponse) {
PayLogFileUtils.writeLog("支付查询订单号:${payServiceResponse.shopTradeNo}")
payResultJob = viewModelScope.launch(Dispatchers.IO) {
while (isActive) {
try {
XLog.d("支付查询订单号:${payServiceResponse.shopTradeNo}")
val payServiceResponseResult =
PayRepository.payResultQuery(payServiceResponse.shopTradeNo)
XLog.d("支付查询结果:${GsonUtils.toJson(payServiceResponseResult)}")
//加入数据库
ViewPayOrderData.insert(payServiceResponseResult)
payResultLiveData.postValue(Result.success(payServiceResponseResult))
XLog.d("支付查询结果:${GsonUtils.toJson(payServiceResponseResult)}")
PayLogFileUtils.writeLog("支付查询结果:${GsonUtils.toJson(payServiceResponseResult)}")
break
} catch (e: Exception) {
XLog.d("支付查询异常:${e.message}")
......@@ -192,12 +203,15 @@ class PayViewModel : ViewModel() {
* 订单查询,退款查询
*/
fun payResultQuery(orderNo: String) {
PayLogFileUtils.writeLog("退款查询:订单号${orderNo}")
viewModelScope.launch(Dispatchers.IO) {
try {
XLog.d("开始退款支付查询:${orderNo}")
val payServiceResponseResult = PayRepository.payResultQuery(orderNo)
XLog.d("退款支付查询成功:${GsonUtils.toJson(payServiceResponseResult)}")
payResultLiveData.postValue(Result.success(payServiceResponseResult))
XLog.d("退款查询成功:${GsonUtils.toJson(payServiceResponseResult)}")
PayLogFileUtils.writeLog("退款查询成功:${GsonUtils.toJson(payServiceResponseResult)}")
} catch (e: Exception) {
e.printStackTrace()
XLog.d("退款支付查询异常:${e.message}")
......@@ -211,7 +225,6 @@ class PayViewModel : ViewModel() {
* 被扫支付,金额是元,首先要转成分
*/
fun pay(price: String, payCode: String) {
XLog.d("被扫开始")
if (TextUtils.isEmpty(price)) {
payResultLiveData.value = Result.failure(RuntimeException("请输入金额!"))
return
......@@ -234,7 +247,8 @@ class PayViewModel : ViewModel() {
val sassid = AccountService.getAccountInfo()?.shopInfo?.saasid
val orderNo = sassid + System.currentTimeMillis()
XLog.d("被扫参数 orderNo = $orderNo price = $priceFen payCode = $payCode")
XLog.d("被扫: 参数 orderNo = $orderNo price = $priceFen payCode = $payCode")
PayLogFileUtils.writeLog("被扫:开始,参数orderNo = $orderNo price = $priceFen payCode = $payCode")
viewModelScope.launch(Dispatchers.IO) {
try {
//0代表不分类别付款
......@@ -242,6 +256,7 @@ class PayViewModel : ViewModel() {
//保存到数据库
ViewPayOrderData.insert(payServiceResponse)
payResultLiveData.postValue(Result.success(payServiceResponse))
PayLogFileUtils.writeLog("被扫:支付成功${GsonUtils.toJson(payServiceResponse)}")
XLog.d("被扫支付成功${GsonUtils.toJson(payServiceResponse)}")
} catch (e: Exception) {
e.printStackTrace()
......
......@@ -2,10 +2,12 @@ package com.fastcashier.lib_common.function.pay
import android.text.TextUtils
import androidx.annotation.WorkerThread
import com.blankj.utilcode.util.GsonUtils
import com.fastcashier.lib_common.function.account.AccountService
import com.fastcashier.lib_common.util.DateUtils
import com.sdy.miya.moblie.component.pay.core.constance.AppTagConstance
import com.sdy.miya.moblie.component.pay.core.result.ResultBuilder
import com.sdy.miya.moblie.component.pay.core.utils.PayLogFileUtils
import com.sdy.miya.moblie.component.pay.platform.MiYaPlatformPayService
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import com.sdy.miya.moblie.component.pay.platform.bean.QueryTradesByTimeResponse
......@@ -65,6 +67,7 @@ object PayRepository {
if (miYaMobilePayResult != null && miYaMobilePayResult.resultCode == ResultBuilder.SUCCESS) {
return miYaMobilePayResult.payServiceResponse
} else {
PayLogFileUtils.writeLog("支付异常${GsonUtils.toJson(miYaMobilePayResult!!)}")
throw RuntimeException(miYaMobilePayResult!!.errorMsg)
}
} catch (e: Exception) {
......@@ -122,6 +125,7 @@ object PayRepository {
if (miYaMobilePayResult != null && miYaMobilePayResult.resultCode == ResultBuilder.SUCCESS) {
return miYaMobilePayResult.payServiceResponse
} else {
PayLogFileUtils.writeLog("退款异常:${GsonUtils.toJson(miYaMobilePayResult!!)}")
throw RuntimeException(miYaMobilePayResult!!.errorMsg)
}
} catch (e: Exception) {
......@@ -180,6 +184,7 @@ object PayRepository {
if (miYaMobilePayResult != null && miYaMobilePayResult.resultCode == ResultBuilder.SUCCESS) {
return miYaMobilePayResult.payServiceResponse
} else {
PayLogFileUtils.writeLog("生成付款码异常${GsonUtils.toJson(miYaMobilePayResult!!)}")
throw RuntimeException(miYaMobilePayResult!!.errorMsg)
}
} catch (e: Exception) {
......@@ -230,6 +235,7 @@ object PayRepository {
//微信多次退款会有该提示,视为查询成功状态
return miYaMobilePayResult.payServiceResponse
} else {
PayLogFileUtils.writeLog("查询异常:${GsonUtils.toJson(miYaMobilePayResult!!)}")
throw RuntimeException(miYaMobilePayResult.payServiceResponse.chanelErrorMsg)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment