会员 mainShopId

This commit is contained in:
2025-09-23 13:43:27 +08:00
parent eb31057b3e
commit fc2757ff17
20 changed files with 599 additions and 482 deletions

View File

@@ -2,11 +2,10 @@ package com.czg.controller.admin;
import com.czg.account.dto.shopuser.*; import com.czg.account.dto.shopuser.*;
import com.czg.account.entity.ShopUser; import com.czg.account.entity.ShopUser;
import com.czg.account.service.AShopUserService;
import com.czg.account.service.ShopUserFlowService; import com.czg.account.service.ShopUserFlowService;
import com.czg.account.service.ShopUserService;
import com.czg.account.vo.ShopUserFlowVO; import com.czg.account.vo.ShopUserFlowVO;
import com.czg.annotation.SaAdminCheckPermission; import com.czg.annotation.SaAdminCheckPermission;
import com.czg.annotation.SaStaffCheckPermission;
import com.czg.enums.ShopUserFlowBizEnum; import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
@@ -29,7 +28,7 @@ import java.math.BigDecimal;
public class ShopUserController { public class ShopUserController {
@Resource @Resource
private ShopUserService shopUserService; private AShopUserService shopUserService;
@Resource @Resource
private ShopUserFlowService shopUserFlowService; private ShopUserFlowService shopUserFlowService;
@@ -43,7 +42,7 @@ public class ShopUserController {
@GetMapping("/summary") @GetMapping("/summary")
// @SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi") // @SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi")
public CzgResult<ShopUserSummaryDTO> summary(Integer isVip) { public CzgResult<ShopUserSummaryDTO> summary(Integer isVip) {
return CzgResult.success(shopUserService.getSummary(StpKit.USER.getUsableShopId(), isVip)); return CzgResult.success(shopUserService.getSummary(StpKit.USER.getHeadShopIdBySession(), isVip));
} }
/** /**
@@ -67,7 +66,7 @@ public class ShopUserController {
@GetMapping("/flow") @GetMapping("/flow")
// @SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi") // @SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi")
public CzgResult<Page<ShopUserFlowVO>> flow(Integer userId, String bizCode, String startTime, String endTime) { public CzgResult<Page<ShopUserFlowVO>> flow(Integer userId, String bizCode, String startTime, String endTime) {
return CzgResult.success(shopUserFlowService.pageInfo(StpKit.USER.getUsableShopId(), userId, bizCode, startTime, endTime)); return CzgResult.success(shopUserFlowService.pageInfo(StpKit.USER.getHeadShopIdBySession(), userId, bizCode, startTime, endTime));
} }
/** /**
@@ -83,7 +82,7 @@ public class ShopUserController {
@GetMapping("/flow/download") @GetMapping("/flow/download")
// @SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi") // @SaStaffCheckPermission("yun_xu_guan_li_hui_yuan_xin_xi")
public void flowDownload(Integer userId, String bizCode, String startTime, String endTime, HttpServletResponse response) throws IOException { public void flowDownload(Integer userId, String bizCode, String startTime, String endTime, HttpServletResponse response) throws IOException {
shopUserFlowService.flowDownload(StpKit.USER.getUsableShopId(), userId, bizCode, startTime, endTime, response); shopUserFlowService.flowDownload(StpKit.USER.getHeadShopIdBySession(), userId, bizCode, startTime, endTime, response);
} }
/** /**
@@ -125,7 +124,7 @@ public class ShopUserController {
@SaAdminCheckPermission(value = "shopUser:add", name = "店铺用户添加") @SaAdminCheckPermission(value = "shopUser:add", name = "店铺用户添加")
@PostMapping @PostMapping
public CzgResult<Boolean> add(@RequestBody @Validated ShopUserAddDTO shopUserAddDTO) { public CzgResult<Boolean> add(@RequestBody @Validated ShopUserAddDTO shopUserAddDTO) {
return CzgResult.success(shopUserService.add(StpKit.USER.getUsableShopId(), shopUserAddDTO)); return CzgResult.success(shopUserService.add(StpKit.USER.getHeadShopIdBySession(), shopUserAddDTO));
} }
/** /**
@@ -137,7 +136,7 @@ public class ShopUserController {
@SaAdminCheckPermission(value = "shopUser:edit", name = "店铺用户修改") @SaAdminCheckPermission(value = "shopUser:edit", name = "店铺用户修改")
@PutMapping @PutMapping
public CzgResult<Boolean> edit(@RequestBody @Validated ShopUserEditDTO shopUserEditDTO) { public CzgResult<Boolean> edit(@RequestBody @Validated ShopUserEditDTO shopUserEditDTO) {
return CzgResult.success(shopUserService.updateInfo(StpKit.USER.getUsableShopId(), shopUserEditDTO)); return CzgResult.success(shopUserService.updateInfo(StpKit.USER.getHeadShopIdBySession(), shopUserEditDTO));
} }
/** /**
@@ -150,7 +149,7 @@ public class ShopUserController {
@PutMapping("/money") @PutMapping("/money")
public CzgResult<Boolean> editMoney(@RequestBody @Validated ShopUserMoneyEditDTO shopUserMoneyEditDTO) { public CzgResult<Boolean> editMoney(@RequestBody @Validated ShopUserMoneyEditDTO shopUserMoneyEditDTO) {
shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.ADMIN_IN); shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.ADMIN_IN);
return CzgResult.success(shopUserService.updateMoney(StpKit.USER.getUsableShopId(), shopUserMoneyEditDTO) > 0L); return CzgResult.success(shopUserService.updateMoney(StpKit.USER.getHeadShopIdBySession(), shopUserMoneyEditDTO) > 0L);
} }
} }

View File

@@ -7,9 +7,8 @@ import com.czg.account.entity.MemberPointsLog;
import com.czg.account.entity.ShopUser; import com.czg.account.entity.ShopUser;
import com.czg.account.entity.ShopUserFlow; import com.czg.account.entity.ShopUserFlow;
import com.czg.account.service.MemberPointsLogService; import com.czg.account.service.MemberPointsLogService;
import com.czg.account.service.PointsExchangeRecordService;
import com.czg.account.service.ShopUserFlowService; import com.czg.account.service.ShopUserFlowService;
import com.czg.account.service.ShopUserService; import com.czg.account.service.UShopUserService;
import com.czg.annotation.Debounce; import com.czg.annotation.Debounce;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
@@ -29,12 +28,10 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/user/shopUser") @RequestMapping("/user/shopUser")
public class UShopUserController { public class UShopUserController {
@Resource @Resource
private ShopUserService shopUserService; private UShopUserService shopUserService;
@Resource @Resource
private ShopUserFlowService shopUserFlowService; private ShopUserFlowService shopUserFlowService;
@Resource @Resource
private PointsExchangeRecordService pointsExchangeRecordService;
@Resource
private MemberPointsLogService memberPointsLogService; private MemberPointsLogService memberPointsLogService;
/** /**
@@ -45,7 +42,7 @@ public class UShopUserController {
*/ */
@GetMapping @GetMapping
public CzgResult<ShopUserDetailDTO> get(Long shopId) { public CzgResult<ShopUserDetailDTO> get(Long shopId) {
return CzgResult.success(shopUserService.getInfo(shopId == null ? StpKit.USER.getUsableShopId() : shopId, StpKit.USER.getLoginIdAsLong())); return CzgResult.success(shopUserService.getInfo(shopId == null ? StpKit.USER.getShopId() : shopId, StpKit.USER.getLoginIdAsLong()));
} }
/** /**
@@ -65,7 +62,7 @@ public class UShopUserController {
*/ */
@GetMapping("/code") @GetMapping("/code")
public CzgResult<String> code(Long shopId) { public CzgResult<String> code(Long shopId) {
return shopUserService.getCode(StpKit.USER.getLoginIdAsLong(), shopId == null ? StpKit.USER.getUsableShopId() : shopId); return shopUserService.getCode(StpKit.USER.getLoginIdAsLong(), shopId == null ? StpKit.USER.getShopId() : shopId);
} }
/** /**
@@ -76,7 +73,7 @@ public class UShopUserController {
@PostMapping @PostMapping
@Debounce("#shopUserAddDTO.phone") @Debounce("#shopUserAddDTO.phone")
public CzgResult<Boolean> join(@RequestBody @Validated ShopUserAddDTO shopUserAddDTO) { public CzgResult<Boolean> join(@RequestBody @Validated ShopUserAddDTO shopUserAddDTO) {
return CzgResult.success(shopUserService.join(StpKit.USER.getUsableShopId(), StpKit.USER.getLoginIdAsLong(), shopUserAddDTO)); return CzgResult.success(shopUserService.join(StpKit.USER.getShopId(), StpKit.USER.getLoginIdAsLong(), shopUserAddDTO));
} }
@@ -107,7 +104,7 @@ public class UShopUserController {
*/ */
@GetMapping("/pointsRecord") @GetMapping("/pointsRecord")
public CzgResult<Page<MemberPointsLog>> getPointsRecord() { public CzgResult<Page<MemberPointsLog>> getPointsRecord() {
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getShopId()).eq(ShopUser::getUserId, StpKit.USER.getLoginIdAsLong())); ShopUser shopUser = shopUserService.getShopUserInfo(StpKit.USER.getShopId(), StpKit.USER.getLoginIdAsLong());
return CzgResult.success(memberPointsLogService.page(PageUtil.buildPage(), new QueryWrapper().eq(MemberPointsLog::getShopId, StpKit.USER.getShopId()) return CzgResult.success(memberPointsLogService.page(PageUtil.buildPage(), new QueryWrapper().eq(MemberPointsLog::getShopId, StpKit.USER.getShopId())
.eq(MemberPointsLog::getShopUserId, shopUser.getId()).orderBy(MemberPointsLog::getId, false))); .eq(MemberPointsLog::getShopUserId, shopUser.getId()).orderBy(MemberPointsLog::getId, false)));
} }
@@ -119,13 +116,8 @@ public class UShopUserController {
*/ */
@GetMapping("/pointsRecord/detail") @GetMapping("/pointsRecord/detail")
public CzgResult<MemberPointsLog> getPointsRecordDetail(@RequestParam Long id) { public CzgResult<MemberPointsLog> getPointsRecordDetail(@RequestParam Long id) {
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getShopId()).eq(ShopUser::getUserId, StpKit.USER.getLoginIdAsLong())); ShopUser shopUser = shopUserService.getShopUserInfo(StpKit.USER.getShopId(), StpKit.USER.getLoginIdAsLong());
return CzgResult.success(memberPointsLogService.getOne(new QueryWrapper().eq(MemberPointsLog::getShopId, StpKit.USER.getShopId()) return CzgResult.success(memberPointsLogService.getOne(new QueryWrapper().eq(MemberPointsLog::getShopId, StpKit.USER.getShopId())
.eq(MemberPointsLog::getShopUserId, shopUser.getId()).eq(MemberPointsLog::getId, id))); .eq(MemberPointsLog::getShopUserId, shopUser.getId()).eq(MemberPointsLog::getId, id)));
} }
public static void main(String[] args) {
}
} }

