From d08ec8845a4c2663b3502cd83872964b07d7d589 Mon Sep 17 00:00:00 2001
From: jyy <935090232@qq.com>
Date: Mon, 22 Mar 2021 11:14:52 +0800
Subject: [PATCH] 积分商城11
---
zq-erp/src/main/java/com/matrix/system/score/dao/ScoreVipDetailDao.java | 5
zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxCommonAction.java | 5 -
zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/ScoreOrderTask.java | 77 +++++++++++++++++++
zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/SalesOrderRefundTask.java | 18 ++++
zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/MQTaskRouting.java | 1
zq-erp/src/main/java/com/matrix/config/RabbitMqConfig.java | 6 +
zq-erp/src/main/java/com/matrix/system/score/service/ScoreVipDetailService.java | 53 ++++++++++--
zq-erp/src/main/resources/templates/views/admin/shop/shopProduct-form.html | 36 +++++++++
8 files changed, 184 insertions(+), 17 deletions(-)
diff --git a/zq-erp/src/main/java/com/matrix/config/RabbitMqConfig.java b/zq-erp/src/main/java/com/matrix/config/RabbitMqConfig.java
index 11f480b..0993a3f 100644
--- a/zq-erp/src/main/java/com/matrix/config/RabbitMqConfig.java
+++ b/zq-erp/src/main/java/com/matrix/config/RabbitMqConfig.java
@@ -39,6 +39,11 @@
public static final String MQ_EXCHANGE_TOPIC = "hive_exchange_fanout";
@Bean
+ ScoreOrderTask ScoreOrderTask() {
+ return new ScoreOrderTask();
+ }
+
+ @Bean
VipCreateTask VipCreateTask() {
return new VipCreateTask();
}
@@ -96,6 +101,7 @@
//不同任务在不同的队列,但是routingKey一样则可以收到生产者消息
taskList.add(new MqTask(MQ_EXCHANGE_TOPIC + evn, MQTaskRouting.CREATE_ORDER + evn,MQTaskRouting.CREATE_ORDER + evn,SalesOrderTask()));
taskList.add(new MqTask(MQ_EXCHANGE_TOPIC + evn, MQTaskRouting.SALES_ORDER + evn,MQTaskRouting.CREATE_ORDER + evn,OrderrCreateTask()));
+ taskList.add(new MqTask(MQ_EXCHANGE_TOPIC + evn, MQTaskRouting.SCORE_ORDER + evn,MQTaskRouting.CREATE_ORDER + evn,ScoreOrderTask()));
rabiitMqTemplate.binding(taskList);
diff --git a/zq-erp/src/main/java/com/matrix/system/score/dao/ScoreVipDetailDao.java b/zq-erp/src/main/java/com/matrix/system/score/dao/ScoreVipDetailDao.java
index ec22abe..1f0ed56 100644
--- a/zq-erp/src/main/java/com/matrix/system/score/dao/ScoreVipDetailDao.java
+++ b/zq-erp/src/main/java/com/matrix/system/score/dao/ScoreVipDetailDao.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.matrix.system.score.entity.ScoreVipDetail;
+import org.apache.ibatis.annotations.Param;
import java.util.List;
@@ -18,12 +19,12 @@
* @param vipId
* @return
*/
- int selectUserTotalScore(String openId, Long vipId);
+ int selectUserTotalScore(@Param("openId") String openId, @Param("openId")Long vipId);
/**
* 查询用户有效的积分,按时间顺序排
* @param
* @return
*/
- List<ScoreVipDetail> selectEffectiveScore(String openId, Long vipId);
+ List<ScoreVipDetail> selectEffectiveScore(@Param("openId") String openId, @Param("openId")Long vipId);
}
\ No newline at end of file
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 3faa9fb..0c44570 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
@@ -1,6 +1,7 @@
package com.matrix.system.score.service;
import cn.hutool.core.date.DateTime;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.matrix.biz.dao.BizUserDao;
import com.matrix.core.constance.MatrixConstance;
@@ -51,11 +52,6 @@
/**
* 扣除用户积分
- *
- * @param openId
- * @param score
- * @param businessId
- * @param type
*/
@Transactional(rollbackFor = Exception.class)
public void deductionScore(String openId, Long vipId,Long shopId, Integer score, Long businessId, int type) {
@@ -120,12 +116,6 @@
/**
* 新增用户积分
- * @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,Long shopId, Integer score, Long businessId, int type) {
@@ -193,5 +183,46 @@
}
+ /**
+ * 退积分
+ */
+ public void refundScore(String openId, Long vipId, Integer score, Long oldBusinessId, 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必须有为大于零的数");
+ }
+
+ //查询原始使用记录
+ QueryWrapper queryWrapper=new QueryWrapper();
+ queryWrapper.eq("business_id",oldBusinessId);
+ queryWrapper.eq("company_id",companyId);
+ queryWrapper.eq("type",type);
+ List<ScoreUseRecord> scoreUseRecordList = scoreUseRecordDao.selectList(queryWrapper);
+ scoreUseRecordList.forEach(scoreUseRecord -> {
+ ScoreVipDetail scoreVipDetail = scoreVipDetailDao.selectById(scoreUseRecord.getScoreVipDetailId());
+ if(scoreVipDetail!=null){
+ if(DateTime.now().isAfter(scoreVipDetail.getValiditeTime())){
+ //积分还有效
+ scoreVipDetail.setRemainScore( scoreVipDetail.getRemainScore()+score);
+ scoreVipDetail.setUsedScore(scoreVipDetail.getUsedScore()-score);
+ scoreVipDetail.setState(ScoreVipDetail.SCORE_STATUS_YX);
+ scoreVipDetailDao.updateById(scoreVipDetail);
+ scoreUseRecordDao.deleteById(scoreUseRecord.getId());
+ }
+ }
+
+ });
+ }
+
+ public static void main(String[] args) {
+ System.out.println(DateTime.now().isAfter(DateTime.of("2020-11-11 23:22","yyyy-MM-dd HH:mm")));
+ }
}
\ No newline at end of file
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxCommonAction.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxCommonAction.java
index 88c4948..d5423a3 100644
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxCommonAction.java
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxCommonAction.java
@@ -200,10 +200,7 @@
// 根据订单类型创建不同的处理任务
rabiitMqTemplate.sendTopicMsg(RabbitMqConfig.MQ_EXCHANGE_TOPIC +evn, MQTaskRouting.CREATE_ORDER+evn, orderId);
- //扣除积分
- if(order.getScorePay()!=null){
- scoreVipDetailService.deductionScore(order.getUserId(),null,Long.parseLong(order.getStoreId()+""),order.getScorePay(),Long.parseLong(order.getId()+""), ScoreVipDetail.SCORE_VIP_TYPE_CASH);
- }
+
threadResult.putInMap("status", "success");
resXml = AppConstance.RESULT_XML_SUCCESS;
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/MQTaskRouting.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/MQTaskRouting.java
index 2b548ed..8bd67c4 100644
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/MQTaskRouting.java
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/MQTaskRouting.java
@@ -9,6 +9,7 @@
String CREATE_ORDER = "CREATE_ORDER";
String SALES_ORDER = "SALES_ORDER";
+ String SCORE_ORDER = "SCORE_ORDER";
/**
* 发送微信消息
*/
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/SalesOrderRefundTask.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/SalesOrderRefundTask.java
index 2b56f6b..3077d78 100644
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/SalesOrderRefundTask.java
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/SalesOrderRefundTask.java
@@ -5,6 +5,10 @@
import com.matrix.core.tools.LogUtil;
import com.matrix.system.fenxiao.dao.ShopSalesmanOrderDao;
import com.matrix.system.fenxiao.entity.ShopSalesmanOrder;
+import com.matrix.system.score.entity.ScoreVipDetail;
+import com.matrix.system.score.service.ScoreVipDetailService;
+import com.matrix.system.shopXcx.bean.ShopOrder;
+import com.matrix.system.shopXcx.dao.ShopOrderDao;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.Delivery;
import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +26,12 @@
@Autowired
private ShopSalesmanOrderDao shopSalesmanOrderDao;
+ @Autowired
+ private ShopOrderDao shopOrderDao;
+
+ @Autowired
+ private ScoreVipDetailService scoreVipDetailService;
+
@Override
@@ -38,6 +48,14 @@
}else{
LogUtil.debug("改订单为生成分销订单={}", orderId);
}
+ ShopOrder order=shopOrderDao.selectById(Integer.parseInt(orderId));
+
+ if(order.getScorePay()!=null && order.getScorePay()>0){
+ LogUtil.debug("处理积分退款={}", orderId);
+ scoreVipDetailService.refundScore(order.getUserId(),null,order.getScorePay(),Long.parseLong(order.getId()+""), ScoreVipDetail.SCORE_VIP_TYPE_CASH);
+ }
+
+
}
}
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/ScoreOrderTask.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/ScoreOrderTask.java
new file mode 100644
index 0000000..439b741
--- /dev/null
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/ScoreOrderTask.java
@@ -0,0 +1,77 @@
+package com.matrix.system.shopXcx.mqTask;
+
+
+import com.matrix.biz.service.BizUserService;
+import com.matrix.core.tools.LogUtil;
+import com.matrix.system.score.entity.ScoreVipDetail;
+import com.matrix.system.score.service.ScoreVipDetailService;
+import com.matrix.system.shopXcx.bean.ShopOrder;
+import com.matrix.system.shopXcx.bean.ShopOrderDetails;
+import com.matrix.system.shopXcx.dao.ShopOrderDao;
+import com.matrix.system.shopXcx.dao.ShopOrderDetailsDao;
+import com.rabbitmq.client.DeliverCallback;
+import com.rabbitmq.client.Delivery;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * 订单创建积分事件处理
+ */
+@Component
+public class ScoreOrderTask implements DeliverCallback {
+
+
+ @Autowired
+ ShopOrderDao shopOrderDao;
+ @Autowired
+ ShopOrderDetailsDao shopOrderDetailsDao;
+
+ @Autowired
+ BizUserService bizUserService;
+
+ @Autowired
+ ScoreVipDetailService scoreVipDetailService;
+
+
+
+ @Override
+ public void handle(String consumerTag, Delivery message) throws IOException {
+
+ String orderId = new String(message.getBody(), "UTF-8");
+ LogUtil.debug("收到订单积分任务orderId={}", orderId);
+ //获取订单信息
+ ShopOrder order = shopOrderDao.selectById(Integer.valueOf(orderId));
+ //获取订单详情
+ List<ShopOrderDetails> orderDetails = shopOrderDetailsDao.selectByOrderId(Integer.valueOf(orderId));
+ order.setDetails(orderDetails);
+ //扣除积分
+ if(order.getScorePay()!=null){
+ scoreVipDetailService.deductionScore(order.getUserId(),null,Long.parseLong(order.getStoreId()+""),order.getScorePay(),Long.parseLong(order.getId()+""), ScoreVipDetail.SCORE_VIP_TYPE_CASH);
+ }
+ //消费获得积分
+ orderDetails.forEach(shopOrderDetail -> {
+ int addScore=0;
+ if(shopOrderDetail.getPayType()==ShopOrderDetails.PAYTYPE_MICRO){
+ Integer xfkdScore= shopOrderDetail.getShopSku().getScore();
+ if(xfkdScore!=null && xfkdScore>0){
+ addScore+=xfkdScore;
+ }
+ }
+ if(addScore>0){
+ //插入新的积分
+ scoreVipDetailService.addScore(
+ order.getUserId(),null,
+ null,
+ Long.parseLong(order.getStoreId()+""),
+ addScore,
+ Long.parseLong(orderId+""),
+ ScoreVipDetail.SCORE_VIP_TYPE_CASH);
+ }
+ });
+
+ }
+
+}
diff --git a/zq-erp/src/main/resources/templates/views/admin/shop/shopProduct-form.html b/zq-erp/src/main/resources/templates/views/admin/shop/shopProduct-form.html
index 8c49a16..fe12dac 100644
--- a/zq-erp/src/main/resources/templates/views/admin/shop/shopProduct-form.html
+++ b/zq-erp/src/main/resources/templates/views/admin/shop/shopProduct-form.html
@@ -825,6 +825,11 @@
/*验证sku表格中的参数*/
function getSkusValues() {
+
+ var ableScorePay=$("#ableScorePay").val();
+ var ableSales=$("#ableSales").val();
+
+
var flag = false;
var reg = new RegExp("(^[1-9]([0-9]+)?(\\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\\.[0-9]([0-9])?$)");
$("#skutable tbody").find("tr").each(function(i) {
@@ -832,6 +837,37 @@
if (i != 0) {
var tds = $(this).find("td");
var length = tds.length - 1;
+
+ if(ableSales==1){
+ //推广提成
+ var sealesPrice = tds.eq(length - 4).find("input").val();
+ //邀请提成
+ var invitationPrice = tds.eq(length - 3).find("input").val();
+ if(sealesPrice == ""||invitationPrice==""){
+ layer.msg("请填写推广提成和邀请提成",{
+ icon : 2,
+ time : 2000
+ });
+ flag = true;
+ return false;
+ }
+ }
+
+ if(ableScorePay==1){
+ //兑换所需金额
+ var scorePrice = tds.eq(length - 2).find("input").val();
+ //兑换所需积分
+ var scoreCount = tds.eq(length - 1).find("input").val();
+ if(scorePrice == ""||scoreCount==""){
+ layer.msg("请填写兑换所需金额和积分",{
+ icon : 2,
+ time : 2000
+ });
+ flag = true;
+ return false;
+ }
+ }
+
var name = tds.eq(length - 11).find("input").val();
if(name == ""){
layer.msg("请填写规格名称",{
--
Gitblit v1.9.1