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);
}
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();
}
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();
}
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());
}
}
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;
}
Aggregations