merchantDish.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. }
  104. }
  105. /** 餐盒记录映射 */
  106. export function mapMealBoxItem(item) {
  107. return {
  108. ...item,
  109. id: item.id,
  110. name: item.boxName,
  111. price: item.boxPrice,
  112. image: item.boxImage || '',
  113. bindCount: item.packageCount != null ? item.packageCount : 0,
  114. bindIds: item.bindIds || []
  115. }
  116. }
  117. const api = {
  118. getMerchantId,
  119. /** 商品分页 */
  120. packagePageList(params = {}) {
  121. return http.post(`${PACKAGE_BASE}/pageListV2`, {
  122. pageNo: 1,
  123. pageSize: 20,
  124. merchantId: getMerchantId(),
  125. ...params
  126. })
  127. },
  128. /** 新增/编辑送审 */
  129. packageSubmit(data) {
  130. return http.post(`${PACKAGE_BASE}/submitV2`, data)
  131. },
  132. /** 商品详情 */
  133. packageDetail(id) {
  134. return http.get(`${PACKAGE_BASE}/queryByIdV2`, { params: { id } })
  135. },
  136. /** 单个上/下架 */
  137. packageLaunch(id, status) {
  138. return http.post(`${PACKAGE_BASE}/launch`, { id, status })
  139. },
  140. /** 批量上/下架 */
  141. packageBatchLaunch(ids, status) {
  142. return http.post(`${PACKAGE_BASE}/batchLaunch`, { ids, status })
  143. },
  144. /** 单个删除 */
  145. packageDelete(id) {
  146. return http.delete(`${PACKAGE_BASE}/delete`, {}, { params: { id } })
  147. },
  148. /** 批量删除 */
  149. packageDeleteBatch(ids) {
  150. const idStr = Array.isArray(ids) ? ids.join(',') : ids
  151. return http.delete(`${PACKAGE_BASE}/deleteBatch`, {}, { params: { ids: idStr } })
  152. },
  153. /** 特色分类 */
  154. specialCategoryList() {
  155. return http.get('/groupmeal/gmSpecialCategory/listAll')
  156. },
  157. /** 餐品分类(早/午/晚) */
  158. groupMealCategory() {
  159. return http.get(`${PACKAGE_BASE}/getGroupMealCategory`)
  160. },
  161. /** 团餐报名状态 */
  162. isApply() {
  163. return http.post('/groupmeal/gmMerchantApplicationRecord/isApply', {})
  164. },
  165. /** 餐盒分页 */
  166. mealBoxList(params = {}) {
  167. return http.get(`${MEALBOX_BASE}/list`, {
  168. params: {
  169. pageNo: 1,
  170. pageSize: 50,
  171. merchantId: getMerchantId(),
  172. ...params
  173. }
  174. })
  175. },
  176. /** 新增餐盒并绑定 */
  177. mealBoxAdd(data) {
  178. return http.post(`${MEALBOX_BASE}/addWithPackages`, {
  179. merchantId: getMerchantId(),
  180. ...data
  181. })
  182. },
  183. /** 编辑餐盒并更新绑定 */
  184. mealBoxEdit(data) {
  185. return http.put(`${MEALBOX_BASE}/editWithPackages`, data)
  186. },
  187. /** 删除餐盒 */
  188. mealBoxDelete(id) {
  189. return http.delete(`${MEALBOX_BASE}/deleteWithPackages`, {}, { params: { id } })
  190. },
  191. /** 餐盒详情 */
  192. mealBoxDetail(id) {
  193. return http.get(`${MEALBOX_BASE}/queryById`, { params: { id } })
  194. },
  195. /** 餐盒绑定套餐(全量替换) */
  196. mealBoxBind(mealBoxId, packageIds) {
  197. return http.post(
  198. `${MEALBOX_BASE}/bindPackages`,
  199. packageIds,
  200. {
  201. params: {
  202. merchantId: getMerchantId(),
  203. mealBoxId
  204. }
  205. }
  206. )
  207. },
  208. /** 查询餐盒已绑定套餐 */
  209. mealBoxPackages(mealBoxId, category) {
  210. const params = {
  211. merchantId: getMerchantId(),
  212. mealBoxId
  213. }
  214. if (category != null && category !== '') params.category = category
  215. return http.get(`${MEALBOX_BASE}/listPackages`, { params })
  216. },
  217. /** 按套餐查餐盒 */
  218. mealBoxByPackage(packageId) {
  219. return http.get(`${MEALBOX_BASE}/listByPackageId`, { params: { packageId } })
  220. }
  221. }
  222. export default api