/* * @Author: gaorf30153 gaorf30153@hundsun.com * @Date: 2024-06-24 09:53:36 * @LastEditors: gaorf30153 gaorf30153@hundsun.com * @LastEditTime: 2024-09-10 17:09:00 * @FilePath: \wxminipro\plugin\utils\commonReq.js * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ import Api from "../api/index.js" import { getStore, removeStore, setStore } from "./index.js" import { requestFnc } from "./request.js" import { configObj } from "../config.js" import { encrypt } from "./aesutils.js" // 微信车主签约 export function wxSign(cb, status) { let params = { filename: Api.signBank.filename, data: { accountId: getStore("accountId"), productId: JSON.parse(getStore("productObj")).productId, preVehicleId: getStore("vehicleId"), etcProductId: getStore("etcProductId"), signArgs: JSON.stringify({ openId: getStore("myWxOpenId") }), signChannelCode: "102", notifyAppId: "#", notifyPage: "#", }, } requestFnc( Api.signBank.url, params, (res) => { setStore("signChannelId", res.signChannelId) // 已签约未支付 if (status === 5) { getOrderRenewalPayInfo((handleFees) => { if (!getStore("wechatSignNo")) { wx.redirectTo({ url: "plugin://issuer-plugin/delivery-method", }) } if (getStore("wechatSignNo")) { wechatSignNoOrderRenewalPayInfo(handleFees, cb) } }) return } // 已签约未绑定 if (res.signStatus === 1) { getSignResult(cb) } else { let list = JSON.parse(res.signParameter) let params = {} for (let obj of list) { // 高速 if (obj.tradeScene === "HIGHWAY") { params = obj.wxVehicleModel } } console.log("签约参数", params) wx.navigateToMiniProgram({ appId: params.appId, path: params.path, extraData: params.extraData, success(res) { setStore("sign", "1") console.log("跳转车主小程序") }, fail(res) { console.log("未跳转小程序", res) }, }) cb && cb() } }, () => { cb && cb() } ) } // 签约结果查询 export function getSignResult(cb) { let params = { filename: Api.signResult.filename, data: { accountId: getStore("accountId"), vehicleId: getStore("vehicleId"), signArgs: JSON.stringify({ openId: getStore("myWxOpenId"), }), signChannelId: getStore("signChannelId"), }, } if (getStore("sign") == 2) { //恢复签约 params.data = { ...params.data, source: "resumeSign" } } requestFnc( Api.signResult.url, params, (res) => { if (res.status === 1) { if (getStore("sign") == 2) { //恢复签约 wx.showModal({ title: "提示", content: "车辆恢复签约已完成", showCancel: false, success: (res) => { if (res.confirm) { wx.reLaunch({ url: getStore("redirectUrl"), }) } }, }) } else { bindSignChannel(cb) } } else { if (getStore("sign") === 2) { //恢复签约 wx.showModal({ title: "提示", content: "签约失败, 请重新签约", showCancel: false, success: (res) => { if (res.confirm) { wx.reLaunch({ url: getStore("redirectUrl"), }) } }, }) } else { wx.showToast({ title: "签约失败, 请重新签约", icon: "none", }) } cb && cb() } removeStore("sign") }, () => { cb && cb() } ) } // 校验车辆状态 export function checkCarStatus(cb) { getCarStatus((status) => { // 不存在 if (status === 0) { wx.showModal({ title: "提示", content: "该车辆不存在", showCancel: false, success(res) { if (res.confirm) { wx.navigateBack(1) } }, }) cb && cb() return } // 已完成 if (status === 1) { wx.showModal({ title: "提示", content: "该车辆已完成办理", showCancel: false, success(res) { if (res.confirm) { wx.navigateBack(1) } }, }) cb && cb() return } // 上传车主证件 if (status === 2) { // wx.showModal({ // title: "提示", // content: text, // confirmText: "传身份证", // cancelText: "传企业证", // success(res) { // if (res.confirm) { // wx.redirectTo({ // url: "plugin://issuer-plugin/uploadPersion?type=carOwners", // }) // } else if (res.cancel) { // wx.redirectTo({ // url: "plugin://issuer-plugin/uploadCorp?type=carOwners", // }) // } // }, // }) cb && cb(status) return } // 未签约或已签约未绑定 if (status === 4) { //app扫码签约 if (getStore("wechatSignNo")) { wx.showModal({ title: "提示", content: "即将前往微信车主认证", confirmColor: "#00B38B", confirmText: "前往认证", success(res) { if (res.confirm) { wxSign(cb) } else if (res.cancel) { wx.reLaunch({ url: getStore("redirectUrl"), }) } }, }) } else { wxSign(cb) } return } // 未下单未支付 if (status === 5) { wxSign(cb, status) return } // 未二发 if (status === 6) { if (getStore("wechatSignNo")) { wx.showModal({ title: "提示", content: "车辆绑定签约支付已完成", showCancel: false, success: (res) => { if (res.confirm) { wx.reLaunch({ url: getStore("redirectUrl"), }) } }, }) } else { wx.redirectTo({ url: "plugin://issuer-plugin/device-act-guidance?activeCode=6", }) } return } // 已二发未激活 if (status === 7) { wx.redirectTo({ url: "plugin://issuer-plugin/device-act-guidance?activeCode=7", }) return } }, cb) } // 获取车辆办理状态 function getCarStatus(cb1, cb2) { let params = { filename: Api.carHandle.filename, data: { vehicleId: getStore("vehicleId"), accountId: getStore("accountId"), }, } console.log("查询车辆办理状态", params.data) requestFnc( Api.carHandle.url, params, (res) => { let { etcProductId = "" } = res setStore("etcProductId", etcProductId) // 续办 if (getStore("handleType") === "continuation") { cb1(res.status) return } // 重新激活 if (getStore("handleType") === "reactivate") { if (res.status === 1) { wx.redirectTo({ url: "plugin://issuer-plugin/device-act-guidance?activeCode=7", }) } else { wx.showModal({ title: "提示", content: "该车辆未完成办理", showCancel: false, success(res) { if (res.confirm) { wx.navigateBack(1) } }, }) } cb2 && cb2() return } //恢复签约 if (getStore("handleType") === "resumeSigning") { if (res.status === 1) { _accountResumesign(cb2) } else { wx.showModal({ title: "提示", content: "该车辆未完成办理", showCancel: false, success(res) { if (res.confirm) { wx.reLaunch({ url: getStore("redirectUrl"), }) } }, }) cb2 && cb2() } return } // 售后(包含新办的退货,换货,补货) if (getStore("handleType") === "aftersale") { let type = getStore("afterType") if (!type) { wx.showModal({ title: "提示", content: "售后类型缺失", showCancel: false, success(res) { if (res.confirm) { wx.navigateBack(1) } }, }) cb2 && cb2() return } // 续期,挂失,解挂,注销需要校验车辆状态,不需要校验订单状态 if (res.status === 1) { // 续期 if (type === "4") { wx.redirectTo({ url: "plugin://issuer-plugin/renewal-connecting", }) return // 注销 } else if (type === "6") { wx.redirectTo({ url: "plugin://issuer-plugin/logOff", }) return } else if (type === "1") { // 挂失/解挂 wx.redirectTo({ url: "plugin://issuer-plugin/devApplyReplace", }) return } } else if (type !== "7" && type !== "8" && type !== "9") { wx.showModal({ title: "提示", content: "该车辆未完成办理", showCancel: false, success(res) { if (res.confirm) { wx.navigateBack(1) } }, }) cb2 && cb2() return } // 新办 if (getStore("orderType") === "1") { // 新办订单办理类型校验 getPreSalesOrderDetail(() => { dealAfter(type) }, cb2) } else if (getStore("orderType") === "2") { // 售后订单办理 getAfterSalesOrderDetail(() => { if (res.status === 1) { dealAfter(type) } else { wx.showModal({ title: "提示", content: "该车辆未完成办理", showCancel: false, success(res) { if (res.confirm) { wx.navigateBack(1) } }, }) cb2 && cb2() } }, cb2) } else { wx.showModal({ title: "提示", content: "未查询到订单类型", showCancel: false, success(res) { if (res.confirm) { wx.navigateBack(1) } }, }) cb2 && cb2() } } //APP拉起前签约 if (getStore("wechatSignNo")) { cb1(res.status) return } }, (msg) => { cb2 && cb2() } ) } // 售后处理 function dealAfter(type) { // 退货、换货、补货 if (type === "7" || type === "8" || type === "9") { // 还要结合订单状态 const orderStatus = getStore("orderStatus") console.log("工单状态 2333----", orderStatus) if (orderStatus == "4" || orderStatus == "5" || orderStatus == "6") { // 已发货,才能申请 退、换、补 wx.redirectTo({ url: "plugin://issuer-plugin/applyExchange", }) } else { wx.redirectTo({ url: "plugin://issuer-plugin/exchangeDetail", }) } return } // 更换、补办 if (type === "3" || type === "5") { // 14-卡补办 15-OBU补办 16-卡更换 17-OBU更换 18-卡和OBU更换 let afterOrderType = getStore("afterOrderType") let orderStatus = getStore("orderStatus") // 3 审核不通过 5 已激活 6 取消订单 if (orderStatus == "3" || orderStatus == "5" || orderStatus == "6") { wx.redirectTo({ url: "plugin://issuer-plugin/devApplyReplace", }) } else { if (afterOrderType == "14" || afterOrderType == "15") { wx.redirectTo({ url: `plugin://issuer-plugin/divReissue?type=${ afterOrderType == "14" ? 1 : 2 }`, }) } if ( afterOrderType == "16" || afterOrderType == "17" || afterOrderType == "18" ) { wx.redirectTo({ url: `plugin://issuer-plugin/deviceReplace?type=${ afterOrderType == "16" ? 1 : afterOrderType == "17" ? 2 : 3 }`, }) } } } } // 获取账户列表 export function getAccountList(cb1, cb2) { let params = { filename: Api.getAccountList.filename, data: {}, } requestFnc( Api.getAccountList.url, params, (res) => { let list = JSON.parse(res.data) let hasPersion = false let integralFlag = 1 for (let obj of list) { if (obj.accountType == "1" && obj.idType === "101") { setStore("persionAccountId", obj.accountId) if (getStore("accountType") == "1") { setStore("accountId", obj.accountId) } hasPersion = true integralFlag = obj.integralFlag } } cb1 && cb1(hasPersion, list, integralFlag) }, (msg) => { cb2 && cb2() } ) } // 获取车辆列表 function getCarList(cb1, cb2) { let params = { filename: Api.getCarList.filename, data: { accountId: getStore("accountId"), pageNo: 1, pageSize: 99, }, } requestFnc( Api.getCarList.url, params, (res) => { let carList = JSON.parse(res.encryptedData) let hasCar = false for (let obj of carList) { if (obj.vehicleId === getStore("vehicleId")) { hasCar = true setStore("plateNum", obj.plateNum) setStore("plateColor", `${obj.plateColor}`) getCarStatus(cb1, cb2) } } if (!hasCar) { wx.showModal({ title: "提示", content: "当前账户下无该车辆", showCancel: false, success(res) { if (res.confirm) { wx.navigateBack(1) } }, }) cb2 && cb2() } }, (msg) => { cb2 && cb2() } ) } // 关联签约渠道 function bindSignChannel(cb) { let productId = JSON.parse(getStore("productObj")).productId let params = { filename: Api.bindSignChannel.filename, data: { accountId: getStore("accountId"), vehicleId: getStore("vehicleId"), signChannelId: getStore("signChannelId"), code: encrypt(productId, configObj.aesKey), validType: "2", }, } requestFnc( Api.bindSignChannel.url, params, (res) => { // APP端只签约绑定之后需要下单 if (getStore("wechatSignNo")) { getOrderRenewalPayInfo((handleFees) => { wechatSignNoOrderRenewalPayInfo(handleFees, cb) }) } else { wx.redirectTo({ url: "plugin://issuer-plugin/delivery-method", }) } }, () => { cb && cb() } ) } // 创建支付订单 function preOrder({ addressId, sendType, packageId, processingFeeType, cb }) { console.log("----preOrder1111-----", { addressId, sendType, packageId, processingFeeType, }) let params = { filename: Api.preOrder.filename, data: { accountId: getStore("accountId"), packageId, vehicleId: getStore("vehicleId"), signChannelId: getStore("signChannelId"), wxOpenId: getStore("myWxOpenId"), bizType: "1", addressId, sendType, processingFeeType, payRouteCode: "04" }, } console.log("----preOrder2222-----", params) requestFnc( Api.preOrder.url, params, (res) => { let paymentArgs = { timeStamp: res.timeStamp + "", nonceStr: res.nonceStr, signType: res.signType, paySign: res.paySign, package: res.wxPackage, fee: res.money, payTradeNo: res.payTradeNo, } cb && cb(paymentArgs) // if (paymentArgs.fee === 0) { // payResult(paymentArgs.payTradeNo, cb) // } else { // setStore("paymentArgs", paymentArgs) // wx.navigateTo({ // url: "plugin://issuer-plugin/payment", // }) // } }, () => { cb && cb() } ) } // 支付 export function pay(paymentArgs, cb) { if (wx.requestPluginPayment) { wx.requestPluginPayment({ version: configObj.env, fee: Number(paymentArgs.fee), paymentArgs: { timeStamp: paymentArgs.timeStamp, nonceStr: paymentArgs.nonceStr, signType: paymentArgs.signType, paySign: paymentArgs.paySign, package: paymentArgs.package, }, currencyType: "CNY", success(res) { appPayResult(paymentArgs.payTradeNo, (result) => { cb && cb(result) }) }, fail(res) { wx.showToast({ title: "支付失败", icon: "error", }) cb && cb(false) }, }) } else { wx.showModal({ title: "提示", content: "当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。", }) } } // app支付结果查询 export function appPayResult(payTradeNo, cb) { let params = { filename: Api.appPayResult.filename, data: { payTradeNo, }, } requestFnc( Api.appPayResult.url, params, (res) => { if (res.tradeStatus == 2) { cb && cb(true) } else { wx.showToast({ title: "支付失败: 状态" + res.tradeStatus, icon: "error", }) cb && cb(false) } }, () => { cb && cb(false) } ) } // 支付结果查询 export function payResult(payTradeNo, cb) { let params = { filename: Api.payResult.filename, data: { accountId: getStore("accountId"), payTradeNo, }, } requestFnc( Api.payResult.url, params, (res) => { // APP端只签约绑定之后需要下单 if (getStore("wechatSignNo")) { wx.showModal({ title: "提示", content: "车辆绑定签约渠道成功", showCancel: false, success: (res) => { if (res.confirm) { wx.reLaunch({ url: getStore("redirectUrl"), }) } }, }) } cb && cb(res) }, () => { cb && cb(false) } ) } // 已签约渠道列表 function signChannelList(cb1, cb2) { let params = { filename: Api.signChannelList.filename, data: { accountId: getStore("accountId"), }, } requestFnc( Api.signChannelList.url, params, (res) => { let list = res.list || [] if (list.length > 0) { setStore("signChannelId", list[0].signChannelId) wx.redirectTo({ url: "plugin://issuer-plugin/delivery-method", }) } else { cb1() } }, () => { cb2 && cb2() } ) } //校验获取授权码 export function getApplyReqSender(businessType, cb) { let params = { filename: Api.getApplyReqSender.filename, data: { accountId: getStore("accountId"), vehicleId: getStore("vehicleId"), plateNum: getStore("plateNum"), plateColor: getStore("plateColor"), businessType, }, } requestFnc(Api.getApplyReqSender.url, params, (res) => { cb(res.authCode) }) } // 获取新办订单详情 function getPreSalesOrderDetail(cb1, cb2) { let params = { filename: Api.preSalesOrderDetail.filename, data: { orderNo: getStore("orderNo"), }, } requestFnc( Api.preSalesOrderDetail.url, params, (res) => { let data = JSON.parse(res.data) if (data.length > 0) { setStore("orderStatus", data[0].orderStatus) setStore( "orderDetail", JSON.stringify({ sendType: `${data[0].orderSendType}`, ...data[0], }) ) } cb1() }, () => { cb2 && cb2() } ) } // 获取售后订单详情 function getAfterSalesOrderDetail(cb1, cb2) { let params = { filename: Api.afterSalesOrderDetail.filename, data: { orderNo: getStore("orderNo"), }, } requestFnc( Api.afterSalesOrderDetail.url, params, (res) => { let data = JSON.parse(res.data) if (data.length > 0) { setStore("afterOrderType", `${data[0].orderType}`) setStore("orderStatus", data[0].orderStatus) setStore( "orderDetail", JSON.stringify({ sendType: `${data[0].orderSendType}`, ...data[0], }) ) cb1() } else { wx.showModal({ title: "提示", content: "无售后订单", showCancel: false, success(res) { if (res.confirm) { wx.navigateBack(1) } }, }) } }, () => { cb2 && cb2() } ) } // 获取收货地址 export function getAddress(cb, errorCb) { let params = { filename: Api.getAddress.filename, data: { accountId: getStore("accountId"), }, } requestFnc( Api.getAddress.url, params, (res) => { let adressObj = res.dataModel[0] cb && cb(adressObj) }, () => errorCb && errorCb() ) } //获取车辆详情 export function getVehicleInformation(cb, errorCb) { let params = { filename: Api.getUserQueryReq.filename, data: { vehicleId: getStore("vehicleId"), accountId: getStore("accountId"), }, } requestFnc( Api.getUserQueryReq.url, params, (res) => { let { data = {} } = res cb(data) }, () => errCb && errCb() ) } //获取卡详情 export function getCpuInfo(cb, errorCb) { let params = { filename: Api.getCpuInfo.filename, data: { accountId: getStore("accountId"), plateNum: getStore("plateNum"), plateColor: getStore("plateColor"), }, } requestFnc( Api.getCpuInfo.url, params, (res) => { let { data = [] } = res cb(data) }, () => errorCb && errorCb() ) } //获取obu详情 export function getObuInfo(cb, errorCb) { let params = { filename: Api.getObuInfo.filename, data: { accountId: getStore("accountId"), plateNum: getStore("plateNum"), plateColor: getStore("plateColor"), }, } requestFnc( Api.getObuInfo.url, params, (res) => { let { data = [] } = res cb(data) }, () => errorCb && errorCb() ) } //获取支付产品列表 function getOrderRenewalPayInfo(cb) { let params = { filename: Api.orderRenewalPayInfo.filename, data: { vehicleId: getStore("vehicleId"), accountId: getStore("accountId"), }, } requestFnc(Api.orderRenewalPayInfo.url, params, (res) => { let { data = "" } = res let list = JSON.parse(data) let productObj = JSON.parse(getStore("productObj")) setStore("productObj", { ...productObj, handleFees: list, }) cb && cb(list) }) } //app拉起签约支付产品 function wechatSignNoOrderRenewalPayInfo(handleFees, cb) { let fee = handleFees.filter((el) => el.processingAmount === 0) if (fee.length === handleFees.length) { //支付金额为0 preOrder({ addressId: "", sendType: "2", packageId: JSON.parse(getStore("productObj")).productId, processingFeeType: "EQUITY_FEE", cb: (paymentArgs) => { if (paymentArgs.fee === 0) payResult(paymentArgs.payTradeNo, cb) }, }) } else { let obj = { accountId: getStore("accountId"), packageId: JSON.parse(getStore("productObj")).productId, vehicleId: getStore("vehicleId"), signChannelId: getStore("signChannelId"), wxOpenId: getStore("myWxOpenId"), bizType: "1", addressId: "", sendType: "2", } wx.navigateTo({ url: `plugin://issuer-plugin/product-selection?deliveryMethod=${JSON.stringify( obj )}`, }) } } function _accountResumesign(cb) { let params = { filename: Api.accountResumesign.filename, data: { accountId: getStore("accountId"), // productId: JSON.parse(getStore("productObj")).productId, preVehicleId: getStore("vehicleId"), wxOpenId: getStore("myWxOpenId"), notifyAppId: "#", notifyPage: "#", } } requestFnc( Api.accountResumesign.url, params, (res) => { let { signChannelId = "" } = res; setStore("signChannelId", signChannelId) if (res.signStatus === -1) { wx.showModal({ title: "提示", content: res.signParameter, showCancel: false, success: (res) => { if (res.confirm) { wx.reLaunch({ url: getStore("redirectUrl"), }) } }, }) } // 已签约 if (res.signStatus === 1) { wx.showModal({ title: "提示", content: "车辆恢复签约已完成", showCancel: false, success: (res) => { if (res.confirm) { wx.reLaunch({ url: getStore("redirectUrl"), }) } }, }) } //未签约 if (res.signStatus === 0) { let signParameter = JSON.parse(res.signParameter) let f = signParameter.find(el => el.tradeScene === "HIGHWAY") // 高速 if (f) { let { wxVehicleModel = {} } = f let { appId = "", path = "", extraData = {} } = wxVehicleModel wx.navigateToMiniProgram({ appId, path, extraData, success(res) { setStore("sign", "2") console.log("跳转车主小程序") }, fail(res) { console.log("未跳转小程序", res) }, }) } } cb && cb() }, () => { cb && cb() } ) } // 获取支付信息 export function getPayInfo(cb) { let params = { filename: Api.afterPrePay.filename, data: { accountId: getStore("accountId"), vehicleId: getStore("vehicleId"), businessType: getStore("afterOrderType"), orderNo: getStore("orderNo"), wxOpenId: getStore("myWxOpenId"), }, } requestFnc( Api.createdOrder.url, params, (res) => { let paymentArgs = { timeStamp: res.timeStamp + "", nonceStr: res.nonceStr, signType: res.signType, paySign: res.paySign, package: res.wxPackage, fee: res.money, payTradeNo: res.payTradeNo, } cb(paymentArgs) }, () => { cb(false) } ) }