1 files added
7 files modified
| | |
| | | public static final String MQ_EXCHANGE_TOPIC = "hive_exchange_fanout"; |
| | | |
| | | @Bean |
| | | ScoreOrderTask ScoreOrderTask() { |
| | | return new ScoreOrderTask(); |
| | | } |
| | | |
| | | @Bean |
| | | VipCreateTask VipCreateTask() { |
| | | return new VipCreateTask(); |
| | | } |
| | |
| | | //不同任务在不同的队列,但是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); |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.matrix.system.score.entity.ScoreVipDetail; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | * @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); |
| | | } |
| | |
| | | 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; |
| | |
| | | |
| | | /** |
| | | * 扣除用户积分 |
| | | * |
| | | * @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) { |
| | |
| | | |
| | | /** |
| | | * 新增用户积分 |
| | | * @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) { |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 退积分 |
| | | */ |
| | | 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"))); |
| | | } |
| | | |
| | | } |
| | |
| | | // 根据订单类型创建不同的处理任务 |
| | | 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; |
| | |
| | | |
| | | String CREATE_ORDER = "CREATE_ORDER"; |
| | | String SALES_ORDER = "SALES_ORDER"; |
| | | String SCORE_ORDER = "SCORE_ORDER"; |
| | | /** |
| | | * 发送微信消息 |
| | | */ |
| | |
| | | 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; |
| | |
| | | @Autowired |
| | | private ShopSalesmanOrderDao shopSalesmanOrderDao; |
| | | |
| | | @Autowired |
| | | private ShopOrderDao shopOrderDao; |
| | | |
| | | @Autowired |
| | | private ScoreVipDetailService scoreVipDetailService; |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | }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); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | 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); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | /*验证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) { |
| | |
| | | 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("请填写规格名称",{ |