| | |
| | | package cc.mrbird.febs; |
| | | |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.enumerates.DataDictionaryEnum; |
| | | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; |
| | | import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum; |
| | | import cc.mrbird.febs.common.properties.XcxProperties; |
| | | import cc.mrbird.febs.common.utils.MallUtils; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.common.utils.SpringContextHolder; |
| | | import cc.mrbird.febs.mall.dto.ApiLeaderOrderConfirmDto; |
| | | import cc.mrbird.febs.mall.entity.MallOrderItem; |
| | | import cc.mrbird.febs.mall.mapper.MallOrderInfoMapper; |
| | | import cc.mrbird.febs.mall.mapper.MallOrderItemMapper; |
| | | import cc.mrbird.febs.mall.service.IAgentService; |
| | | import cc.mrbird.febs.mall.service.IApiMallTeamLeaderService; |
| | | import cc.mrbird.febs.mall.service.IMallAchieveService; |
| | | import cc.mrbird.febs.mall.service.IMemberProfitService; |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | | import cc.mrbird.febs.mall.service.*; |
| | | import cc.mrbird.febs.mall.vo.ApiLeaderProfitVo; |
| | | import cc.mrbird.febs.pay.model.WxGenerateQrCodeDto; |
| | | import cc.mrbird.febs.pay.service.IXcxPayService; |
| | | import cc.mrbird.febs.pay.util.WechatConfigure; |
| | | import cc.mrbird.febs.rabbit.consumer.AgentConsumer; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.entity.StringEntity; |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | | import org.apache.http.impl.client.HttpClientBuilder; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.net.HttpURLConnection; |
| | | import java.util.*; |
| | | import java.io.BufferedInputStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.InputStream; |
| | | import java.io.PrintWriter; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.util.Base64; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | |
| | | @Test |
| | | public void confirm(){ |
| | | ApiLeaderOrderConfirmDto apiLeaderOrderConfirmDto = new ApiLeaderOrderConfirmDto(); |
| | | apiLeaderOrderConfirmDto.setIds("90"); |
| | | iApiMallTeamLeaderService.leaderOrderConfirm(apiLeaderOrderConfirmDto); |
| | | // ApiLeaderOrderConfirmDto apiLeaderOrderConfirmDto = new ApiLeaderOrderConfirmDto(); |
| | | // apiLeaderOrderConfirmDto.setIds("90"); |
| | | // iApiMallTeamLeaderService.leaderOrderConfirm(apiLeaderOrderConfirmDto); |
| | | String productNames = getProductNames(35L, 106L); |
| | | System.out.println(productNames); |
| | | } |
| | | |
| | | /** |
| | | * 根据用户ID和订单ID获取所购买商品名称 |
| | | * @return 所含商品名称(多个以","隔开) |
| | | */ |
| | | public String getProductNames(Long memberId, Long orderId) { |
| | | MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectOrderByMemberIdAndId(memberId, orderId); |
| | | List<MallOrderItem> details = mallOrderInfo.getItems(); |
| | | if (CollectionUtils.isEmpty(details)) { |
| | | return ""; |
| | | } |
| | | StringBuffer productNameBuffer = new StringBuffer(); |
| | | Integer maxLength = 30; |
| | | for (int i = 0; i< details.size(); i++) { |
| | | MallOrderItem mallOrderItem = details.get(i); |
| | | String goodsName = mallOrderItem.getGoodsName(); |
| | | if (goodsName == null) { |
| | | continue; |
| | | } |
| | | if (i == 0 && goodsName.length() > maxLength) { |
| | | productNameBuffer.append(goodsName.substring(0, maxLength) + "..."); |
| | | break; |
| | | } |
| | | if ((productNameBuffer.length() + goodsName.length()) > maxLength) { |
| | | productNameBuffer.append("等"); |
| | | break; |
| | | } |
| | | productNameBuffer.append(goodsName + ","); |
| | | } |
| | | String productNames = productNameBuffer.toString(); |
| | | if (productNames.endsWith(",")) { |
| | | productNames = productNames.substring(0, productNames.length() - 1); |
| | | } |
| | | if (productNames.endsWith(",等")) { |
| | | productNames = productNames.substring(0, productNames.length() - 2) + "等"; |
| | | } |
| | | return productNames; |
| | | } |
| | | @Autowired |
| | | private IXcxPayService iXcxPayService; |
| | | |
| | | @Test |
| | | public void qrcodeBase64(){ |
| | | WxGenerateQrCodeDto wxGenerateQrCodeDto = new WxGenerateQrCodeDto(); |
| | | wxGenerateQrCodeDto.setPage("wxGenerateQrCodeDto"); |
| | | wxGenerateQrCodeDto.setScene("15"); |
| | | FebsResponse febsResponse = iXcxPayService.generateQrCode(wxGenerateQrCodeDto); |
| | | String data = febsResponse.get("data").toString(); |
| | | System.out.println(data); |
| | | } |
| | | |
| | | |
| | | // |
| | | // @Autowired |
| | | // private MallOrderInfoMapper mallOrderInfoMapper; |
| | | // |
| | | // @Autowired |
| | | // private MallGoodsSkuMapper mallGoodsSkuMapper; |
| | | |
| | | @Autowired |
| | | private MallLeaderAchieveMapper mallLeaderAchieveMapper; |
| | | // |
| | | // @Autowired |
| | | // private MallTeamLeaderMapper mallTeamLeaderMapper; |
| | | // |
| | | // @Autowired |
| | | // private IMemberProfitService memberProfitService; |
| | | |
| | | // @Autowired |
| | | // private IMallAchieveService mallAchieveService; |
| | | |
| | | @Autowired |
| | | private DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | |
| | | @Autowired |
| | | private MallMemberMapper mallMemberMapper; |
| | | |
| | | @Autowired |
| | | private IMallMoneyFlowService mallMoneyFlowService; |
| | | |
| | | @Autowired |
| | | private IApiMallMemberWalletService memberWalletService; |
| | | |
| | | @Test |
| | | public void achieve(){ |
| | | DataDictionaryCustom dicBonusSwitch = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.BONUS_SWITCH.getType(), DataDictionaryEnum.BONUS_SWITCH.getCode()); |
| | | String bonusSwitch = dicBonusSwitch.getValue(); |
| | | if("1".equals(bonusSwitch)){ |
| | | DataDictionaryCustom dicBonusPercent = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.BONUS_PERCENT.getType(), DataDictionaryEnum.BONUS_PERCENT.getCode()); |
| | | BigDecimal bonusPercent = new BigDecimal(dicBonusPercent.getValue()).setScale(2,BigDecimal.ROUND_DOWN);; |
| | | //获取每日提成总数 |
| | | /** |
| | | * a.unique_code uniqueCode 团长特征码 |
| | | * , IFNULL(sum(a.amount),0) amount 每日提成总金额 |
| | | */ |
| | | // DateTime dateTime = DateUtil.offsetDay(new Date(), -1); |
| | | DateTime dateTime = DateUtil.offsetDay(new Date(), 0); |
| | | List<Map<String, String>> allLeaderAchieve = mallLeaderAchieveMapper.selectListByStateAndCreateTimeAndUniqueCode(MallLeaderAchieve.STATE_ONE,dateTime); |
| | | if (CollUtil.isNotEmpty(allLeaderAchieve)) { |
| | | for (Map<String, String> map : allLeaderAchieve) { |
| | | String uniqueCode = map.get("uniqueCode"); |
| | | Object amountOrder = map.get("amount"); |
| | | //直接舍弃小数点的第三位 |
| | | BigDecimal amount = new BigDecimal(String.valueOf(amountOrder)).setScale(2,BigDecimal.ROUND_DOWN); |
| | | BigDecimal achieveMoney = amount.multiply(bonusPercent).setScale(2,BigDecimal.ROUND_DOWN); |
| | | MallMember mallMember = mallMemberMapper.selectInfoByInviteId(uniqueCode); |
| | | memberWalletService.addBalance(achieveMoney,mallMember.getId()); |
| | | String achieveNo = "TC."+ MallUtils.getOrderNum(); |
| | | mallMoneyFlowService.addMoneyFlow( |
| | | mallMember.getId(), |
| | | achieveMoney, |
| | | MoneyFlowTypeEnum.LEADERACHIEVE.getValue(), |
| | | achieveNo, |
| | | FlowTypeEnum.BALANCE.getValue()); |
| | | |
| | | |
| | | //更新到已提成状态 |
| | | mallLeaderAchieveMapper.updateByUniqueCodeStateAndTime(DateUtil.date(),uniqueCode,MallLeaderAchieve.STATE_ONE,dateTime); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | @Autowired |
| | | private MallMoneyFlowMapper mallMoneyFlowMapper; |
| | | |
| | | @Test |
| | | public void testAddress(){ |
| | | MallMember loginUser = mallMemberMapper.selectById(47L); |
| | | BigDecimal totalProfit = mallMoneyFlowMapper.selectAmountByFlowtypeAndType(loginUser.getId(),FlowTypeEnum.BALANCE.getValue(),MoneyFlowTypeEnum.LEADERACHIEVE.getValue(),null,null,null); |
| | | BigDecimal todayProfit = mallMoneyFlowMapper.selectAmountByFlowtypeAndType(loginUser.getId(),FlowTypeEnum.BALANCE.getValue(), |
| | | MoneyFlowTypeEnum.LEADERACHIEVE.getValue(), |
| | | null,DateUtil.date(), |
| | | null); |
| | | |
| | | BigDecimal monthProfit = mallMoneyFlowMapper.selectAmountByFlowtypeAndType(loginUser.getId(),FlowTypeEnum.BALANCE.getValue(), |
| | | MoneyFlowTypeEnum.LEADERACHIEVE.getValue(), |
| | | null,null, |
| | | DateUtil.date()); |
| | | BigDecimal waitProfit = mallLeaderAchieveMapper.selectProfitByStateAndDateTimeAndUniqueCode(1,null,loginUser.getInviteId()).setScale(2,BigDecimal.ROUND_DOWN); |
| | | System.out.println(todayProfit +";"); |
| | | System.out.println(waitProfit +";"); |
| | | System.out.println(totalProfit +";"); |
| | | System.out.println(monthProfit +";"); |
| | | } |
| | | |
| | | @Autowired |
| | | RedisUtils redisUtils; |
| | | |
| | | |
| | | |
| | | @Test |
| | | public void qrcode(){ |
| | | // RestTemplate restTemplate = new RestTemplate(); |
| | | // String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + redisUtils.get(WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY); |
| | | // Map<String, Object> params = new HashMap<>(); |
| | | // params.put("scene", "pages/index/index"); |
| | | // params.put("page", "15"); |
| | | // params.put("width", 430); |
| | | // ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(url, params, byte[].class); |
| | | // System.out.println(responseEntity.getBody());xcx_appid: wx0b515f652282158e |
| | | // xcx_secret: 8d3d3c14221f7dc37650b861dc0fc570 |
| | | |
| | | String imageNames = System.currentTimeMillis() + IdUtil.simpleUUID(); |
| | | String s = getminiqrQr("15", redisUtils.get(WechatConfigure.WX_ACCESS_TOKEN_REDIS_KEY).toString(), "pages/index/index"); |
| | | System.out.print(s); |
| | | } |
| | | |
| | | private static final String GET_WXACODE ="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="; |
| | | /** |
| | | * 生成小程序码返回base64字符串 |
| | | * @param sceneStr 要携带的参数 |
| | | * @param accessToken 上面方法得到的token |
| | | * @param page 要跳转的小程序页面(必须是已发布的) |
| | | * @return |
| | | */ |
| | | |
| | | private static final String GETWXACODEUNLIMIT_URL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s";// 生成小程序码地址 |
| | | private static final String URL_GET_TOKEN = "https://api.weixin.qq.com/cgi-bin/token";//获取access_token地址 |
| | | private static final String APP_ID = "wx0b515f652282158e";// 小程序appid |
| | | private static final String APP_SECRET = "8d3d3c14221f7dc37650b861dc0fc570"; // 小程序秘钥 |
| | | |
| | | public static final String PATH_HOME = ""; |
| | | private static final String BASE_PREFIX = "data:image/png;base64,"; // base64图片固定前缀 |
| | | public static String getminiqrQr(String sceneStr, String accessToken,String page) { |
| | | HttpURLConnection httpURLConnection = null; |
| | | try { |
| | | URL url = new URL(String.format(GETWXACODEUNLIMIT_URL,accessToken)); |
| | | httpURLConnection = (HttpURLConnection) url.openConnection(); |
| | | httpURLConnection.setRequestMethod("POST");// 提交模式 |
| | | // 发送POST请求必须设置如下两行 |
| | | httpURLConnection.setDoOutput(true); |
| | | httpURLConnection.setDoInput(true); |
| | | // 获取URLConnection对象对应的输出流 |
| | | PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream()); |
| | | // 发送请求参数 |
| | | JSONObject paramJson = new JSONObject(); |
| | | paramJson.put("scene", sceneStr); |
| | | paramJson.put("page", page); |
| | | printWriter.write(paramJson.toString()); |
| | | // flush输出流的缓冲 |
| | | printWriter.flush(); |
| | | //开始获取数据 |
| | | |
| | | BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream()); |
| | | try (InputStream is = httpURLConnection.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();){ |
| | | byte[] buffer = new byte[1024]; |
| | | int len = -1; |
| | | while ((len = is.read(buffer)) != -1) { |
| | | baos.write(buffer, 0, len); |
| | | } |
| | | return BASE_PREFIX+ Base64.getEncoder().encodeToString(baos.toByteArray()); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | if (httpURLConnection != null){ |
| | | httpURLConnection.disconnect(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | BigDecimal amount = new BigDecimal("0.15").setScale(2,BigDecimal.ROUND_DOWN); |
| | | System.out.println(amount); |
| | | } |
| | | } |