xiaoyong931011
2021-04-12 a13a93a493e7e94e28b2225c26e7e13b52d3288c
zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxShopScoreAction.java
@@ -1,104 +1,67 @@
package com.matrix.system.shopXcx.api.action;
import com.matrix.biz.bean.BizUser;
import com.matrix.biz.service.BizUserService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.matrix.system.hive.bean.SysVipInfo;
import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.system.shopXcx.bean.ShopScoreExchange;
import com.matrix.system.shopXcx.bean.ShopScoreRecord;
import com.matrix.system.shopXcx.dao.ShopScoreExchangeDao;
import com.matrix.system.shopXcx.dao.ShopScoreRecordDao;
import com.matrix.system.score.dao.ScoreUseRecordDao;
import com.matrix.system.score.dao.ScoreVipDetailDao;
import com.matrix.system.shopXcx.api.dto.ScoreFlowDto;
import com.matrix.system.shopXcx.api.vo.ScoreUseRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import org.springframework.web.bind.annotation.RestController;
/**
 * @description 用户积分控制器
 * @author jyy
 * @date 2019-08-09 15:10
 * @date 2021-03-22 15:10
 */
@Controller
@RequestMapping(value="/wxapi/shopScoreRecord")
@CrossOrigin(origins = "*", maxAge = 3600)
@Api(tags = "用户积分接口类")
@RestController
@RequestMapping(value = "/wxapi/score")
public class WxShopScoreAction {
   @Autowired
   private ShopScoreRecordDao shopScoreRecordDao;
   @Autowired
   private ShopScoreExchangeDao shopScoreExchangeDao;
   @Autowired
   private RedisUserLoginUtils redisUserLoginUtils;
   @Autowired
   private BizUserService bizUserService;
    @Autowired
    RedisUserLoginUtils redisUserLoginUtils;
    @Autowired
    ScoreUseRecordDao scoreUseRecordDao;
    @Autowired
    ScoreVipDetailDao scoreVipDetailDao;
    @ApiOperation(value = "获取积分流水", notes = "")
    @PostMapping(value = "/getFlowList")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = ScoreUseRecordVo.class)
    })
    AjaxResult getFlowList(@RequestBody @Validated ScoreFlowDto scoreFlowDto) {
        SysVipInfo loginUser = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
        Page<ScoreUseRecordVo> page=new Page<>(scoreFlowDto.getPageNum(),scoreFlowDto.getPageSize());
        scoreFlowDto.setVipId(loginUser.getId());
        IPage<ScoreUseRecordVo> shopScoreRecord = scoreUseRecordDao.selectFlowList(page,  scoreFlowDto);
        AjaxResult result=AjaxResult.buildSuccessInstance(shopScoreRecord.getRecords());
        return result;
    }
    @ApiOperation(value = "获取用户积分", notes = "")
    @PostMapping(value = "/getUserScore")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = AjaxResult.class)
    })
    AjaxResult getUserScore() {
        SysVipInfo loginUser = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
        AjaxResult result=AjaxResult.buildSuccessInstance(scoreVipDetailDao.selectUserTotalScore(loginUser.getId()));
        return result;
    }
   /**
    * 查询我的获得积分列表
    * @return
    */
   @RequestMapping(value = "/getRecordList")
   @ResponseBody
   public AjaxResult getRecordList(@RequestBody PaginationVO pageVo) {
      pageVo.setSort("create_time");
      pageVo.setOrder("desc");
      BizUser loginBizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
      ShopScoreRecord params = new ShopScoreRecord();
      params.setBeneficiaryId(loginBizUser.getOpenId());
      List<ShopScoreRecord> dataList = shopScoreRecordDao.selectInPage(params, pageVo);
      int total = shopScoreRecordDao.selectTotalRecord(params);
      AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, total);
      //查询用户总积分
      BizUser user = bizUserService.findById(loginBizUser.getUserId());
      Integer totalScore = 0;
      if (user != null && user.getTotalScore() != null) {
         totalScore = user.getTotalScore();
      }
      result.putInMap("totalScore", totalScore);
      //查询下级总人数
      BizUser peopleSumParams = new BizUser();
      peopleSumParams.setParentOpenId(loginBizUser.getOpenId());
      int peopleSum = bizUserService.findTotal(peopleSumParams);
      result.putInMap("peopleSum", peopleSum);
      return result;
   }
   /**
    * 查询我的积分兑换列表
    * @return
    */
   @RequestMapping(value = "/getChangeRecordList")
   @ResponseBody
   public AjaxResult getChangeRecordList(@RequestBody PaginationVO pageVo) {
      //不分页
      pageVo.setOffset(null);
      pageVo.setLimit(null);
      //按生成时间倒序排列
      pageVo.setSort("create_time");
      pageVo.setOrder("desc");
      BizUser loginBizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
      ShopScoreExchange params = new ShopScoreExchange();
      params.setUserId(loginBizUser.getOpenId());
      List<ShopScoreExchange> dataList = shopScoreExchangeDao.selectInPage(params, pageVo);
      int total = shopScoreExchangeDao.selectTotalRecord(params);
      AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, total);
      //查询用户当前积分
      BizUser user = bizUserService.findById(loginBizUser.getUserId());
      Integer currentScore = 0;
      if (user != null && user.getCurrentScore() != null) {
         currentScore = user.getCurrentScore();
      }
      result.putInMap("currentScore", currentScore);
      return result;
   }
}