View File

@@ -69,14 +69,4 @@ public class UserAuthorizationController {
"shopName", shopInfo.getShopName() "shopName", shopInfo.getShopName()
)); ));
} }
/**
* 小程序登录
* @return 登录信息
*/
@PostMapping("/test")
public CzgResult<String> login(@RequestParam long id) {
StpKit.USER.login(id, "2342", null, "", MyStpLogic.LoginType.USER, false, "");
return CzgResult.success(StpKit.USER.getTokenValue());
}
} }

View File

@@ -2,6 +2,8 @@ package com.czg.controller.admin;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import com.czg.account.entity.ShopInfo;
import com.czg.account.service.ShopInfoService;
import com.czg.annotation.SaStaffCheckPermission; import com.czg.annotation.SaStaffCheckPermission;
import com.czg.config.RabbitPublisher; import com.czg.config.RabbitPublisher;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
@@ -49,6 +51,8 @@ public class ProductController {
private ShopSyncService shopSyncService; private ShopSyncService shopSyncService;
@Resource @Resource
private UProductService uProductService; private UProductService uProductService;
@Resource
private ShopInfoService shopInfoService;
/** /**
* 商品-分页 * 商品-分页
@@ -104,7 +108,7 @@ public class ProductController {
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId); dto.setShopId(shopId);
productService.addProduct(dto); productService.addProduct(dto);
asyncToBranchShop(dto.getId()); asyncProductToShop(dto.getId());
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}); });
@@ -133,7 +137,7 @@ public class ProductController {
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId); dto.setShopId(shopId);
productService.updateProduct(dto); productService.updateProduct(dto);
asyncToBranchShop(dto.getId()); asyncProductToShop(dto.getId());
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}); });
@@ -168,7 +172,7 @@ public class ProductController {
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
Long shopId = StpKit.USER.getShopId(0L); Long shopId = StpKit.USER.getShopId(0L);
productService.deleteProduct(shopId, id); productService.deleteProduct(shopId, id);
asyncToBranchShop(id); asyncProductToShop(id);
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId)); rabbitPublisher.sendProductInfoChangeMsg(Convert.toStr(shopId));
}); });
@@ -217,7 +221,7 @@ public class ProductController {
//@SaAdminCheckPermission("product:bind") //@SaAdminCheckPermission("product:bind")
public CzgResult<Void> bindCons(@RequestBody @Validated({DefaultGroup.class}) ProdConsBindDTO param) { public CzgResult<Void> bindCons(@RequestBody @Validated({DefaultGroup.class}) ProdConsBindDTO param) {
prodConsRelationService.saveProdConsRelation(param); prodConsRelationService.saveProdConsRelation(param);
asyncToBranchShop2(param.getId()); asyncConsProToShop(param.getId());
return CzgResult.success(); return CzgResult.success();
} }
@@ -229,7 +233,7 @@ public class ProductController {
//@SaAdminCheckPermission("product:update") //@SaAdminCheckPermission("product:update")
public CzgResult<Void> refundToStock(@RequestBody @Validated({DefaultGroup.class}) ProdRefundToStockParam param) { public CzgResult<Void> refundToStock(@RequestBody @Validated({DefaultGroup.class}) ProdRefundToStockParam param) {
productService.refundToStock(param); productService.refundToStock(param);
asyncToBranchShop(param.getId()); asyncProductToShop(param.getId());
return CzgResult.success(); return CzgResult.success();
} }
@@ -293,36 +297,34 @@ public class ProductController {
//@SaAdminCheckPermission("product:sync") //@SaAdminCheckPermission("product:sync")
public CzgResult<Void> sync() { public CzgResult<Void> sync() {
long shopId = StpKit.USER.getShopId(0L); long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong(); ShopInfo shopInfo = shopInfoService.getById(shopId);
boolean isEnableSync = StpKit.USER.isEnableSync(shopId); if (shopInfo == null) {
long headShopId = StpKit.USER.getHeadShopId(); throw new CzgException("店铺不存在");
if (!isEnableSync) {
throw new CzgException("主店未开启商品资料同步功能");
} }
if (shopId == headShopId) { AssertUtil.isNotEqual(shopInfo.getIsEnableProdSync(), 1, "主店未开启商品资料同步功能");
if (shopInfo.getMainId() == null || shopId == shopInfo.getMainId()) {
throw new CzgException("不存在主子店铺关系,无需同步商品信息"); throw new CzgException("不存在主子店铺关系,无需同步商品信息");
} }
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
shopSyncService.sync(headShopId, shopId, sysUserId); shopSyncService.sync(shopInfo.getMainId(), shopId, shopId);
}); });
CzgResult<Void> ret = CzgResult.success(); CzgResult<Void> ret = CzgResult.success();
ret.setMsg("操作成功,数据正在后台同步中..."); ret.setMsg("操作成功,数据正在后台同步中...");
return ret; return ret;
} }
private void asyncToBranchShop(Long id) { private void asyncProductToShop(Long id) {
long shopId = StpKit.USER.getShopId(0L); long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
shopSyncService.syncProductBySourceShop(shopId, id, sysUserId); shopSyncService.syncProductBySourceShop(shopId, id, shopId);
}); });
} }
private void asyncToBranchShop2(Long id) { private void asyncConsProToShop(Long id) {
long shopId = StpKit.USER.getShopId(0L); long shopId = StpKit.USER.getShopId(0L);
long sysUserId = StpKit.USER.getLoginIdAsLong();
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
shopSyncService.syncConsProBySourceShop(shopId, id, sysUserId); shopSyncService.syncConsProBySourceShop(shopId, id, shopId);
}); });
} }
} }

View File

@@ -80,7 +80,7 @@ public class MyStpLogic {
logic.createLoginSession(id); logic.createLoginSession(id);
session = logic.getSession(); session = logic.getSession();
} }
Object parentId1 = session.get("headId"); Object parentId1 = session.get("headShopId");
if (!isMain && parentId1 == null) { if (!isMain && parentId1 == null) {
session.set("headId", headId); session.set("headId", headId);
} }
@@ -95,7 +95,7 @@ public class MyStpLogic {
* @param loginType 登录类型枚举 * @param loginType 登录类型枚举
* @param isAdmin 是否为管理员账号 * @param isAdmin 是否为管理员账号
*/ */
public void login(Long id, String account, Long shopId, String shopName, LoginType loginType, boolean isAdmin, String platForm) { public void login(Long id, String account, Long shopId, Long headShopId, String shopName, LoginType loginType, boolean isAdmin, String platForm) {
StpLogic logic = getLogic(); StpLogic logic = getLogic();
logic.login(id); logic.login(id);
if (loginType.equals(LoginType.MANAGER) && shopId == null) { if (loginType.equals(LoginType.MANAGER) && shopId == null) {
@@ -107,6 +107,9 @@ public class MyStpLogic {
if (shopId != null) { if (shopId != null) {
session.set("shopId", shopId); session.set("shopId", shopId);
} }
if (headShopId != null) {
session.set("headShopId", headShopId);
}
if (shopName != null) { if (shopName != null) {
session.set("shopName", shopName); session.set("shopName", shopName);
} }
@@ -153,7 +156,7 @@ public class MyStpLogic {
* @return id * @return id
*/ */
public Long getHeadId() { public Long getHeadId() {
Object headId = getLogic().getSession().get("headId"); Object headId = getLogic().getSession().get("headShopId");
return headId == null ? null : Long.parseLong(headId.toString()); return headId == null ? null : Long.parseLong(headId.toString());
} }
@@ -214,79 +217,27 @@ public class MyStpLogic {
} }
/** /**
* 获取适用的店铺id主分店模式使用若全部开启同步返回主店id。若未开启同步则返回分店id * 获取主店Id 非主店铺则获取当前shopId
* *
* @return 主店id * @return 主店id
*/ */
public Long getUsableShopId() { public Long getHeadShopIdBySession() {
Long shopId = getShopId(0L); SaSession session = getLogic().getSession();
Long mainId = DbChain.table("tb_shop_config").select("main_id").where("id = ? and is_enable_prod_sync = 1 and is_enable_vip_sync = 1 and is_enable_cons_sync = 1", shopId).objAs(Long.class); Object headId = session.get("headShopId");
if (mainId != null) { return headId != null ? Long.parseLong(headId.toString()) : session.get("shopId") instanceof Long l ? l : null;
return mainId;
}
return shopId;
} }
/** /**
* 获取主店id * 是否为管理端登录
* *
* @return 主店id * @return 布尔值
*/ */
public Long getHeadShopId() { public boolean isManager() {
return getHeadShopId(getShopId(0L));
}
/**
* 获取主店id
*
* @param shopId 店铺id
* @return 主店id
*/
public Long getHeadShopId(Long shopId) {
Long mainId = DbChain.table("tb_shop_config").select("main_id").where("id = ?", shopId).objAs(Long.class);
if (mainId != null) {
return mainId;
}
return shopId;
}
/**
* 是否启用同步功能
*
* @param shopId 店铺id
* @return 主店id
*/
public boolean isEnableSync(Long shopId) {
Integer isEnableProdSync = DbChain.table("tb_shop_config").select("is_enable_prod_sync").where("id = ?", shopId).objAs(Integer.class);
if (isEnableProdSync == null) {
return false;
}
return isEnableProdSync == 1;
}
/**
* 校验是否为管理端登录
*/
public void checkManager() {
StpLogic logic = getLogic(); StpLogic logic = getLogic();
logic.checkLogin();
Object object = logic.getSession().get("isManager"); Object object = logic.getSession().get("isManager");
if (object instanceof Boolean t && !t) { return object instanceof Boolean t && t;
throw new NotPermissionException("权限不足");
}
} }
/**
* 校验是否为小程序登录
*/
public void checkMiniUser() {
StpLogic logic = getLogic();
logic.checkLogin();
Object object = logic.getSession().get("isManager");
if (object instanceof Boolean t && t) {
throw new NotPermissionException("权限不足");
}
}
/** /**
* 是否为管理端登录 * 是否为管理端登录
@@ -303,16 +254,6 @@ public class MyStpLogic {
return object instanceof LoginType t && t.equals(LoginType.STAFF); return object instanceof LoginType t && t.equals(LoginType.STAFF);
} }
/**
* 是否为管理端登录
*
* @return 布尔值
*/
public boolean isManager() {
StpLogic logic = getLogic();
Object object = logic.getSession().get("isManager");
return object instanceof Boolean t && t;
}
/** /**
* 是否为管理员 * 是否为管理员

View File

@@ -61,9 +61,14 @@ public class ShopUser implements Serializable {
private Integer sex; private Integer sex;
/** /**
* 店铺Id * 店铺Id
*/ */
private Long shopId; private Long mainShopId;
/**
* 来源店铺Id
*/
private Long sourceShopId;
/** /**
* 用户Id * 用户Id

View File

@@ -0,0 +1,28 @@
package com.czg.account.service;
import com.czg.account.dto.shopuser.*;
import com.czg.account.entity.ShopUser;
import com.czg.resp.CzgResult;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import java.math.BigDecimal;
/**
* 商户储值会员 服务层。
*
* @author Administrator
* @since 2025-02-08
*/
public interface AShopUserService {
Page<ShopUserDTO> getPage(String key, Integer isVip, BigDecimal amount);
Boolean add(Long shopId, ShopUserAddDTO shopUserAddDTO);
Boolean updateInfo(Long shopId, ShopUserEditDTO shopUserEditDTO);
ShopUserSummaryDTO getSummary(Long shopId, Integer isVip);
ShopUser getDetail(Integer id, Integer userId);
}

View File

@@ -27,4 +27,6 @@ public interface ShopInfoService extends IService<ShopInfo> {
Page<ShopInfoSubVO> getSubList(String lat, String lng, float distance); Page<ShopInfoSubVO> getSubList(String lat, String lng, float distance);
List<ShopBranchSelectDTO> findShopBranch(Long shopId); List<ShopBranchSelectDTO> findShopBranch(Long shopId);
Long getMainIdByShopId(Long shopId);
} }

View File

@@ -16,31 +16,11 @@ import java.math.BigDecimal;
*/ */
public interface ShopUserService extends IService<ShopUser> { public interface ShopUserService extends IService<ShopUser> {
Page<ShopUserDTO> getPage(String key, Integer isVip, BigDecimal amount);
Boolean updateInfo(Long shopId, ShopUserEditDTO shopUserEditDTO);
/** /**
* 返回流水Id * 返回流水Id
*/ */
Long updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO); Long updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO);
ShopUserSummaryDTO getSummary(Long shopId, Integer isVip);
ShopUser getShopUserInfo(Long shopId, long userId); ShopUser getShopUserInfo(Long shopId, long userId);
Boolean add(Long shopId, ShopUserAddDTO shopUserAddDTO);
/**
* 获取小程序登录用户所有店铺会员信息
*/
Page<ShopUserVipCardDTO> vipCard(long userInfoId);
CzgResult<String> getCode(long userInfoId, long shopId);
boolean join(Long shopId, Long userId, ShopUserAddDTO shopUserAddDTO);
ShopUserDetailDTO getInfo(Long shopId, long userId);
ShopUser getDetail(Integer id, Integer userId);
} }

View File

@@ -0,0 +1,32 @@
package com.czg.account.service;
import com.czg.account.dto.shopuser.*;
import com.czg.account.entity.ShopUser;
import com.czg.resp.CzgResult;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import java.math.BigDecimal;
/**
* 商户储值会员 服务层。
*
* @author Administrator
* @since 2025-02-08
*/
public interface UShopUserService {
ShopUser getShopUserInfo(Long shopId, long userId);
/**
* 获取小程序登录用户所有店铺会员信息
*/
Page<ShopUserVipCardDTO> vipCard(long userInfoId);
CzgResult<String> getCode(long userInfoId, long shopId);
boolean join(Long shopId, Long userId, ShopUserAddDTO shopUserAddDTO);
ShopUserDetailDTO getInfo(Long shopId, long userId);
}

View File

@@ -20,11 +20,16 @@ public class AssertUtil {
/** /**
* 判断两个对象是否不相等,如果不相等则抛出异常 * 判断两个对象是否不相等,如果不相等则抛出异常
* @param a 实际值 *
* @param b 期望 * @param a 实际
* @param b 期望值
* @param message 异常消息 * @param message 异常消息
*/ */
public static void isNotEqual(Object a, Object b, String message) { public static void isNotEqual(Object a, Object b, String message) {
// 检查是否有任何一个为null
if (a == null || b == null) {
throw new ValidateException("参数不能为null: " + message);
}
// 如果实际值与期望值不相等,则抛出异常 // 如果实际值与期望值不相等,则抛出异常
if (!Objects.equals(a, b)) { if (!Objects.equals(a, b)) {
throw new ValidateException(message); throw new ValidateException(message);
@@ -43,6 +48,7 @@ public class AssertUtil {
throw new ValidateException(msg); throw new ValidateException(msg);
} }
} }
/** /**
* 检查字符串是否不为空或空白字符,如果为空或空白字符则抛出异常 * 检查字符串是否不为空或空白字符,如果为空或空白字符则抛出异常
* *
@@ -54,6 +60,7 @@ public class AssertUtil {
public static void isBlank(String str, String errorMsgTemplate, Object... params) { public static void isBlank(String str, String errorMsgTemplate, Object... params) {
isBlank(str, StrUtil.format(errorMsgTemplate, params)); isBlank(str, StrUtil.format(errorMsgTemplate, params));
} }
/** /**
* 检查对象是否不为 null如果为 null 则抛出异常 * 检查对象是否不为 null如果为 null 则抛出异常
* *
@@ -66,6 +73,7 @@ public class AssertUtil {
throw new ValidateException(msg); throw new ValidateException(msg);
} }
} }
/** /**
* 检查对象是否不为 null如果为 null 则抛出异常 * 检查对象是否不为 null如果为 null 则抛出异常
* *
@@ -77,6 +85,7 @@ public class AssertUtil {
public static void isNull(Object object, String errorMsgTemplate, Object... params) { public static void isNull(Object object, String errorMsgTemplate, Object... params) {
isNull(object, StrUtil.format(errorMsgTemplate, params)); isNull(object, StrUtil.format(errorMsgTemplate, params));
} }
public static void isTrue(boolean flag, String errorMsgTemplate, Object... params) { public static void isTrue(boolean flag, String errorMsgTemplate, Object... params) {
if (flag) { if (flag) {
throw new ValidateException(StrUtil.format(errorMsgTemplate, params)); throw new ValidateException(StrUtil.format(errorMsgTemplate, params));
@@ -95,6 +104,7 @@ public class AssertUtil {
throw new ValidateException(msg); throw new ValidateException(msg);
} }
} }
/** /**
* 检查数组是否不为空,如果为空则抛出异常 * 检查数组是否不为空,如果为空则抛出异常
* *
@@ -106,6 +116,7 @@ public class AssertUtil {
public static void isArrayEmpty(Object[] array, String errorMsgTemplate, Object... params) { public static void isArrayEmpty(Object[] array, String errorMsgTemplate, Object... params) {
isArrayEmpty(array, StrUtil.format(errorMsgTemplate, params)); isArrayEmpty(array, StrUtil.format(errorMsgTemplate, params));
} }
/** /**
* 检查列表是否不为空,如果为空则抛出异常 * 检查列表是否不为空,如果为空则抛出异常
* *
@@ -118,6 +129,7 @@ public class AssertUtil {
throw new ValidateException(msg); throw new ValidateException(msg);
} }
} }
/** /**
* 检查列表是否不为空,如果为空则抛出异常 * 检查列表是否不为空,如果为空则抛出异常
* *
@@ -129,13 +141,14 @@ public class AssertUtil {
public static void isListEmpty(List<?> list, String errorMsgTemplate, Object... params) { public static void isListEmpty(List<?> list, String errorMsgTemplate, Object... params) {
isListEmpty(list, StrUtil.format(errorMsgTemplate, params)); isListEmpty(list, StrUtil.format(errorMsgTemplate, params));
} }
/** /**
* 检查 Map 是否不为空,如果为空则抛出异常 * 检查 Map 是否不为空,如果为空则抛出异常
* *
* @param <K> Map 的键类型 * @param <K> Map 的键类型
* @param <V> Map 的值类型 * @param <V> Map 的值类型
* @param map 要检查的 Map * @param map 要检查的 Map
* @param msg 异常信息 * @param msg 异常信息
* @throws ValidateException 如果 Map 为空 * @throws ValidateException 如果 Map 为空
*/ */
public static <K, V> void isMapEmpty(Map<K, V> map, String msg) { public static <K, V> void isMapEmpty(Map<K, V> map, String msg) {
@@ -143,6 +156,7 @@ public class AssertUtil {
throw new ValidateException(msg); throw new ValidateException(msg);
} }
} }
/** /**
* 检查 Map 是否不为空,如果为空则抛出异常 * 检查 Map 是否不为空,如果为空则抛出异常
* *

View File

@@ -23,12 +23,13 @@ public interface ShopUserMapper extends BaseMapper<ShopUser> {
List<ShopUserDTO> selectPageByKeyAndIsVip(@Param("shopId") Long shopId, @Param("isVip") Integer isVip, @Param("key") String key, @Param("amount") BigDecimal amount); List<ShopUserDTO> selectPageByKeyAndIsVip(@Param("shopId") Long shopId, @Param("isVip") Integer isVip, @Param("key") String key, @Param("amount") BigDecimal amount);
int incrAccount(@Param("shopId") long shopId, @Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money); int incrAccount(@Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money);
int decrAccount(@Param("shopId") long shopId, @Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money); int decrAccount(@Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money);
ShopUserSummaryDTO selectUserSummary(@Param("shopId") Long shopId, @Param("isVip") Integer isVip); ShopUserSummaryDTO selectUserSummary(@Param("shopId") Long shopId, @Param("isVip") Integer isVip);
Page<ShopUserVipCardDTO> selectVipCard(); Page<ShopUserVipCardDTO> selectVipCard();
long selectVipCard_COUNT(); long selectVipCard_COUNT();
UserInfoAssetsSummaryDTO selectAssetsSummary(@Param("userId") Long userInfoId); UserInfoAssetsSummaryDTO selectAssetsSummary(@Param("userId") Long userInfoId);

View File

@@ -0,0 +1,150 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.shopuser.*;
import com.czg.account.entity.*;
import com.czg.account.service.*;
import com.czg.config.RedisCst;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.enums.YesNoEnum;
import com.czg.exception.ApiNotPrintException;
import com.czg.market.entity.MkShopCouponRecord;
import com.czg.market.service.MkShopCouponRecordService;
import com.czg.market.service.TbMemberConfigService;
import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderDetailService;
import com.czg.order.service.OrderInfoService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
import com.czg.service.account.mapper.ShopConfigMapper;
import com.czg.service.account.mapper.ShopUserMapper;
import com.czg.system.entity.SysParams;
import com.czg.system.service.SysParamsService;
import com.czg.utils.AssertUtil;
import com.czg.utils.JoinQueryWrapper;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
/**
* 商户储值会员 服务层实现。
*
* @author Administrator
* @since 2025-02-08
*/
@Service
public class AShopUserServiceImpl implements AShopUserService {
@Resource
private ShopUserService shopUserService;
@Resource
private ShopUserMapper shopUserMapper;
@DubboReference
private SysParamsService sysParamsService;
@DubboReference
private OrderInfoService orderInfoService;
@DubboReference
private OrderDetailService orderDetailService;
@Resource
private ShopUserFlowService shopUserFlowService;
@Resource
private UserInfoService userInfoService;
@Resource
private RedisService redisService;
@DubboReference
private MkShopCouponRecordService couponRecordService;
@Resource
// private ShopInfoMapper shopInfoMapper;
private ShopInfoService shopInfoService;
@Resource
private ShopExtendService shopExtendService;
@Resource
private FreeDineConfigService freeDineConfigService;
@Resource
private ShopConfigMapper shopConfigMapper;
@DubboReference
private TbMemberConfigService memberConfigService;
private ShopUser getUserInfo(Long shopUserId) {
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getId, shopUserId).one();
if (shopUser == null) {
throw new ApiNotPrintException("用户信息不存在");
}
return shopUser;
}
@Override
public Page<ShopUserDTO> getPage(String key, Integer isVip, BigDecimal amount) {
Long shopId = StpKit.USER.getHeadShopIdBySession();
PageHelper.startPage(PageUtil.buildPageHelp());
return PageUtil.convert(new PageInfo<>(shopUserMapper.selectPageByKeyAndIsVip(shopId, isVip, key, amount)));
}
@Override
public Boolean updateInfo(Long shopId, ShopUserEditDTO shopUserEditDTO) {
if (StrUtil.isNotBlank(shopUserEditDTO.getPhone())) {
long count = count(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getPhone, shopUserEditDTO.getPhone()).ne(ShopUser::getId, shopUserEditDTO.getId()));
if (count > 0) {
throw new ApiNotPrintException("手机号已存在");
}
}
ShopUser shopUser = getUserInfo(shopId, shopUserEditDTO.getId());
BeanUtil.copyProperties(shopUserEditDTO, shopUser);
return updateById(shopUser);
}
@Override
public ShopUserSummaryDTO getSummary(Long shopId, Integer isVip) {
return mapper.selectUserSummary(shopId, isVip);
}
@Override
@Transactional
public Boolean add(Long shopId, ShopUserAddDTO shopUserAddDTO) {
UserInfo userInfo = userInfoService.queryChain().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()).one();
if (userInfo == null) {
userInfo = BeanUtil.copyProperties(shopUserAddDTO, UserInfo.class);
userInfoService.save(userInfo);
}
ShopUser shopUser = BeanUtil.copyProperties(shopUserAddDTO, ShopUser.class);
shopUser.setCode(generateCode(shopId));
shopUser.setSourceShopId(shopId);
shopUser.setSourceShopId(shopId);
shopUser.setUserId(userInfo.getId());
shopUser.setJoinTime(shopUser.getIsVip() != null && shopUser.getIsVip() == 1 ? DateUtil.date().toLocalDateTime() : null);
return save(shopUser);
}
@Override
public ShopUser getDetail(Integer id, Integer userId) {
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getUsableShopId()).eq(ShopUser::getId, id).eq(ShopUser::getUserId, userId));
long count = couponRecordService.count(new QueryWrapper()
.eq(MkShopCouponRecord::getShopUserId, shopUser.getId())
.eq(MkShopCouponRecord::getStatus, 0)
.eq(MkShopCouponRecord::getIsDel, 0)
);
ShopUserDTO shopUserDTO = BeanUtil.copyProperties(shopUser, ShopUserDTO.class);
shopUserDTO.setCouponNum(count);
shopUserDTO.setOrderNumber(orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, userId).eq(OrderInfo::getShopId, StpKit.USER.getShopId(0L)).eq(OrderInfo::getStatus, "done")));
return shopUserDTO;
}
}

