|
@@ -3,14 +3,25 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkankan.common.constant.Constant;
|
|
|
import com.fdkankan.common.constant.ConstantUrl;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
-import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.sale.common.CacheUtil;
|
|
|
+import com.fdkankan.sale.common.ResultCode;
|
|
|
import com.fdkankan.sale.common.ResultData;
|
|
|
import com.fdkankan.sale.controller.BaseController;
|
|
|
+import com.fdkankan.sale.entity.Repair;
|
|
|
+import com.fdkankan.sale.entity.RepairPay;
|
|
|
+import com.fdkankan.sale.exception.BusinessException;
|
|
|
+import com.fdkankan.sale.pay.wx.WXPayDefaultConfig;
|
|
|
import com.fdkankan.sale.pay.wx.WechatPayService;
|
|
|
+import com.fdkankan.sale.service.IPriceListService;
|
|
|
+import com.fdkankan.sale.service.IRepairLogService;
|
|
|
+import com.fdkankan.sale.service.IRepairPayService;
|
|
|
+import com.fdkankan.sale.service.IRepairService;
|
|
|
+import com.fdkankan.sale.util.DateUtil;
|
|
|
import com.fdkankan.sale.util.UrlUtils;
|
|
|
import com.fdkankan.sale.vo.request.WechatMobileParam;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -33,6 +44,14 @@ import java.util.Map;
|
|
|
public class OrderWechatPayController extends BaseController {
|
|
|
@Autowired
|
|
|
WechatPayService wechatPayService;
|
|
|
+ @Autowired
|
|
|
+ IPriceListService priceListService;
|
|
|
+ @Autowired
|
|
|
+ IRepairPayService repairPayService;
|
|
|
+ @Autowired
|
|
|
+ IRepairService repairService;
|
|
|
+ @Autowired
|
|
|
+ IRepairLogService repairLogService;
|
|
|
|
|
|
@ResponseBody
|
|
|
@RequestMapping(value = "/wechatMobilePay", method = RequestMethod.POST)
|
|
@@ -41,6 +60,62 @@ public class OrderWechatPayController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @RequestMapping(value = "/wechatPreJsPay")
|
|
|
+ public String wechatPreJsPay(String repairId,String openId) throws Exception {
|
|
|
+ // 这个url链接地址和参数皆不能变
|
|
|
+ try {
|
|
|
+ if(StringUtils.isBlank(repairId)){
|
|
|
+ throw new com.fdkankan.sale.exception.BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ Repair repair = repairService.getById(repairId);
|
|
|
+ if(repair == null){
|
|
|
+ throw new com.fdkankan.sale.exception.BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ if(repair.getStatus() != 9 && repair.getStatus() != 4){
|
|
|
+ throw new com.fdkankan.sale.exception.BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
|
|
|
+ }
|
|
|
+ RepairPay repairPay = repairPayService.getByRepairId(repairId,1);
|
|
|
+ if(repairPay != null ){
|
|
|
+ throw new BusinessException(ResultCode.ORDER_PAY_ERROR);
|
|
|
+ }
|
|
|
+ String orderSn = null;
|
|
|
+
|
|
|
+ BigDecimal amount = BigDecimal.ZERO;
|
|
|
+ String subject = null;
|
|
|
+ Integer orderType = null;
|
|
|
+ if(repair.getStatus() == 9){
|
|
|
+ amount = priceListService.getAmountByRepairId(repairId);
|
|
|
+ orderSn = "se_s"+ DateUtil.getDate(DateUtil.repairIdFmt);
|
|
|
+ subject = "维修订单";
|
|
|
+ orderType = 0;
|
|
|
+ }
|
|
|
+ if(repair.getStatus() == 3){
|
|
|
+ amount = priceListService.getRobAmountByRepairId(repairId);
|
|
|
+ orderSn = "se_c"+DateUtil.getDate(DateUtil.repairIdFmt);
|
|
|
+ subject = "取消维修订单";
|
|
|
+ orderType = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ repairPay = new RepairPay();
|
|
|
+ repairPay.setRepairId(repairId);
|
|
|
+ repairPay.setPayType(1);
|
|
|
+ repairPay.setOrderSn(orderSn);
|
|
|
+ repairPay.setPayAmount(amount);
|
|
|
+ repairPay.setOrderType(orderType);
|
|
|
+ repairPayService.save(repairPay);
|
|
|
+
|
|
|
+ amount =amount .multiply(new BigDecimal(100));
|
|
|
+ Map<String, String> resp = wechatPayService.wechatPay(orderSn,subject, subject+subject, amount, UrlUtils.getIpAddr(request), openId);
|
|
|
+ String timeStamp = String.valueOf(System.currentTimeMillis() / 1000);
|
|
|
+ return "redirect:" + CacheUtil.mainUrl + ConstantUrl.WEIXIN_MOBILE_PAY_URL + timeStamp + "&signType=MD5&appId=" + resp.get("appid")
|
|
|
+ + "&nonceStr=" + resp.get("nonce_str") + "&prepay_id=" + resp.get("prepay_id") + "&paySign=" + resp.get("paySign");
|
|
|
+ }catch (Exception e){
|
|
|
+ log.debug("获取access_token发生异常",e);
|
|
|
+ }
|
|
|
+ return "redirect:" + CacheUtil.mainUrl + "mobile.html#/payresult/fail";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@RequestMapping(value = "/wechatPay/notify", method = RequestMethod.POST)
|
|
|
public void callback() {
|
|
|
wechatPayService.callBack(request,response);
|