import axios from 'axios' import config from './config' import qs from 'qs' import pingpp from '../../../webapp/common/js/pingpp' // let apiPath = 'http://commontest.yiguanjia.me/index.php?r=' export default ({ // 获取用户信息 getO2oUserInfo: function (cb) { axios.get('o2o/user/info&user_id=' + config.userId).then(function (res) { cb(res.data) }) }, // 获取用户订单信息 根据制定的订单类型 getMyOrderList: function (type, page, cb) { let orderList = {user_id: config.userId, type: type, page: page} orderList = qs.stringify(orderList) axios.post('o2o/order/list', orderList).then(function (res) { cb(res.data) }) }, // 获取商品列表 getProductList: function (cb) { axios.get('o2o/product/list').then(function (res) { cb(res.data) }) }, // 获得充值卡列表 o2o/recharge/rechargeList getRechargeList: function (cb) { axios.get('o2o/recharge/rechargeList').then(res => { cb(res.data) }) }, // 充值卡支付状态获取 getPayCharge: function (cb) { axios.get('o2o/recharge/payRecharge', config.formData).then(function (res) { cb(res.data) }).catch(function (error) { console.log(error) }) }, // 修改订单状态 完成 modifyOrderStatusForComplete: function (userId, orderId, cb) { axios.get('o2o/order/confirmComplete&user_id=' + userId + '&order_id=' + orderId).then(function (res) { cb(res.data) }).catch(function (error) { console.log(error) }) }, // 获取订单信息 getOrderDetail: function (orderID, cb) { config.formData.append('order_id', orderID) axios.post('o2o/order/detail', config.formData).then(function (res) { cb(res.data) }).catch(function (e) { console.log(e) }) }, // 获取支付信息 getPayOrderChange: function (orderID, payChannel, cb) { let test = {user_id: config.userId, order_id: orderID, pay_channel: payChannel} let json = qs.stringify(test) axios.post('o2o/order/pay', json).then(function (res) { cb(res.data) }).catch(function (e) { console.log(e) }) }, // 新增订单 addOrder: function (cb) { axios.post('o2o/order/add', qs.stringify(config.orderInfo)).then(function (res) { console.log(res) let data = res.data.data // 支付成功 if (data.status === 1) { } else { // 支付失败 let orderID = data.id let bookingTime = data.booking_time_str const payChannel = 'wx_pub' let payInfo = {user_id: config.userId, order_id: orderID, pay_channel: payChannel} payInfo = qs.stringify(payInfo) axios.post('o2o/order/pay', payInfo).then(function (res) { if (!config.test) { pingpp.createPayment(res.data.data, function (result, err) { if (result === 'success') { // 只有微信公众账号 wx_pub 支付成功的结果会在这里返回,其他的支付结果都会跳转到 extra 中对应的 URL。 var res = { success: true } console.log(res) } else if (result === 'fail') { // charge 不正确或者微信公众账号支付失败时会在此处返回 console.log(err) } else if (result === 'cancel') { // 微信公众账号支付取消支付 console.log(err) } }) } else { // 支付凭据 let wxPay = res.data.data let option = wxPay.credential.wx_pub let prepay = option['package'].replace('prepay_id=', '') window.location.href = 'http://common.yiguanjia.me/webapp/o2o/module/pay/index.html?appId=' + option.appId + '&nonceStr=' + option.nonceStr + '&package=' + prepay + '&signType=' + option.signType + '&timeStamp=' + option.timeStamp + '&paySign=' + option.paySign + '&amount=' + wxPay.amount + '&created=' + wxPay.created + '&body=' + wxPay.body + '&bookingTime=' + bookingTime } }).catch(function (e) { console.log(e) }) } }).catch(function (error) { console.log(error) }) } })