|
@@ -5,25 +5,32 @@
|
|
|
|
|
|
package com.shawn.web.controller;
|
|
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.shawn.model.Bean.ChartBean;
|
|
|
import com.shawn.model.Bean.ChartColumn;
|
|
|
import com.shawn.model.Bean.ChartColumn2;
|
|
|
+import com.shawn.model.entity.*;
|
|
|
import com.shawn.model.param.StatisticsParam;
|
|
|
+import com.shawn.service.interfac.*;
|
|
|
import com.shawn.util.FgObjectUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.annotation.Order;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import com.shawn.model.dto.ResultMessage;
|
|
|
import com.shawn.web.controller.base.BaseController;
|
|
|
-import com.shawn.model.entity.TOrder;
|
|
|
-import com.shawn.model.entity.TOrderExample;
|
|
|
import com.shawn.model.param.TOrderParam;
|
|
|
-import com.shawn.service.interfac.TOrderServiceInterface;
|
|
|
|
|
|
@Slf4j
|
|
|
@RestController
|
|
@@ -32,6 +39,14 @@ public class TOrderController extends BaseController<TOrder,TOrderExample,TOrder
|
|
|
@Autowired
|
|
|
private TOrderServiceInterface tOrderService;
|
|
|
@Autowired
|
|
|
+ private TEquipmentServiceInterface tEquipmentServiceInterface;
|
|
|
+ @Autowired
|
|
|
+ private TProportionServiceInterface tProportionServiceInterface;
|
|
|
+ @Autowired
|
|
|
+ private TAdminServiceInterface tAdminServiceInterface;
|
|
|
+ @Autowired
|
|
|
+ private TPromoCodeServiceInterface tPromoCodeServiceInterface;
|
|
|
+ @Autowired
|
|
|
public TOrderController(TOrderServiceInterface service) {
|
|
|
super(service);
|
|
|
}
|
|
@@ -122,4 +137,389 @@ public class TOrderController extends BaseController<TOrder,TOrderExample,TOrder
|
|
|
.setData(chartColumn)
|
|
|
.setMessage("SUCCESS"));
|
|
|
}
|
|
|
+
|
|
|
+ @PostMapping("/pay")
|
|
|
+ public ResponseEntity<?> pay(@RequestBody StatisticsParam param) {
|
|
|
+ Long equipmentId = Long.valueOf(param.getEquipmentId());
|
|
|
+ String adminId = param.getAdminId();
|
|
|
+ String payType = param.getType();
|
|
|
+ Double price1 = param.getPrice();
|
|
|
+ String frpCode = "WEIXIN_NATIVE";
|
|
|
+ TEquipment equipment = tEquipmentServiceInterface.selectEntityById(equipmentId);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal price = BigDecimal.valueOf(price1);
|
|
|
+ if (BigDecimal.ZERO.compareTo(price) >= 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ String sn = initSn(equipmentId);
|
|
|
+
|
|
|
+ TProportionExample example = new TProportionExample();
|
|
|
+ TProportionExample.Criteria criteria = example.createCriteria();
|
|
|
+ criteria.andAdminIdEqualTo(Long.valueOf(adminId));
|
|
|
+ List<TProportion> tProportions = tProportionServiceInterface.selectByOption(example);
|
|
|
+ TProportion proportion =tProportions.get(0);
|
|
|
+
|
|
|
+ if (proportion == null) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("设备商家未完成分销设置")
|
|
|
+ .setMessage("设备商家未完成分销设置"));
|
|
|
+ }
|
|
|
+
|
|
|
+ TAdmin admin = tAdminServiceInterface.selectEntityById(Long.valueOf(adminId));
|
|
|
+ if (admin == null) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("找不到设备商家")
|
|
|
+ .setMessage("找不到设备商家"));
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer 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();
|
|
|
+// TOrder.Type orderType = null;
|
|
|
+ Integer orderType = null;
|
|
|
+
|
|
|
+ if (type == null) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("设备商家未完成分销设置")
|
|
|
+ .setMessage("设备商家未完成分销设置"));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 1:
|
|
|
+
|
|
|
+ if (admin.getType() != 1) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("设备商家类型错误")
|
|
|
+ .setMessage("设备商家类型错误"));
|
|
|
+ }
|
|
|
+
|
|
|
+ agencyMch = tPromoCodeServiceInterface.getMch(admin.getAgencyId());
|
|
|
+ if (agencyMch == null || StringUtils.isBlank(agencyMch.getOrder_status())) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("设备商家未注册提现账户")
|
|
|
+ .setMessage("设备商家未注册提现账户"));
|
|
|
+ }
|
|
|
+
|
|
|
+ agencyProportion = BigDecimal.valueOf(proportion.getAgencyProportion());
|
|
|
+ adminProportion = BigDecimal.valueOf(proportion.getAdminProportion());
|
|
|
+// orderType = TOrder.Type.agency;
|
|
|
+ orderType = 1;
|
|
|
+
|
|
|
+ // 代理分销获得利润
|
|
|
+ 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 2:
|
|
|
+
|
|
|
+ if (admin.getType() != 2) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("设备商家类型错误")
|
|
|
+ .setMessage("设备商家类型错误"));
|
|
|
+ }
|
|
|
+
|
|
|
+ agencyMch =tPromoCodeServiceInterface.getMch(admin.getAgencyId());
|
|
|
+ merchantMch = tPromoCodeServiceInterface.getMch(admin.getMerchantId());
|
|
|
+
|
|
|
+ if (agencyMch == null || StringUtils.isBlank(agencyMch.getOrder_status())) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("设备商家未注册提现账户")
|
|
|
+ .setMessage("设备商家未注册提现账户"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (merchantMch == null || StringUtils.isBlank(merchantMch.getOrder_status())) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("设备商家未注册提现账户")
|
|
|
+ .setMessage("设备商家未注册提现账户"));
|
|
|
+ }
|
|
|
+
|
|
|
+ agencyProportion = BigDecimal.valueOf(proportion.getAgencyProportion());
|
|
|
+ adminProportion = BigDecimal.valueOf(proportion.getAdminProportion());
|
|
|
+ merchantProportion = BigDecimal.valueOf(proportion.getMerchantProportion());
|
|
|
+ orderType = 2;
|
|
|
+
|
|
|
+ // 代理分销获得利润
|
|
|
+ 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 3:
|
|
|
+
|
|
|
+ if (admin.getType() != 3) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("设备商家类型错误")
|
|
|
+ .setMessage("设备商家类型错误"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ agencyMch =tPromoCodeServiceInterface.getMch(admin.getAgencyId());
|
|
|
+ merchantMch = tPromoCodeServiceInterface.getMch(admin.getMerchantId());
|
|
|
+ personageMch =tPromoCodeServiceInterface.getMch(admin.getPersonageId());
|
|
|
+
|
|
|
+
|
|
|
+ if (agencyMch == null || StringUtils.isBlank(agencyMch.getOrder_status())) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("设备商家未注册提现账户")
|
|
|
+ .setMessage("设备商家未注册提现账户"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (merchantMch == null || StringUtils.isBlank(merchantMch.getOrder_status())) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("设备商家未注册提现账户")
|
|
|
+ .setMessage("设备商家未注册提现账户"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (personageMch == null || StringUtils.isBlank(personageMch.getOrder_status())) {
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("设备商家未注册提现账户")
|
|
|
+ .setMessage("设备商家未注册提现账户"));
|
|
|
+ }
|
|
|
+
|
|
|
+ agencyProportion = BigDecimal.valueOf(proportion.getAgencyProportion());
|
|
|
+ adminProportion = BigDecimal.valueOf(proportion.getAdminProportion());
|
|
|
+ merchantProportion = BigDecimal.valueOf(proportion.getMerchantProportion());
|
|
|
+ personageProportion = BigDecimal.valueOf(proportion.getPersonageProportion());
|
|
|
+
|
|
|
+ orderType = 3;
|
|
|
+
|
|
|
+ // 代理分销获得利润
|
|
|
+ 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 = "http://app.sunzee.com.cn/api/order/notify.htm";
|
|
|
+ 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;
|
|
|
+ String productName = "";
|
|
|
+ if(payType.equals("0")){
|
|
|
+ productName = "按天数购买";
|
|
|
+ }else{
|
|
|
+ productName = "按次数购买";
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+// TOrder order = new TOrder(sn, 0, productName, price, equipment.getClientId(), equipmentId,
|
|
|
+// orderType, admin.getId(), agencyId, merchantId, personageId,
|
|
|
+// frpCode, altInfo.toString(), adminProportion, agencyProportion, merchantProportion, personageProportion,);
|
|
|
+
|
|
|
+// orderService.create(order);
|
|
|
+ TOrder order1 = new TOrder();
|
|
|
+ order1.setSn(sn);
|
|
|
+ order1.setType(orderType);
|
|
|
+ order1.setAgencyId(agencyId);
|
|
|
+ order1.setMerchantId(merchantId);
|
|
|
+ order1.setPersonageId(personageId);
|
|
|
+ order1.setAdminId(admin.getId());
|
|
|
+ order1.setProductName(productName);
|
|
|
+ float p = Float.parseFloat(price1.toString());
|
|
|
+ order1.setPrice(p);
|
|
|
+ order1.setEquipmentId(equipmentId);
|
|
|
+ order1.setClientId(equipment.getClientId());
|
|
|
+ order1.setStatus(0);
|
|
|
+ order1.setTrxNo(productName);
|
|
|
+ order1.setCreateDate(new Date());
|
|
|
+ order1.setModifyDate(new Date());
|
|
|
+ order1.setFrpCode(frpCode);
|
|
|
+ tOrderService.insert(order1);
|
|
|
+
|
|
|
+ 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 client6= clientId.substring(clientId.length()-6,clientId.length());
|
|
|
+// productName=productName+"-"+equipment.getName()+"-"+client6;
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = tOrderService.uniPay(
|
|
|
+
|
|
|
+ orderNo, amount, productName, productDesc,
|
|
|
+ commonParameter, returnUrl, notifyUrl, frpCode,
|
|
|
+ isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
|
|
|
+ buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
|
|
|
+ );
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("申请支付失败")
|
|
|
+ .setMessage("申请支付失败"));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData("找不到支付图片")
|
|
|
+ .setMessage("找不到支付图片"));
|
|
|
+ }
|
|
|
+// send(clientId,sn,productName);
|
|
|
+// return JsonMessage.success(rd_Pic);
|
|
|
+// JSONObject kindData = new JSONObject();
|
|
|
+// kindData.put("sn" , sn);
|
|
|
+// kindData.put("rd_Pic",rd_Pic);
|
|
|
+ return ResponseEntity
|
|
|
+ .status(HttpStatus.OK)
|
|
|
+ .body(new ResultMessage()
|
|
|
+ .setCode(true)
|
|
|
+ .setData(rd_Pic)
|
|
|
+ .setMessage("SUCCESS"));
|
|
|
+ }
|
|
|
+ private String initSn(Long equipmentId) {
|
|
|
+ StringBuilder number = new StringBuilder();
|
|
|
+ if (equipmentId != null) {
|
|
|
+ Random random = new Random();
|
|
|
+ /**
|
|
|
+ * 6位随机
|
|
|
+ */
|
|
|
+ for (int i = 0; i < 6; i++) {
|
|
|
+ number.append(String.valueOf(random.nextInt(10)));
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 设备id
|
|
|
+ */
|
|
|
+ number.append(equipmentId.toString());
|
|
|
+ /**
|
|
|
+ * 日期
|
|
|
+ */
|
|
|
+ number.append(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
|
|
|
+ }
|
|
|
+ return number.toString();
|
|
|
+ }
|
|
|
}
|