|
|
@@ -0,0 +1,282 @@
|
|
|
+/**
|
|
|
+ * 与 dining.js 接口一一对应,路径中的 dining 改为 generic-dining。
|
|
|
+ * 用于扫码进入且 m≠1 时的业务后端(非美食专线)。
|
|
|
+ */
|
|
|
+import { api } from '@/utils/request.js';
|
|
|
+import { BASE_API_URL } from '@/settings/siteSetting.js';
|
|
|
+import { useUserStore } from '@/store/user.js';
|
|
|
+
|
|
|
+// 微信登录
|
|
|
+export const DiningUserWechatLogin = (params) =>
|
|
|
+ api.post({ url: '/generic-dining/user/wechatLogin', params });
|
|
|
+
|
|
|
+// 获取用户信息(GET /generic-dining/user/getUserInfo),登录后调用以拿到头像等
|
|
|
+export const GetUserInfo = () => api.get({ url: '/generic-dining/user/getUserInfo' });
|
|
|
+
|
|
|
+// 更新用户个人信息(POST /generic-dining/user/updateProfile,body 为 dto)
|
|
|
+export const PostUpdateProfile = (dto) =>
|
|
|
+ api.post({ url: '/generic-dining/user/updateProfile', params: dto });
|
|
|
+
|
|
|
+// 文件上传(POST multipart,返回图片 URL/path 供 avatarUrl 使用)
|
|
|
+function uploadFileToServerImpl(filePath) {
|
|
|
+ const userStore = useUserStore();
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ uni.uploadFile({
|
|
|
+ url: BASE_API_URL + '/generic-dining/file/upload',
|
|
|
+ filePath,
|
|
|
+ name: 'file',
|
|
|
+ header: { Authorization: userStore.getToken || '' },
|
|
|
+ success: (res) => {
|
|
|
+ if (res.statusCode === 200) {
|
|
|
+ try {
|
|
|
+ const data = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
|
|
|
+ const payload = data?.data ?? data;
|
|
|
+ const url = payload?.url ?? payload?.path ?? payload?.relativePath ?? (typeof payload === 'string' ? payload : '');
|
|
|
+ resolve(url || '');
|
|
|
+ } catch (e) {
|
|
|
+ reject(e);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ reject(new Error(res.data || '上传失败'));
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: reject
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+export const uploadFileToServer = uploadFileToServerImpl;
|
|
|
+export const uploadFileToSever = uploadFileToServerImpl; // 兼容拼写错误
|
|
|
+
|
|
|
+// 点餐页数据(入参 dinerCount 就餐人数、tableId 桌号)
|
|
|
+export const DiningOrderFood = (params) => api.get({ url: '/store/generic-dining/page-info', params });
|
|
|
+
|
|
|
+// 服务费估算
|
|
|
+export const GetServiceFeeEstimate = (params) => {
|
|
|
+ const q = {};
|
|
|
+ if (params?.storeId != null && params.storeId !== '') q.storeId = String(params.storeId);
|
|
|
+ if (params?.tableId != null && params.tableId !== '') q.tableId = String(params.tableId);
|
|
|
+ if (params?.dinerCount != null && params.dinerCount !== '') q.dinerCount = params.dinerCount;
|
|
|
+ if (params?.goodsSubtotal != null && params.goodsSubtotal !== '') q.goodsSubtotal = params.goodsSubtotal;
|
|
|
+ return api.get({ url: '/store/generic-dining/service-fee/estimate', params: q, loading: false });
|
|
|
+};
|
|
|
+
|
|
|
+// 桌台预约记录详情
|
|
|
+export const GetReservationDetailByStoreTableRecord = (params) => {
|
|
|
+ const q = {};
|
|
|
+ if (params?.storeId != null && params?.storeId !== '') q.storeId = String(params.storeId);
|
|
|
+ if (params?.userReservationTableId != null && params?.userReservationTableId !== '') {
|
|
|
+ q.userReservationTableId = String(params.userReservationTableId);
|
|
|
+ }
|
|
|
+ return api.get({
|
|
|
+ url: '/store/generic-dining/reservation/detail-by-store-table-record',
|
|
|
+ params: q,
|
|
|
+ loading: false
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+// 查询桌位是否已选就餐人数
|
|
|
+export const GetTableDiningStatus = (tableId, extra = {}) =>
|
|
|
+ api.get({
|
|
|
+ url: '/store/generic-dining/table-generic-dining-status',
|
|
|
+ params: { tableId: tableId != null && tableId !== '' ? String(tableId) : '' },
|
|
|
+ ...extra
|
|
|
+ });
|
|
|
+
|
|
|
+// 到店就餐信息提交
|
|
|
+export const PostDiningWalkInReservation = (dto) =>
|
|
|
+ api.post({ url: '/store/generic-dining/walk-in/reservation', params: dto });
|
|
|
+
|
|
|
+// 门店详情(GET /store/info/detail/{storeId},入参 storeId)
|
|
|
+export const GetStoreDetail = (storeId) =>
|
|
|
+ api.get({ url: `/store/info/detail/${encodeURIComponent(storeId)}` });
|
|
|
+
|
|
|
+// 菜品种类(入参 storeId,GET /store/info/categories?storeId=)
|
|
|
+export const GetStoreCategories = (params) => api.get({ url: '/store/info/categories', params });
|
|
|
+
|
|
|
+// 根据菜品种类获取菜品(入参 categoryId,GET /store/info/cuisines?categoryId=)
|
|
|
+export const GetStoreCuisines = (params) => api.get({ url: '/store/info/cuisines', params });
|
|
|
+
|
|
|
+// 左侧分类+右侧菜品一体(通用价目 alienDining:固定 menuType=2)
|
|
|
+export const GetCategoriesWithCuisines = (params) =>
|
|
|
+ api.get({
|
|
|
+ url: '/store/info/categories-with-cuisines',
|
|
|
+ params: { ...(params || {}), menuType: 2 }
|
|
|
+ });
|
|
|
+
|
|
|
+// 菜品详情
|
|
|
+export const GetCuisineDetail = (cuisineId, tableId) => {
|
|
|
+ const id = cuisineId != null ? encodeURIComponent(cuisineId) : '';
|
|
|
+ const url = id ? `/store/generic-dining/cuisine/${id}` : '/store/generic-dining/cuisine/0';
|
|
|
+ const params = tableId != null && tableId !== '' ? { tableId } : {};
|
|
|
+ return api.get({ url, params });
|
|
|
+};
|
|
|
+
|
|
|
+// 门店全部优惠券列表
|
|
|
+function getStoreAllCouponListImpl(params) {
|
|
|
+ return api.get({
|
|
|
+ url: '/generic-dining/coupon/getStoreAllCouponList',
|
|
|
+ params: {
|
|
|
+ storeId: params?.storeId,
|
|
|
+ tab: 1,
|
|
|
+ page: params?.page ?? 1,
|
|
|
+ size: params?.size ?? 10
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+export const GetStoreAllCouponList = getStoreAllCouponListImpl;
|
|
|
+export const GetStoreUsableCouponList = getStoreAllCouponListImpl;
|
|
|
+
|
|
|
+// 用户已领/可用优惠券
|
|
|
+function getUserOwnedCouponListImpl(params) {
|
|
|
+ return api.get({
|
|
|
+ url: '/generic-dining/coupon/userOwnedByStore',
|
|
|
+ params: {
|
|
|
+ storeId: params?.storeId
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+export const GetUserOwnedCouponList = getUserOwnedCouponListImpl;
|
|
|
+
|
|
|
+// 用户优惠券列表
|
|
|
+export const GetUserCouponList = (params) =>
|
|
|
+ api.get({
|
|
|
+ url: '/generic-dining/coupon/getUserCouponList',
|
|
|
+ params: {
|
|
|
+ storeId: params?.storeId,
|
|
|
+ tabType: params?.tabType ?? 0,
|
|
|
+ page: params?.page ?? 1,
|
|
|
+ size: params?.size ?? 20
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+// 获取购物车(路径无 dining)
|
|
|
+export const GetOrderCart = (tableId) =>
|
|
|
+ api.get({ url: `/store/order/cart/${encodeURIComponent(tableId)}` });
|
|
|
+
|
|
|
+// 加入购物车
|
|
|
+export const PostOrderCartAdd = (dto) =>
|
|
|
+ api.post({ url: '/store/order/cart/add', params: dto });
|
|
|
+
|
|
|
+// 更新购物车
|
|
|
+export const PostOrderCartUpdate = (params) =>
|
|
|
+ api.put({ url: '/store/order/cart/update', params, formUrlEncoded: true });
|
|
|
+
|
|
|
+// 清空购物车
|
|
|
+export const PostOrderCartClear = (tableId) => {
|
|
|
+ const id = tableId != null ? String(tableId) : '';
|
|
|
+ const url = id ? `/store/order/cart/clear?tableId=${encodeURIComponent(id)}` : '/store/order/cart/clear';
|
|
|
+ return api.delete({ url, params: id ? { tableId: id } : {} });
|
|
|
+};
|
|
|
+
|
|
|
+// 锁定订单
|
|
|
+function postOrderLockImpl(params) {
|
|
|
+ const tableId = params?.tableId != null ? String(params.tableId) : '';
|
|
|
+ const url = tableId
|
|
|
+ ? `/store/generic-dining/order/lock?tableId=${encodeURIComponent(tableId)}`
|
|
|
+ : '/store/generic-dining/order/lock';
|
|
|
+ return api.post({ url, params: {} });
|
|
|
+}
|
|
|
+export const PostOrderLock = postOrderLockImpl;
|
|
|
+
|
|
|
+// 解锁订单
|
|
|
+function postOrderUnlockImpl(params) {
|
|
|
+ const tableId = params?.tableId != null ? String(params.tableId) : '';
|
|
|
+ const url = tableId
|
|
|
+ ? `/store/generic-dining/order/unlock?tableId=${encodeURIComponent(tableId)}`
|
|
|
+ : '/store/generic-dining/order/unlock';
|
|
|
+ return api.post({ url, params: {} });
|
|
|
+}
|
|
|
+export const PostOrderUnlock = postOrderUnlockImpl;
|
|
|
+export const postOrderUnlock = postOrderUnlockImpl;
|
|
|
+
|
|
|
+// 结算页锁定订单
|
|
|
+function postOrderSettlementLockImpl(params) {
|
|
|
+ const orderId = params?.orderId != null ? String(params.orderId) : '';
|
|
|
+ const url = orderId
|
|
|
+ ? `/store/generic-dining/order/settlement/lock?orderId=${encodeURIComponent(orderId)}`
|
|
|
+ : '/store/generic-dining/order/settlement/lock';
|
|
|
+ return api.post({ url, params: {} });
|
|
|
+}
|
|
|
+export const PostOrderSettlementLock = postOrderSettlementLockImpl;
|
|
|
+
|
|
|
+// 结算页解锁订单
|
|
|
+function postOrderSettlementUnlockImpl(params) {
|
|
|
+ const orderId = params?.orderId != null ? String(params.orderId) : '';
|
|
|
+ const url = orderId
|
|
|
+ ? `/store/generic-dining/order/settlement/unlock?orderId=${encodeURIComponent(orderId)}`
|
|
|
+ : '/store/generic-dining/order/settlement/unlock';
|
|
|
+ return api.post({ url, params: {} });
|
|
|
+}
|
|
|
+export const PostOrderSettlementUnlock = postOrderSettlementUnlockImpl;
|
|
|
+
|
|
|
+// 创建订单
|
|
|
+export const PostOrderCreate = (dto) =>
|
|
|
+ api.post({ url: '/store/order/create', params: dto });
|
|
|
+
|
|
|
+// 订单分页列表
|
|
|
+export const GetOrderPage = (params) =>
|
|
|
+ api.get({ url: '/store/order/page', params });
|
|
|
+
|
|
|
+// 我的订单
|
|
|
+export const GetMyOrders = (params) =>
|
|
|
+ api.get({ url: '/store/order/my-orders', params });
|
|
|
+
|
|
|
+// 订单详情
|
|
|
+export const GetOrderInfo = (orderId) =>
|
|
|
+ api.get({ url: `/store/order/info/${encodeURIComponent(orderId)}` });
|
|
|
+
|
|
|
+// 订单支付
|
|
|
+export const PostOrderPay = (params) => {
|
|
|
+ const query = {
|
|
|
+ orderNo: params.orderNo,
|
|
|
+ payType: 'wechatPayMininProgram',
|
|
|
+ payer: params.payer,
|
|
|
+ price: params.price,
|
|
|
+ subject: params.subject ?? '订单支付',
|
|
|
+ storeId: params.storeId
|
|
|
+ };
|
|
|
+ if (params.couponId != null && params.couponId !== '') {
|
|
|
+ query.couponId = params.couponId;
|
|
|
+ }
|
|
|
+ if (params.payerId != null && params.payerId !== '') {
|
|
|
+ query.payerId = params.payerId;
|
|
|
+ }
|
|
|
+ if (params.discountAmount != null && params.discountAmount !== '') {
|
|
|
+ query.discountAmount = params.discountAmount;
|
|
|
+ }
|
|
|
+ if (params.payAmount != null && params.payAmount !== '') {
|
|
|
+ query.payAmount = params.payAmount;
|
|
|
+ }
|
|
|
+ return api.get({
|
|
|
+ url: '/payment/prePay',
|
|
|
+ params: query
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+// 根据第三方订单号查询支付结果
|
|
|
+export const GetSearchOrderByOutTradeNoPath = (params) =>
|
|
|
+ api.get({
|
|
|
+ url: '/payment/searchOrderByOutTradeNoPath',
|
|
|
+ params: {
|
|
|
+ payType: params.payType ?? 'wechatPayMininProgram',
|
|
|
+ transactionId: params.transactionId,
|
|
|
+ storeId: params.storeId
|
|
|
+ },
|
|
|
+ loading: false
|
|
|
+ });
|
|
|
+
|
|
|
+// 订单翻转/完成
|
|
|
+export const PostOrderComplete = (orderId) =>
|
|
|
+ api.post({ url: `/store/order/complete/${encodeURIComponent(orderId)}`, loading: false });
|
|
|
+
|
|
|
+/**
|
|
|
+ * 订单 SSE 接口配置(路径无 dining,与美食线一致)
|
|
|
+ */
|
|
|
+export function getOrderSseConfig(tableId) {
|
|
|
+ const userStore = useUserStore();
|
|
|
+ return {
|
|
|
+ url: `${BASE_API_URL}/store/order/sse/${encodeURIComponent(tableId)}`,
|
|
|
+ header: { Authorization: userStore.getToken || '' },
|
|
|
+ timeout: 0
|
|
|
+ };
|
|
|
+}
|