管理端店铺用户相关接口
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.ShopUserFlow;
|
||||
|
||||
/**
|
||||
* 用户余额流水 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-13
|
||||
*/
|
||||
public interface ShopUserFlowMapper extends BaseMapper<ShopUserFlow> {
|
||||
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.czg.account.dto.shopuser.ShopUserSummaryDTO;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 商户储值会员 映射层。
|
||||
@@ -11,4 +17,11 @@ import com.mybatisflex.core.BaseMapper;
|
||||
*/
|
||||
public interface ShopUserMapper extends BaseMapper<ShopUser> {
|
||||
|
||||
Page<ShopUser> selectPageByKeyAndIsVip(Page<Object> objectPage, @Param("key") String key, @Param("isVip") Integer isVip,
|
||||
@Param("shopId") Long shopId);
|
||||
|
||||
int incrAccount(@Param("shopId") long shopId, @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);
|
||||
|
||||
ShopUserSummaryDTO selectUserSummary(@Param("shopId") Long shopId, @Param("isVip") Integer isVip);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.ShopUserFlow;
|
||||
import com.czg.account.service.ShopUserFlowService;
|
||||
import com.czg.service.account.mapper.ShopUserFlowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 用户余额流水 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-02-13
|
||||
*/
|
||||
@Service
|
||||
public class ShopUserFlowServiceImpl extends ServiceImpl<ShopUserFlowMapper, ShopUserFlow> implements ShopUserFlowService{
|
||||
|
||||
}
|
||||
@@ -1,11 +1,26 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.account.dto.shopuser.ShopUserEditDTO;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
import com.czg.account.dto.shopuser.ShopUserSummaryDTO;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.entity.ShopUserFlow;
|
||||
import com.czg.account.service.ShopUserFlowService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.account.mapper.ShopUserMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
|
||||
/**
|
||||
* 商户储值会员 服务层实现。
|
||||
*
|
||||
@@ -14,5 +29,58 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Service
|
||||
public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> implements ShopUserService {
|
||||
@Resource
|
||||
private ShopUserFlowService shopUserFlowService;
|
||||
|
||||
private ShopUser getUserInfo(Long shopUserId, Long shopId) {
|
||||
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getId, shopUserId).one();
|
||||
if (shopUser == null) {
|
||||
throw new ApiNotPrintException("用户信息不存在");
|
||||
}
|
||||
|
||||
return shopUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ShopUser> getPage(String key, Integer isVip) {
|
||||
return mapper.selectPageByKeyAndIsVip(PageUtil.buildPage(), key, isVip, StpKit.USER.getShopId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateInfo(Long shopId, ShopUserEditDTO shopUserEditDTO) {
|
||||
ShopUser shopUser = getUserInfo(shopId, shopUserEditDTO.getId());
|
||||
BeanUtil.copyProperties(shopUserEditDTO, shopUser);
|
||||
return updateById(shopUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO) {
|
||||
shopUserEditDTO.setMoney(shopUserEditDTO.getMoney().setScale(2, RoundingMode.DOWN));
|
||||
ShopUser userInfo = getUserInfo(shopId, shopUserEditDTO.getId());
|
||||
|
||||
ShopUserFlow userFlow = new ShopUserFlow();
|
||||
int flag = 0;
|
||||
if (shopUserEditDTO.getType() == 0) {
|
||||
flag = mapper.decrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
|
||||
}else {
|
||||
flag = mapper.incrAccount(shopId, shopUserEditDTO.getId(), DateUtil.date().toLocalDateTime(), shopUserEditDTO.getMoney());
|
||||
}
|
||||
if (flag == 0) {
|
||||
throw new ApiNotPrintException("增减用户余额操作失败");
|
||||
}
|
||||
|
||||
userFlow.setUserId(userInfo.getUserId());
|
||||
userFlow.setShopId(userInfo.getShopId());
|
||||
userFlow.setAmount(shopUserEditDTO.getMoney());
|
||||
userFlow.setBalance(shopUserEditDTO.getType() == 0 ? userInfo.getAmount().subtract(shopUserEditDTO.getMoney()) : userInfo.getAmount().add(shopUserEditDTO.getMoney()));
|
||||
userFlow.setBizCode(ShopUserFlowBizEnum.ADMIN_IN.getCode());
|
||||
userFlow.setType(shopUserEditDTO.getType() == 0 ? "-" : "+");
|
||||
userFlow.setRemark(shopUserEditDTO.getRemark());
|
||||
return shopUserFlowService.save(userFlow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopUserSummaryDTO getSummary(Long shopId, Integer isVip) {
|
||||
return mapper.selectUserSummary(shopId, isVip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.account.mapper.ShopUserFlowMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -3,5 +3,39 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.account.mapper.ShopUserMapper">
|
||||
<update id="incrAccount">
|
||||
update tb_shop_user
|
||||
set amount=amount + #{money},
|
||||
update_time=#{time}
|
||||
where id = #{id}
|
||||
and shop_id = #{shopId}
|
||||
</update>
|
||||
<update id="decrAccount">
|
||||
update tb_shop_user
|
||||
set amount=amount - #{money},
|
||||
update_time=#{time}
|
||||
where id = #{id}
|
||||
and shop_id = #{shopId}
|
||||
and amount - #{money} >= 0
|
||||
</update>
|
||||
|
||||
<select id="selectPageByKeyAndIsVip" resultType="com.czg.account.entity.ShopUser">
|
||||
select a.* from tb_user_info as a
|
||||
left join tb_shop_user as b on a.id=b.user_id
|
||||
where b.shop_id=#{shopId}
|
||||
<if test="key != null and key != ''">
|
||||
and (a.nick_name like %#{key}% or a.phone like %#{key}%)
|
||||
</if>
|
||||
<if test="isVip != null">
|
||||
and b.is_vip=#{isVip}
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectUserSummary" resultType="com.czg.account.dto.shopuser.ShopUserSummaryDTO">
|
||||
select count(a.id) userTotal, sum(IFNULL(a.amount, 0)) balanceTotal,sum(IFNULL(b.amount,0)) chargeTotal from tb_shop_user as a
|
||||
left join tb_shop_user_flow as b on a.id=b.user_id and b.type='+' and b.biz_code in ('cashIn', 'wechatIn', 'alipayIn')
|
||||
where a.shop_id = #{shopId}
|
||||
<if test="isVip !=null">
|
||||
and a.is_vip=#{isVip}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user