Search in sources :

Example 1 with BadRequestException

use of co.yixiang.exception.BadRequestException in project yshopmall by guchengwuyue.

the class YxUserExtractServiceImpl method doExtract.

@Override
public void doExtract(YxUserExtract resources) {
    if (resources.getStatus() == null) {
        throw new BadRequestException("请选择审核状态");
    }
    if (ShopCommonEnum.EXTRACT_0.getValue().equals(resources.getStatus())) {
        throw new BadRequestException("请选择审核状态");
    }
    if (ShopCommonEnum.EXTRACT_MINUS_1.getValue().equals(resources.getStatus())) {
        if (StrUtil.isEmpty(resources.getFailMsg())) {
            throw new BadRequestException("请填写失败原因");
        }
        String mark = "提现失败,退回佣金" + resources.getExtractPrice() + "元";
        YxUserDto userDTO = generator.convert(yxUserService.getOne(new LambdaQueryWrapper<YxUser>().eq(YxUser::getUid, resources.getUid())), YxUserDto.class);
        // 增加流水
        YxUserBill userBill = new YxUserBill();
        userBill.setTitle("提现失败");
        userBill.setUid(resources.getUid());
        userBill.setCategory("now_money");
        userBill.setType("extract");
        userBill.setNumber(resources.getExtractPrice());
        userBill.setLinkId(resources.getId().toString());
        userBill.setBalance(NumberUtil.add(userDTO.getBrokeragePrice(), resources.getExtractPrice()));
        userBill.setMark(mark);
        userBill.setStatus(1);
        userBill.setPm(1);
        billService.save(userBill);
        // 返回提现金额
        yxUserService.incBrokeragePrice(resources.getExtractPrice().doubleValue(), resources.getUid());
        resources.setFailTime(new Date());
    }
    // todo 此处为企业付款,没经过测试
    boolean isTest = true;
    if (!isTest) {
        String openid = this.getUserOpenid(resources.getUid());
        if (StrUtil.isNotBlank(openid)) {
            try {
                payService.entPay(openid, resources.getId().toString(), resources.getRealName(), resources.getExtractPrice().multiply(new BigDecimal(100)).intValue());
            } catch (WxPayException e) {
                throw new BadRequestException(e.getMessage());
            }
        } else {
            throw new BadRequestException("不是微信用户无法退款");
        }
    }
    this.saveOrUpdate(resources);
}
Also used : WxPayException(com.github.binarywang.wxpay.exception.WxPayException) YxUser(co.yixiang.modules.shop.domain.YxUser) BadRequestException(co.yixiang.exception.BadRequestException) YxUserBill(co.yixiang.modules.shop.domain.YxUserBill) Date(java.util.Date) BigDecimal(java.math.BigDecimal) YxUserDto(co.yixiang.modules.shop.service.dto.YxUserDto)

Example 2 with BadRequestException

use of co.yixiang.exception.BadRequestException in project yshopmall by guchengwuyue.

the class AlipayConfigServiceImpl method toPayAsPc.

@Override
public String toPayAsPc(AlipayConfig alipay, TradeVo trade) throws Exception {
    if (alipay.getId() == null) {
        throw new BadRequestException("请先添加相应配置,再操作");
    }
    AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());
    // 创建API对应的request(电脑网页版)
    AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
    // 订单完成后返回的页面和异步通知地址
    request.setReturnUrl(alipay.getReturnUrl());
    request.setNotifyUrl(alipay.getNotifyUrl());
    // 填充订单参数
    request.setBizContent("{" + "    \"out_trade_no\":\"" + trade.getOutTradeNo() + "\"," + "    \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," + "    \"total_amount\":" + trade.getTotalAmount() + "," + "    \"subject\":\"" + trade.getSubject() + "\"," + "    \"body\":\"" + trade.getBody() + "\"," + "    \"extend_params\":{" + "    \"sys_service_provider_id\":\"" + alipay.getSysServiceProviderId() + "\"" + "    }" + // 填充业务参数
    "  }");
    // 调用SDK生成表单, 通过GET方式,口可以获取url
    return alipayClient.pageExecute(request, "GET").getBody();
}
Also used : DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayClient(com.alipay.api.AlipayClient) BadRequestException(co.yixiang.exception.BadRequestException) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayTradePagePayRequest(com.alipay.api.request.AlipayTradePagePayRequest)

