api.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import axios from 'axios'
  2. import config from './config'
  3. import qs from 'qs'
  4. import pingpp from '../../../webapp/common/js/pingpp'
  5. // let apiPath = 'http://commontest.yiguanjia.me/index.php?r='
  6. export default ({
  7. // 获取用户信息
  8. getO2oUserInfo: function (cb) {
  9. axios.get('o2o/user/info&user_id=' + config.userId).then(function (res) {
  10. cb(res.data)
  11. })
  12. },
  13. // 获取用户订单信息 根据制定的订单类型
  14. getMyOrderList: function (type, page, cb) {
  15. let orderList = {user_id: config.userId, type: type, page: page}
  16. orderList = qs.stringify(orderList)
  17. axios.post('o2o/order/list', orderList).then(function (res) {
  18. cb(res.data)
  19. })
  20. },
  21. // 获取商品列表
  22. getProductList: function (cb) {
  23. axios.get('o2o/product/list').then(function (res) {
  24. cb(res.data)
  25. })
  26. },
  27. // 获得充值卡列表 o2o/recharge/rechargeList
  28. getRechargeList: function (cb) {
  29. axios.get('o2o/recharge/rechargeList').then(res => {
  30. cb(res.data)
  31. })
  32. },
  33. // 充值卡支付状态获取
  34. getPayCharge: function (cb) {
  35. axios.get('o2o/recharge/payRecharge', config.formData).then(function (res) {
  36. cb(res.data)
  37. }).catch(function (error) {
  38. console.log(error)
  39. })
  40. },
  41. // 修改订单状态 完成
  42. modifyOrderStatusForComplete: function (userId, orderId, cb) {
  43. axios.get('o2o/order/confirmComplete&user_id=' + userId + '&order_id=' + orderId).then(function (res) {
  44. cb(res.data)
  45. }).catch(function (error) {
  46. console.log(error)
  47. })
  48. },
  49. // 获取订单信息
  50. getOrderDetail: function (orderID, cb) {
  51. config.formData.append('order_id', orderID)
  52. axios.post('o2o/order/detail', config.formData).then(function (res) {
  53. cb(res.data)
  54. }).catch(function (e) {
  55. console.log(e)
  56. })
  57. },
  58. // 获取支付信息
  59. getPayOrderChange: function (orderID, payChannel, cb) {
  60. let test = {user_id: config.userId, order_id: orderID, pay_channel: payChannel}
  61. let json = qs.stringify(test)
  62. axios.post('o2o/order/pay', json).then(function (res) {
  63. cb(res.data)
  64. }).catch(function (e) {
  65. console.log(e)
  66. })
  67. },
  68. // 新增订单
  69. addOrder: function (cb) {
  70. axios.post('o2o/order/add', qs.stringify(config.orderInfo)).then(function (res) {
  71. console.log(res)
  72. let data = res.data.data
  73. // 支付成功
  74. if (data.status === 1) {
  75. } else {
  76. // 支付失败
  77. let orderID = data.id
  78. let bookingTime = data.booking_time_str
  79. const payChannel = 'wx_pub'
  80. let payInfo = {user_id: config.userId, order_id: orderID, pay_channel: payChannel}
  81. payInfo = qs.stringify(payInfo)
  82. axios.post('o2o/order/pay', payInfo).then(function (res) {
  83. if (!config.test) {
  84. pingpp.createPayment(res.data.data, function (result, err) {
  85. if (result === 'success') {
  86. // 只有微信公众账号 wx_pub 支付成功的结果会在这里返回,其他的支付结果都会跳转到 extra 中对应的 URL。
  87. var res = {
  88. success: true
  89. }
  90. console.log(res)
  91. } else if (result === 'fail') {
  92. // charge 不正确或者微信公众账号支付失败时会在此处返回
  93. console.log(err)
  94. } else if (result === 'cancel') {
  95. // 微信公众账号支付取消支付
  96. console.log(err)
  97. }
  98. })
  99. } else {
  100. // 支付凭据
  101. let wxPay = res.data.data
  102. let option = wxPay.credential.wx_pub
  103. let prepay = option['package'].replace('prepay_id=', '')
  104. window.location.href = 'http://common.yiguanjia.me/webapp/o2o/module/pay/index.html?appId=' +
  105. option.appId + '&nonceStr=' + option.nonceStr +
  106. '&package=' + prepay + '&signType=' +
  107. option.signType + '&timeStamp=' +
  108. option.timeStamp + '&paySign=' +
  109. option.paySign + '&amount=' + wxPay.amount +
  110. '&created=' + wxPay.created + '&body=' +
  111. wxPay.body + '&bookingTime=' + bookingTime
  112. }
  113. }).catch(function (e) {
  114. console.log(e)
  115. })
  116. }
  117. }).catch(function (error) {
  118. console.log(error)
  119. })
  120. }
  121. })