New file |
| | |
| | | package com.ruoyi.account.controller; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.account.api.model.UserPoint; |
| | | import com.ruoyi.account.api.model.UserPointCopy; |
| | | import com.ruoyi.account.mapper.UserPointCopyMapper; |
| | | import com.ruoyi.account.service.AppUserService; |
| | | import com.ruoyi.account.service.UserPointService; |
| | | import com.ruoyi.account.vo.TransferPoint; |
| | | import com.ruoyi.account.vo.UserPointDetailVO; |
| | | import com.ruoyi.account.vo.UserPointStatistics; |
| | | import com.ruoyi.account.vo.UserPointVO; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.core.web.controller.BaseController; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.core.web.page.TableDataInfo; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.order.feignClient.OrderClient; |
| | | import com.ruoyi.order.model.Order; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.YearMonth; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * 前端控制器 |
| | | * </p> |
| | | * |
| | | * @author luodangjia |
| | | * @since 2024-11-21 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/user-point") |
| | | @Api(tags = "个人积分") |
| | | public class UserPointController extends BaseController { |
| | | @Resource |
| | | private UserPointService userPointService; |
| | | @Resource |
| | | private UserPointCopyMapper userPointCopyMapper; |
| | | @Resource |
| | | private OrderClient orderClient; |
| | | |
| | | |
| | | /** |
| | | * 获取个人积分 |
| | | */ |
| | | @GetMapping("/getUserPoint") |
| | | @ApiOperation("获取个人积分") |
| | | public R<UserPointVO> getUserPoint() { |
| | | return R.ok(userPointService.getUserPoint(SecurityUtils.getUserId())); |
| | | } |
| | | |
| | | /** |
| | | * 获取变更明细 |
| | | */ |
| | | @GetMapping("/getUserPointDetail") |
| | | @ApiOperation("获取变更明细") |
| | | public R<PageInfo<UserPointDetailVO>> getUserPointDetail(@ApiParam("指定日期") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date, |
| | | @ApiParam("变动类型(1=消费积分,2=返佣积分,3=拉新人积分,4=兑换商品 " + |
| | | "5 = 门店业绩积分 6 =门店返佣积分7=技师业绩积分8 =转赠积分 9 =做工积分 " + |
| | | "10 =注册积分)") Integer type, Integer pageCurr, Integer pageSize) { |
| | | LocalDateTime startTime = null; |
| | | LocalDateTime endTime = null; |
| | | if (date != null) { |
| | | // 将 createTime 设置为当天的开始时间 (00:00) |
| | | startTime = date.atStartOfDay(); |
| | | |
| | | // 使用 YearMonth 来获取该月的最后一天 |
| | | YearMonth yearMonth = YearMonth.from(date); |
| | | LocalDate lastDayOfMonth = yearMonth.atEndOfMonth(); |
| | | |
| | | // 将最后一天转换为 LocalDateTime,并设置为当天的最后一秒 (23:59:59.999) |
| | | endTime = lastDayOfMonth.atTime(LocalTime.MAX); |
| | | } |
| | | |
| | | PageInfo<UserPointDetailVO> userPointDetail = userPointService.getUserPointDetail(SecurityUtils.getUserId(), startTime, endTime, type, pageCurr, pageSize); |
| | | return R.ok(userPointDetail); |
| | | } |
| | | |
| | | /** |
| | | * 转赠积分 |
| | | */ |
| | | @PostMapping("/transferPoint") |
| | | @ApiOperation("转赠积分") |
| | | public R<Void> transferPoint(@RequestBody TransferPoint transferPoint) { |
| | | return userPointService.transferPoint(transferPoint.getPoint(), transferPoint.getPhone()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 保存积分流水记录 |
| | | * |
| | | * @param userPoint |
| | | * @return |
| | | */ |
| | | @PostMapping("/saveUserPoint") |
| | | public R saveUserPoint(@RequestBody UserPoint userPoint) { |
| | | userPointService.save(userPoint); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("/saveUserPointCopy") |
| | | public R saveUserPointCopy(@RequestBody UserPointCopy userPointCopy) { |
| | | userPointCopyMapper.insert(userPointCopy); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @DeleteMapping("/deleteUserPointCopy") |
| | | public R deleteUserPointCopy(@RequestParam("orderId") Long orderId, @RequestParam("type") List<Integer> type) { |
| | | userPointCopyMapper.delete(new LambdaQueryWrapper<UserPointCopy>().in(UserPointCopy::getType, type) |
| | | .eq(UserPointCopy::getObjectId, orderId)); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | @DeleteMapping("/deleteUserPointCopyByIds") |
| | | public R deleteUserPointCopyByIds(@RequestParam("ids") List<Long> ids){ |
| | | userPointCopyMapper.deleteBatchIds(ids); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/getUserPointCopy") |
| | | public R<List<UserPointCopy>> getUserPointCopy(@RequestParam("orderId") Long orderId, @RequestParam("type") List<Integer> type) { |
| | | List<UserPointCopy> list = userPointCopyMapper.selectList(new LambdaQueryWrapper<UserPointCopy>().in(UserPointCopy::getType, type) |
| | | .eq(UserPointCopy::getObjectId, orderId)); |
| | | return R.ok(list); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 积分统计 |
| | | */ |
| | | @GetMapping("/statistics") |
| | | @ApiOperation(value = "积分统计", tags = "管理后台-财务统计-用户积分统计") |
| | | public R<UserPointStatistics> statistics(UserPoint userPoint) { |
| | | return R.ok(userPointService.getStatistics(userPoint)); |
| | | } |
| | | |
| | | /** |
| | | * 变更记录 |
| | | */ |
| | | @GetMapping("/list") |
| | | @ApiOperation(value = "积分变更记录", tags = "管理后台-财务统计-用户积分统计") |
| | | public R<IPage<UserPoint>> list(UserPoint userPoint) { |
| | | IPage<UserPoint> userPointPage = userPointService.getUserPointPage(Page.of(userPoint.getPageNum(), userPoint.getPageSize()), userPoint); |
| | | return R.ok(userPointPage); |
| | | } |
| | | |
| | | @GetMapping("/user/list") |
| | | @ApiOperation(value = "积分管理-用户积分明细(必传用户id)", tags = "后台") |
| | | public R<IPage<UserPoint>> userlist(UserPoint userPoint) { |
| | | IPage<UserPoint> page = userPointService.getUserPointPage(Page.of(userPoint.getPageNum(), userPoint.getPageSize()), userPoint); |
| | | for (UserPoint record : page.getRecords()) { |
| | | if (record.getType()==1 || record.getType()==11){ |
| | | Order data = orderClient.getOrderById(record.getObjectId()).getData(); |
| | | if (data!=null){ |
| | | record.setExtention(data.getOrderNumber()); |
| | | } |
| | | } |
| | | if (record.getChangeDirection() == -1){ |
| | | record.setVariableType(2); |
| | | }else{ |
| | | record.setVariableType(1); |
| | | } |
| | | } |
| | | return R.ok(page); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 导出 |
| | | */ |
| | | @GetMapping("/export") |
| | | @ApiOperation(value = "积分变更记录导出", tags = "管理后台-财务统计-用户积分统计") |
| | | public void export(HttpServletResponse response, UserPoint userPoint) { |
| | | IPage<UserPoint> userPointPage = userPointService.getUserPointPage(Page.of(1, Integer.MAX_VALUE), userPoint); |
| | | List<UserPoint> userPointList = userPointPage.getRecords(); |
| | | ExcelUtil<UserPoint> util = new ExcelUtil<>(UserPoint.class); |
| | | util.exportExcel(response, userPointList, "用户积分统计"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取积分变动记录 |
| | | * @param userPoint |
| | | * @return |
| | | */ |
| | | @PostMapping("/getUserPointList") |
| | | public R<List<UserPoint>> getUserPointList(@RequestBody UserPoint userPoint){ |
| | | LambdaQueryWrapper<UserPoint> queryWrapper = new LambdaQueryWrapper<>(); |
| | | if(null != userPoint.getType()){ |
| | | queryWrapper.eq(UserPoint::getType, userPoint.getType()); |
| | | } |
| | | if(null != userPoint.getObjectId()){ |
| | | queryWrapper.eq(UserPoint::getObjectId, userPoint.getObjectId()); |
| | | } |
| | | if(null != userPoint.getAppUserId()){ |
| | | queryWrapper.eq(UserPoint::getAppUserId, userPoint.getAppUserId()); |
| | | } |
| | | List<UserPoint> list = userPointService.list(queryWrapper); |
| | | return R.ok(list); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 判断当天是否分享获得过积分 |
| | | * @param appUserId |
| | | * @return |
| | | */ |
| | | @PostMapping("/judgmentDailyShare") |
| | | public R<Boolean> judgmentDailyShare(@RequestParam("appUserId") Long appUserId){ |
| | | long count = userPointService.count(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUserId) |
| | | .eq(UserPoint::getType, 4).last(" and DATE_FORMAT(NOW(), '%Y-%m-%d') = DATE_FORMAT(create_time, '%Y-%m-%d')")); |
| | | return R.ok(count != 0); |
| | | } |
| | | } |
| | | |