|
|
@@ -211,86 +211,121 @@ export const addAppealNew = (params: FormData | Record<string, unknown>) => {
|
|
|
};
|
|
|
|
|
|
// 动态-------------------------------------------------------------------------------------
|
|
|
-/** 商家端 commonComment/addComment:发表评论/回复(评价回复 sourceType=1,动态评论 sourceType=2) */
|
|
|
-// 发表评论 - 表单形式提交(字符串键值对,非 JSON 对象)
|
|
|
-export const addComment = (data: {
|
|
|
- commentContent: string;
|
|
|
- businessType: number;
|
|
|
- businessId: string | number;
|
|
|
- storeId: string;
|
|
|
- phoneId: string;
|
|
|
- replyId: string;
|
|
|
- commentStar: string;
|
|
|
- multipartRequest: string;
|
|
|
-}) => {
|
|
|
- const formData = new FormData();
|
|
|
- formData.append("commentContent", data.commentContent);
|
|
|
- formData.append("businessType", String(data.businessType));
|
|
|
- formData.append("businessId", String(data.businessId));
|
|
|
- formData.append("storeId", data.storeId);
|
|
|
- formData.append("phoneId", data.phoneId);
|
|
|
- formData.append("replyId", data.replyId);
|
|
|
- formData.append("commentStar", data.commentStar);
|
|
|
- formData.append("multipartRequest", data.multipartRequest);
|
|
|
- return httpLogin.post(`/alienStore/storeComment/saveComment`, formData);
|
|
|
+/** commonComment/addComment 请求体(与接口模型一致;新增评论一般只传部分字段) */
|
|
|
+export interface AddCommonCommentBody {
|
|
|
+ auditReason?: string;
|
|
|
+ /** 0-待审核 1-通过 2-驳回 */
|
|
|
+ auditStatus?: number;
|
|
|
+ /** 1-用户评论 2-商户评论(仅回复) */
|
|
|
+ commentType?: number;
|
|
|
+ content?: string;
|
|
|
+ createdTime?: string;
|
|
|
+ /** 0-未删除 1-已删除 */
|
|
|
+ deleteFlag?: number;
|
|
|
+ extInfo?: string;
|
|
|
+ id?: number;
|
|
|
+ imageUrls?: string;
|
|
|
+ /** 0-否 1-是(仅用户评论生效) */
|
|
|
+ isAnonymous?: number;
|
|
|
+ /** 0-隐藏 1-展示 */
|
|
|
+ isShow?: number;
|
|
|
+ likeCount?: number;
|
|
|
+ /** commentType=2 时必填 */
|
|
|
+ merchantId?: number;
|
|
|
+ /** 0=根评论,>0=回复某条评论 */
|
|
|
+ parentId?: number;
|
|
|
+ replyCount?: number;
|
|
|
+ /** sourceType=1 rating.id;=2 动态ID;=3 打卡;=4 二手商品 */
|
|
|
+ sourceId?: number;
|
|
|
+ /** 1-评价的评论 2-动态 3-打卡 4-二手商品 */
|
|
|
+ sourceType?: number;
|
|
|
+ updatedTime?: string;
|
|
|
+ /** 用户=用户ID,商户=商户运营账号ID */
|
|
|
+ userId?: number;
|
|
|
+}
|
|
|
+
|
|
|
+function omitUndefinedRecord(obj: Record<string, unknown>): Record<string, unknown> {
|
|
|
+ return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined && v !== null));
|
|
|
+}
|
|
|
+
|
|
|
+/** 将可转为整型的 id 字段转为 number,无法转换则返回 undefined */
|
|
|
+function toInt64(v: unknown): number | undefined {
|
|
|
+ if (v === undefined || v === null || v === "") return undefined;
|
|
|
+ const n = Number(v);
|
|
|
+ return Number.isFinite(n) ? Math.trunc(n) : undefined;
|
|
|
+}
|
|
|
+
|
|
|
+function buildSaveCommentBody(params: any): AddCommonCommentBody {
|
|
|
+ const businessType = Number(params.businessType ?? 2);
|
|
|
+ const isRating = businessType === 1;
|
|
|
+ const sourceType = isRating ? 1 : 2;
|
|
|
+ const sourceIdRaw = isRating ? (params.replyId ?? params.businessId) : (params.businessId ?? params.sourceId);
|
|
|
+ const parentId = isRating ? 0 : Number(params.replyId || 0);
|
|
|
+ const merchantRaw = params.merchantId ?? params.storeId ?? (isRating ? params.businessId : undefined);
|
|
|
+
|
|
|
+ const body: AddCommonCommentBody = {
|
|
|
+ userId: toInt64(params.userId ?? params.phoneId),
|
|
|
+ sourceType,
|
|
|
+ sourceId: toInt64(sourceIdRaw),
|
|
|
+ parentId,
|
|
|
+ content: String(params.commentContent ?? params.content ?? ""),
|
|
|
+ commentType: Number(params.commentType ?? 2),
|
|
|
+ merchantId: toInt64(merchantRaw),
|
|
|
+ isAnonymous: params.isAnonymous !== undefined ? Number(params.isAnonymous) : 0
|
|
|
+ };
|
|
|
+
|
|
|
+ if (params.auditReason != null && params.auditReason !== "") body.auditReason = String(params.auditReason);
|
|
|
+ if (params.auditStatus !== undefined) body.auditStatus = Number(params.auditStatus);
|
|
|
+ if (params.createdTime) body.createdTime = String(params.createdTime);
|
|
|
+ if (params.deleteFlag !== undefined) body.deleteFlag = Number(params.deleteFlag);
|
|
|
+ if (params.extInfo != null && params.extInfo !== "") body.extInfo = String(params.extInfo);
|
|
|
+ if (params.id !== undefined && params.id !== null && params.id !== "") {
|
|
|
+ const idNum = toInt64(params.id);
|
|
|
+ if (idNum !== undefined) body.id = idNum;
|
|
|
+ }
|
|
|
+ if (params.imageUrls != null && params.imageUrls !== "") body.imageUrls = String(params.imageUrls);
|
|
|
+ if (params.isShow !== undefined) body.isShow = Number(params.isShow);
|
|
|
+ if (params.likeCount !== undefined) body.likeCount = Number(params.likeCount);
|
|
|
+ if (params.replyCount !== undefined) body.replyCount = Number(params.replyCount);
|
|
|
+ if (params.updatedTime) body.updatedTime = String(params.updatedTime);
|
|
|
+
|
|
|
+ return body;
|
|
|
+}
|
|
|
+
|
|
|
+/** 商家端 commonComment/addComment,请求体字段与接口一致 */
|
|
|
+export const addComment = (data: AddCommonCommentBody) => {
|
|
|
+ const raw: Record<string, unknown> = { ...data };
|
|
|
+ return httpLogin.post(`/alienStore/commonComment/addComment`, omitUndefinedRecord(raw));
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * 发表评论/回复(兼容旧参数,内部转为 addComment)
|
|
|
- * - 评价回复:businessType=1,replyId=评价ID → sourceType=1, sourceId=replyId, parentId=0
|
|
|
- * - 动态评论:businessType=2,businessId=动态ID,replyId 有值为回复评论ID → sourceType=2, sourceId=businessId, parentId=replyId||0
|
|
|
+ * 发表评论/回复(兼容旧入参:businessId、replyId、commentContent、phoneId/userId、businessType、storeId)
|
|
|
+ * - businessType=1:评价相关,sourceType=1,sourceId 取 replyId/businessId,parentId=0
|
|
|
+ * - businessType=2:动态,sourceType=2,sourceId=动态 id,parentId=回复的评论 id 或 0
|
|
|
*/
|
|
|
export const saveComment = (params: any) => {
|
|
|
- const businessType = Number(params.businessType ?? 0);
|
|
|
- const isRating = businessType === 1;
|
|
|
- const payload = {
|
|
|
- commentContent: String(params.commentContent ?? params.content ?? ""),
|
|
|
- businessType: 2,
|
|
|
- businessId: isRating ? params.replyId : params.businessId,
|
|
|
- storeId: String(params.storeId ?? ""),
|
|
|
- phoneId: String(params.userId ?? params.phoneId ?? ""),
|
|
|
- replyId: String(params.replyId ?? ""),
|
|
|
- commentStar: "",
|
|
|
- multipartRequest: ""
|
|
|
- };
|
|
|
- return addComment(payload);
|
|
|
+ return addComment(buildSaveCommentBody(params));
|
|
|
};
|
|
|
|
|
|
// 评价-------------------------------------------------------------------------------------
|
|
|
-export const addComment2 = (data: {
|
|
|
- sourceType: number; // 1-评价的评论 2-动态等
|
|
|
- sourceId: string | number; // 评价ID或动态ID
|
|
|
- userId: string;
|
|
|
- parentId: number; // 0-根评论
|
|
|
- content: string;
|
|
|
- commentType: number; // 2-商户评论
|
|
|
- merchantId: string;
|
|
|
- isAnonymous?: number;
|
|
|
-}) => {
|
|
|
- return httpLogin.post(`/alienStore/commonComment/addComment`, {
|
|
|
- ...data,
|
|
|
- isAnonymous: data.isAnonymous ?? 0
|
|
|
- });
|
|
|
-};
|
|
|
-export const saveComment2 = (params: any) => {
|
|
|
- const businessType = Number(params.businessType ?? 0);
|
|
|
- const isRating = businessType === 1;
|
|
|
- const payload = {
|
|
|
- sourceType: isRating ? 1 : 2,
|
|
|
- sourceId: isRating ? params.replyId : params.businessId,
|
|
|
- userId: String(params.userId ?? params.phoneId ?? ""),
|
|
|
- parentId: isRating ? 0 : Number(params.replyId || 0),
|
|
|
- content: String(params.commentContent ?? params.content ?? ""),
|
|
|
- commentType: 2,
|
|
|
- merchantId: String(params.merchantId ?? params.storeId ?? params.businessId ?? ""),
|
|
|
- isAnonymous: 0
|
|
|
- };
|
|
|
- return addComment2(payload);
|
|
|
-};
|
|
|
-
|
|
|
-//评论列表
|
|
|
-export const commentList = (params: any) => {
|
|
|
- return httpLogin.get(`/alienStore/storeComment/getList`, params);
|
|
|
+export const addComment2 = (data: AddCommonCommentBody) => addComment(data);
|
|
|
+
|
|
|
+export const saveComment2 = (params: any) => saveComment(params);
|
|
|
+
|
|
|
+/** 评论列表查询(getListBySourceType) */
|
|
|
+export interface CommentListParams {
|
|
|
+ pageNum: number;
|
|
|
+ pageSize: number;
|
|
|
+ /** 来源 id,如动态 id */
|
|
|
+ sourceId: number | string;
|
|
|
+ /** 1-评价 2-动态 3-打卡 4-二手商品 */
|
|
|
+ sourceType: number;
|
|
|
+ /** 可选,评论发布者/当前用户 id */
|
|
|
+ userId?: number;
|
|
|
+}
|
|
|
+
|
|
|
+export const commentList = (params: CommentListParams) => {
|
|
|
+ return httpLogin.get(`/alienStore/commonComment/getListBySourceType`, params);
|
|
|
};
|
|
|
|
|
|
//我的动态
|