营养接口调试、支付接口联调
This commit is contained in:
@@ -122,30 +122,30 @@ class UserViewModel : BaseViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getUserFaceCache2(index: Int = 0) {
|
||||
Timber.d("getUserFaceCache index = $index")
|
||||
launch {
|
||||
_loadFaceResult.value = false
|
||||
val response = repository.getUserFaceCache2(index)
|
||||
if (parseResponse(response)) {
|
||||
// 获取成功一次后缓存状态
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
||||
withContext(Dispatchers.Default) {
|
||||
val list: List<UserFaceModel2> = response.result?.records ?: emptyList()
|
||||
val faceEntity = list.map {
|
||||
FaceEntity(it.userId, null, Base64.decode(it.face))
|
||||
}
|
||||
faceApi.updateFaceData2(index, faceEntity)
|
||||
}
|
||||
val nextPageIndex = response.result?.nextPageIndex ?: -1
|
||||
if (nextPageIndex > 0) {
|
||||
getUserFaceCache2(nextPageIndex)
|
||||
} else {
|
||||
_loadFaceResult.value = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fun getUserFaceCache2(index: Int = 0) {
|
||||
Timber.d("getUserFaceCache index = $index")
|
||||
launch {
|
||||
_loadFaceResult.value = false
|
||||
val response = repository.getUserFaceCache2(index)
|
||||
if (parseResponse(response)) {
|
||||
// 获取成功一次后缓存状态
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
||||
withContext(Dispatchers.Default) {
|
||||
val list: List<UserFaceModel2> = response.result?.records ?: emptyList()
|
||||
val faceEntity = list.map {
|
||||
FaceEntity(it.userId, null, Base64.decode(it.face))
|
||||
}
|
||||
faceApi.updateFaceData2(index, faceEntity)
|
||||
}
|
||||
val nextPageIndex = response.result?.nextPageIndex ?: -1
|
||||
if (nextPageIndex > 0) {
|
||||
getUserFaceCache2(nextPageIndex)
|
||||
} else {
|
||||
_loadFaceResult.value = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getCollectedFoodList(
|
||||
pageNo: Int = 1,
|
||||
@@ -155,7 +155,11 @@ class UserViewModel : BaseViewModel() {
|
||||
) {
|
||||
Timber.tag(TAG).d("getCollectedFoodList index = $pageNo")
|
||||
launch {
|
||||
val response = repository.getCollectedFoodList(pageNum = pageNo, pageSize = pageSize, foodName = foodName)
|
||||
val response = repository.getCollectedFoodList(
|
||||
pageNum = pageNo,
|
||||
pageSize = pageSize,
|
||||
foodName = foodName
|
||||
)
|
||||
if (parseResponse(response)) {
|
||||
withContext(Dispatchers.Default) {
|
||||
val list: List<CollectedFoodInfo> = response.data ?: emptyList()
|
||||
@@ -269,9 +273,9 @@ class UserViewModel : BaseViewModel() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户就餐数据
|
||||
* 获取支付二维码
|
||||
*/
|
||||
fun getQrCodeImg(orderId: String, userId: String?=null, block: (String?) -> Unit) {
|
||||
fun getQrCodeImg(orderId: String, userId: String? = null, block: (String?) -> Unit) {
|
||||
Timber.tag(TAG).d("getQrCodeImg orderId = $orderId, userId = $userId")
|
||||
launch {
|
||||
val response = repository.getQrCodeImg(orderNo = orderId, memberId = userId)
|
||||
@@ -321,11 +325,11 @@ class UserViewModel : BaseViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun createOrder(order: FoodOrder, block:(String)-> Unit) {
|
||||
fun createOrder(order: FoodOrder, block: (String) -> Unit) {
|
||||
Timber.tag(TAG).d("createOrder")
|
||||
launchWithLoading {
|
||||
val response = repository.createOrder(order)
|
||||
if (parseResponse(response)) {
|
||||
if (parseResponse(response)) {
|
||||
block(response.data.toString())
|
||||
} else {
|
||||
block("")
|
||||
@@ -337,72 +341,60 @@ class UserViewModel : BaseViewModel() {
|
||||
/**
|
||||
* 现金支付
|
||||
*/
|
||||
fun cashPay(param: HashMap<String, String>, block:(Boolean)-> Unit) {
|
||||
fun cashPay(param: HashMap<String, String>, block: (Boolean) -> Unit) {
|
||||
Timber.tag(TAG).d("cashPay")
|
||||
launchWithLoading {
|
||||
val response = repository.cashPay(param)
|
||||
if (parseResponse(response)) {
|
||||
block(response.data?:false)
|
||||
block(response.data ?: false)
|
||||
} else {
|
||||
block(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单状态
|
||||
*
|
||||
* @param queryType 查询类型 1支付2退款
|
||||
* @param orderId 订单号
|
||||
*/
|
||||
fun queryOrderState(queryType:Int, orderId:String, block:(PayResult?)-> Unit) {
|
||||
Timber.tag(TAG).d("queryOrderState")
|
||||
val param = hashMapOf(
|
||||
"queryType" to "$queryType",
|
||||
"payOrderNo" to orderId
|
||||
)
|
||||
launchWithLoading {
|
||||
val response = repository.queryOrderState(param)
|
||||
if (parseResponse(response)) {
|
||||
block(response.data)
|
||||
} else {
|
||||
block(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * 查询订单状态
|
||||
// *
|
||||
// * @param queryType 查询类型 1支付2退款
|
||||
// * @param orderId 订单号
|
||||
// */
|
||||
// fun queryOrderState(queryType:Int, orderId:String, block:(PayResult?)-> Unit) {
|
||||
// Timber.tag(TAG).d("queryOrderState")
|
||||
// val param = hashMapOf(
|
||||
// "queryType" to "$queryType",
|
||||
// "payOrderNo" to orderId
|
||||
// )
|
||||
// launchWithLoading {
|
||||
// val response = repository.queryOrderState(param)
|
||||
// if (parseResponse(response)) {
|
||||
// block(response.data)
|
||||
// } else {
|
||||
// block(null)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 扫码成功回调
|
||||
*
|
||||
* @param queryType 查询类型 1支付2退款
|
||||
* @param orderId 订单号
|
||||
*/
|
||||
fun paySuccessCallback(queryType:Int, orderId:String, block:()-> Unit) {
|
||||
Timber.tag(TAG).d("paySuccessCallback")
|
||||
val param = hashMapOf(
|
||||
"queryType" to "$queryType",
|
||||
"payOrderNo" to orderId
|
||||
)
|
||||
launchWithLoading {
|
||||
var orderState = false
|
||||
while (orderState.not()) {
|
||||
val response = repository.queryOrderState(param)
|
||||
if (parseResponse(response)) {
|
||||
orderState = response.data?.paySuc == "1"
|
||||
if (orderState) {
|
||||
block()
|
||||
}
|
||||
}else {
|
||||
orderState = false
|
||||
}
|
||||
}
|
||||
suspend fun queryOrderState(orderId: String, block: (Boolean) -> Unit) {
|
||||
Timber.tag(TAG).d("queryOrderState")
|
||||
val response = repository.queryOrderState(orderNo = orderId)
|
||||
if (parseResponse(response)) {
|
||||
val orderState = response.data == "1"
|
||||
block(orderState)
|
||||
} else {
|
||||
block(false)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员支付
|
||||
*/
|
||||
fun memberPay(param: HashMap<String, String>, block:(Boolean)-> Unit) {
|
||||
fun memberPay(param: HashMap<String, String>, block: (Boolean) -> Unit) {
|
||||
Timber.tag(TAG).d("memberPay")
|
||||
launchWithLoading {
|
||||
val response = repository.memberPay(param)
|
||||
@@ -417,7 +409,7 @@ class UserViewModel : BaseViewModel() {
|
||||
/**
|
||||
* 绑定订单
|
||||
*/
|
||||
fun bindOrder(userId: String, orderId: String, block:(Boolean)-> Unit){
|
||||
fun bindOrder(userId: String, orderId: String, block: (Boolean) -> Unit) {
|
||||
Timber.tag(TAG).d("bindOrder")
|
||||
launchWithLoading {
|
||||
val response = repository.bindOrder(userId = userId, orderId = orderId)
|
||||
@@ -429,7 +421,7 @@ class UserViewModel : BaseViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getMemberInfo(memberId: String, block:(MemberInfo?)-> Unit) {
|
||||
fun getMemberInfo(memberId: String, block: (MemberInfo?) -> Unit) {
|
||||
Timber.tag(TAG).d("getMemberInfo")
|
||||
launchWithLoading {
|
||||
val response = repository.getMemberInfo(memberId)
|
||||
|
||||
Reference in New Issue
Block a user