View File

@@ -148,7 +148,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
if (!isAllowAccountLogin) { if (!isAllowAccountLogin) {
throw new ApiNotPrintException("当前分店账号被禁止登录"); throw new ApiNotPrintException("当前分店账号被禁止登录");
} }
StpKit.USER.login(user.getId(), user.getAccount(), shopInfo.getId(), shopInfo.getShopName(), isStaff ? MyStpLogic.LoginType.STAFF : MyStpLogic.LoginType.MANAGER, user.getIsAdmin(), platType); StpKit.USER.login(user.getId(), user.getAccount(), shopInfo.getId(), shopInfo.getMainId(), shopInfo.getShopName(), isStaff ? MyStpLogic.LoginType.STAFF : MyStpLogic.LoginType.MANAGER, user.getIsAdmin(), platType);
// 查询角色 // 查询角色
List<SysRole> roleList = sysRoleService.getByUserId(user.getId()); List<SysRole> roleList = sysRoleService.getByUserId(user.getId());
List<String> roleNames = roleList.stream().map(SysRole::getName).collect(Collectors.toList()); List<String> roleNames = roleList.stream().map(SysRole::getName).collect(Collectors.toList());
@@ -161,13 +161,10 @@ public class AuthorizationServiceImpl implements AuthorizationService {
if (shopStaffPromissionList != null && !shopStaffPromissionList.isEmpty()) { if (shopStaffPromissionList != null && !shopStaffPromissionList.isEmpty()) {
promissionList.addAll(shopStaffPromissionList); promissionList.addAll(shopStaffPromissionList);
} }
boolean isEnableSync = StpKit.USER.isEnableSync(shopInfo.getId()); if (shopInfo.getMainId() != null && CollUtil.contains(roleNames, "商户")) {
if (isEnableSync && CollUtil.contains(roleNames, "商户")) {
roleNames.remove("商户"); roleNames.remove("商户");
roleNames.add("分店商户"); roleNames.add("分店商户");
List<String> headShopPromissionList = sysMenuMapper.selectByRoleId(2L).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList();
List<String> branchShopPromissionList = sysMenuMapper.selectByRoleId(3L).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList(); List<String> branchShopPromissionList = sysMenuMapper.selectByRoleId(3L).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList();
// promissionList.removeAll(headShopPromissionList);
promissionList.addAll(branchShopPromissionList); promissionList.addAll(branchShopPromissionList);
} }
StpKit.USER.addRoleList(roleNames); StpKit.USER.addRoleList(roleNames);
@@ -187,7 +184,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
Long headId = StpKit.USER.getHeadId(); Long headId = StpKit.USER.getHeadId();
long shopId = StpKit.USER.getLoginIdAsLong(); long shopId = StpKit.USER.getLoginIdAsLong();
ShopInfo currentInfo = shopInfoService.getById(shopId); ShopInfo currentInfo = shopInfoService.getById(shopId);
if (currentInfo.getIsHeadShop() != YesNoEnum.YES.value() && headId == null) { if (currentInfo.getIsHeadShop() != YesNoEnum.YES.value()) {
throw new ApiNotPrintException("登录账号无权限切换"); throw new ApiNotPrintException("登录账号无权限切换");
} }
@@ -201,15 +198,9 @@ public class AuthorizationServiceImpl implements AuthorizationService {
throw new ApiNotPrintException("店铺信息不存在"); throw new ApiNotPrintException("店铺信息不存在");
} }
// 主店铺切换子店铺 // 主店铺切换子店铺
if ((headId == null && !shopInfo.getMainId().equals(shopId)) || (!sysUser.getId().equals(headId) && shopInfo.getMainId() == null) || if (!shopInfo.getMainId().equals(shopId)) {
(headId != null && !sysUserId.equals(headId) && !shopInfo.getMainId().equals(headId))) { throw new ApiNotPrintException("目标店铺非登录账号所有");
Long headShopId = StpKit.USER.getHeadShopId();
Long changeHeadShopId = StpKit.USER.getHeadShopId(sysUserId);
if (!changeHeadShopId.equals(headShopId)) {
throw new ApiNotPrintException("目标店铺非登录账号所有");
}
} }
// 查询角色 // 查询角色
@@ -221,8 +212,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
// 权限赋予 // 权限赋予
List<String> promissionList = sysMenuMapper.selectByUserId(sysUser.getId(), null).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList(); List<String> promissionList = sysMenuMapper.selectByUserId(sysUser.getId(), null).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList();
List<String> newPromissionList = new ArrayList<>(promissionList); List<String> newPromissionList = new ArrayList<>(promissionList);
boolean isEnableSync = StpKit.USER.isEnableSync(shopInfo.getId()); if (shopInfo.getMainId() != null && CollUtil.contains(roleNames, "商户")) {
if (isEnableSync && CollUtil.contains(roleNames, "商户")) {
roleNames.remove("商户"); roleNames.remove("商户");
roleNames.add("分店商户"); roleNames.add("分店商户");
List<String> headShopPromissionList = sysMenuMapper.selectByRoleId(2L).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList(); List<String> headShopPromissionList = sysMenuMapper.selectByRoleId(2L).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).toList();

View File

@@ -7,9 +7,11 @@ import com.czg.account.dto.points.OrderDeductionPointsDTO;
import com.czg.account.entity.MemberPoints; import com.czg.account.entity.MemberPoints;
import com.czg.account.entity.MemberPointsLog; import com.czg.account.entity.MemberPointsLog;
import com.czg.account.entity.PointsBasicSetting; import com.czg.account.entity.PointsBasicSetting;
import com.czg.account.entity.ShopInfo;
import com.czg.account.enums.PointUserGroupEnum; import com.czg.account.enums.PointUserGroupEnum;
import com.czg.account.param.MemberPointsParam; import com.czg.account.param.MemberPointsParam;
import com.czg.account.service.MemberPointsService; import com.czg.account.service.MemberPointsService;
import com.czg.account.service.ShopInfoService;
import com.czg.enums.YesNoEnum; import com.czg.enums.YesNoEnum;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
import com.czg.order.entity.OrderInfo; import com.czg.order.entity.OrderInfo;
@@ -42,6 +44,8 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
private PointsBasicSettingMapper pointsBasicSettingMapper; private PointsBasicSettingMapper pointsBasicSettingMapper;
@Resource @Resource
private MemberPointsLogMapper memberPointsLogMapper; private MemberPointsLogMapper memberPointsLogMapper;
@Resource
private ShopInfoService shopInfoService;
private QueryWrapper buildQueryWrapper(MemberPointsParam param) { private QueryWrapper buildQueryWrapper(MemberPointsParam param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper(); QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
@@ -52,7 +56,14 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
queryWrapper.like(MemberPoints::getPhone, param.getPhone()); queryWrapper.like(MemberPoints::getPhone, param.getPhone());
} }
Long shopId = StpKit.USER.getUsableShopId(); Long shopId = StpKit.USER.getShopId();
ShopInfo byId = shopInfoService.getById(shopId);
if (byId == null) {
throw new CzgException("店铺不存在");
}
if (byId.getIsEnableVipSync().equals(1)) {
shopId = byId.getMainId();
}
queryWrapper.eq(MemberPoints::getShopId, shopId); queryWrapper.eq(MemberPoints::getShopId, shopId);
queryWrapper.orderBy(MemberPoints::getShopUserId, false); queryWrapper.orderBy(MemberPoints::getShopUserId, false);
return queryWrapper; return queryWrapper;

View File

@@ -353,7 +353,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
distance = GeoUtil.getDistance(Long.parseLong(shopInfo.getLat()), Long.parseLong(shopInfo.getLng()), Long.parseLong(lat), Long.parseLong(lng)); distance = GeoUtil.getDistance(Long.parseLong(shopInfo.getLat()), Long.parseLong(shopInfo.getLng()), Long.parseLong(lat), Long.parseLong(lng));
} }
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, shopInfo.getId()).eq(ShopUser::getUserId, StpKit.USER.getLoginIdAsLong()).one(); ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getUserId, StpKit.USER.getLoginIdAsLong()).one();
List<ShopExtend> shopExtends = shopExtendService.listInfo(shopInfo.getId(), null); List<ShopExtend> shopExtends = shopExtendService.listInfo(shopInfo.getId(), null);
Map<String, ShopExtend> shopExtendMap = shopExtends.stream().collect(Collectors.toMap(ShopExtend::getAutoKey, i -> i)); Map<String, ShopExtend> shopExtendMap = shopExtends.stream().collect(Collectors.toMap(ShopExtend::getAutoKey, i -> i));
return new ShopInfoByCodeDTO(distance, shopInfo, shopExtendMap, shopTable, shopUser != null && shopUser.getIsVip() != null && shopUser.getIsVip() == 1); return new ShopInfoByCodeDTO(distance, shopInfo, shopExtendMap, shopTable, shopUser != null && shopUser.getIsVip() != null && shopUser.getIsVip() == 1);
@@ -382,7 +382,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
head.setShopName(shopInfo.getShopName()); head.setShopName(shopInfo.getShopName());
list.add(head); list.add(head);
MyStpLogic.LoginType loginType = (MyStpLogic.LoginType) StpKit.USER.getSession().get("loginType"); MyStpLogic.LoginType loginType = (MyStpLogic.LoginType) StpKit.USER.getSession().get("loginType");
if(loginType.compareTo(MyStpLogic.LoginType.STAFF) == 0){ if (loginType.compareTo(MyStpLogic.LoginType.STAFF) == 0) {
return list; return list;
} }
List<ShopInfo> branchList = mapper.selectListByQuery(query().select(ShopInfo::getId, ShopInfo::getShopName).eq(ShopInfo::getMainId, shopId).orderBy(ShopInfo::getId, true)); List<ShopInfo> branchList = mapper.selectListByQuery(query().select(ShopInfo::getId, ShopInfo::getShopName).eq(ShopInfo::getMainId, shopId).orderBy(ShopInfo::getId, true));
@@ -394,4 +394,14 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
} }
return list; return list;
} }
@Override
public Long getMainIdByShopId(Long shopId) {
ShopInfo shopInfo = this.getById(shopId);
if (shopInfo == null) {
throw new CzgException("店铺信息不存在");
}
return shopInfo.getMainId() == null ? shopId : shopInfo.getMainId();
}
} }

