| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- import { http } from '@/common/service/service.js'
- import { USER_INFO } from '@/common/util/constants.js'
- const PACKAGE_BASE = '/groupmeal/gmMerchantPackage'
- const MEALBOX_BASE = '/groupmeal/gmMerchantMealBox'
- /** 当前登录商户 ID */
- export function getMerchantId() {
- const info = uni.getStorageSync(USER_INFO) || {}
- return info.merchantId || ''
- }
- /** statusType ↔ 前端文案 key */
- export const STATUS_TYPE_MAP = {
- 0: '',
- 1: 'selling',
- 2: 'soldout',
- 3: 'pending',
- 4: 'reviewing',
- 5: 'rejected'
- }
- export const STATUS_KEY_TO_TYPE = {
- '': 0,
- selling: 1,
- soldout: 2,
- pending: 3,
- reviewing: 4,
- rejected: 5
- }
- export const STATUS_TEXT = {
- selling: '销售中',
- soldout: '已售完',
- pending: '待上架',
- reviewing: '审核中',
- rejected: '未通过'
- }
- /** productBelonging ↔ 归属 */
- export function belongingToKey(productBelonging) {
- return Number(productBelonging) === 2 ? 'group' : 'store'
- }
- export function belongingToApi(belong) {
- return belong === 'group' ? 2 : 1
- }
- /** 早/午/晚 ↔ category */
- export const PRODUCT_TYPE_TO_CATEGORY = {
- breakfast: '1',
- lunch: '2',
- dinner: '3'
- }
- export const CATEGORY_TO_PRODUCT_TYPE = {
- 1: 'breakfast',
- 2: 'lunch',
- 3: 'dinner',
- '1': 'breakfast',
- '2': 'lunch',
- '3': 'dinner'
- }
- /** 套餐明细分类 meat/veg/... ↔ 1-5 */
- export const COMBO_CAT_TO_API = {
- meat: '1',
- veg: '2',
- staple: '3',
- soup: '4',
- other: '5'
- }
- export const COMBO_API_TO_CAT = {
- 1: 'meat',
- 2: 'veg',
- 3: 'staple',
- 4: 'soup',
- 5: 'other',
- '1': 'meat',
- '2': 'veg',
- '3': 'staple',
- '4': 'soup',
- '5': 'other'
- }
- /** 将分页商品记录映射为列表展示结构 */
- export function mapPackageToListItem(item) {
- const statusType = item.statusType != null ? Number(item.statusType) : null
- let status = STATUS_TYPE_MAP[statusType]
- if (!status) {
- // 兼容未返回 statusType 的情况
- if (Number(item.reviewStatus) === 0) status = 'reviewing'
- else if (Number(item.reviewStatus) === 2) status = 'rejected'
- else if (Number(item.status) === 0) status = 'pending'
- else if (Number(item.isSoldOut) === 1 || Number(item.dailyStock) === 0) status = 'soldout'
- else status = 'selling'
- }
- const image = (item.productImage || '').split(',').filter(Boolean)[0] || ''
- return {
- ...item,
- id: item.id,
- name: item.name,
- image,
- belong: belongingToKey(item.productBelonging),
- desc: item.dishName || item.mealBoxNames || '',
- // 售价 price,原价 sellingPrice
- price: item.price != null ? item.price : item.sellingPrice,
- originPrice: item.sellingPrice != null ? item.sellingPrice : item.originalPrice,
- stock: item.dailyStock != null ? item.dailyStock : 0,
- sales: item.sales != null ? item.sales : 0,
- status,
- statusName: item.statusName || STATUS_TEXT[status] || '',
- hasInProgressOrder: item.hasInProgressOrder,
- ungroupedOrderCount: Number(item.ungroupedOrderCount) || 0,
- groupedOrderCount: Number(item.groupedOrderCount) || 0
- }
- }
- /** 餐盒记录映射 */
- export function mapMealBoxItem(item) {
- return {
- ...item,
- id: item.id,
- name: item.boxName,
- price: item.boxPrice,
- image: item.boxImage || '',
- bindCount: item.packageCount != null ? item.packageCount : 0,
- bindIds: item.bindIds || []
- }
- }
- const api = {
- getMerchantId,
- /** 商品分页 */
- packagePageList(params = {}) {
- return http.post(`${PACKAGE_BASE}/pageListV2`, {
- pageNo: 1,
- pageSize: 20,
- merchantId: getMerchantId(),
- ...params
- })
- },
- /** 新增/编辑送审 */
- packageSubmit(data) {
- return http.post(`${PACKAGE_BASE}/submitV2`, data)
- },
- /** 商品详情 */
- packageDetail(id) {
- return http.get(`${PACKAGE_BASE}/queryByIdV2`, { params: { id } })
- },
- /** 单个上/下架 */
- packageLaunch(id, status) {
- return http.post(`${PACKAGE_BASE}/launch`, { id, status })
- },
- /** 批量上/下架 */
- packageBatchLaunch(ids, status) {
- return http.post(`${PACKAGE_BASE}/batchLaunch`, { ids, status })
- },
- /** 单个删除 */
- packageDelete(id) {
- return http.delete(`${PACKAGE_BASE}/delete`, {}, { params: { id } })
- },
- /** 批量删除 */
- packageDeleteBatch(ids) {
- const idStr = Array.isArray(ids) ? ids.join(',') : ids
- return http.delete(`${PACKAGE_BASE}/deleteBatch`, {}, { params: { ids: idStr } })
- },
- /** 特色分类 */
- specialCategoryList() {
- return http.get('/groupmeal/gmSpecialCategory/listAll')
- },
- /** 餐品分类(早/午/晚) */
- groupMealCategory() {
- return http.get(`${PACKAGE_BASE}/getGroupMealCategory`)
- },
- /** 团餐报名状态 */
- isApply() {
- return http.post('/groupmeal/gmMerchantApplicationRecord/isApply', {})
- },
- /** 商户团餐订单详情 */
- packageOrderDetail(hostOrderId) {
- return http.get('/groupmeal/merchantPackageOrder/detail', {
- params: { hostOrderId }
- })
- },
- /** 商户端直接退款 */
- packageOrderDirectRefund(userOrderId) {
- return http.post('/groupmeal/merchantPackageOrder/directRefund', {}, {
- params: { userOrderId }
- })
- },
- /** 餐盒分页 */
- mealBoxList(params = {}) {
- return http.get(`${MEALBOX_BASE}/list`, {
- params: {
- pageNo: 1,
- pageSize: 50,
- merchantId: getMerchantId(),
- ...params
- }
- })
- },
- /** 新增餐盒并绑定 */
- mealBoxAdd(data) {
- return http.post(`${MEALBOX_BASE}/addWithPackages`, {
- merchantId: getMerchantId(),
- ...data
- })
- },
- /** 编辑餐盒并更新绑定 */
- mealBoxEdit(data) {
- return http.put(`${MEALBOX_BASE}/editWithPackages`, data)
- },
- /** 删除餐盒 */
- mealBoxDelete(id) {
- return http.delete(`${MEALBOX_BASE}/deleteWithPackages`, {}, { params: { id } })
- },
- /** 餐盒详情 */
- mealBoxDetail(id) {
- return http.get(`${MEALBOX_BASE}/queryById`, { params: { id } })
- },
- /** 餐盒绑定套餐(全量替换) */
- mealBoxBind(mealBoxId, packageIds) {
- return http.post(
- `${MEALBOX_BASE}/bindPackages`,
- packageIds,
- {
- params: {
- merchantId: getMerchantId(),
- mealBoxId
- }
- }
- )
- },
- /** 查询餐盒已绑定套餐 */
- mealBoxPackages(mealBoxId, category) {
- const params = {
- merchantId: getMerchantId(),
- mealBoxId
- }
- if (category != null && category !== '') params.category = category
- return http.get(`${MEALBOX_BASE}/listPackages`, { params })
- },
- /** 按套餐查餐盒 */
- mealBoxByPackage(packageId) {
- return http.get(`${MEALBOX_BASE}/listByPackageId`, { params: { packageId } })
- }
- }
- export default api
|