|
@@ -0,0 +1,385 @@
|
|
|
|
+/*
|
|
|
|
+ *
|
|
|
|
+ * AlarmRecordController
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+package com.hboxs.control.admin;
|
|
|
|
+
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
|
+import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.hboxs.common.*;
|
|
|
|
+import com.hboxs.entity.*;
|
|
|
|
+import com.hboxs.entity.Order;
|
|
|
|
+import com.hboxs.excel.AlarmRecordTarget;
|
|
|
|
+import com.hboxs.joinpay.entity.Mch;
|
|
|
|
+import com.hboxs.service.*;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
+import org.apache.commons.lang.time.DateUtils;
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
+import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Controller - 报警记录
|
|
|
|
+ */
|
|
|
|
+@Controller("payController")
|
|
|
|
+@RequestMapping("/asl-admin/pay")
|
|
|
|
+public class payController extends BaseController {
|
|
|
|
+
|
|
|
|
+ @Resource(name = "equipmentServiceImpl")
|
|
|
|
+ private EquipmentService equipmentService;
|
|
|
|
+
|
|
|
|
+ @Resource(name = "priceServiceImpl")
|
|
|
|
+ private PriceService priceService;
|
|
|
|
+
|
|
|
|
+ @Resource(name = "orderServiceImpl")
|
|
|
|
+ private OrderService orderService;
|
|
|
|
+
|
|
|
|
+ @Resource(name = "proportionServiceImpl")
|
|
|
|
+ private ProportionService proportionService;
|
|
|
|
+
|
|
|
|
+ @Resource(name = "adminServiceImpl")
|
|
|
|
+ private AdminService adminService;
|
|
|
|
+
|
|
|
|
+ @Resource(name = "mchServiceImpl")
|
|
|
|
+ private MchService mchService;
|
|
|
|
+
|
|
|
|
+ @Resource(name = "tradeServiceImpl")
|
|
|
|
+ private TradeService tradeService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 列表
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
|
+ public String list( Pageable pageable, ModelMap model) {
|
|
|
|
+ Admin admin = adminService.getCurrent();
|
|
|
|
+ model.addAttribute("admin", admin);
|
|
|
|
+ List<Admin> admins = adminService.findAllLowerAdmin(admin.getId());
|
|
|
|
+ Long[] lowerIds = null;
|
|
|
|
+ if (admins == null) {
|
|
|
|
+ lowerIds = new Long[]{};
|
|
|
|
+ } else {
|
|
|
|
+ lowerIds = new Long[admins.size()];
|
|
|
|
+ for (int i = 0; i < admins.size(); i++) {
|
|
|
|
+ lowerIds[i] = admins.get(i).getId();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<Equipment> equipmentList = equipmentService.findByAdminId(admin.getId());
|
|
|
|
+ model.addAttribute("equipmentList", equipmentList);
|
|
|
|
+ List<Price> priceList = priceService.findAll();
|
|
|
|
+ for(Price price:priceList){
|
|
|
|
+ if(price.getName().equals("dayPay")){
|
|
|
|
+ model.addAttribute("dayPrice", price.getPrice());
|
|
|
|
+ }
|
|
|
|
+ if(price.getName().equals("timesPay")){
|
|
|
|
+ model.addAttribute("timesPrice", price.getPrice());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ model.addAttribute("admin", adminService.getCurrent());
|
|
|
|
+ return "/admin/pay/list";
|
|
|
|
+ }
|
|
|
|
+ @RequestMapping(value = "/pay", method = RequestMethod.POST)
|
|
|
|
+ public String img(Double number,Long equipmentId, String dayOrTimes, String frpCode , ModelMap model) {
|
|
|
|
+ Equipment equipment = equipmentService.find(equipmentId);
|
|
|
|
+ if (!frpCode.equals("ALIPAY_NATIVE") && !frpCode.equals("WEIXIN_NATIVE")) {
|
|
|
|
+ return "参数错误";
|
|
|
|
+ }
|
|
|
|
+ if(equipment==null){
|
|
|
|
+ return "找不到设备";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Price> priceList = priceService.findAll();
|
|
|
|
+ Double dayPrice = null;
|
|
|
|
+ Double timesPrice =null;
|
|
|
|
+ for(Price price:priceList){
|
|
|
|
+ if(price.getName().equals("dayPay")){
|
|
|
|
+ dayPrice = price.getPrice();
|
|
|
|
+ }
|
|
|
|
+ if(price.getName().equals("timesPay")){
|
|
|
|
+ timesPrice = price.getPrice();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String productName = "";
|
|
|
|
+ BigDecimal price = null;
|
|
|
|
+ if(dayOrTimes.equals("day")){
|
|
|
|
+ productName = "按天数支付";
|
|
|
|
+ double pri = dayPrice * number;
|
|
|
|
+ price = BigDecimal.valueOf(pri);
|
|
|
|
+ }
|
|
|
|
+ if(dayOrTimes.equals("times")){
|
|
|
|
+ productName = "按次数支付";
|
|
|
|
+ double pri = timesPrice * number;
|
|
|
|
+ price = BigDecimal.valueOf(pri);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (BigDecimal.ZERO.compareTo(price) >= 0) {
|
|
|
|
+ return "商品价格异常";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String sn = orderService.initSn(equipmentId);
|
|
|
|
+
|
|
|
|
+ Proportion proportion = proportionService.getUniqueness(equipment.getAdminId());
|
|
|
|
+ if (proportion == null) {
|
|
|
|
+ return "设备商家未完成分销设置";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Admin admin = adminService.find(equipment.getAdminId());
|
|
|
|
+ if (admin == null) {
|
|
|
|
+ return"找不到设备商家";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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 "设备商家未完成分销设置";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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 "设备商家类型错误";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ agencyMch = mchService.getUniqueness(admin.getAgencyId());
|
|
|
|
+ if (agencyMch == null || StringUtils.isBlank(agencyMch.getOrder_status())) {
|
|
|
|
+ return "设备商家未注册提现账户";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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 "设备商家类型错误";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ agencyMch = mchService.getUniqueness(admin.getAgencyId());
|
|
|
|
+ merchantMch = mchService.getUniqueness(admin.getMerchantId());
|
|
|
|
+
|
|
|
|
+ if (agencyMch == null || StringUtils.isBlank(agencyMch.getOrder_status())) {
|
|
|
|
+ return "设备商家未注册提现账户";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (merchantMch == null || StringUtils.isBlank(merchantMch.getOrder_status())) {
|
|
|
|
+ return "设备商家未注册提现账户";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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 "设备商家类型错误";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ agencyMch = mchService.getUniqueness(admin.getAgencyId());
|
|
|
|
+ merchantMch = mchService.getUniqueness(admin.getMerchantId());
|
|
|
|
+ personageMch = mchService.getUniqueness(admin.getPersonageId());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (agencyMch == null || StringUtils.isBlank(agencyMch.getOrder_status())) {
|
|
|
|
+ return "设备商家未注册提现账户";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (merchantMch == null || StringUtils.isBlank(merchantMch.getOrder_status())) {
|
|
|
|
+ return "设备商家未注册提现账户";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (personageMch == null || StringUtils.isBlank(personageMch.getOrder_status())) {
|
|
|
|
+ return "设备商家未注册提现账户";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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, null, 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 "申请支付失败";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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 "找不到支付图片";
|
|
|
|
+ }
|
|
|
|
+// send(clientId,sn,productName);
|
|
|
|
+// return JsonMessage.success(rd_Pic);
|
|
|
|
+ JSONObject kindData = new JSONObject();
|
|
|
|
+ kindData.put("sn" , sn);
|
|
|
|
+ kindData.put("rd_Pic",rd_Pic);
|
|
|
|
+ model.addAttribute("sn", sn);
|
|
|
|
+ model.addAttribute("image", rd_Pic);
|
|
|
|
+ model.addAttribute("frpCode", frpCode);
|
|
|
|
+ model.addAttribute("price", price);
|
|
|
|
+ return "/admin/pay/payImg";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|