Geen omschrijving

PhotoPurchaseViewModel.swift 6.5KB

    // // PhotoPurchaseViewModel.swift // PaiaiDataKit // // Created by ffib on 2019/3/19. // Copyright © 2019 yb. All rights reserved. // import Foundation //wechat pay extension PhotoDetailViewModel { public final func handleResult(errorCode: Int, success: @escaping ((_ item: PhotoItem) -> Void)) { // func fetchOrderDetail() { // detailPageApi.post(param: ["order_id": orderId, "user_id": SharedUserInfo.userId] as [String: AnyObject], url: .orderDetail) { (result) in // guard let status = result["status"] as? Int, let data = result["data"] as? [String: AnyObject], let photoInfo = data["group_photo_info"] as? [String: AnyObject], status == 200 else { //// FFToastView.hideLoadingToast() //// FFToastView.showToast(inView: UIApplication.shared.keyWindow!, withText: "") // return // } // let PhotoItem = PhotoItem(map: Map(mappingType: .fromJSON, JSON: photoInfo)) // self.currentPhoto.murl = PhotoItem.murl // self.currentPhoto.rurl = PhotoItem.rurl // success(PhotoItem) //// FFToastView.hideLoadingToast() //// FFToastView.showToast(inView: UIApplication.shared.keyWindow!, withText: "") //// PhotoLocalStorage.instance.updateLocalData(PhotoItem: PhotoItem) // } // } //// Delay(3) { // let orderQequest = StatusNetworkRequest(param: ["order_id": self.orderId as AnyObject], path: .orderQuery) // self.detailPageApi.post(request: orderQequest, handler: { (res) in // if res.status == 200 { // fetchOrderDetail() // } else { //// FFToastView.hideLoadingToast() //// FFToastView.showToast(inView: UIApplication.shared.keyWindow!, withText: "支付失败") // } // }) //// } } public final func getHD(getPriceSuccess: ((_ isExist: Bool) -> Void)?) { // if !currentPhoto.rurl.isEmpty { // getPriceSuccess!(true) // return // } else { // if hdPrice != -0.01 { // payPrice(photoType: "origin") // } else { // getPrice(photoType: "origin", success: getPriceSuccess) // } // } } public final func getWatermark(getPriceSuccess: ((_ isExist: Bool) -> Void)?) { // if !currentPhoto.murl.isEmpty { // getPriceSuccess!(true) // return // } else { // if watermarkPrice != -0.01 { // payPrice(photoType: "nomark") // } else { // getPrice(photoType: "nomark", success: getPriceSuccess) // } // } } public final func payPrice(photoType: String) { //下单 // let body = photoType == "origin" ? "获取高清照片" : "获取去水印照片" // let price = photoType == "origin" ? hdPrice : watermarkPrice // let params = ["user_id": SharedUserInfo.userId, "body": body, "total_fee": price, "trade_type": "APP", "group_id": currentPhoto.group_id, "photo_id": currentPhoto.photo_id, "photo_type": photoType] as [String: AnyObject] // detailPageApi.post(param: params, url: .wxorderCreat) { (result) in //// FFToastView.hideLoadingToast() // guard let status = result["status"] as? Int, let items = result["data"] as? [String: AnyObject], status == 200 else { // return // } // if let orderid = items["order_id"] as? String, let prepay_id = items["prepay_id"] as? String, let wxpay_params = items["wxpay_params"] as? [String: AnyObject], let appid = wxpay_params["appid"] as? String, let noncestr = wxpay_params["noncestr"] as? String, let package = wxpay_params["package"] as? String, let sign = wxpay_params["sign"] as? String, let partnerid = wxpay_params["partnerid"] as? String, let timestamp = wxpay_params["timestamp"] as? String { // //支付 // self.orderId = orderid // #if !((arch(i386) || arch(x86_64))) // guard WXApi.isWXAppInstalled() else { // FFToastView.showToast(inView: UIApplication.shared.keyWindow!, withText: "尚未安装微信") // return // } // // WXApi.registerApp(appid) // let payRequest = PayReq() // payRequest.openID = appid // payRequest.partnerId = partnerid // payRequest.prepayId = prepay_id // payRequest.package = package // payRequest.nonceStr = noncestr // payRequest.timeStamp = UInt32(timestamp) ?? 0 // payRequest.sign = sign // WXApi.send(payRequest) // #endif // } // } } public final func getPrice(photoType: String, success: ((_ isExist: Bool) -> Void)?) { // let params = ["user_id": SharedUserInfo.userId, "photo_id": currentPhoto.photo_id, "photo_type": photoType] as [String: AnyObject] // detailPageApi.post(param: params, url: .picPrice) {[weak self] (result) in // guard let status = result["status"] as? Int, // let items = result["data"] as? [String: AnyObject], // status == 200, // let weakself = self else { // return // } // if let price = items["price"] as? Double { // if photoType == "origin"{ // weakself.hdPrice = price // } else { // weakself.watermarkPrice = price // } // success!(false) // } // } } }