View File

@@ -2,45 +2,24 @@ package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil; import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import cn.hutool.core.util.StrUtil; import com.czg.account.entity.ShopUser;
import com.czg.account.dto.shopuser.*; import com.czg.account.entity.ShopUserFlow;
import com.czg.account.entity.*; import com.czg.account.entity.UserInfo;
import com.czg.account.service.*; import com.czg.account.service.ShopInfoService;
import com.czg.config.RedisCst; import com.czg.account.service.ShopUserFlowService;
import com.czg.account.service.ShopUserService;
import com.czg.account.service.UserInfoService;
import com.czg.enums.ShopUserFlowBizEnum; import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.enums.YesNoEnum;
import com.czg.exception.ApiNotPrintException; import com.czg.exception.ApiNotPrintException;
import com.czg.market.entity.MkShopCouponRecord;
import com.czg.market.service.MkShopCouponRecordService;
import com.czg.market.service.TbMemberConfigService;
import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderDetailService;
import com.czg.order.service.OrderInfoService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
import com.czg.service.account.mapper.ShopConfigMapper;
import com.czg.service.account.mapper.ShopInfoMapper;
import com.czg.service.account.mapper.ShopUserMapper; import com.czg.service.account.mapper.ShopUserMapper;
import com.czg.system.entity.SysParams;
import com.czg.system.service.SysParamsService;
import com.czg.utils.AssertUtil;
import com.czg.utils.JoinQueryWrapper;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl; import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.List;
/** /**
@@ -51,85 +30,62 @@ import java.util.List;
*/ */
@DubboService @DubboService
public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> implements ShopUserService { public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> implements ShopUserService {
@DubboReference
private SysParamsService sysParamsService;
@DubboReference
private OrderInfoService orderInfoService;
@DubboReference
private OrderDetailService orderDetailService;
@Resource @Resource
private ShopUserFlowService shopUserFlowService; private ShopUserFlowService shopUserFlowService;
@Resource @Resource
private UserInfoService userInfoService; private UserInfoService userInfoService;
@Resource @Resource
private RedisService redisService; private ShopInfoService shopInfoService;
@DubboReference
private MkShopCouponRecordService couponRecordService;
@Resource
private ShopInfoMapper shopInfoMapper;
@Resource
private ShopExtendService shopExtendService;
@Resource
private FreeDineConfigService freeDineConfigService;
@Resource
private ShopConfigMapper shopConfigMapper;
@DubboReference
private TbMemberConfigService memberConfigService;
private ShopUser getUserInfo(Long shopId, Long shopUserId) { private ShopUser getUserInfo(Long shopUserId) {
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getId, shopUserId).one(); ShopUser shopUser = queryChain().eq(ShopUser::getId, shopUserId).one();
if (shopUser == null) { if (shopUser == null) {
throw new ApiNotPrintException("用户信息不存在"); throw new ApiNotPrintException("用户信息不存在");
} }
return shopUser; return shopUser;
} }
@Override @Override
public Page<ShopUserDTO> getPage(String key, Integer isVip, BigDecimal amount) { public ShopUser getShopUserInfo(Long shopId, long userId) {
Long shopId = StpKit.USER.getUsableShopId(); Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
PageHelper.startPage(PageUtil.buildPageHelp()); ShopUser shopUser = queryChain().eq(ShopUser::getMainShopId, shopId).eq(ShopUser::getUserId, userId).one();
return PageUtil.convert(new PageInfo<>(mapper.selectPageByKeyAndIsVip(shopId, isVip, key, amount))); if (shopUser == null) {
} shopUser = new ShopUser();
UserInfo userInfo = userInfoService.getById(userId);
@Override BeanUtil.copyProperties(userInfo, shopUser);
public Boolean updateInfo(Long shopId, ShopUserEditDTO shopUserEditDTO) { shopUser.setMainShopId(mainShopId);
if (StrUtil.isNotBlank(shopUserEditDTO.getPhone())) { shopUser.setSourceShopId(shopId);
long count = count(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getPhone, shopUserEditDTO.getPhone()).ne(ShopUser::getId, shopUserEditDTO.getId())); shopUser.setUserId(userId);
if (count > 0) { shopUser.setId(null);
throw new ApiNotPrintException("手机号已存在"); save(shopUser);
}
} }
ShopUser shopUser = getUserInfo(shopId, shopUserEditDTO.getId()); return shopUser;
BeanUtil.copyProperties(shopUserEditDTO, shopUser);
return updateById(shopUser);
} }
@Override @Override
@Transactional @Transactional
public Long updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO) { public Long updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO) {
shopUserEditDTO.setMoney(shopUserEditDTO.getMoney().setScale(2, RoundingMode.DOWN)); shopUserEditDTO.setMoney(shopUserEditDTO.getMoney().setScale(2, RoundingMode.DOWN));
ShopUser userInfo = getUserInfo(shopId, shopUserEditDTO.getId()); ShopUser userInfo = getUserInfo(shopUserEditDTO.getId());
ShopUserFlow userFlow = new ShopUserFlow(); ShopUserFlow userFlow = new ShopUserFlow();
int flag; int flag;
if (shopUserEditDTO.getType() == 0) { if (shopUserEditDTO.getType() == 0) {
if (shopUserEditDTO.getMoney().compareTo(userInfo.getAmount()) > 0) { if (shopUserEditDTO.getMoney().compareTo(userInfo.getAmount()) > 0) {
//如果超额退款 则退为0 //如果超额退款 则退为0
flag = mapper.decrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), userInfo.getAmount()); flag = mapper.decrAccount(shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), userInfo.getAmount());
} else { } else {
flag = mapper.decrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney()); flag = mapper.decrAccount(shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
} }
} else { } else {
flag = mapper.incrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney()); flag = mapper.incrAccount(shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
} }
if (flag == 0) { if (flag == 0) {
throw new ApiNotPrintException("增减用户余额操作失败"); throw new ApiNotPrintException("增减用户余额操作失败");
} }
userFlow.setUserId(userInfo.getUserId()); userFlow.setUserId(userInfo.getUserId());
userFlow.setShopId(userInfo.getShopId()); userFlow.setShopId(userInfo.getSourceShopId());
userFlow.setAmount(shopUserEditDTO.getType() == 0 ? shopUserEditDTO.getMoney().negate() : shopUserEditDTO.getMoney()); userFlow.setAmount(shopUserEditDTO.getType() == 0 ? shopUserEditDTO.getMoney().negate() : shopUserEditDTO.getMoney());
userFlow.setBalance(shopUserEditDTO.getType() == 0 ? userInfo.getAmount().subtract(shopUserEditDTO.getMoney()) : userInfo.getAmount().add(shopUserEditDTO.getMoney())); userFlow.setBalance(shopUserEditDTO.getType() == 0 ? userInfo.getAmount().subtract(shopUserEditDTO.getMoney()) : userInfo.getAmount().add(shopUserEditDTO.getMoney()));
if (userFlow.getBalance().compareTo(BigDecimal.ZERO) < 0) { if (userFlow.getBalance().compareTo(BigDecimal.ZERO) < 0) {
@@ -150,234 +106,4 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
} }
return userFlow.getId(); return userFlow.getId();
} }
@Override
public ShopUserSummaryDTO getSummary(Long shopId, Integer isVip) {
return mapper.selectUserSummary(shopId, isVip);
}
@Override
public ShopUser getShopUserInfo(Long shopId, long userId) {
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopId);
if (shopConfig != null && shopConfig.getIsEnableVipSync() == YesNoEnum.YES.value() && shopConfig.getMainId() != null) {
shopId = shopConfig.getMainId();
}
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userId).one();
if (shopUser == null) {
shopUser = new ShopUser();
UserInfo userInfo = userInfoService.getById(userId);
BeanUtil.copyProperties(userInfo, shopUser);
shopUser.setShopId(shopId);
shopUser.setUserId(userId);
shopUser.setId(null);
save(shopUser);
}
return shopUser;
}
@Override
@Transactional
public Boolean add(Long shopId, ShopUserAddDTO shopUserAddDTO) {
UserInfo userInfo = userInfoService.queryChain().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()).one();
if (userInfo == null) {
userInfo = BeanUtil.copyProperties(shopUserAddDTO, UserInfo.class);
userInfoService.save(userInfo);
}
ShopUser shopUser = BeanUtil.copyProperties(shopUserAddDTO, ShopUser.class);
shopUser.setCode(generateCode(shopId));
shopUser.setShopId(shopId);
shopUser.setUserId(userInfo.getId());
shopUser.setJoinTime(shopUser.getIsVip() != null && shopUser.getIsVip() == 1 ? DateUtil.date().toLocalDateTime() : null);
return save(shopUser);
}
@Override
public Page<ShopUserVipCardDTO> vipCard(long userInfoId) {
return mapper.xmlPaginate("selectVipCard", PageUtil.buildPage(), new JoinQueryWrapper().eq(ShopUser::getUserId, userInfoId));
}
@Override
public CzgResult<String> getCode(long userInfoId, long shopId) {
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopId);
if (shopConfig != null && shopConfig.getIsEnableVipSync() == YesNoEnum.YES.value() && shopConfig.getMainId() != null) {
shopId = shopConfig.getMainId();
}
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userInfoId).one();
AssertUtil.isNull(shopUser, "会员信息不存在");
if (shopUser.getIsVip().equals(0)) {
return CzgResult.failure("加入会员后使用");
}
String dynamicCode = generatePaymentCode(String.valueOf(shopId), String.valueOf(userInfoId));
redisService.set(RedisCst.SHOP_USER_DYNAMIC_CODE + shopUser.getShopId() + ":" + dynamicCode, shopUser.getId(), 180);
return CzgResult.success(dynamicCode);
}
public String generatePaymentCode(String shopId, String platformNumber) {
// 获取当前毫秒时间戳的后四位
String date = String.format("%04d", System.currentTimeMillis() % 10000);
// 获取店铺ID的最后2位数字
String shopIdLastTwoDigits = String.format("%02d", Integer.parseInt(shopId) % 100);
// 生成一个6位随机数
String randomPart = RandomUtil.randomNumbers(6);
// 拼接生成支付码:毫秒后的四位 + 平台号码 + 店铺ID的最后2位 + 随机数
return date + platformNumber + shopIdLastTwoDigits + randomPart;
}
public String generateCode(long shopId) {
String code = "shop_user_code_val%d".formatted(shopId);
SysParams sysParam = sysParamsService.getOne(new QueryWrapper().eq(SysParams::getParamCode, code));
if (sysParam == null) {
SysParams sysParams = new SysParams()
.setParamValue("1")
.setParamType(1)
.setCreateTime(DateUtil.date().toLocalDateTime())
.setParamCode(code);
sysParamsService.save(sysParams);
return generateRandomCode(1);
}
long parseLong = Long.parseLong(sysParam.getParamValue());
long l = ++parseLong;
sysParam.setParamValue(String.valueOf(l));
sysParamsService.updateById(sysParam);
return generateRandomCode(l);
}
// 使用Hutool生成十六进制代码并随机填充字母
private String generateRandomCode(long value) {
// 生成十六进制代码确保为10位
String hexCode = String.format("%010X", value);
// 计算需要补充的字母数量
int missingLength = 10 - hexCode.length();
StringBuilder codeBuilder = new StringBuilder(hexCode);
for (int i = 0; i < missingLength; i++) {
// 生成随机字母
char randomChar = RandomUtil.randomChar("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
codeBuilder.append(randomChar);
}
return codeBuilder.toString();
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean join(Long shopId, Long userId, ShopUserAddDTO shopUserAddDTO) {
// 当前用户信息
UserInfo userInfo = userInfoService.getById(userId);
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userInfo.getId()));
if (shopUser == null) {
shopUser = new ShopUser();
shopUser.setUserId(userId);
shopUser.setShopId(shopId);
}
// 查询系统添加的会员
UserInfo oriInfo = userInfoService.getOne(new QueryWrapper().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()));
if (oriInfo != null && !oriInfo.getId().equals(userId)) {
// 迁移订单
OrderInfo orderInfo = new OrderInfo();
orderInfo.setUserId(userId);
orderInfoService.update(orderInfo, new QueryWrapper().eq(OrderInfo::getUserId, oriInfo.getId()));
// 删除多余用户信息
userInfoService.removeById(oriInfo.getId());
BeanUtil.copyProperties(oriInfo, userInfo, "id", "alipayOpenId", "wechatOpenId");
ShopUser oldUserInfo = getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, oriInfo.getId()));
if (oldUserInfo != null) {
removeById(oldUserInfo.getId());
BeanUtil.copyProperties(oldUserInfo, shopUser, "id", "userId");
}
}
BeanUtil.copyProperties(shopUserAddDTO, shopUser, "accountPoints", "amount");
BeanUtil.copyProperties(shopUserAddDTO, userInfo);
userInfoService.updateById(userInfo);
if ((shopUser.getIsVip() == null || shopUser.getIsVip() != 1) && shopUser.getId() != null) {
shopUser.setIsVip(1);
if (StrUtil.isBlank(shopUser.getCode())) {
shopUser.setCode(generateCode(shopId));
}
shopUser.setJoinTime(DateUtil.date().toLocalDateTime());
shopUser.setUserId(null);
shopUser.setShopId(null);
}
memberConfigService.joinMember(shopId, userId, null);
return saveOrUpdate(shopUser);
}
@Override
public ShopUserDetailDTO getInfo(Long shopId, long userId) {
ShopConfig shopConfig = shopConfigMapper.selectOneById(shopId);
if (shopConfig != null && shopConfig.getIsEnableVipSync() == YesNoEnum.YES.value() && shopConfig.getMainId() != null) {
shopId = shopConfig.getMainId();
}
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userId));
UserInfo userInfo = userInfoService.getById(userId);
if (userInfo == null) {
throw new ApiNotPrintException("用户信息不存在");
}
long couponNum = 0;
if (shopUser == null) {
shopUser = BeanUtil.copyProperties(userInfo, ShopUser.class);
shopUser.setShopId(shopId);
shopUser.setId(null);
shopUser.setUserId(userId);
save(shopUser);
shopUser = getById(shopUser.getId());
} else {
couponNum = couponRecordService.count(new QueryWrapper()
.eq(MkShopCouponRecord::getShopUserId, shopUser.getId())
.eq(MkShopCouponRecord::getStatus, 0)
.eq(MkShopCouponRecord::getIsDel,0)
);
}
ShopUserDetailDTO shopUserDetailDTO = BeanUtil.copyProperties(shopUser, ShopUserDetailDTO.class);
shopUserDetailDTO.setCouponNum(couponNum);
ShopInfo shopInfo = shopInfoMapper.selectOneById(shopId);
if (shopInfo != null) {
shopUserDetailDTO.setShopName(shopInfo.getShopName());
shopUserDetailDTO.setShopId(shopInfo.getId());
ShopConfig config = shopConfigMapper.selectOneByQuery(new QueryWrapper().eq(ShopConfig::getId, shopId));
if (config != null) {
BeanUtil.copyProperties(config, shopInfo, "id");
}
shopUserDetailDTO.setShopInfo(shopInfo);
List<ShopExtend> shopExtends = shopExtendService.list(new QueryWrapper().eq(ShopExtend::getShopId, shopInfo.getId()));
shopUserDetailDTO.setShopExtendList(shopExtends);
}
shopUserDetailDTO.setFreeDineConfig(freeDineConfigService.getConfig(shopId));
shopUserDetailDTO.setPayPwd(userInfo.getPayPwd());
return shopUserDetailDTO;
}
@Override
public ShopUser getDetail(Integer id, Integer userId) {
ShopUser shopUser = getOne(new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getUsableShopId()).eq(ShopUser::getId, id).eq(ShopUser::getUserId, userId));
long count = couponRecordService.count(new QueryWrapper()
.eq(MkShopCouponRecord::getShopUserId, shopUser.getId())
.eq(MkShopCouponRecord::getStatus, 0)
.eq(MkShopCouponRecord::getIsDel,0)
);
ShopUserDTO shopUserDTO = BeanUtil.copyProperties(shopUser, ShopUserDTO.class);
shopUserDTO.setCouponNum(count);
shopUserDTO.setOrderNumber(orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, userId).eq(OrderInfo::getShopId, StpKit.USER.getShopId(0L)).eq(OrderInfo::getStatus, "done")));
return shopUserDTO;
}
} }

