From 585f72d4f6022cd9498a9a1e4309f51821f1995a Mon Sep 17 00:00:00 2001 From: 935090232@qq.com <ak473600000> Date: Mon, 22 Mar 2021 08:25:33 +0800 Subject: [PATCH] 用户积分流水查询 --- zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxShopScoreAction.java | 51 ++++++++- /dev/null | 40 -------- zq-erp/src/test/java/com/matrix/JyyTests.java | 2 zq-erp/src/main/java/com/matrix/system/shopXcx/api/dto/ScoreFlowDto.java | 26 +++++ zq-erp/src/main/java/com/matrix/system/shopXcx/api/tools/WxShopOrderUtil.java | 2 zq-erp/src/main/java/com/matrix/system/score/entity/ScoreVipDetail.java | 2 zq-erp/src/main/resources/mybatis/mapper/score/ScoreUseRecordDao.xml | 49 ++------- zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java | 89 +++++++++++++++++ zq-erp/src/main/java/com/matrix/system/score/dao/ScoreUseRecordDao.java | 16 ++ 9 files changed, 184 insertions(+), 93 deletions(-) diff --git a/zq-erp/src/main/java/com/matrix/system/score/dao/ScoreUseRecordDao.java b/zq-erp/src/main/java/com/matrix/system/score/dao/ScoreUseRecordDao.java index 2162dc5..a2e4549 100644 --- a/zq-erp/src/main/java/com/matrix/system/score/dao/ScoreUseRecordDao.java +++ b/zq-erp/src/main/java/com/matrix/system/score/dao/ScoreUseRecordDao.java @@ -1,11 +1,12 @@ package com.matrix.system.score.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; -import java.util.List; -import java.util.Map; -import com.matrix.core.pojo.PaginationVO; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.matrix.system.score.entity.ScoreUseRecord; +import com.matrix.system.shopXcx.api.dto.ScoreFlowDto; +import com.matrix.system.shopXcx.vo.SalesOrderVo; +import org.apache.ibatis.annotations.Param; /** * @description 积分记录表 @@ -14,4 +15,11 @@ */ public interface ScoreUseRecordDao extends BaseMapper<ScoreUseRecord> { + /** + * 查询收支记录 + * @param page + * @param scoreFlowDto + * @return + */ + IPage<ScoreUseRecord> selectFlowList(Page<SalesOrderVo> page, @Param("record")ScoreFlowDto scoreFlowDto); } \ No newline at end of file diff --git a/zq-erp/src/main/java/com/matrix/system/score/entity/ScoreVipDetail.java b/zq-erp/src/main/java/com/matrix/system/score/entity/ScoreVipDetail.java index f777ee6..33ff3ca 100644 --- a/zq-erp/src/main/java/com/matrix/system/score/entity/ScoreVipDetail.java +++ b/zq-erp/src/main/java/com/matrix/system/score/entity/ScoreVipDetail.java @@ -42,7 +42,7 @@ /** * erp用户Id */ - private String vipId; + private Long vipId; /** diff --git a/zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java b/zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java index 38cfd4d..1b939fc 100644 --- a/zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java +++ b/zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java @@ -5,7 +5,12 @@ import com.matrix.biz.dao.BizUserDao; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.exception.GlobleException; +import com.matrix.core.tools.DateUtil; +import com.matrix.system.common.bean.BusParameterSettings; +import com.matrix.system.common.dao.BusParameterSettingsDao; +import com.matrix.system.common.dao.SysUsersDao; import com.matrix.system.hive.dao.SysVipInfoDao; +import com.matrix.system.score.constant.ScoreSettingConstant; import com.matrix.system.score.dao.ScoreUseRecordDao; import com.matrix.system.score.dao.ScoreVipDetailDao; import com.matrix.system.score.entity.ScoreUseRecord; @@ -14,6 +19,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Calendar; +import java.util.Date; import java.util.List; /** @@ -35,6 +42,12 @@ @Autowired SysVipInfoDao vipInfoDao; + + @Autowired + SysUsersDao sysUsersDao; + + @Autowired + BusParameterSettingsDao busParameterSettingsDao; /** * 扣除用户积分 @@ -89,7 +102,7 @@ scoreUseRecord.setCompanyId(companyId); scoreUseRecord.setScoreVipDetailId(scoreVipDetail.getId()); scoreUseRecord.setBusinessId(businessId); - scoreUseRecord.setRecNum(currentDedution); + scoreUseRecord.setRecNum(-currentDedution); scoreUseRecord.setRecType(type); scoreUseRecord.setOpenId(openId); scoreUseRecord.setVipId(vipId); @@ -102,6 +115,80 @@ if(score>0){ throw new GlobleException("积分不足"); } + } + + /** + * 新增用户积分 + * @param openId + * @param vipId + * @param oprationUserId + * @param score + * @param businessId + * @param type + */ + @Transactional(rollbackFor = Exception.class) + public void addScore(String openId, Long vipId, Long oprationUserId, Integer score, Long businessId, int type) { + Long companyId=null; + if(openId!=null){ + companyId= bizUserDao.findByOpenId(openId).getCompanyId(); + }else if(vipId!=null){ + companyId= vipInfoDao.selectById(vipId).getCompanyId(); + }else{ + throw new IllegalArgumentException("vipId,openId必须有一个"); + } + if(score<0){ + throw new IllegalArgumentException("score必须有为大于零的数"); + } + + String createBy=MatrixConstance.SYSTEM_USER; + if(oprationUserId!=null){ + createBy=sysUsersDao.selectById(oprationUserId).getSuName(); + } + + //计算过期时间 + BusParameterSettings yxqSetting = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.VALID_PERIOD_POINTS, companyId); + Calendar cal=Calendar.getInstance(); + int year = cal.get(Calendar.YEAR); + int sxYear=year+(Integer.parseInt(yxqSetting.getParamValue())-1); + Date sxys=DateUtil.stringToDate(year+"-12-31 23:59",DateUtil.DATE_FORMAT_MM ); + + ScoreVipDetail scoreVipDetail=new ScoreVipDetail(); + + scoreVipDetail.setCreateBy(createBy); + scoreVipDetail.setUpdateBy(createBy); + scoreVipDetail.setCreateTime(DateTime.now()); + scoreVipDetail.setUpdateTime(DateTime.now()); + scoreVipDetail.setState(ScoreVipDetail.SCORE_STATUS_YX); + scoreVipDetail.setRemainScore(score); + scoreVipDetail.setUsedScore(0); + scoreVipDetail.setValiditeTime(sxys); + scoreVipDetail.setOpenId(openId); + scoreVipDetail.setVipId(vipId); + scoreVipDetail.setGainTime(DateTime.now()); + scoreVipDetail.setAllScore(score); + scoreVipDetail.setType(type); + scoreVipDetail.setCompanyId(companyId); + scoreVipDetailDao.insert(scoreVipDetail); + + //新增添加记录 + ScoreUseRecord scoreUseRecord = new ScoreUseRecord(); + scoreUseRecord.setPreScore(score); + scoreUseRecord.setCreateBy(createBy); + scoreUseRecord.setUpdateBy(createBy); + scoreUseRecord.setCreateTime(DateTime.now()); + scoreUseRecord.setUpdateTime(DateTime.now()); + scoreUseRecord.setNowScore(score); + scoreUseRecord.setCompanyId(companyId); + scoreUseRecord.setScoreVipDetailId(scoreVipDetail.getId()); + scoreUseRecord.setBusinessId(businessId); + scoreUseRecord.setRecNum(score); + scoreUseRecord.setRecType(type); + scoreUseRecord.setOpenId(openId); + scoreUseRecord.setVipId(vipId); + scoreUseRecordDao.insert(scoreUseRecord); + } + + } \ No newline at end of file diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxShopScoreAction.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxShopScoreAction.java index a18df97..f6c5172 100644 --- a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxShopScoreAction.java +++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxShopScoreAction.java @@ -1,19 +1,54 @@ package com.matrix.system.shopXcx.api.action; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.CrossOrigin; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.matrix.biz.bean.BizUser; +import com.matrix.component.redis.RedisUserLoginUtils; +import com.matrix.core.pojo.AjaxResult; +import com.matrix.system.score.dao.ScoreUseRecordDao; +import com.matrix.system.score.entity.ScoreUseRecord; +import com.matrix.system.shopXcx.api.dto.ScoreFlowDto; +import com.matrix.system.shopXcx.vo.SalesOrderVo; +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.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.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 + RedisUserLoginUtils redisUserLoginUtils; - + @Autowired + ScoreUseRecordDao scoreUseRecordDao; + + @ApiOperation(value = "获取积分流水", notes = "") + @PostMapping(value = "/getOrderList") + @ApiResponses({ + @ApiResponse(code = 200, message = "ok", response = ScoreUseRecord.class) + }) + AjaxResult getInvitationuserList(@RequestBody @Validated ScoreFlowDto scoreFlowDto) { + BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); + Page<SalesOrderVo> page=new Page<>(scoreFlowDto.getPageNum(),scoreFlowDto.getPageSize()); + scoreFlowDto.setUserId(loginUser.getOpenId()); + IPage<ScoreUseRecord> shopScoreRecord = scoreUseRecordDao.selectFlowList(page, scoreFlowDto); + AjaxResult result=AjaxResult.buildSuccessInstance(shopScoreRecord.getRecords()); + return result; + } + + + } \ No newline at end of file diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/dto/ScoreFlowDto.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/dto/ScoreFlowDto.java new file mode 100644 index 0000000..b1a94b3 --- /dev/null +++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/dto/ScoreFlowDto.java @@ -0,0 +1,26 @@ +package com.matrix.system.shopXcx.api.dto; + +import com.matrix.core.pojo.BasePageQueryDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Data +@ApiModel(value = "ScoreFlowDto", description = "积分流水查询参数接收类") +public class ScoreFlowDto extends BasePageQueryDto { + + @NotNull(message = "查询月份不能为空") + @ApiModelProperty(value = "查询月份",example = "2021-03") + private String queryTime; + + + @ApiModelProperty(value = "收支类型 不传全部,1,收入,2支出", example = "1") + private Integer revenueType; + + @ApiModelProperty(hidden = true) + private String userId; + + +} diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/tools/WxShopOrderUtil.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/tools/WxShopOrderUtil.java index e0b6c40..283da6a 100644 --- a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/tools/WxShopOrderUtil.java +++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/tools/WxShopOrderUtil.java @@ -46,8 +46,6 @@ private WxShopMemberDayService wxShopMemberDayService; @Autowired private BizUserService bizUserService; - @Autowired - private ShopScoreRecordDao shopScoreRecordDao; private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日"); diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/bean/ShopScoreRecord.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/bean/ShopScoreRecord.java deleted file mode 100644 index 59de19f..0000000 --- a/zq-erp/src/main/java/com/matrix/system/shopXcx/bean/ShopScoreRecord.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.matrix.system.shopXcx.bean; - -import com.matrix.core.pojo.EntityDTO; -import com.matrix.core.anotations.Extend; -import com.matrix.core.tools.DateUtil; - -import java.math.BigDecimal; - -/** - * @description 用户积分获取记录 - * @author jyy - * @date 2019-08-09 15:10 - */ -public class ShopScoreRecord extends EntityDTO{ - @Extend - private static final long serialVersionUID = 1L; - - - /** - * 主键 - */ - private Integer id; - - - /** - * 受益人openID - */ - private String beneficiaryId; - - - /** - * 购买人openID - */ - private String buyerId; - - - /** - * 购买人名称 - */ - private String buyerName; - - - /** - * 购买人头像地址 - */ - private String buyerAvatarUrl; - - - /** - * 订单ID - */ - private Integer orderId; - - - /** - * 订单金额 - */ - private BigDecimal amount; - - - /** - * 获得积分 - */ - private Integer score; - - - /** - * 创建时间格式化成字符串 - */ - @Extend - private String createTimeStr; - - - public String getCreateTimeStr() { - if (this.getCreateTime() == null) { - return ""; - } - return DateUtil.dateToString(this.getCreateTime(), DateUtil.DATE_FORMAT_DD); - } - - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id=id; - } - - - public String getBeneficiaryId() { - return beneficiaryId; - } - - public void setBeneficiaryId(String beneficiaryId) { - this.beneficiaryId=beneficiaryId; - } - - - public String getBuyerId() { - return buyerId; - } - - public void setBuyerId(String buyerId) { - this.buyerId=buyerId; - } - - - public String getBuyerName() { - return buyerName; - } - - public void setBuyerName(String buyerName) { - this.buyerName=buyerName; - } - - - public String getBuyerAvatarUrl() { - return buyerAvatarUrl; - } - - public void setBuyerAvatarUrl(String buyerAvatarUrl) { - this.buyerAvatarUrl = buyerAvatarUrl; - } - - public Integer getOrderId() { - return orderId; - } - - public void setOrderId(Integer orderId) { - this.orderId=orderId; - } - - - public BigDecimal getAmount() { - return amount; - } - - public void setAmount(BigDecimal amount) { - this.amount=amount; - } - - - public Integer getScore() { - return score; - } - - public void setScore(Integer score) { - this.score=score; - } - - - - -} \ No newline at end of file diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/dao/ShopScoreRecordDao.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/dao/ShopScoreRecordDao.java deleted file mode 100644 index 9475abe..0000000 --- a/zq-erp/src/main/java/com/matrix/system/shopXcx/dao/ShopScoreRecordDao.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.matrix.system.shopXcx.dao; - -import org.apache.ibatis.annotations.Param; -import java.util.List; -import java.util.Map; -import com.matrix.core.pojo.PaginationVO; -import com.matrix.system.shopXcx.bean.ShopScoreRecord; - -/** - * @description 用户积分获取记录 - * @author jyy - * @date 2019-08-09 15:10 - */ -public interface ShopScoreRecordDao{ - - public int insert(@Param("item") ShopScoreRecord shopScoreRecord); - - public int batchInsert(@Param("list") List<ShopScoreRecord> shopScoreRecordList); - - public int updateByMap(Map<String, Object> modifyMap); - - public int updateByModel(@Param("record") ShopScoreRecord shopScoreRecord); - - public int deleteByIds(@Param("list") List<String> list); - - public int deleteById(Integer id); - - public int deleteByModel(@Param("record") ShopScoreRecord shopScoreRecord); - - public List<ShopScoreRecord> selectInPage(@Param("record") ShopScoreRecord shopScoreRecord, @Param("pageVo") PaginationVO pageVo); - - public List<ShopScoreRecord> selectByModel(@Param("record") ShopScoreRecord shopScoreRecord); - - public int selectTotalRecord(@Param("record") ShopScoreRecord shopScoreRecord); - - public ShopScoreRecord selectById(Integer id); - - public ShopScoreRecord selectForUpdate(Integer id); - -} \ No newline at end of file diff --git a/zq-erp/src/main/resources/mybatis/mapper/score/ScoreUseRecordDao.xml b/zq-erp/src/main/resources/mybatis/mapper/score/ScoreUseRecordDao.xml index ca3b694..ab3d85e 100644 --- a/zq-erp/src/main/resources/mybatis/mapper/score/ScoreUseRecordDao.xml +++ b/zq-erp/src/main/resources/mybatis/mapper/score/ScoreUseRecordDao.xml @@ -3,41 +3,18 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.matrix.system.score.dao.ScoreUseRecordDao"> - <!-- 定义ScoreUseRecord 的复杂关联map --> - <resultMap type="com.matrix.system.score.entity.ScoreUseRecord" id="ScoreUseRecordMap"> - <id property="id" column="id" /> - <result property="createBy" column="create_by" /> - <result property="createTime" column="create_time" /> - <result property="updateBy" column="update_by" /> - <result property="updateTime" column="update_time" /> - <result property="recType" column="rec_type" /> - <result property="recNum" column="rec_num" /> - <result property="businessId" column="business_id" /> - <result property="scoreVipDetailId" column="score_vip_detail_id" /> - <result property="preScore" column="pre_score" /> - <result property="nowScore" column="now_score" /> - <result property="userId" column="user_id" /> - <result property="remarks" column="remarks" /> - <result property="companyId" column="company_id" /> - </resultMap> - - - <!-- 定义ScoreUseRecord 的简单map ,本map不添加其他的关联属性 --> - <resultMap type="com.matrix.system.score.entity.ScoreUseRecord" id="ScoreUseRecordSimpleMap"> - <id property="id" column="id" /> - <result property="createBy" column="create_by" /> - <result property="createTime" column="create_time" /> - <result property="updateBy" column="update_by" /> - <result property="updateTime" column="update_time" /> - <result property="recType" column="rec_type" /> - <result property="recNum" column="rec_num" /> - <result property="businessId" column="business_id" /> - <result property="scoreVipDetailId" column="score_vip_detail_id" /> - <result property="preScore" column="pre_score" /> - <result property="nowScore" column="now_score" /> - <result property="userId" column="user_id" /> - <result property="remarks" column="remarks" /> - <result property="companyId" column="company_id" /> - </resultMap> + + <select id="selectFlowList" resultType="com.matrix.system.score.entity.ScoreUseRecord"> + select * from score_use_record + where open_id=#{record.userId} + and DATE_FORMAT(create_time,'%Y-%m')=#{record.queryTime} + <if test="record.revenueType==1"> + and rec_num>0 + </if> + <if test="record.revenueType==2"> + <![CDATA[ and rec_num<0 ]]> + </if> + order by create_time desc + </select> </mapper> \ No newline at end of file diff --git a/zq-erp/src/test/java/com/matrix/JyyTests.java b/zq-erp/src/test/java/com/matrix/JyyTests.java index ced21db..f199835 100644 --- a/zq-erp/src/test/java/com/matrix/JyyTests.java +++ b/zq-erp/src/test/java/com/matrix/JyyTests.java @@ -32,7 +32,7 @@ @Test public void scoreVipDetailService() throws InterruptedException { - scoreVipDetailService.deductionScore("oJkRK4yelehsY4S7I6Ee1ydWtQMI",null,15,1L,1); + scoreVipDetailService.addScore("oJkRK4yelehsY4S7I6Ee1ydWtQMI",null,null,15,1L,1); } /** -- Gitblit v1.9.1