修复:优化解绑优惠券和余额历史
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<a-space>
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索优惠券名称或编码"
|
||||
placeholder="搜索优惠券名称"
|
||||
style="width: 260px"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
@@ -115,10 +115,6 @@
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="优惠券编码" name="couponCode">
|
||||
<a-input v-model:value="formState.couponCode" placeholder="请输入优惠券编码" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="优惠券名称" name="couponName">
|
||||
<a-input v-model:value="formState.couponName" placeholder="请输入优惠券名称" />
|
||||
</a-form-item>
|
||||
@@ -212,7 +208,6 @@
|
||||
@cancel="viewModalVisible = false"
|
||||
>
|
||||
<a-descriptions bordered :column="1" size="small">
|
||||
<a-descriptions-item label="优惠券编码">{{ currentCoupon?.couponCode || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠券名称">{{ currentCoupon?.couponName || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="所属店铺">{{ currentCoupon?.shopName || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="优惠券类型">{{ currentCoupon?.couponType === 1 ? '折扣券' : '满减券' }}</a-descriptions-item>
|
||||
@@ -368,7 +363,6 @@ const distributeFormState = reactive({
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
couponCode: [{ required: true, message: '请输入优惠券编码', trigger: 'blur' }],
|
||||
couponName: [{ required: true, message: '请输入优惠券名称', trigger: 'blur' }],
|
||||
couponType: [{ required: true, message: '请选择优惠券类型', trigger: 'change' }],
|
||||
couponScene: [{ required: true, message: '请选择优惠场景', trigger: 'change' }],
|
||||
@@ -385,7 +379,6 @@ const distributeFormRules = {
|
||||
} as any
|
||||
|
||||
const columns = [
|
||||
{ title: '优惠券编码', dataIndex: 'couponCode', key: 'couponCode' },
|
||||
{ title: '优惠券名称', dataIndex: 'couponName', key: 'couponName' },
|
||||
{ title: '所属店铺', key: 'shop', width: 140 },
|
||||
{ title: '类型', key: 'couponType', width: 100 },
|
||||
@@ -530,8 +523,7 @@ const fetchCoupons = async () => {
|
||||
const list = Array.isArray(coupons) ? coupons : []
|
||||
const keyword = searchText.value.trim()
|
||||
couponList.value = keyword
|
||||
? list.filter(item =>
|
||||
(item.couponName || '').includes(keyword) || (item.couponCode || '').includes(keyword))
|
||||
? list.filter(item => (item.couponName || '').includes(keyword))
|
||||
: list
|
||||
pagination.total = couponList.value.length
|
||||
} catch (error) {
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
v-if="canShowUnbind(record)"
|
||||
title="确定要解绑该用户与当前店铺的关系吗?"
|
||||
:title="getUnbindConfirmText(record)"
|
||||
@confirm="handleUnbind(record)"
|
||||
>
|
||||
<a-button type="link" size="small">
|
||||
@@ -710,6 +710,13 @@ const canShowUnbind = (record: Partial<UserVO> | Record<string, any>) => {
|
||||
return record.type !== 4
|
||||
}
|
||||
|
||||
const getUnbindConfirmText = (record: Partial<UserVO> | Record<string, any>) => {
|
||||
if (currentUserType.value === 2 && record.type === 3) {
|
||||
return '确定要解绑该美甲师与当前店铺的关系吗?解绑后该账号会同步降级为普通用户。'
|
||||
}
|
||||
return '确定要解绑该用户与当前店铺的关系吗?'
|
||||
}
|
||||
|
||||
const getSceneText = (scene?: string) => {
|
||||
const map: Record<string, string> = {
|
||||
RECHARGE: '充值',
|
||||
@@ -1097,7 +1104,11 @@ const handleUnbind = async (record: any) => {
|
||||
}
|
||||
userList.value = userList.value.filter(user => user.id !== record.id)
|
||||
pagination.total = Math.max(0, Number(pagination.total || 0) - 1)
|
||||
message.success('已解绑当前店铺下的用户')
|
||||
if (currentUserType.value === 2 && record.type === 3) {
|
||||
message.success('已解绑当前店铺下的美甲师,并已同步降级为普通用户')
|
||||
} else {
|
||||
message.success('已解绑当前店铺下的用户')
|
||||
}
|
||||
await fetchUserList()
|
||||
} catch (error) {
|
||||
console.error('解绑用户失败:', error)
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ public class AdminUserController {
|
||||
if (Integer.valueOf(4).equals(targetUser.getType())) {
|
||||
throw new RuntimeException("管理员账号不允许解绑");
|
||||
}
|
||||
boolean success = userService.unbindUserInShop(id, currentUser.getShopId());
|
||||
boolean success = userService.unbindUserInShopWithOperator(id, currentUser.getShopId(), currentUser.getType());
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ public class UserController {
|
||||
if (Integer.valueOf(4).equals(targetUser.getType())) {
|
||||
throw new RuntimeException("管理员账号不允许解绑");
|
||||
}
|
||||
boolean success = userService.unbindUserInShop(id, currentUser.getShopId());
|
||||
boolean success = userService.unbindUserInShopWithOperator(id, currentUser.getShopId(), currentUser.getType());
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -1,9 +1,10 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -16,9 +17,11 @@ import java.time.LocalDateTime;
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_balance_change_detail")
|
||||
public class BalanceChangeDetailDO extends BaseEntity {
|
||||
public class BalanceChangeDetailDO {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 关联用户表主键
|
||||
|
||||
@@ -80,6 +80,8 @@ public interface UserService extends IService<UserDO> {
|
||||
boolean deleteUserInShop(Long id, Long shopId);
|
||||
|
||||
boolean unbindUserInShop(Long id, Long shopId);
|
||||
|
||||
boolean unbindUserInShopWithOperator(Long id, Long shopId, Integer operatorType);
|
||||
|
||||
boolean updateUserAvatar(Long userId, String avatarUrl);
|
||||
|
||||
|
||||
+31
-2
@@ -25,6 +25,7 @@ import com.xiaowang.yuminailcore.vo.UserCouponVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -32,6 +33,7 @@ import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -65,7 +67,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
public Long createCoupon(CouponDTO couponDTO, Long shopId) {
|
||||
// 创建优惠券
|
||||
CouponDO couponDO = new CouponDO();
|
||||
couponDO.setCouponCode(couponDTO.getCouponCode());
|
||||
couponDO.setCouponCode(resolveCouponCodeForCreate(couponDTO.getCouponCode()));
|
||||
couponDO.setCouponName(couponDTO.getCouponName());
|
||||
couponDO.setCouponType(couponDTO.getCouponType());
|
||||
couponDO.setDiscountValue(couponDTO.getDiscountValue());
|
||||
@@ -97,7 +99,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
return false;
|
||||
}
|
||||
|
||||
couponDO.setCouponCode(couponDTO.getCouponCode());
|
||||
couponDO.setCouponCode(resolveCouponCodeForUpdate(couponDO.getCouponCode(), couponDTO.getCouponCode()));
|
||||
couponDO.setCouponName(couponDTO.getCouponName());
|
||||
couponDO.setCouponType(couponDTO.getCouponType());
|
||||
couponDO.setDiscountValue(couponDTO.getDiscountValue());
|
||||
@@ -587,6 +589,33 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
return String.format("VIP_AUTO_SHOP_%d_%s", shopId, codeSuffix);
|
||||
}
|
||||
|
||||
private String resolveCouponCodeForCreate(String requestedCode) {
|
||||
if (StringUtils.hasText(requestedCode)) {
|
||||
return requestedCode.trim();
|
||||
}
|
||||
return generateUniqueManualCouponCode();
|
||||
}
|
||||
|
||||
private String resolveCouponCodeForUpdate(String existingCode, String requestedCode) {
|
||||
if (StringUtils.hasText(requestedCode)) {
|
||||
return requestedCode.trim();
|
||||
}
|
||||
if (StringUtils.hasText(existingCode)) {
|
||||
return existingCode.trim();
|
||||
}
|
||||
return generateUniqueManualCouponCode();
|
||||
}
|
||||
|
||||
private String generateUniqueManualCouponCode() {
|
||||
for (int attempt = 0; attempt < 10; attempt++) {
|
||||
String candidate = "CPN_" + UUID.randomUUID().toString().replace("-", "").substring(0, 12).toUpperCase();
|
||||
if (lambdaQuery().eq(CouponDO::getCouponCode, candidate).count() == 0) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("生成优惠券编码失败,请稍后重试");
|
||||
}
|
||||
|
||||
private CouponVO convertToCouponVO(CouponDO couponDO) {
|
||||
CouponVO couponVO = new CouponVO();
|
||||
couponVO.setId(couponDO.getId());
|
||||
|
||||
+23
-1
@@ -1105,11 +1105,33 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean unbindUserInShop(Long id, Long shopId) {
|
||||
return unbindUserInShopWithOperator(id, shopId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean unbindUserInShopWithOperator(Long id, Long shopId, Integer operatorType) {
|
||||
Long normalizedShopId = normalizeShopId(shopId);
|
||||
if (normalizedShopId == null) {
|
||||
throw new RuntimeException("当前操作缺少店铺上下文");
|
||||
}
|
||||
return userShopBindingSupport.updateBindingStatus(id, normalizedShopId, 0);
|
||||
UserDO userDO = userMapper.selectById(id);
|
||||
if (userDO == null || Integer.valueOf(1).equals(userDO.getIsDelete())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean success = userShopBindingSupport.updateBindingStatus(id, normalizedShopId, 0);
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Integer.valueOf(2).equals(operatorType) && Integer.valueOf(3).equals(userDO.getType())) {
|
||||
userDO.setType(0);
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
userMapper.updateById(userDO);
|
||||
syncDefaultPermissions(userDO.getId(), userDO.getType());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
# 2026-03-27 解绑降级、优惠券编码隐藏与余额流水修复
|
||||
|
||||
## 本轮处理
|
||||
|
||||
- 店长解绑美甲师时,除了将当前店铺绑定状态改为禁用外,还会把该账号同步降级为普通用户。
|
||||
- 后台优惠券管理页面不再展示优惠券编码,搜索也改为仅按优惠券名称检索。
|
||||
- 修复后台用户余额流水查询报错:`t_balance_change_detail` 实体不再错误继承带有 `create_time/update_time` 的通用基类,兼容当前表结构。
|
||||
|
||||
## 具体变更
|
||||
|
||||
### 1. 店长解绑美甲师后自动降级
|
||||
|
||||
- 更新 [`UserServiceImpl.java`](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/UserServiceImpl.java)
|
||||
- 新增按操作者类型处理解绑的服务方法:
|
||||
- 店长解绑美甲师:解绑当前店铺后,将目标账号 `type` 从 `3` 改为 `0`
|
||||
- 同步触发默认权限收敛,移除原美甲师后台权限
|
||||
- 更新 [`AdminUserController.java`](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/AdminUserController.java) 与 [`UserController.java`](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/controller/UserController.java),统一走新语义。
|
||||
|
||||
### 2. 后台优惠券管理不再展示编码
|
||||
|
||||
- 更新 [`CouponsView.vue`](/E:/code/xiaowang/Frontend/src/views/admin/CouponsView.vue)
|
||||
- 移除:
|
||||
- 列表中的“优惠券编码”列
|
||||
- 详情弹窗中的“优惠券编码”展示
|
||||
- 搜索框中的“按编码搜索”提示与逻辑
|
||||
- 同时补充后端兜底:
|
||||
- 更新 [`CouponServiceImpl.java`](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/CouponServiceImpl.java)
|
||||
- 新建优惠券若前端未传编码,则后端自动生成唯一编码
|
||||
- 编辑优惠券若前端未传编码,则保留原有编码
|
||||
|
||||
### 3. 用户余额流水查询报错修复
|
||||
|
||||
- 更新 [`BalanceChangeDetailDO.java`](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/entity/BalanceChangeDetailDO.java)
|
||||
- 原问题:
|
||||
- `BalanceChangeDetailDO` 继承了 [`BaseEntity.java`](/E:/code/xiaowang/YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/entity/BaseEntity.java)
|
||||
- 该基类会映射 `create_time`、`update_time`
|
||||
- 但 `t_balance_change_detail` 当前结构只有 `change_time`,没有这两个字段
|
||||
- 修复后:
|
||||
- 余额流水实体改为只映射该表真实存在的字段
|
||||
- 后台“余额/VIP 管理”中的余额流水查询可直接兼容现库
|
||||
|
||||
## SQL 说明
|
||||
|
||||
- 本轮未新增 SQL。
|
||||
- 余额流水问题通过代码兼容当前表结构修复,不要求你手工改库。
|
||||
|
||||
## 验证建议
|
||||
|
||||
1. 店长解绑一个美甲师后,刷新用户列表,目标账号应从当前店铺消失,并且再次进入该账号详情时应显示为普通用户。
|
||||
2. 打开后台优惠券管理页,列表和详情不再展示编码,创建/编辑优惠券仍可正常保存。
|
||||
3. 在后台用户管理中打开任意用户的“余额 / VIP 管理”,余额流水列表应能正常加载,不再出现 `Unknown column 'create_time'`。
|
||||
Reference in New Issue
Block a user