|
@@ -25,10 +25,7 @@ import java.math.RoundingMode;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Controller("apiOrderController")
|
|
|
@RequestMapping("/api/order")
|
|
@@ -60,7 +57,6 @@ public class OrderController extends BaseController {
|
|
|
@ResponseBody
|
|
|
public Object uniPay(String clientId, String productName, String frpCode) {
|
|
|
|
|
|
-
|
|
|
Equipment equipment = equipmentService.findByClientId(clientId);
|
|
|
if (!frpCode.equals("ALIPAY_NATIVE") && !frpCode.equals("WEIXIN_NATIVE")) {
|
|
|
return JsonMessage.error("参数错误");
|
|
@@ -313,13 +309,318 @@ public class OrderController extends BaseController {
|
|
|
if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
|
|
|
return JsonMessage.error("找不到支付图片");
|
|
|
}
|
|
|
-
|
|
|
return JsonMessage.success(rd_Pic);
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 请求在线支付NEW
|
|
|
+ *
|
|
|
+ * @param clientId 设备client id
|
|
|
+ * @param productName 商品名称
|
|
|
+ * @param frpCode 支付方式 支付宝:ALIPAY_NATIVE , 微信:WEIXIN_NATIVE
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/newUniPay", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public Object newUniPay(String clientId, String productName, String frpCode) {
|
|
|
+ //解决中文乱码
|
|
|
+// try{
|
|
|
+// if(productName!=null){
|
|
|
+// productName = URLDecoder.decode(productName, "GB2312");
|
|
|
+//// productName = new String(productName.getBytes("ISO8859_1"), "UTF-8");productName = "玫瑰精灵"
|
|
|
+// }
|
|
|
+// }catch (Exception e){
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// productName = "玫瑰精灵";
|
|
|
+ Equipment equipment = equipmentService.findByClientId(clientId);
|
|
|
+ if (!frpCode.equals("ALIPAY_NATIVE") && !frpCode.equals("WEIXIN_NATIVE")) {
|
|
|
+ return JsonMessage.error("参数错误");
|
|
|
+ }
|
|
|
+ if(equipment==null){
|
|
|
+ return JsonMessage.error("找不到设备");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long equipmentId = equipment.getId();
|
|
|
+
|
|
|
+ Product product = productService.getByProductName(equipmentId, productName);
|
|
|
+
|
|
|
+ if (product == null) {
|
|
|
+ return JsonMessage.error("找不到商品");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal price = product.getRmbPrice();
|
|
|
+ if (BigDecimal.ZERO.compareTo(price) >= 0) {
|
|
|
+ return JsonMessage.error("商品价格异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ String sn = orderService.initSn(equipmentId);
|
|
|
+
|
|
|
+ Proportion proportion = proportionService.getUniqueness(equipment.getAdminId());
|
|
|
+ if (proportion == null) {
|
|
|
+ return JsonMessage.error("设备商家未完成分销设置");
|
|
|
+ }
|
|
|
+
|
|
|
+ Admin admin = adminService.find(equipment.getAdminId());
|
|
|
+ if (admin == null) {
|
|
|
+ return JsonMessage.error("找不到设备商家");
|
|
|
+ }
|
|
|
+
|
|
|
+ Proportion.Type type = proportion.getType();
|
|
|
+ JSONArray altInfo = new JSONArray();
|
|
|
+ JSONArray altNewInfo = new JSONArray();
|
|
|
+
|
|
|
+ BigDecimal adminProportion = null, agencyProportion = null, merchantProportion = null, personageProportion = null;
|
|
|
+ Long agencyId = admin.getAgencyId();
|
|
|
+ Long merchantId = admin.getMerchantId();
|
|
|
+ Long personageId = admin.getPersonageId();
|
|
|
+ Order.Type orderType = null;
|
|
|
+
|
|
|
+ if (type == null) {
|
|
|
+ return JsonMessage.error("设备商家未完成分销设置");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal agencyAmount = null;
|
|
|
+ BigDecimal merchantAmount = null;
|
|
|
+ BigDecimal personageAmount = null;
|
|
|
+
|
|
|
+ Mch agencyMch = null;
|
|
|
+ Mch merchantMch = null;
|
|
|
+ Mch personageMch = null;
|
|
|
+
|
|
|
+ JSONObject agencyJson = null;
|
|
|
+ JSONObject merchantJson = null;
|
|
|
+ JSONObject personageJson = null;
|
|
|
+
|
|
|
+ // 砍掉千6手续费
|
|
|
+// BigDecimal cutPrice = price.multiply(new BigDecimal(99.4)).divide(new BigDecimal(100));
|
|
|
+ //取消平台扣手续费
|
|
|
+ BigDecimal cutPrice = price.multiply(new BigDecimal(100)).divide(new BigDecimal(100));
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+
|
|
|
+ case agency:
|
|
|
+
|
|
|
+ if (admin.getType() != Admin.Type.agency) {
|
|
|
+ return JsonMessage.error("设备商家类型错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ agencyMch = mchService.getUniqueness(admin.getAgencyId());
|
|
|
+ if (agencyMch == null || StringUtils.isBlank(agencyMch.getOrder_status())) {
|
|
|
+ return JsonMessage.error("设备商家未注册提现账户");
|
|
|
+ }
|
|
|
+
|
|
|
+ agencyProportion = proportion.getAgencyProportion();
|
|
|
+ adminProportion = proportion.getAdminProportion();
|
|
|
+ orderType = Order.Type.agency;
|
|
|
+
|
|
|
+ // 代理分销获得利润
|
|
|
+ agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+
|
|
|
+ agencyJson = new JSONObject();
|
|
|
+ agencyJson.put("altMchNo", agencyMch.getAlt_mch_no());
|
|
|
+ agencyJson.put("altAmount", agencyAmount.toString());
|
|
|
+ agencyJson.put("isGuar", "12");
|
|
|
+ altInfo.add(agencyJson);
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case merchant:
|
|
|
+
|
|
|
+ if (admin.getType() != Admin.Type.merchant) {
|
|
|
+ return JsonMessage.error("设备商家类型错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ agencyMch = mchService.getUniqueness(admin.getAgencyId());
|
|
|
+ merchantMch = mchService.getUniqueness(admin.getMerchantId());
|
|
|
+
|
|
|
+ if (agencyMch == null || StringUtils.isBlank(agencyMch.getOrder_status())) {
|
|
|
+ return JsonMessage.error("设备商家未注册提现账户");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (merchantMch == null || StringUtils.isBlank(merchantMch.getOrder_status())) {
|
|
|
+ return JsonMessage.error("设备商家未注册提现账户");
|
|
|
+ }
|
|
|
+
|
|
|
+ agencyProportion = proportion.getAgencyProportion();
|
|
|
+ adminProportion = proportion.getAdminProportion();
|
|
|
+ merchantProportion = proportion.getMerchantProportion();
|
|
|
+ orderType = Order.Type.merchant;
|
|
|
|
|
|
+ // 代理分销获得利润
|
|
|
+ agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
|
|
+ // 经销商分销获得利润
|
|
|
+ merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+
|
|
|
+ agencyJson = new JSONObject();
|
|
|
+ agencyJson.put("altMchNo", agencyMch.getAlt_mch_no());
|
|
|
+ agencyJson.put("altAmount", agencyAmount.toString());
|
|
|
+ agencyJson.put("isGuar", "12");
|
|
|
+ altInfo.add(agencyJson);
|
|
|
+
|
|
|
+ merchantJson = new JSONObject();
|
|
|
+ merchantJson.put("altMchNo", merchantMch.getAlt_mch_no());
|
|
|
+ merchantJson.put("altAmount", merchantAmount.toString());
|
|
|
+ merchantJson.put("isGuar", "12");
|
|
|
+ altInfo.add(merchantJson);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case personage:
|
|
|
+
|
|
|
+ if (admin.getType() != Admin.Type.personage) {
|
|
|
+ return JsonMessage.error("设备商家类型错误");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ agencyMch = mchService.getUniqueness(admin.getAgencyId());
|
|
|
+ merchantMch = mchService.getUniqueness(admin.getMerchantId());
|
|
|
+ personageMch = mchService.getUniqueness(admin.getPersonageId());
|
|
|
+
|
|
|
+
|
|
|
+ if (agencyMch == null || StringUtils.isBlank(agencyMch.getOrder_status())) {
|
|
|
+ return JsonMessage.error("设备商家未注册提现账户");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (merchantMch == null || StringUtils.isBlank(merchantMch.getOrder_status())) {
|
|
|
+ return JsonMessage.error("设备商家未注册提现账户");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (personageMch == null || StringUtils.isBlank(personageMch.getOrder_status())) {
|
|
|
+ return JsonMessage.error("设备商家未注册提现账户");
|
|
|
+ }
|
|
|
+
|
|
|
+ agencyProportion = proportion.getAgencyProportion();
|
|
|
+ adminProportion = proportion.getAdminProportion();
|
|
|
+ merchantProportion = proportion.getMerchantProportion();
|
|
|
+ personageProportion = proportion.getPersonageProportion();
|
|
|
+
|
|
|
+ orderType = Order.Type.personage;
|
|
|
+
|
|
|
+ // 代理分销获得利润
|
|
|
+ agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+
|
|
|
+ // 经销商分销获得利润
|
|
|
+ merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+
|
|
|
+ // 经销商分销获得利润
|
|
|
+ personageAmount = cutPrice.multiply(personageProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+
|
|
|
+ agencyJson = new JSONObject();
|
|
|
+ agencyJson.put("altMchNo", agencyMch.getAlt_mch_no());
|
|
|
+ agencyJson.put("altAmount", agencyAmount.toString());
|
|
|
+ agencyJson.put("isGuar", "12");
|
|
|
+ altInfo.add(agencyJson);
|
|
|
+
|
|
|
+ merchantJson = new JSONObject();
|
|
|
+ merchantJson.put("altMchNo", merchantMch.getAlt_mch_no());
|
|
|
+ merchantJson.put("altAmount", merchantAmount.toString());
|
|
|
+ merchantJson.put("isGuar", "12");
|
|
|
+ altInfo.add(merchantJson);
|
|
|
+
|
|
|
+ personageJson = new JSONObject();
|
|
|
+ personageJson.put("altMchNo", personageMch.getAlt_mch_no());
|
|
|
+ personageJson.put("altAmount", personageAmount.toString());
|
|
|
+ personageJson.put("isGuar", "12");
|
|
|
+ altInfo.add(personageJson);
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String orderNo = sn;
|
|
|
+ BigDecimal amount = price;
|
|
|
+ String productDesc = "";
|
|
|
+ String commonParameter = "";
|
|
|
+ String returnUrl = null;
|
|
|
+ String notifyUrl = JoinpayConstant.Notify_Url;
|
|
|
+ String isShowPic = "1";
|
|
|
+ String openId = null;
|
|
|
+ String authCode = null;
|
|
|
+ String appid = null;
|
|
|
+ String transactionModel = null;
|
|
|
+ String tradeMerchantNo = null;
|
|
|
+ String buyerId = null;
|
|
|
+ String isAlt = "1";
|
|
|
+ String altType = "11";
|
|
|
+ String altUrl = null;
|
|
|
+ BigDecimal marketingAmount = null;
|
|
|
+
|
|
|
+ Order order = new Order(sn, product.getId(), productName, price, equipment.getClientId(), equipmentId,
|
|
|
+ orderType, admin.getId(), agencyId, merchantId, personageId,
|
|
|
+ frpCode, altInfo.toString(), adminProportion, agencyProportion, merchantProportion, personageProportion, Order.Status.unpay);
|
|
|
+
|
|
|
+ orderService.create(order);
|
|
|
+
|
|
|
+ Iterator<Object> iterator = altInfo.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ JSONObject jsonObject = (JSONObject) iterator.next();
|
|
|
+ String altAmount = jsonObject.getString("altAmount");
|
|
|
+ if (altAmount.equals("0.00")) {
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = tradeService.uniPay(
|
|
|
+
|
|
|
+ orderNo, amount, productName, productDesc,
|
|
|
+ commonParameter, returnUrl, notifyUrl, frpCode,
|
|
|
+ isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
|
|
|
+ buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
|
|
|
+ );
|
|
|
+
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return JsonMessage.error("申请支付失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ // 汇聚支付支付申请返回支付二维码图片
|
|
|
+ String rd_Pic = resultJson.getString("rd_Pic");
|
|
|
+// Map<String,String> map2 = new HashMap<>();
|
|
|
+// map2.put("sn",sn);
|
|
|
+// map2.put("rd_Pic",rd_Pic);
|
|
|
+ if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
|
|
|
+ return JsonMessage.error("找不到支付图片");
|
|
|
+ }
|
|
|
+// send(clientId,sn,productName);
|
|
|
+// return JsonMessage.success(rd_Pic);
|
|
|
+ JSONObject kindData = new JSONObject();
|
|
|
+ kindData.put("sn" , sn);
|
|
|
+ kindData.put("rd_Pic",rd_Pic);
|
|
|
+ return JsonMessage.success(kindData.toString());
|
|
|
+ }
|
|
|
+ @RequestMapping(value = "/send", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public void send(String client,String sn,String productName){
|
|
|
+ JSONObject kindData = new JSONObject();
|
|
|
+ kindData.put("sn" , sn);
|
|
|
+ kindData.put("productName" , productName);
|
|
|
+
|
|
|
+
|
|
|
+// new Thread(){
|
|
|
+// public void run(){
|
|
|
+// try {
|
|
|
+// Thread.sleep(5000);
|
|
|
+// System.out.println("123");
|
|
|
+// } catch (InterruptedException e) { }
|
|
|
+// }
|
|
|
+// }.start();
|
|
|
+ PushUtils.push(equipmentService.findByClientId(client).getGtClientId(), "支付成功", "您的订单支付成功", PushUtils.buildJson("pay_success", kindData.toString()).toString());
|
|
|
+
|
|
|
+// Timer timer=new Timer();//实例化Timer类
|
|
|
+// timer.schedule(new TimerTask(client,kindData){
|
|
|
+// public void run(){
|
|
|
+// PushUtils.push(equipmentService.findByClientId(client).getGtClientId(), "支付成功", "您的订单支付成功", PushUtils.buildJson("pay_success", kindData.toString()).toString());
|
|
|
+// System.out.println("退出");
|
|
|
+// this.cancel();}},20000);
|
|
|
+
|
|
|
+ }
|
|
|
/**
|
|
|
* 支付成功回调
|
|
|
*
|
|
@@ -378,6 +679,21 @@ public class OrderController extends BaseController {
|
|
|
|
|
|
|
|
|
/**
|
|
|
+ * 查询订单是否付款
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getOrderStatus", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public JsonMessage getOrderStatus(String sn ) {
|
|
|
+ Order order = orderService.findBySn(sn);
|
|
|
+ Order.Status status = order.getStatus();
|
|
|
+ return JsonMessage.success(status.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 请求在线退款
|
|
|
* @param sn
|
|
|
* @param clientId
|