merchantDish.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. import { http } from '@/common/service/service.js'
  2. import { USER_INFO } from '@/common/util/constants.js'
  3. const PACKAGE_BASE = '/groupmeal/gmMerchantPackage'
  4. const MEALBOX_BASE = '/groupmeal/gmMerchantMealBox'
  5. /** 当前登录商户 ID */
  6. export function getMerchantId() {
  7. const info = uni.getStorageSync(USER_INFO) || {}
  8. return info.merchantId || ''
  9. }
  10. /** statusType ↔ 前端文案 key */
  11. export const STATUS_TYPE_MAP = {
  12. 0: '',
  13. 1: 'selling',
  14. 2: 'soldout',
  15. 3: 'pending',
  16. 4: 'reviewing',
  17. 5: 'rejected'
  18. }
  19. export const STATUS_KEY_TO_TYPE = {
  20. '': 0,
  21. selling: 1,
  22. soldout: 2,
  23. pending: 3,
  24. reviewing: 4,
  25. rejected: 5
  26. }
  27. export const STATUS_TEXT = {
  28. selling: '销售中',
  29. soldout: '已售完',
  30. pending: '待上架',
  31. reviewing: '审核中',
  32. rejected: '未通过'
  33. }
  34. /** productBelonging ↔ 归属 */
  35. export function belongingToKey(productBelonging) {
  36. return Number(productBelonging) === 2 ? 'group' : 'store'
  37. }
  38. export function belongingToApi(belong) {
  39. return belong === 'group' ? 2 : 1
  40. }
  41. /** 早/午/晚 ↔ category */
  42. export const PRODUCT_TYPE_TO_CATEGORY = {
  43. breakfast: '1',
  44. lunch: '2',
  45. dinner: '3'
  46. }
  47. export const CATEGORY_TO_PRODUCT_TYPE = {
  48. 1: 'breakfast',
  49. 2: 'lunch',
  50. 3: 'dinner',
  51. '1': 'breakfast',
  52. '2': 'lunch',
  53. '3': 'dinner'
  54. }
  55. /** 套餐明细分类 meat/veg/... ↔ 1-5 */
  56. export const COMBO_CAT_TO_API = {
  57. meat: '1',
  58. veg: '2',
  59. staple: '3',
  60. soup: '4',
  61. other: '5'
  62. }
  63. export const COMBO_API_TO_CAT = {
  64. 1: 'meat',
  65. 2: 'veg',
  66. 3: 'staple',
  67. 4: 'soup',
  68. 5: 'other',
  69. '1': 'meat',
  70. '2': 'veg',
  71. '3': 'staple',
  72. '4': 'soup',
  73. '5': 'other'
  74. }
  75. /** 将分页商品记录映射为列表展示结构 */
  76. export function mapPackageToListItem(item) {
  77. const statusType = item.statusType != null ? Number(item.statusType) : null
  78. let status = STATUS_TYPE_MAP[statusType]
  79. if (!status) {
  80. // 兼容未返回 statusType 的情况
  81. if (Number(item.reviewStatus) === 0) status = 'reviewing'
  82. else if (Number(item.reviewStatus) === 2) status = 'rejected'
  83. else if (Number(item.status) === 0) status = 'pending'
  84. else if (Number(item.isSoldOut) === 1 || Number(item.dailyStock) === 0) status = 'soldout'
  85. else status = 'selling'
  86. }
  87. const image = (item.productImage || '').split(',').filter(Boolean)[0] || ''
  88. return {
  89. ...item,
  90. id: item.id,
  91. name: item.name,
  92. image,
  93. belong: belongingToKey(item.productBelonging),
  94. desc: item.dishName || item.mealBoxNames || '',
  95. // 售价 price,原价 sellingPrice
  96. price: item.price != null ? item.price : item.sellingPrice,
  97. originPrice: item.sellingPrice != null ? item.sellingPrice : item.originalPrice,
  98. stock: item.dailyStock != null ? item.dailyStock : 0,
  99. sales: item.sales != null ? item.sales : 0,
  100. status,
  101. statusName: item.statusName || STATUS_TEXT[status] || '',
  102. hasInProgressOrder: item.hasInProgressOrder,
  103. ungroupedOrderCount: Number(item.ungroupedOrderCount) || 0,
  104. groupedOrderCount: Number(item.groupedOrderCount) || 0
  105. }
  106. }
  107. /** 餐盒记录映射 */
  108. export function mapMealBoxItem(item) {
  109. return {
  110. ...item,
  111. id: item.id,
  112. name: item.boxName,
  113. price: item.boxPrice,
  114. image: item.boxImage || '',
  115. bindCount: item.packageCount != null ? item.packageCount : 0,
  116. bindIds: item.bindIds || []
  117. }
  118. }
  119. const api = {
  120. getMerchantId,
  121. /** 商品分页 */
  122. packagePageList(params = {}) {
  123. return http.post(`${PACKAGE_BASE}/pageListV2`, {
  124. pageNo: 1,
  125. pageSize: 20,
  126. merchantId: getMerchantId(),
  127. ...params
  128. })
  129. },
  130. /** 新增/编辑送审 */
  131. packageSubmit(data) {
  132. return http.post(`${PACKAGE_BASE}/submitV2`, data)
  133. },
  134. /** 商品详情 */
  135. packageDetail(id) {
  136. return http.get(`${PACKAGE_BASE}/queryByIdV2`, { params: { id } })
  137. },
  138. /** 单个上/下架 */
  139. packageLaunch(id, status) {
  140. return http.post(`${PACKAGE_BASE}/launch`, { id, status })
  141. },
  142. /** 批量上/下架 */
  143. packageBatchLaunch(ids, status) {
  144. return http.post(`${PACKAGE_BASE}/batchLaunch`, { ids, status })
  145. },
  146. /** 单个删除 */
  147. packageDelete(id) {
  148. return http.delete(`${PACKAGE_BASE}/delete`, {}, { params: { id } })
  149. },
  150. /** 批量删除 */
  151. packageDeleteBatch(ids) {
  152. const idStr = Array.isArray(ids) ? ids.join(',') : ids
  153. return http.delete(`${PACKAGE_BASE}/deleteBatch`, {}, { params: { ids: idStr } })
  154. },
  155. /** 特色分类 */
  156. specialCategoryList() {
  157. return http.get('/groupmeal/gmSpecialCategory/listAll')
  158. },
  159. /** 餐品分类(早/午/晚) */
  160. groupMealCategory() {
  161. return http.get(`${PACKAGE_BASE}/getGroupMealCategory`)
  162. },
  163. /** 团餐报名状态 */
  164. isApply() {
  165. return http.post('/groupmeal/gmMerchantApplicationRecord/isApply', {})
  166. },
  167. /** 餐盒分页 */
  168. mealBoxList(params = {}) {
  169. return http.get(`${MEALBOX_BASE}/list`, {
  170. params: {
  171. pageNo: 1,
  172. pageSize: 50,
  173. merchantId: getMerchantId(),
  174. ...params
  175. }
  176. })
  177. },
  178. /** 新增餐盒并绑定 */
  179. mealBoxAdd(data) {
  180. return http.post(`${MEALBOX_BASE}/addWithPackages`, {
  181. merchantId: getMerchantId(),
  182. ...data
  183. })
  184. },
  185. /** 编辑餐盒并更新绑定 */
  186. mealBoxEdit(data) {
  187. return http.put(`${MEALBOX_BASE}/editWithPackages`, data)
  188. },
  189. /** 删除餐盒 */
  190. mealBoxDelete(id) {
  191. return http.delete(`${MEALBOX_BASE}/deleteWithPackages`, {}, { params: { id } })
  192. },
  193. /** 餐盒详情 */
  194. mealBoxDetail(id) {
  195. return http.get(`${MEALBOX_BASE}/queryById`, { params: { id } })
  196. },
  197. /** 餐盒绑定套餐(全量替换) */
  198. mealBoxBind(mealBoxId, packageIds) {
  199. return http.post(
  200. `${MEALBOX_BASE}/bindPackages`,
  201. packageIds,
  202. {
  203. params: {
  204. merchantId: getMerchantId(),
  205. mealBoxId
  206. }
  207. }
  208. )
  209. },
  210. /** 查询餐盒已绑定套餐 */
  211. mealBoxPackages(mealBoxId, category) {
  212. const params = {
  213. merchantId: getMerchantId(),
  214. mealBoxId
  215. }
  216. if (category != null && category !== '') params.category = category
  217. return http.get(`${MEALBOX_BASE}/listPackages`, { params })
  218. },
  219. /** 按套餐查餐盒 */
  220. mealBoxByPackage(packageId) {
  221. return http.get(`${MEALBOX_BASE}/listByPackageId`, { params: { packageId } })
  222. }
  223. }
  224. export default api