View File

@@ -0,0 +1,244 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.shopuser.ShopUserAddDTO;
import com.czg.account.dto.shopuser.ShopUserDetailDTO;
import com.czg.account.dto.shopuser.ShopUserVipCardDTO;
import com.czg.account.entity.*;
import com.czg.account.service.*;
import com.czg.config.RedisCst;
import com.czg.exception.ApiNotPrintException;
import com.czg.market.entity.MkShopCouponRecord;
import com.czg.market.service.MkShopCouponRecordService;
import com.czg.market.service.TbMemberConfigService;
import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderInfoService;
import com.czg.resp.CzgResult;
import com.czg.service.RedisService;
import com.czg.service.account.mapper.ShopConfigMapper;
import com.czg.system.entity.SysParams;
import com.czg.system.service.SysParamsService;
import com.czg.utils.AssertUtil;
import com.czg.utils.JoinQueryWrapper;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 商户储值会员 服务层实现。
*
* @author Administrator
* @since 2025-02-08
*/
@Service
public class UShopUserServiceImpl implements UShopUserService {
@Resource
private ShopUserService shopUserService;
@DubboReference
private SysParamsService sysParamsService;
@DubboReference
private OrderInfoService orderInfoService;
@Resource
private UserInfoService userInfoService;
@Resource
private RedisService redisService;
@DubboReference
private MkShopCouponRecordService couponRecordService;
@Resource
private ShopInfoService shopInfoService;
@Resource
private ShopExtendService shopExtendService;
@Resource
private FreeDineConfigService freeDineConfigService;
@Resource
private ShopConfigMapper shopConfigMapper;
@DubboReference
private TbMemberConfigService memberConfigService;
@Override
public ShopUser getShopUserInfo(Long shopId, long userId) {
return shopUserService.getShopUserInfo(shopId, userId);
}
@Override
public Page<ShopUserVipCardDTO> vipCard(long userInfoId) {
return shopUserService.getMapper().xmlPaginate("selectVipCard", PageUtil.buildPage(), new JoinQueryWrapper().eq(ShopUser::getUserId, userInfoId));
}
@Override
public CzgResult<String> getCode(long userInfoId, long shopId) {
shopId = shopInfoService.getMainIdByShopId(shopId);
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getMainShopId, shopId).eq(ShopUser::getUserId, userInfoId).one();
AssertUtil.isNull(shopUser, "会员信息不存在");
if (shopUser.getIsVip().equals(0)) {
return CzgResult.failure("加入会员后使用");
}
String dynamicCode = generatePaymentCode(String.valueOf(shopId), String.valueOf(userInfoId));
redisService.set(RedisCst.SHOP_USER_DYNAMIC_CODE + shopUser.getMainShopId() + ":" + dynamicCode, shopUser.getId(), 180);
return CzgResult.success(dynamicCode);
}
public String generatePaymentCode(String shopId, String platformNumber) {
// 获取当前毫秒时间戳的后四位
String date = String.format("%04d", System.currentTimeMillis() % 10000);
// 获取店铺ID的最后2位数字
String shopIdLastTwoDigits = String.format("%02d", Integer.parseInt(shopId) % 100);
// 生成一个6位随机数
String randomPart = RandomUtil.randomNumbers(6);
// 拼接生成支付码:毫秒后的四位 + 平台号码 + 店铺ID的最后2位 + 随机数
return date + platformNumber + shopIdLastTwoDigits + randomPart;
}
public String generateCode(long shopId) {
String code = "shop_user_code_val%d".formatted(shopId);
SysParams sysParam = sysParamsService.getOne(new QueryWrapper().eq(SysParams::getParamCode, code));
if (sysParam == null) {
SysParams sysParams = new SysParams()
.setParamValue("1")
.setParamType(1)
.setCreateTime(DateUtil.date().toLocalDateTime())
.setParamCode(code);
sysParamsService.save(sysParams);
return generateRandomCode(1);
}
long parseLong = Long.parseLong(sysParam.getParamValue());
long l = ++parseLong;
sysParam.setParamValue(String.valueOf(l));
sysParamsService.updateById(sysParam);
return generateRandomCode(l);
}
// 使用Hutool生成十六进制代码并随机填充字母
private String generateRandomCode(long value) {
// 生成十六进制代码确保为10位
String hexCode = String.format("%010X", value);
// 计算需要补充的字母数量
int missingLength = 10 - hexCode.length();
StringBuilder codeBuilder = new StringBuilder(hexCode);
for (int i = 0; i < missingLength; i++) {
// 生成随机字母
char randomChar = RandomUtil.randomChar("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
codeBuilder.append(randomChar);
}
return codeBuilder.toString();
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean join(Long shopId, Long userId, ShopUserAddDTO shopUserAddDTO) {
Long mainId = shopInfoService.getMainIdByShopId(shopId);
// 当前用户信息
UserInfo userInfo = userInfoService.getById(userId);
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getSourceShopId, shopId).eq(ShopUser::getUserId, userInfo.getId()));
if (shopUser == null) {
shopUser = new ShopUser();
shopUser.setUserId(userId);
shopUser.setSourceShopId(shopId);
shopUser.setMainShopId(mainId);
}
// 查询系统添加的会员
UserInfo oriInfo = userInfoService.getOne(new QueryWrapper().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()));
if (oriInfo != null && !oriInfo.getId().equals(userId)) {
// 迁移订单
OrderInfo orderInfo = new OrderInfo();
orderInfo.setUserId(userId);
orderInfoService.update(orderInfo, new QueryWrapper().eq(OrderInfo::getUserId, oriInfo.getId()));
// 删除多余用户信息
userInfoService.removeById(oriInfo.getId());
BeanUtil.copyProperties(oriInfo, userInfo, "id", "alipayOpenId", "wechatOpenId");
ShopUser oldUserInfo = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getMainShopId, mainId).eq(ShopUser::getUserId, oriInfo.getId()));
if (oldUserInfo != null) {
shopUserService.removeById(oldUserInfo.getId());
BeanUtil.copyProperties(oldUserInfo, shopUser, "id", "userId");
}
}
BeanUtil.copyProperties(shopUserAddDTO, shopUser, "accountPoints", "amount");
BeanUtil.copyProperties(shopUserAddDTO, userInfo);
userInfoService.updateById(userInfo);
if ((shopUser.getIsVip() == null || shopUser.getIsVip() != 1) && shopUser.getId() != null) {
shopUser.setIsVip(1);
if (StrUtil.isBlank(shopUser.getCode())) {
shopUser.setCode(generateCode(shopId));
}
shopUser.setJoinTime(DateUtil.date().toLocalDateTime());
shopUser.setUserId(null);
shopUser.setSourceShopId(shopId);
shopUser.setMainShopId(mainId);
}
memberConfigService.joinMember(shopId, userId, null);
return shopUserService.saveOrUpdate(shopUser);
}
@Override
public ShopUserDetailDTO getInfo(Long shopId, long userId) {
Long mainId = shopInfoService.getMainIdByShopId(shopId);
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getMainShopId, mainId).eq(ShopUser::getUserId, userId));
UserInfo userInfo = userInfoService.getById(userId);
if (userInfo == null) {
throw new ApiNotPrintException("用户信息不存在");
}
long couponNum = 0;
if (shopUser == null) {
shopUser = BeanUtil.copyProperties(userInfo, ShopUser.class);
shopUser.setMainShopId(mainId);
shopUser.setSourceShopId(shopId);
shopUser.setId(null);
shopUser.setUserId(userId);
shopUserService.save(shopUser);
// shopUser = getById(shopUser.getId());
} else {
couponNum = couponRecordService.count(new QueryWrapper()
.eq(MkShopCouponRecord::getShopUserId, shopUser.getId())
.eq(MkShopCouponRecord::getStatus, 0)
.eq(MkShopCouponRecord::getIsDel, 0)
);
}
ShopUserDetailDTO shopUserDetailDTO = BeanUtil.copyProperties(shopUser, ShopUserDetailDTO.class);
shopUserDetailDTO.setCouponNum(couponNum);
ShopInfo shopInfo = shopInfoService.getById(shopId);
if (shopInfo != null) {
shopUserDetailDTO.setShopName(shopInfo.getShopName());
shopUserDetailDTO.setShopId(shopInfo.getId());
ShopConfig config = shopConfigMapper.selectOneByQuery(new QueryWrapper().eq(ShopConfig::getId, shopId));
if (config != null) {
BeanUtil.copyProperties(config, shopInfo, "id");
}
shopUserDetailDTO.setShopInfo(shopInfo);
List<ShopExtend> shopExtends = shopExtendService.list(new QueryWrapper().eq(ShopExtend::getShopId, shopInfo.getId()));
shopUserDetailDTO.setShopExtendList(shopExtends);
}
shopUserDetailDTO.setFreeDineConfig(freeDineConfigService.getConfig(shopId));
shopUserDetailDTO.setPayPwd(userInfo.getPayPwd());
return shopUserDetailDTO;
}
}

