feat: 新增后台复制店铺商品目录接口
支持按用户ID复制商品类型、专区与商品,OSS图片独立拷贝,并提供覆盖/补充两种模式。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -931,3 +931,46 @@ class ProductModifyView(APIView):
|
||||
product.save(update_fields=update_fields)
|
||||
return Response({'code': 0, 'msg': '商品修改成功'})
|
||||
|
||||
|
||||
class ShopCopyCatalogView(APIView):
|
||||
"""
|
||||
复制店铺商品目录(类型 + 专区 + 商品,含 OSS 图片独立拷贝)。
|
||||
请求路径: /houtai/htfzdpspsj
|
||||
权限: 店铺管理权限 999a~999e 任一
|
||||
"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def post(self, request):
|
||||
username = request.data.get('username')
|
||||
kefu, permissions = verify_kefu_permission(request, username)
|
||||
if kefu is None:
|
||||
return Response({'code': 403, 'msg': '身份验证失败,请检查登录状态'})
|
||||
|
||||
required_perms = {'999a', '999b', '999c', '999d', '999e'}
|
||||
if not required_perms.intersection(set(permissions)):
|
||||
return Response({'code': 403, 'msg': '您没有权限执行店铺商品复制操作'})
|
||||
|
||||
source_user_uid = str(request.data.get('source_user_uid', '')).strip()
|
||||
target_user_uid = str(request.data.get('target_user_uid', '')).strip()
|
||||
copy_mode = str(request.data.get('copy_mode', 'append')).strip().lower()
|
||||
|
||||
if not source_user_uid or not target_user_uid:
|
||||
return Response({'code': 400, 'msg': '请填写源店铺与目标店铺的用户ID'})
|
||||
|
||||
from backend.services.shop_copy_service import copy_shop_catalog, ShopCopyError
|
||||
|
||||
try:
|
||||
result = copy_shop_catalog(source_user_uid, target_user_uid, copy_mode)
|
||||
return Response({
|
||||
'code': 0,
|
||||
'msg': (
|
||||
f'复制成功:商品类型 {result["copied_types"]} 个,'
|
||||
f'专区 {result["copied_zones"]} 个,商品 {result["copied_products"]} 个'
|
||||
),
|
||||
'data': result,
|
||||
})
|
||||
except ShopCopyError as e:
|
||||
return Response({'code': e.code, 'msg': e.message})
|
||||
except Exception:
|
||||
logger.exception('复制店铺商品失败')
|
||||
return Response({'code': 500, 'msg': '复制失败,请稍后重试'})
|
||||
|
||||
Reference in New Issue
Block a user