genericDining.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /**
  2. * 与 dining.js 接口一一对应,路径中的 dining 改为 generic-dining。
  3. * 用于扫码进入且 m≠1 时的业务后端(非美食专线)。
  4. */
  5. import { api } from '@/utils/request.js';
  6. import { BASE_API_URL } from '@/settings/siteSetting.js';
  7. import { useUserStore } from '@/store/user.js';
  8. // 微信登录
  9. export const DiningUserWechatLogin = (params) =>
  10. api.post({ url: '/generic-dining/user/wechatLogin', params });
  11. // 获取用户信息(GET /generic-dining/user/getUserInfo),登录后调用以拿到头像等
  12. export const GetUserInfo = () => api.get({ url: '/generic-dining/user/getUserInfo' });
  13. // 更新用户个人信息(POST /generic-dining/user/updateProfile,body 为 dto)
  14. export const PostUpdateProfile = (dto) =>
  15. api.post({ url: '/generic-dining/user/updateProfile', params: dto });
  16. // 文件上传(POST multipart,返回图片 URL/path 供 avatarUrl 使用)
  17. function uploadFileToServerImpl(filePath) {
  18. const userStore = useUserStore();
  19. return new Promise((resolve, reject) => {
  20. uni.uploadFile({
  21. url: BASE_API_URL + '/generic-dining/file/upload',
  22. filePath,
  23. name: 'file',
  24. header: { Authorization: userStore.getToken || '' },
  25. success: (res) => {
  26. if (res.statusCode === 200) {
  27. try {
  28. const data = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
  29. const payload = data?.data ?? data;
  30. const url = payload?.url ?? payload?.path ?? payload?.relativePath ?? (typeof payload === 'string' ? payload : '');
  31. resolve(url || '');
  32. } catch (e) {
  33. reject(e);
  34. }
  35. } else {
  36. reject(new Error(res.data || '上传失败'));
  37. }
  38. },
  39. fail: reject
  40. });
  41. });
  42. }
  43. export const uploadFileToServer = uploadFileToServerImpl;
  44. export const uploadFileToSever = uploadFileToServerImpl; // 兼容拼写错误
  45. // 点餐页数据(入参 dinerCount 就餐人数、tableId 桌号)
  46. export const DiningOrderFood = (params) => api.get({ url: '/store/generic-dining/page-info', params });
  47. // 服务费估算
  48. export const GetServiceFeeEstimate = (params) => {
  49. const q = {};
  50. if (params?.storeId != null && params.storeId !== '') q.storeId = String(params.storeId);
  51. if (params?.tableId != null && params.tableId !== '') q.tableId = String(params.tableId);
  52. if (params?.dinerCount != null && params.dinerCount !== '') q.dinerCount = params.dinerCount;
  53. if (params?.goodsSubtotal != null && params.goodsSubtotal !== '') q.goodsSubtotal = params.goodsSubtotal;
  54. return api.get({ url: '/store/generic-dining/service-fee/estimate', params: q, loading: false });
  55. };
  56. // 桌台预约记录详情
  57. export const GetReservationDetailByStoreTableRecord = (params) => {
  58. const q = {};
  59. if (params?.storeId != null && params?.storeId !== '') q.storeId = String(params.storeId);
  60. if (params?.userReservationTableId != null && params?.userReservationTableId !== '') {
  61. q.userReservationTableId = String(params.userReservationTableId);
  62. }
  63. return api.get({
  64. url: '/store/generic-dining/reservation/detail-by-store-table-record',
  65. params: q,
  66. loading: false
  67. });
  68. };
  69. // 查询桌位是否已选就餐人数
  70. export const GetTableDiningStatus = (tableId, extra = {}) =>
  71. api.get({
  72. url: '/store/generic-dining/table-generic-dining-status',
  73. params: { tableId: tableId != null && tableId !== '' ? String(tableId) : '' },
  74. ...extra
  75. });
  76. // 到店就餐信息提交
  77. export const PostDiningWalkInReservation = (dto) =>
  78. api.post({ url: '/store/generic-dining/walk-in/reservation', params: dto });
  79. // 门店详情(GET /store/info/detail/{storeId},入参 storeId)
  80. export const GetStoreDetail = (storeId) =>
  81. api.get({ url: `/store/info/detail/${encodeURIComponent(storeId)}` });
  82. // 菜品种类(入参 storeId,GET /store/info/categories?storeId=)
  83. export const GetStoreCategories = (params) => api.get({ url: '/store/info/categories', params });
  84. // 根据菜品种类获取菜品(入参 categoryId,GET /store/info/cuisines?categoryId=)
  85. export const GetStoreCuisines = (params) => api.get({ url: '/store/info/cuisines', params });
  86. // 左侧分类+右侧菜品一体(通用价目 alienDining:固定 menuType=2)
  87. export const GetCategoriesWithCuisines = (params) =>
  88. api.get({
  89. url: '/store/info/categories-with-cuisines',
  90. params: { ...(params || {}), menuType: 2 }
  91. });
  92. // 菜品详情
  93. export const GetCuisineDetail = (cuisineId, tableId) => {
  94. const id = cuisineId != null ? encodeURIComponent(cuisineId) : '';
  95. const url = id ? `/store/generic-dining/cuisine/${id}` : '/store/generic-dining/cuisine/0';
  96. const params = tableId != null && tableId !== '' ? { tableId } : {};
  97. return api.get({ url, params });
  98. };
  99. // 门店全部优惠券列表
  100. function getStoreAllCouponListImpl(params) {
  101. return api.get({
  102. url: '/generic-dining/coupon/getStoreAllCouponList',
  103. params: {
  104. storeId: params?.storeId,
  105. tab: 1,
  106. page: params?.page ?? 1,
  107. size: params?.size ?? 10
  108. }
  109. });
  110. }
  111. export const GetStoreAllCouponList = getStoreAllCouponListImpl;
  112. export const GetStoreUsableCouponList = getStoreAllCouponListImpl;
  113. // 用户已领/可用优惠券
  114. function getUserOwnedCouponListImpl(params) {
  115. return api.get({
  116. url: '/generic-dining/coupon/userOwnedByStore',
  117. params: {
  118. storeId: params?.storeId
  119. }
  120. });
  121. }
  122. export const GetUserOwnedCouponList = getUserOwnedCouponListImpl;
  123. // 用户优惠券列表
  124. export const GetUserCouponList = (params) =>
  125. api.get({
  126. url: '/generic-dining/coupon/getUserCouponList',
  127. params: {
  128. storeId: params?.storeId,
  129. tabType: params?.tabType ?? 0,
  130. page: params?.page ?? 1,
  131. size: params?.size ?? 20
  132. }
  133. });
  134. // 获取购物车(路径无 dining)
  135. export const GetOrderCart = (tableId) =>
  136. api.get({ url: `/store/order/cart/${encodeURIComponent(tableId)}` });
  137. // 加入购物车
  138. export const PostOrderCartAdd = (dto) =>
  139. api.post({ url: '/store/order/cart/add', params: dto });
  140. // 更新购物车
  141. export const PostOrderCartUpdate = (params) =>
  142. api.put({ url: '/store/order/cart/update', params, formUrlEncoded: true });
  143. // 清空购物车
  144. export const PostOrderCartClear = (tableId) => {
  145. const id = tableId != null ? String(tableId) : '';
  146. const url = id ? `/store/order/cart/clear?tableId=${encodeURIComponent(id)}` : '/store/order/cart/clear';
  147. return api.delete({ url, params: id ? { tableId: id } : {} });
  148. };
  149. // 锁定订单
  150. function postOrderLockImpl(params) {
  151. const tableId = params?.tableId != null ? String(params.tableId) : '';
  152. const url = tableId
  153. ? `/store/generic-dining/order/lock?tableId=${encodeURIComponent(tableId)}`
  154. : '/store/generic-dining/order/lock';
  155. return api.post({ url, params: {} });
  156. }
  157. export const PostOrderLock = postOrderLockImpl;
  158. // 解锁订单
  159. function postOrderUnlockImpl(params) {
  160. const tableId = params?.tableId != null ? String(params.tableId) : '';
  161. const url = tableId
  162. ? `/store/generic-dining/order/unlock?tableId=${encodeURIComponent(tableId)}`
  163. : '/store/generic-dining/order/unlock';
  164. return api.post({ url, params: {} });
  165. }
  166. export const PostOrderUnlock = postOrderUnlockImpl;
  167. export const postOrderUnlock = postOrderUnlockImpl;
  168. // 结算页锁定订单
  169. function postOrderSettlementLockImpl(params) {
  170. const orderId = params?.orderId != null ? String(params.orderId) : '';
  171. const url = orderId
  172. ? `/store/generic-dining/order/settlement/lock?orderId=${encodeURIComponent(orderId)}`
  173. : '/store/generic-dining/order/settlement/lock';
  174. return api.post({ url, params: {} });
  175. }
  176. export const PostOrderSettlementLock = postOrderSettlementLockImpl;
  177. // 结算页解锁订单
  178. function postOrderSettlementUnlockImpl(params) {
  179. const orderId = params?.orderId != null ? String(params.orderId) : '';
  180. const url = orderId
  181. ? `/store/generic-dining/order/settlement/unlock?orderId=${encodeURIComponent(orderId)}`
  182. : '/store/generic-dining/order/settlement/unlock';
  183. return api.post({ url, params: {} });
  184. }
  185. export const PostOrderSettlementUnlock = postOrderSettlementUnlockImpl;
  186. // 创建订单
  187. export const PostOrderCreate = (dto) =>
  188. api.post({ url: '/store/order/create', params: dto });
  189. // 订单分页列表
  190. export const GetOrderPage = (params) =>
  191. api.get({ url: '/store/order/page', params });
  192. // 我的订单
  193. export const GetMyOrders = (params) =>
  194. api.get({ url: '/store/order/my-orders', params });
  195. // 订单详情
  196. export const GetOrderInfo = (orderId) =>
  197. api.get({ url: `/store/order/info/${encodeURIComponent(orderId)}` });
  198. // 订单支付
  199. export const PostOrderPay = (params) => {
  200. const query = {
  201. orderNo: params.orderNo,
  202. payType: 'wechatPayMininProgram',
  203. payer: params.payer,
  204. price: params.price,
  205. subject: params.subject ?? '订单支付',
  206. storeId: params.storeId
  207. };
  208. if (params.couponId != null && params.couponId !== '') {
  209. query.couponId = params.couponId;
  210. }
  211. if (params.payerId != null && params.payerId !== '') {
  212. query.payerId = params.payerId;
  213. }
  214. if (params.discountAmount != null && params.discountAmount !== '') {
  215. query.discountAmount = params.discountAmount;
  216. }
  217. if (params.payAmount != null && params.payAmount !== '') {
  218. query.payAmount = params.payAmount;
  219. }
  220. return api.get({
  221. url: '/payment/prePay',
  222. params: query
  223. });
  224. };
  225. // 根据第三方订单号查询支付结果
  226. export const GetSearchOrderByOutTradeNoPath = (params) =>
  227. api.get({
  228. url: '/payment/searchOrderByOutTradeNoPath',
  229. params: {
  230. payType: params.payType ?? 'wechatPayMininProgram',
  231. transactionId: params.transactionId,
  232. storeId: params.storeId
  233. },
  234. loading: false
  235. });
  236. // 订单翻转/完成
  237. export const PostOrderComplete = (orderId) =>
  238. api.post({ url: `/store/order/complete/${encodeURIComponent(orderId)}`, loading: false });
  239. /**
  240. * 订单 SSE 接口配置(路径无 dining,与美食线一致)
  241. */
  242. export function getOrderSseConfig(tableId) {
  243. const userStore = useUserStore();
  244. return {
  245. url: `${BASE_API_URL}/store/order/sse/${encodeURIComponent(tableId)}`,
  246. header: { Authorization: userStore.getToken || '' },
  247. timeout: 0
  248. };
  249. }