View File

@@ -1,6 +1,7 @@
package com.czg.service.account.service.impl; package com.czg.service.account.service.impl;
//import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils; //import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@@ -73,7 +74,7 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
JSONObject jsonObject = JSONObject.parseObject(data); JSONObject jsonObject = JSONObject.parseObject(data);
if (jsonObject.containsKey("phoneNumber")) { if (jsonObject.containsKey("phoneNumber")) {
mobile = jsonObject.getString("phoneNumber"); mobile = jsonObject.getString("phoneNumber");
}else { } else {
throw new ApiNotPrintException("手机号获取失败"); throw new ApiNotPrintException("手机号获取失败");
} }
} }
@@ -117,7 +118,7 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
userInfo.setLastLoginTime(DateUtil.date().toLocalDateTime()); userInfo.setLastLoginTime(DateUtil.date().toLocalDateTime());
userInfoService.saveOrUpdate(userInfo); userInfoService.saveOrUpdate(userInfo);
// StpKit.USER.login(userInfo.getId()); // StpKit.USER.login(userInfo.getId());
StpKit.USER.login(userInfo.getId(), openId, null, null, MyStpLogic.LoginType.USER, false, "userMini"); StpKit.USER.login(userInfo.getId(), openId, null, null, null, MyStpLogic.LoginType.USER, false, "userMini");
return new LoginTokenDTO(StpKit.USER.getTokenValue(), userInfo); return new LoginTokenDTO(StpKit.USER.getTokenValue(), userInfo);
} }
} }

View File

@@ -8,14 +8,12 @@
set amount=amount + #{money}, set amount=amount + #{money},
update_time=#{time} update_time=#{time}
where id = #{id} where id = #{id}
and shop_id = #{shopId}
</update> </update>
<update id="decrAccount"> <update id="decrAccount">
update tb_shop_user update tb_shop_user
set amount=amount - #{money}, set amount=amount - #{money},
update_time=#{time} update_time=#{time}
where id = #{id} where id = #{id}
and shop_id = #{shopId}
and amount - #{money} >= 0 and amount - #{money} >= 0
</update> </update>
@@ -30,6 +28,7 @@
and a.is_vip=#{isVip} and a.is_vip=#{isVip}
</if> </if>
</select> </select>
<select id="selectVipCard" resultType="com.czg.account.dto.shopuser.ShopUserVipCardDTO"> <select id="selectVipCard" resultType="com.czg.account.dto.shopuser.ShopUserVipCardDTO">
select tb_shop_info.logo, tb_shop_info.shop_name shopName, tb_shop_user.amount, tb_shop_user.shop_id shopId select tb_shop_info.logo, tb_shop_info.shop_name shopName, tb_shop_user.amount, tb_shop_user.shop_id shopId
from tb_shop_user from tb_shop_user