trade.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /**
  2. * 交♂易相关API
  3. */
  4. import { http, Method } from "@/utils/request.js";
  5. /**
  6. * 获取购物车列表
  7. * @param show_type 要显示的类型 all:全部 checked:已选中的
  8. */
  9. export function getCarts() {
  10. return http.request({
  11. url: `/trade/carts/all`,
  12. method: Method.GET,
  13. needToken: true,
  14. loading: false,
  15. });
  16. }
  17. /**
  18. * 获取购物车总数
  19. * @param show_type 要显示的类型 all:全部 checked:已选中的
  20. */
  21. export function getCartNum() {
  22. return http.request({
  23. url: `/trade/carts/count`,
  24. method: Method.GET,
  25. needToken: true,
  26. loading: false,
  27. });
  28. }
  29. /**
  30. * 获取购物车可用优惠券数量
  31. * @param way 购物车购买:CART/立即购买:BUY_NOW/拼团购买:PINTUAN / 积分购买:POINT
  32. */
  33. export function getCartCouponNum(way) {
  34. return http.request({
  35. url: `/trade/carts/coupon/num?way=${way}`,
  36. method: Method.GET,
  37. needToken: true,
  38. loading: false,
  39. });
  40. }
  41. /**
  42. * 添加货品到购物车
  43. * @param skuId 产品ID
  44. * @param num 产品的购买数量
  45. * @param cartType 购物车类型,默认加入购物车
  46. */
  47. export function addToCart(data) {
  48. return http.request({
  49. url: "/trade/carts",
  50. method: Method.POST,
  51. needToken: true,
  52. header: { "content-type": "application/x-www-form-urlencoded" },
  53. data,
  54. });
  55. }
  56. /**
  57. * 更新购物车商品数量
  58. * @param skuId
  59. * @param num
  60. */
  61. export function updateSkuNum(skuId, num = 1) {
  62. return http.request({
  63. url: `/trade/carts/sku/num/${skuId}`,
  64. method: Method.POST,
  65. header: { "content-type": "application/x-www-form-urlencoded" },
  66. needToken: true,
  67. data: { num },
  68. });
  69. }
  70. /**
  71. * 更新购物车货品选中状态
  72. * @param skuId
  73. * @param checked
  74. */
  75. export function updateSkuChecked(skuId, checked) {
  76. return http.request({
  77. url: `/trade/carts/sku/checked/${skuId}`,
  78. method: Method.POST,
  79. needToken: true,
  80. header: { "content-type": "application/x-www-form-urlencoded" },
  81. data: { checked },
  82. });
  83. }
  84. /**
  85. * 删除多个货品项
  86. * @param skuIds
  87. */
  88. export function deleteSkuItem(skuIds) {
  89. return http.request({
  90. url: `/trade/carts/sku/remove?skuIds=${skuIds}`,
  91. method: Method.DELETE,
  92. needToken: true,
  93. });
  94. }
  95. /**
  96. * 设置全部货品为选中或不选中
  97. * @param checked
  98. */
  99. export function checkAll(checked) {
  100. return http.request({
  101. url: "/trade/carts/sku/checked",
  102. method: Method.POST,
  103. needToken: true,
  104. params: { checked },
  105. });
  106. }
  107. /**
  108. * 设置店铺内全部货品选中状态
  109. * @param storeId
  110. * @param checked
  111. */
  112. export function checkStore(storeId, checked) {
  113. return http.request({
  114. url: `/trade/carts/store/${storeId}`,
  115. method: Method.POST,
  116. needToken: true,
  117. header: { "content-type": "application/x-www-form-urlencoded" },
  118. data: { checked },
  119. });
  120. }
  121. /**
  122. * 获取结算参数
  123. */
  124. export function getCheckoutParams(way) {
  125. return http.request({
  126. url: "/trade/carts/checked?way=" + way,
  127. method: Method.GET,
  128. needToken: true,
  129. });
  130. }
  131. /**
  132. * 设置收货地址ID
  133. * @param addressId
  134. */
  135. export function setAddressId(addressId,way) {
  136. return http.request({
  137. url: `/trade/carts/shippingAddress?shippingAddressId=${addressId}&way=${way}`,
  138. method: Method.GET,
  139. needToken: true,
  140. });
  141. }
  142. /**
  143. * 创建交易
  144. */
  145. export function createTrade(params) {
  146. return http.request({
  147. url: "/trade/carts/create/trade",
  148. method: Method.POST,
  149. needToken: true,
  150. message: false,
  151. data:params,
  152. });
  153. }
  154. /**
  155. * 根据交易编号或订单编号查询收银台数据
  156. * @param params
  157. */
  158. export function getCashierData(params) {
  159. return http.request({
  160. url: "cashier/tradeDetail",
  161. method: Method.GET,
  162. needToken: true,
  163. params,
  164. });
  165. }
  166. /**
  167. * 发起支付
  168. * @param paymentMethod
  169. * @param paymentClient
  170. * @param params
  171. * @returns {*|*}
  172. */
  173. export function initiatePay(paymentMethod, paymentClient, params) {
  174. return http.request({
  175. url: `cashier/pay/${paymentMethod}/${paymentClient}`,
  176. method: Method.GET,
  177. needToken: true,
  178. params,
  179. });
  180. }
  181. /**
  182. * 查询物流
  183. * @param orderSn
  184. */
  185. export function getExpress(orderSn) {
  186. return http.request({
  187. url: `/orders/getTraces/${orderSn}`,
  188. method: Method.POST,
  189. needToken: true,
  190. });
  191. }
  192. /**
  193. * 获取当前会员的对于当前商品可使用的优惠券列表
  194. */
  195. export function getMemberCanUse(data) {
  196. return http.request({
  197. url: `/promotion/coupon/canUse`,
  198. method: Method.GET,
  199. params: data,
  200. });
  201. }
  202. /**
  203. * 获取当前会员的优惠券列表
  204. */
  205. export function getMemberCouponList(data) {
  206. return http.request({
  207. url: `/promotion/coupon/getCoupons`,
  208. method: Method.GET,
  209. params: data,
  210. });
  211. }
  212. /**
  213. * 使用优惠券
  214. */
  215. export function useCoupon(params) {
  216. return http.request({
  217. url: `/trade/carts/select/coupon`,
  218. method: Method.GET,
  219. needToken: true,
  220. params: params,
  221. });
  222. }
  223. /**
  224. * 更换参与活动
  225. * @param params
  226. */
  227. export function changeActivity(params) {
  228. return http.request({
  229. url: "trade/promotion",
  230. method: Method.POST,
  231. needToken: true,
  232. data: params,
  233. header: { "content-type": "application/x-www-form-urlencoded" },
  234. });
  235. }
  236. /**
  237. * 根据交易单号查询订单列表
  238. * @param trade_sn
  239. */
  240. export function reBuy(sn) {
  241. return http.request({
  242. url: `trade/carts/rebuy/${sn}`,
  243. method: Method.POST,
  244. needToken: true,
  245. });
  246. }