Example 3 with BadRequestException

use of co.yixiang.exception.BadRequestException in project yshopmall by guchengwuyue.

the class AlipayConfigServiceImpl method toPayAsWeb.

@Override
public String toPayAsWeb(AlipayConfig alipay, TradeVo trade) throws Exception {
    if (alipay.getId() == null) {
        throw new BadRequestException("请先添加相应配置,再操作");
    }
    AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());
    double money = Double.parseDouble(trade.getTotalAmount());
    double maxMoney = 5000;
    if (money <= 0 || money >= maxMoney) {
        throw new BadRequestException("测试金额过大");
    }
    // 创建API对应的request(手机网页版)
    AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
    request.setReturnUrl(alipay.getReturnUrl());
    request.setNotifyUrl(alipay.getNotifyUrl());
    request.setBizContent("{" + "    \"out_trade_no\":\"" + trade.getOutTradeNo() + "\"," + "    \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," + "    \"total_amount\":" + trade.getTotalAmount() + "," + "    \"subject\":\"" + trade.getSubject() + "\"," + "    \"body\":\"" + trade.getBody() + "\"," + "    \"extend_params\":{" + "    \"sys_service_provider_id\":\"" + alipay.getSysServiceProviderId() + "\"" + "    }" + "  }");
    return alipayClient.pageExecute(request, "GET").getBody();
}
Also used : DefaultAlipayClient(com.alipay.api.DefaultAlipayClient) AlipayClient(com.alipay.api.AlipayClient) AlipayTradeWapPayRequest(com.alipay.api.request.AlipayTradeWapPayRequest) BadRequestException(co.yixiang.exception.BadRequestException) DefaultAlipayClient(com.alipay.api.DefaultAlipayClient)

Example 4 with BadRequestException

use of co.yixiang.exception.BadRequestException in project yshopmall by guchengwuyue.

the class QiNiuServiceImpl method upload.

@Override
// @CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig) {
    FileUtil.checkSize(maxSize, file.getSize());
    if (qiniuConfig.getId() == null) {
        throw new BadRequestException("请先添加相应配置,再操作");
    }
    // 构造一个带指定Zone对象的配置类
    Configuration cfg = new Configuration(QiNiuUtil.getRegion(qiniuConfig.getZone()));
    UploadManager uploadManager = new UploadManager(cfg);
    Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
    String upToken = auth.uploadToken(qiniuConfig.getBucket());
    try {
        String key = file.getOriginalFilename();
        if (qiniuContentService.getOne(new LambdaQueryWrapper<QiniuContent>().eq(QiniuContent::getName, key)) != null) {
            key = QiNiuUtil.getKey(key);
        }
        Response response = uploadManager.put(file.getBytes(), key, upToken);
        // 解析上传成功的结果
        DefaultPutRet putRet = JSON.parseObject(response.bodyString(), DefaultPutRet.class);
        QiniuContent content = qiniuContentService.getOne(new LambdaQueryWrapper<QiniuContent>().eq(QiniuContent::getName, FileUtil.getFileNameNoEx(putRet.key)));
        if (content == null) {
            // 存入数据库
            QiniuContent qiniuContent = new QiniuContent();
            qiniuContent.setSuffix(FileUtil.getExtensionName(putRet.key));
            qiniuContent.setBucket(qiniuConfig.getBucket());
            qiniuContent.setType(qiniuConfig.getType());
            qiniuContent.setName(FileUtil.getFileNameNoEx(putRet.key));
            qiniuContent.setUrl(qiniuConfig.getHost() + "/" + putRet.key);
            qiniuContent.setSize(FileUtil.getSize(Integer.parseInt(file.getSize() + "")));
            qiniuContentService.save(qiniuContent);
            return qiniuContent;
        }
        return content;
    } catch (Exception e) {
        throw new BadRequestException(e.getMessage());
    }
}
Also used : Response(com.qiniu.http.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) Configuration(com.qiniu.storage.Configuration) Auth(com.qiniu.util.Auth) BadRequestException(co.yixiang.exception.BadRequestException) DefaultPutRet(com.qiniu.storage.model.DefaultPutRet) QiniuContent(co.yixiang.modules.tools.domain.QiniuContent) UploadManager(com.qiniu.storage.UploadManager) BadRequestException(co.yixiang.exception.BadRequestException) QiniuException(com.qiniu.common.QiniuException) IOException(java.io.IOException) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with BadRequestException

