api.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * Copyright (C) 2018-2019
  3. * All rights reserved, Designed By www.joolun.com
  4. * 注意:
  5. * 本软件为www.joolun.com开发研制,项目使用请保留此说明
  6. */
  7. import __config from '../config/env'
  8. const request = (url, method, data, showLoading) => {
  9. let _url = __config.basePath + url
  10. return new Promise((resolve, reject) => {
  11. if (showLoading){
  12. wx.showLoading({
  13. title: '加载中',
  14. })
  15. }
  16. wx.request({
  17. url: _url,
  18. method: method,
  19. data: data,
  20. header: {
  21. 'app-id': wx.getAccountInfoSync().miniProgram.appId,
  22. 'third-session': getApp().globalData.thirdSession != null ? getApp().globalData.thirdSession : ''
  23. },
  24. success(res) {
  25. if (res.statusCode == 200) {
  26. if (res.data.code != 200) {
  27. console.log(res.data)
  28. wx.showModal({
  29. title: '提示',
  30. content: res.data.msg ? res.data.msg : '没有数据' + '',
  31. success() {
  32. },
  33. complete(){
  34. if(res.data.code == 60001){
  35. //session过期,则清除过期session,并重新加载当前页
  36. getApp().globalData.thirdSession = null
  37. wx.reLaunch({
  38. url: getApp().getCurrentPageUrlWithArgs()
  39. })
  40. }
  41. }
  42. })
  43. reject(res.data.msg)
  44. }
  45. resolve(res.data)
  46. } else if (res.statusCode == 404) {
  47. wx.showModal({
  48. title: '提示',
  49. content: '接口请求出错,请检查手机网络',
  50. success(res) {
  51. }
  52. })
  53. reject()
  54. } else {
  55. console.log(res)
  56. wx.showModal({
  57. title: '提示',
  58. content: res.errMsg + ':' + res.data.message + ':' + res.data.msg,
  59. success(res) {
  60. }
  61. })
  62. reject()
  63. }
  64. },
  65. fail(error) {
  66. console.log(error)
  67. wx.showModal({
  68. title: '提示',
  69. content: '接口请求出错:' + error.errMsg,
  70. success(res) {
  71. }
  72. })
  73. reject(error)
  74. },
  75. complete(res) {
  76. wx.hideLoading()
  77. }
  78. })
  79. })
  80. }
  81. module.exports = {
  82. request,
  83. login: (data) => {//小程序登录接口
  84. return request('/weixin/api/ma/wxuser/login', 'post', data, false)
  85. },
  86. wxUserGet: (data) => {//微信用户查询
  87. return request('/weixin/api/ma/wxuser', 'get', null, false)
  88. },
  89. wxUserSave: (data) => {//微信用户新增
  90. return request('/weixin/api/ma/wxuser', 'post', data, true)
  91. },
  92. goodsCategoryGet: (data) => {//商品分类查询
  93. return request('/weixin/api/ma/goodscategory/tree' , 'get', data, true)
  94. },
  95. goodsPage: (data) => {//商品列表
  96. return request('/weixin/api/ma/goodsspu/page', 'get', data, false)
  97. },
  98. goodsGet: (id) => {//商品查询
  99. return request('/weixin/api/ma/goodsspu/' + id, 'get', null, false)
  100. },
  101. shoppingCartPage: (data) => {//购物车列表
  102. return request('/weixin/api/ma/shoppingcart/page', 'get', data, false)
  103. },
  104. shoppingCartAdd: (data) => {//购物车新增
  105. return request('/weixin/api/ma/shoppingcart', 'post', data, true)
  106. },
  107. shoppingCartEdit: (data) => {//购物车修改
  108. return request('/weixin/api/ma/shoppingcart', 'put', data, true)
  109. },
  110. shoppingCartDel: (data) => {//购物车删除
  111. return request('/weixin/api/ma/shoppingcart/del', 'post', data, false)
  112. },
  113. shoppingCartCount: (data) => {//购物车数量
  114. return request('/weixin/api/ma/shoppingcart/count', 'get', data, false)
  115. },
  116. orderSub: (data) => {//订单提交
  117. return request('/weixin/api/ma/orderinfo', 'post', data, true)
  118. },
  119. orderPage: (data) => {//订单列表
  120. return request('/weixin/api/ma/orderinfo/page', 'get', data, false)
  121. },
  122. orderGet: (id) => {//订单详情查询
  123. return request('/weixin/api/ma/orderinfo/' + id, 'get', null, false)
  124. },
  125. orderCancel: (id) => {//订单确认取消
  126. return request('/weixin/api/ma/orderinfo/cancel/' + id, 'put', null, true)
  127. },
  128. orderReceive: (id) => {//订单确认收货
  129. return request('/weixin/api/ma/orderinfo/receive/' + id, 'put', null, true)
  130. },
  131. orderDel: (id) => {//订单删除
  132. return request('/weixin/api/ma/orderinfo/' + id, 'delete', null, false)
  133. },
  134. orderCountAll: (data) => {//订单计数
  135. return request('/weixin/api/ma/orderinfo/countAll', 'get', data, false)
  136. },
  137. unifiedOrder: (data) => {//下单接口
  138. return request('/weixin/api/ma/orderinfo/unifiedOrder', 'post', data, true)
  139. },
  140. userAddressPage: (data) => {//用户收货地址列表
  141. return request('/weixin/api/ma/useraddress/page', 'get', data, false)
  142. },
  143. userAddressSave: (data) => {//用户收货地址新增
  144. return request('/weixin/api/ma/useraddress', 'post', data, true)
  145. },
  146. userAddressDel: (id) => {//用户收货地址删除
  147. return request('/weixin/api/ma/useraddress/' + id, 'delete', null, false)
  148. }
  149. }