增加支付接口相关逻辑
This commit is contained in:
@@ -10,7 +10,10 @@ import com.sw.dualscreen.model.response.DinnerType
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
import com.sw.dualscreen.model.response.FoodOrder
|
||||
import com.sw.dualscreen.model.response.MemberInfo
|
||||
import com.sw.dualscreen.model.response.PayResult
|
||||
import com.sw.dualscreen.model.response.UserFaceModel
|
||||
import com.sw.dualscreen.model.response.UserFaceModel2
|
||||
import com.sw.dualscreen.model.response.UserNutrition
|
||||
import com.sw.dualscreen.model.response.UserNutritionData
|
||||
import com.sw.dualscreen.objbox.CollectedFoodInfo
|
||||
import com.sw.dualscreen.utils.GsonUtils
|
||||
@@ -94,7 +97,7 @@ class UserViewModel : BaseViewModel() {
|
||||
// 获取成功一次后缓存状态
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
||||
withContext(Dispatchers.Default) {
|
||||
val list: List<UserFaceModel> = response.result ?: emptyList()
|
||||
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||
val item = list.firstOrNull { it.userId == "1951105919342936066" }
|
||||
Timber.tag(TAG).d("getUserFaceCache userId = ${item?.userId}")
|
||||
val faceEntity = list.map {
|
||||
@@ -119,6 +122,31 @@ 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 getCollectedFoodList(
|
||||
pageNo: Int = 1,
|
||||
pageSize: Int = 100,
|
||||
@@ -130,7 +158,7 @@ class UserViewModel : BaseViewModel() {
|
||||
val response = repository.getCollectedFoodList(pageNum = pageNo, pageSize = pageSize, foodName = foodName)
|
||||
if (parseResponse(response)) {
|
||||
withContext(Dispatchers.Default) {
|
||||
val list: List<CollectedFoodInfo> = response.result ?: emptyList()
|
||||
val list: List<CollectedFoodInfo> = response.data ?: emptyList()
|
||||
block(list)
|
||||
}
|
||||
}
|
||||
@@ -199,9 +227,9 @@ class UserViewModel : BaseViewModel() {
|
||||
launchWithLoading {
|
||||
val response = repository.getRestInfoFoodsByType(foodName = foodName)
|
||||
if (parseResponse(response)) {
|
||||
val list = response.result ?: emptyList()
|
||||
val list = response.data ?: emptyList()
|
||||
action(list)
|
||||
_identifiedFoodInfoList.value = response.result ?: emptyList()
|
||||
_identifiedFoodInfoList.value = response.data ?: emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -211,16 +239,46 @@ class UserViewModel : BaseViewModel() {
|
||||
_searchFoodInfoList.value = emptyList<FoodInfo>()
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 获取用户就餐数据
|
||||
// */
|
||||
// fun getUserNutritionData(userId: String, foodId: String) {
|
||||
// Timber.tag(TAG).d("getUserNutritionData userId = ${userId}, foodId = $foodId")
|
||||
// _nutritionData.value = null
|
||||
// launch {
|
||||
// val response = repository.getUserNutritionData(userId = userId, foodId = foodId)
|
||||
// if (parseResponse(response)) {
|
||||
// _nutritionData.value = response.result
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取用户就餐数据
|
||||
*/
|
||||
fun getUserNutritionData(userId: String, foodId: String) {
|
||||
Timber.tag(TAG).d("getUserNutritionData userId = ${userId}, foodId = $foodId")
|
||||
_nutritionData.value = null
|
||||
fun getUserNutritionData(userId: String, block: (UserNutrition?) -> Unit) {
|
||||
Timber.tag(TAG).d("getUserNutritionData userId = $userId")
|
||||
launch {
|
||||
val response = repository.getUserNutritionData(userId = userId, foodId = foodId)
|
||||
val response = repository.getUserNutritionData(userId = userId)
|
||||
if (parseResponse(response)) {
|
||||
_nutritionData.value = response.result
|
||||
block(response.data)
|
||||
} else {
|
||||
block(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户就餐数据
|
||||
*/
|
||||
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)
|
||||
if (parseResponse(response)) {
|
||||
block(response.data)
|
||||
} else {
|
||||
block(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,7 +289,7 @@ class UserViewModel : BaseViewModel() {
|
||||
launch {
|
||||
val response = repository.getDinnerType()
|
||||
if (parseResponse(response)) {
|
||||
_dinnerTypeInfo.value = response.result
|
||||
_dinnerTypeInfo.value = response.data
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,7 +312,7 @@ class UserViewModel : BaseViewModel() {
|
||||
launchWithLoading {
|
||||
val response = repository.getFoodInfo(foodName = foodName)
|
||||
if (parseResponse(response)) {
|
||||
val list = response.result ?: emptyList()
|
||||
val list = response.data ?: emptyList()
|
||||
_identifiedFoodInfoList.value = list
|
||||
action(list)
|
||||
} else {
|
||||
@@ -275,6 +333,90 @@ class UserViewModel : BaseViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 现金支付
|
||||
*/
|
||||
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)
|
||||
} 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 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员支付
|
||||
*/
|
||||
fun memberPay(param: HashMap<String, String>, block:(Boolean)-> Unit) {
|
||||
Timber.tag(TAG).d("memberPay")
|
||||
launchWithLoading {
|
||||
val response = repository.memberPay(param)
|
||||
if (parseResponse(response)) {
|
||||
block(true)
|
||||
} else {
|
||||
block(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定订单
|
||||
*/
|
||||
fun bindOrder(userId: String, orderId: String, block:(Boolean)-> Unit){
|
||||
Timber.tag(TAG).d("bindOrder")
|
||||
launchWithLoading {
|
||||
|
||||
Reference in New Issue
Block a user