import request from '@/utils/request'

// JD订单列表
export function listJDOrders(query) {
  return request({
    url: '/system/jdorder/list',
    method: 'get',
    params: query
  })
}

// JD订单详情
export function getJDOrder(id) {
  return request({
    url: `/system/jdorder/${id}`,
    method: 'get'
  })
}

// 更新JD订单
export function updateJDOrder(data) {
  return request({
    url: '/system/jdorder',
    method: 'put',
    data: data
  })
}

// 一键转链
export function generatePromotionContent(data) {
  return request({
    url: '/jarvis/jdorder/generatePromotionContent',
    method: 'post',
    data: data
  })
}

// 创建商品（基于转链生成的文案与图片）
export function createProductByPromotion(data) {
  return request({
    url: '/erp/product/createByPromotion',
    method: 'post',
    data: data
  })
}

// 上架商品
export function publishProduct(data) {
  return request({
    url: '/erp/product/publish',
    method: 'post',
    data
  })
}

// 地区下拉
export function getProvinces() {
  return request({
    url: '/erp/region/provinces',
    method: 'get'
  })
}

export function getCities(provId) {
  return request({
    url: '/erp/region/cities',
    method: 'get',
    params: { provId }
  })
}

export function getAreas(provId, cityId) {
  return request({
    url: '/erp/region/areas',
    method: 'get',
    params: { provId, cityId }
  })
}

// 类目下拉
export function getCategories(params) {
  return request({
    url: '/erp/product/categories',
    method: 'get',
    params
  })
}

// 会员名下拉
export function getUsernames(params) {
  return request({
    url: '/erp/product/usernames',
    method: 'get',
    params
  })
}

// ERP 账号下拉（备用）
export function getERPAccounts() {
  return request({
    url: '/erp/product/ERPAccount',
    method: 'get'
  })
}

// 属性下拉
export function getProperties(params) {
  return request({
    url: '/erp/product/pv',
    method: 'get',
    params
  })
}

// 开礼金
export function createGiftCoupon(data) {
  return request({
    url: '/jarvis/jdorder/createGiftCoupon',
    method: 'post',
    data
  })
}

// 转链（支持礼金）
export function transferWithGift(data) {
  return request({
    url: '/jarvis/jdorder/transfer',
    method: 'post',
    data
  })
}

// 批量创建礼金券
export function batchCreateGiftCoupons(data) {
  return request({
    url: '/jarvis/jdorder/batchCreateGiftCoupons',
    method: 'post',
    data
  })
}

// 文本URL替换（批量创建礼金并替换）
export function replaceUrlsWithGiftCoupons(data) {
  return request({
    url: '/jarvis/jdorder/replaceUrlsWithGiftCoupons',
    method: 'post',
    data
  })
}

// 导出JD订单列表
export function exportJDOrders(query) {
  return request({
    url: '/system/jdorder/export',
    method: 'post',
    params: query
  })
}

// 删除JD订单（支持批量，ids为逗号分隔或数组）
export function delJDOrder(ids) {
  // 兼容数组或字符串
  const idPath = Array.isArray(ids) ? ids.join(',') : ids
  return request({
    url: `/system/jdorder/${idPath}`,
    method: 'delete'
  })
}
1
// 手动获取物流信息（用于调试）
export function fetchLogisticsManually(data) {
  return request({
    url: '/jarvis/jdorder/fetchLogisticsManually',
    method: 'post',
    data
  })
}

// 订单搜索工具接口（返回简易字段）
export function searchOrders(query) {
  return request({
    url: '/system/jdorder/tools/search',
    method: 'get',
    params: query
  })
}

// 批量标记后返到账（赔付金额>0的订单）
export function batchMarkRebateReceived() {
  return request({
    url: '/system/jdorder/tools/batch-mark-rebate-received',
    method: 'post'
  })
}

// 生成录单格式文本（Excel可粘贴格式）
export function generateExcelText(query) {
  return request({
    url: '/system/jdorder/generateExcelText',
    method: 'get',
    params: query
  })
}