From 4e465b7e72b8dc89e4edaa4faa37154e7761425d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 6 Jun 2023 19:12:07 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=AE=A2=E5=8D=95=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E3=80=91=201.=20=E5=88=9D=E6=AD=A5=E6=8E=A5=E5=85=A5=E8=AF=A6?= =?UTF-8?q?=E6=83=85=20API=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/pay/order.js | 11 +++ api/product/category.js | 6 ++ api/product/spu.js | 15 ++++ api/trade/afterSale.js | 5 ++ api/trade/cart.js | 29 +++++++ api/trade/order.js | 29 +++++++ config/app.js | 4 +- pages/goods_details/index.vue | 153 +++++++++++++++++----------------- utils/product.js | 70 ++++++++++++++++ utils/request.js | 15 +++- utils/util.js | 40 +++++---- 11 files changed, 280 insertions(+), 97 deletions(-) create mode 100644 api/pay/order.js create mode 100644 api/product/category.js create mode 100644 api/product/spu.js create mode 100644 api/trade/afterSale.js create mode 100644 api/trade/cart.js create mode 100644 api/trade/order.js create mode 100644 utils/product.js diff --git a/api/pay/order.js b/api/pay/order.js new file mode 100644 index 00000000..d9b439a4 --- /dev/null +++ b/api/pay/order.js @@ -0,0 +1,11 @@ +import request from "@/utils/request.js"; + +export function getOrder(id) { + return request.get("app-api/pay/order/get", { + id + }); +} + +export function submitOrder(data) { + return request.post("app-api/pay/order/submit", data); +} diff --git a/api/product/category.js b/api/product/category.js new file mode 100644 index 00000000..1b405f6b --- /dev/null +++ b/api/product/category.js @@ -0,0 +1,6 @@ +import request from "@/utils/request.js"; + +// 查询分类列表 +export function getCategoryList() { + return request.get('app-api/product/category/list', {}); +} diff --git a/api/product/spu.js b/api/product/spu.js new file mode 100644 index 00000000..8af9f3d1 --- /dev/null +++ b/api/product/spu.js @@ -0,0 +1,15 @@ +import request from "@/utils/request.js"; + +// 获得商品 SPU 分页 +export function getSpuPage(data) { + return request.get('app-api/product/spu/page', data); +} + +// 查询商品 +export function getSpuDetail(id) { + return request.get('app-api/product/spu/get-detail', { + id + }, { + noAuth: true // TODO 芋艿:后续要做调整 + }); +} diff --git a/api/trade/afterSale.js b/api/trade/afterSale.js new file mode 100644 index 00000000..7df5b8ab --- /dev/null +++ b/api/trade/afterSale.js @@ -0,0 +1,5 @@ +import request from "@/utils/request.js"; + +export function getAfterSalePage(data) { + return request.get("app-api/trade/after-sale/page", data); +} diff --git a/api/trade/cart.js b/api/trade/cart.js new file mode 100644 index 00000000..6cfd3c5e --- /dev/null +++ b/api/trade/cart.js @@ -0,0 +1,29 @@ +import request from "@/utils/request.js"; + +export function addCart(data) { + return request.post("app-api/trade/cart/add", data); +} + +export function updateCart(data) { + return request.put("app-api/trade/cart/update", data); +} + +export function resetCart(data) { + return request.put("app-api/trade/cart/reset", data); +} + +export function getCartCount() { + return request.get("app-api/trade/cart/get-count"); +} + +export function getCartCountMap() { + return request.get("app-api/trade/cart/get-count-map"); +} + +export function getCartList() { + return request.get("app-api/trade/cart/list"); +} + +export function deleteCart(ids) { + return request.delete("app-api/trade/cart/delete?ids=" + ids.join(',')); +} diff --git a/api/trade/order.js b/api/trade/order.js new file mode 100644 index 00000000..68899794 --- /dev/null +++ b/api/trade/order.js @@ -0,0 +1,29 @@ +import request from "@/utils/request.js"; + +export function settlementOrder(data) { + return request.get("app-api/trade/order/settlement", data); +} + +export function createOrder(data) { + return request.post("app-api/trade/order/create", data); +} + +export function getOrderDetail(id) { + return request.get("app-api/trade/order/get-detail", { + id + }); +} + +export function getOrderCount() { + return request.get("app-api/trade/order/get-count"); +} + +export function getOrderPage(data) { + return request.get("app-api/trade/order/page", data); +} + +export function getOrderItem(id) { + return request.get("app-api/trade/order/item/get", { + id + }); +} diff --git a/config/app.js b/config/app.js index 1991df11..61cdac5a 100644 --- a/config/app.js +++ b/config/app.js @@ -1,12 +1,12 @@ -let domain = 'http://127.0.0.1:8081' +let domain = 'http://apif.java.crmeb.net' module.exports = { // 请求域名 格式: https://您的域名 // #ifdef MP HTTP_REQUEST_URL: domain, // #endif - HTTP_ADMIN_URL:'http://127.0.0.1:8080', //PC后台的API请求地址,上传图片用 + HTTP_ADMIN_URL:'http://apif.java.crmeb.net', //PC后台的API请求地址,上传图片用 // #ifdef H5 //H5接口是浏览器地址 // HTTP_REQUEST_URL: window.location.protocol+"//"+window.location.host, diff --git a/pages/goods_details/index.vue b/pages/goods_details/index.vue index f4a88e32..8fa0f517 100644 --- a/pages/goods_details/index.vue +++ b/pages/goods_details/index.vue @@ -20,27 +20,26 @@ - + + - {{productInfo.storeName}} + {{ spu.name }} - 原价:¥{{productInfo.otPrice || 0}} - 库存:{{productInfo.stock || 0}}{{productInfo.unitName || ''}} + 原价:¥{{ fen2yuan(spu.marketPrice) }} + 库存:{{ spu.stock }} {{ spu.unitName}} - 销量:{{Math.floor(productInfo.sales) + Math.floor(productInfo.ficti) || 0}}{{productInfo.unitName || ''}} + 销量:{{ spu.salesCount}} {{ spu.unitName }} - + 优惠券: - 满{{coupon.list[0].minPrice}}减{{coupon.list[0].money}} + 满{{ coupon.list[0].minPrice }}减{{ coupon.list[0].money }} + @@ -146,9 +147,8 @@ - + - @@ -203,9 +203,17 @@ - - + @@ -257,14 +265,10 @@ diff --git a/utils/product.js b/utils/product.js new file mode 100644 index 00000000..61ac9cca --- /dev/null +++ b/utils/product.js @@ -0,0 +1,70 @@ +// ========== 商品相关的 Util ========== + +/** + * 从商品 SKU 数组中,转换出商品属性的数组 + * + * 类似结构:[{ + * id: // 属性的编号 + * name: // 属性的名字 + * values: [{ + * id: // 属性值的编号 + * name: // 属性值的名字 + * }] + * }] + * + * @param skus 商品 SKU 数组 + */ +export function convertProductPropertyList(skus) { + let result = []; + for (const sku of skus) { + if (!sku.properties) { + continue + } + for (const property of sku.properties) { + // ① 先处理属性 + let resultProperty = result.find(item => item.id === property.propertyId) + if (!resultProperty) { + resultProperty = { + id: property.propertyId, + name: property.propertyName, + values: [] + } + result.push(resultProperty) + } + // ② 再处理属性值 + let resultValue = resultProperty.values.find(item => item.id === property.valueId) + if (!resultValue) { + resultProperty.values.push({ + id: property.valueId, + name: property.valueName + }) + } + } + } + return result; +} + +/** + * 从商品 SKU 数组中,转换出商品 SKU Map + * + * key: 属性值的拼接,使用 , 间隔,例如说 黑色,CH510 + * + * @param skus 商品 SKU Map + */ +export function convertProductSkuMap(skus) { + let result = {}; + for (const sku of skus) { + let key = ''; + if (!sku.properties) { + continue + } + for (const property of sku.properties) { + if (key !== '') { + key += ',' + } + key += property.valueName + } + result[key] = sku + } + return result +} diff --git a/utils/request.js b/utils/request.js index dd0ab353..807d1834 100644 --- a/utils/request.js +++ b/utils/request.js @@ -31,17 +31,28 @@ function baseRequest(url, method, data, { }); } } + + // TODO 补个 header 多租户 + if (url.indexOf('app-api') >= 0) { + header = { + ...header + } + header['tenant-id'] = 1 + header['Authorization'] = 'Bearer test247' + } + if (store.state.app.token) header[TOKENNAME] = store.state.app.token; return new Promise((reslove, reject) => { uni.request({ - url: Url + '/api/front/' + url, + url: url.indexOf('app-api') < 0 ? Url + '/api/front/' + url + : 'http://127.0.0.1:48080/' + url, // TODO 芋艿:搞个 url 的配置 method: method || 'GET', header: header, data: data || {}, success: (res) => { if (noVerify) reslove(res.data, res); - else if (res.data.code == 200) + else if (res.data.code === 200 || res.data.code === 0) reslove(res.data, res); else if ([410000, 410001, 410002, 401].indexOf(res.data.code) !== -1) { toLogin(); diff --git a/utils/util.js b/utils/util.js index 4847c0e5..8cb355fa 100644 --- a/utils/util.js +++ b/utils/util.js @@ -108,7 +108,7 @@ export default { * @param int index 需要移除的数组的键值 * @param string | int 值 * @return array - * + * */ ArrayRemove: function(array, index, value) { const valueArray = []; @@ -127,7 +127,7 @@ export default { * 生成海报获取文字 * @param string text 为传入的文本 * @param int num 为单行显示的字节长度 - * @return array + * @return array */ textByteLength: function(text, num) { @@ -164,8 +164,8 @@ export default { * @param string price 价格 * @param string ot_price 原始价格 * @param function successFn 回调函数 - * - * + * + * */ PosterCanvas: function(arr2, store_name, price, ot_price, successFn) { let that = this; @@ -173,7 +173,7 @@ export default { ctx.clearRect(0, 0, 0, 0); /** * 只能获取合法域名下的图片信息,本地调试无法获取 - * + * */ ctx.fillStyle = '#fff'; ctx.fillRect(0, 0, 750, 1150); @@ -331,7 +331,7 @@ export default { context.clearRect(0, 0, 0, 0); /** * 只能获取合法域名下的图片信息,本地调试无法获取 - * + * */ context.fillStyle = '#fff'; context.fillRect(0, 0, 594, 850); @@ -425,8 +425,8 @@ export default { /* * 单图上传 * @param object opt - * @param callable successCallback 成功执行方法 data - * @param callable errorCallback 失败执行方法 + * @param callable successCallback 成功执行方法 data + * @param callable errorCallback 失败执行方法 */ uploadImageOne: function(opt, successCallback, errorCallback) { let that = this; @@ -445,11 +445,11 @@ export default { model = opt.model; uni.chooseImage({ - count: count, //最多可以选择的图片总数 - sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有 - sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有 + count: count, //最多可以选择的图片总数 + sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有 + sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有 success: function(res) { - //启动上传等待中... + //启动上传等待中... uni.showLoading({ title: '图片上传中', }); @@ -509,7 +509,7 @@ export default { * @param string k 整体分割符 默认为:& * @param string p 单个分隔符 默认为:= * @return object - * + * */ // #ifdef MP getUrlParams: function(param, k, p) { @@ -781,13 +781,21 @@ export default { else return url.replace('http://', 'https://'); }, - - /** * 姓名除了姓显示其他 */ formatName: function(str) { return str.substr(0, 1) + new Array(str.length).join('*'); - } + }, } + +/** + * 将分转成元 + * + * @param price 分,例如说 100 分 + * @returns {string} 元,例如说 1.00 元 + */ +export function fen2yuan(price) { + return (price / 100.0).toFixed(2) +}