use of co.yixiang.exception.BadRequestException in project yshopmall by guchengwuyue.

the class PictureServiceImpl method upload.

@Override
@Transactional(rollbackFor = Throwable.class)
public Picture upload(MultipartFile multipartFile, String username) {
    File file = FileUtil.toFile(multipartFile);
    // 验证是否重复上传
    Picture picture = this.getOne(new LambdaQueryWrapper<Picture>().eq(Picture::getMd5code, FileUtil.getMd5(file)));
    if (picture != null) {
        return picture;
    }
    HashMap<String, Object> paramMap = new HashMap<>(1);
    paramMap.put("smfile", file);
    // 上传文件
    String result = HttpRequest.post(YshopConstant.Url.SM_MS_URL + "/v2/upload").header("Authorization", token).form(paramMap).timeout(20000).execute().body();
    JSONObject jsonObject = JSONUtil.parseObj(result);
    if (!jsonObject.get(CODE).toString().equals(SUCCESS)) {
        throw new BadRequestException(TranslatorUtil.translate(jsonObject.get(MSG).toString()));
    }
    picture = JSON.parseObject(jsonObject.get("data").toString(), Picture.class);
    picture.setSize(FileUtil.getSize(Integer.parseInt(picture.getSize())));
    picture.setUsername(username);
    picture.setMd5code(FileUtil.getMd5(file));
    picture.setFilename(FileUtil.getFileNameNoEx(multipartFile.getOriginalFilename()) + "." + FileUtil.getExtensionName(multipartFile.getOriginalFilename()));
    this.save(picture);
    // 删除临时文件
    FileUtil.del(file);
    return picture;
}
Also used : JSONObject(cn.hutool.json.JSONObject) Picture(co.yixiang.modules.tools.domain.Picture) BadRequestException(co.yixiang.exception.BadRequestException) JSONObject(cn.hutool.json.JSONObject) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BadRequestException (co.yixiang.exception.BadRequestException)40 ApiOperation (io.swagger.annotations.ApiOperation)14 ResponseEntity (org.springframework.http.ResponseEntity)13 Log (co.yixiang.modules.logging.aop.log.Log)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Transactional (org.springframework.transaction.annotation.Transactional)7 UserDto (co.yixiang.modules.system.service.dto.UserDto)6 JSONObject (com.alibaba.fastjson.JSONObject)6 ForbidSubmit (co.yixiang.modules.aop.ForbidSubmit)5 NoRepeatSubmit (co.yixiang.modules.aop.NoRepeatSubmit)5 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)5 Date (java.util.Date)5 RSA (cn.hutool.crypto.asymmetric.RSA)3 IOException (java.io.IOException)3 Authentication (org.springframework.security.core.Authentication)3 UserDetails (org.springframework.security.core.userdetails.UserDetails)3 EntityExistException (co.yixiang.exception.EntityExistException)2 YxStoreOrderStatus (co.yixiang.modules.shop.domain.YxStoreOrderStatus)2 YxSystemGroupData (co.yixiang.modules.shop.domain.YxSystemGroupData)2 YxStoreOrderDto (co.yixiang.modules.shop.service.dto.YxStoreOrderDto)2