|
@@ -19,10 +19,12 @@ import com.izouma.nineth.repo.OrderRepo;
|
|
|
import com.izouma.nineth.repo.UserAddressRepo;
|
|
import com.izouma.nineth.repo.UserAddressRepo;
|
|
|
import com.izouma.nineth.repo.UserRepo;
|
|
import com.izouma.nineth.repo.UserRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
|
|
+import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.core.env.Environment;
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.ui.Model;
|
|
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
import javax.transaction.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
@@ -90,17 +92,17 @@ public class OrderService {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Object pay(Long id, PayMethod payMethod) throws AlipayApiException {
|
|
|
|
|
- Order order = orderRepo.findByIdAndDelFalse(id).orElseThrow(new BusinessException("订单不存在"));
|
|
|
|
|
- if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
|
|
- throw new BusinessException("订单状态错误");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public void payOrderAlipay(Long id, Model model) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Order order = orderRepo.findByIdAndDelFalse(id).orElseThrow(new BusinessException("订单不存在"));
|
|
|
|
|
+ if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (payMethod == PayMethod.ALIPAY) {
|
|
|
|
|
JSONObject bizContent = new JSONObject();
|
|
JSONObject bizContent = new JSONObject();
|
|
|
bizContent.put("notifyUrl", alipayProperties.getNotifyUrl());
|
|
bizContent.put("notifyUrl", alipayProperties.getNotifyUrl());
|
|
|
bizContent.put("returnUrl", alipayProperties.getReturnUrl());
|
|
bizContent.put("returnUrl", alipayProperties.getReturnUrl());
|
|
|
- bizContent.put("out_trade_no", UUID.randomUUID().toString());
|
|
|
|
|
|
|
+ bizContent.put("out_trade_no", String.valueOf(new SnowflakeIdWorker(0, 0).nextId()));
|
|
|
bizContent.put("total_amount", order.getTotalPrice().stripTrailingZeros().toPlainString());
|
|
bizContent.put("total_amount", order.getTotalPrice().stripTrailingZeros().toPlainString());
|
|
|
bizContent.put("disable_pay_channels", "pcredit,creditCard");
|
|
bizContent.put("disable_pay_channels", "pcredit,creditCard");
|
|
|
if (Arrays.stream(env.getActiveProfiles()).noneMatch(s -> s.equals("prod"))) {
|
|
if (Arrays.stream(env.getActiveProfiles()).noneMatch(s -> s.equals("prod"))) {
|
|
@@ -120,9 +122,21 @@ public class OrderService {
|
|
|
alipayRequest.setNotifyUrl(alipayProperties.getNotifyUrl());
|
|
alipayRequest.setNotifyUrl(alipayProperties.getNotifyUrl());
|
|
|
alipayRequest.setBizContent(JSON.toJSONString(bizContent));
|
|
alipayRequest.setBizContent(JSON.toJSONString(bizContent));
|
|
|
|
|
|
|
|
- String html = alipayClient.pageExecute(alipayRequest).getBody();
|
|
|
|
|
- return html;
|
|
|
|
|
|
|
+ String form = alipayClient.pageExecute(alipayRequest).getBody();
|
|
|
|
|
+ model.addAttribute("form", form);
|
|
|
|
|
+ } catch (BusinessException err) {
|
|
|
|
|
+ model.addAttribute("errMsg", err.getError());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ model.addAttribute("errMsg", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Object payOrderWeixin(Long id) {
|
|
|
|
|
+ Order order = orderRepo.findByIdAndDelFalse(id).orElseThrow(new BusinessException("订单不存在"));
|
|
|
|
|
+ if (order.getStatus() != OrderStatus.NOT_PAID) {
|
|
|
|
|
+ throw new BusinessException("订单状态错误");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|