|
@@ -0,0 +1,384 @@
|
|
|
|
+/*
|
|
|
|
+ *
|
|
|
|
+ *
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+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.common.utils.CookieUtils;
|
|
|
|
+import com.hboxs.common.utils.PushUtils;
|
|
|
|
+import com.hboxs.entity.*;
|
|
|
|
+import com.hboxs.entity.Order;
|
|
|
|
+import com.hboxs.excel.OrderTarget;
|
|
|
|
+import com.hboxs.excel.PromoCodeTarget;
|
|
|
|
+import com.hboxs.joinpay.entity.Mch;
|
|
|
|
+import com.hboxs.service.*;
|
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
+import org.apache.commons.lang.time.DateUtils;
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
|
+import org.apache.shiro.authc.AuthenticationToken;
|
|
|
|
+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.context.request.RequestAttributes;
|
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
+import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.net.URLDecoder;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Controller - 代理商
|
|
|
|
+ */
|
|
|
|
+@Controller("adminPromoCodeController")
|
|
|
|
+@RequestMapping("/asl-admin/promoCode")
|
|
|
|
+public class PromoCodeController extends BaseController {
|
|
|
|
+
|
|
|
|
+ @Resource(name = "adminServiceImpl")
|
|
|
|
+ private AdminService adminService;
|
|
|
|
+ @Resource(name = "promoCodeServiceImpl")
|
|
|
|
+ private PromoCodeService promoCodeService;
|
|
|
|
+ @Resource(name = "roleServiceImpl")
|
|
|
|
+ private RoleService roleService;
|
|
|
|
+ @Resource(name = "globalConfigServiceImpl")
|
|
|
|
+ private GlobalConfigService globalConfigService;
|
|
|
|
+ @Resource(name = "mchServiceImpl")
|
|
|
|
+ private MchService mchService;
|
|
|
|
+ @Resource(name = "equipmentServiceImpl")
|
|
|
|
+ private EquipmentService equipmentService;
|
|
|
|
+ @Resource(name = "tradeServiceImpl")
|
|
|
|
+ private TradeService tradeService;
|
|
|
|
+ @Resource(name = "productServiceImpl")
|
|
|
|
+ private ProductService productService;
|
|
|
|
+ @Resource(name = "orderServiceImpl")
|
|
|
|
+ private OrderService orderService;
|
|
|
|
+ @Resource(name = "proportionServiceImpl")
|
|
|
|
+ private ProportionService proportionService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 列表
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
|
+ public String agencyList(Long code,String isUse,Pageable pageable, ModelMap model) {
|
|
|
|
+ String a = "";
|
|
|
|
+ if (code != null) {
|
|
|
|
+ pageable.getFilters().add(Filter.eq("code", code));
|
|
|
|
+ }
|
|
|
|
+ if (isUse != null) {
|
|
|
|
+ pageable.getFilters().add(Filter.eq("isUse", isUse));
|
|
|
|
+ }
|
|
|
|
+ // pageable.getFilters().add(Filter.eq("type", Admin.Type.agency));
|
|
|
|
+// pageable.getFilters().add(Filter.eq("isAdmined" , false));
|
|
|
|
+ model.addAttribute("isUse", isUse);
|
|
|
|
+ model.addAttribute("code", code);
|
|
|
|
+ model.addAttribute("page", promoCodeService.findPage(pageable));
|
|
|
|
+ model.addAttribute("currentAdmin", adminService.getCurrent());
|
|
|
|
+ return "/admin/promoCode/list";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 添加
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/add", method = RequestMethod.GET)
|
|
|
|
+ public String add(ModelMap model) {
|
|
|
|
+
|
|
|
|
+ return "/admin/promoCode/add";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "/edit", method = RequestMethod.GET)
|
|
|
|
+ public String edit(ModelMap model) {
|
|
|
|
+
|
|
|
|
+ return "/admin/promoCode/edit";
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 请求在线支付
|
|
|
|
+ *
|
|
|
|
+ * @param
|
|
|
|
+ * @param
|
|
|
|
+ * @param
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/img", method = RequestMethod.GET)
|
|
|
|
+ public String img(int number, String frpCode ,Pageable pageable, ModelMap model) {
|
|
|
|
+ Admin admin = adminService.getCurrent();
|
|
|
|
+ List<Equipment> equipmentList = equipmentService.findByAdminId(admin.getId());
|
|
|
|
+ Equipment equipment = equipmentList.get(0);
|
|
|
|
+ Long equipmentId = equipment.getId();
|
|
|
|
+ Proportion proportion = proportionService.getUniqueness(equipment.getAdminId());
|
|
|
|
+ Proportion.Type type = proportion.getType();
|
|
|
|
+ Order.Type orderType = null;
|
|
|
|
+ Long agencyId = admin.getAgencyId();
|
|
|
|
+ Long merchantId = admin.getMerchantId();
|
|
|
|
+ Long personageId = admin.getPersonageId();
|
|
|
|
+ switch (type) {
|
|
|
|
+ case agency:
|
|
|
|
+ orderType = Order.Type.agency;
|
|
|
|
+ break;
|
|
|
|
+ case merchant:
|
|
|
|
+ orderType = Order.Type.merchant;
|
|
|
|
+ break;
|
|
|
|
+ case personage:
|
|
|
|
+ orderType = Order.Type.personage;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ String sn = orderService.initSn(equipmentId);
|
|
|
|
+ String orderNo = sn;
|
|
|
|
+ String productName = "优惠码";
|
|
|
|
+ BigDecimal price = BigDecimal.valueOf(0.02*number);
|
|
|
|
+ BigDecimal cutPrice = price.multiply(new BigDecimal(100)).divide(new BigDecimal(100));
|
|
|
|
+ BigDecimal amount = cutPrice;
|
|
|
|
+ String productDesc = "";
|
|
|
|
+ String commonParameter = "";
|
|
|
|
+ String returnUrl = null;
|
|
|
|
+ String notifyUrl = JoinpayConstant.Notify_Url_PromoCode;
|
|
|
|
+ String isShowPic = "1";
|
|
|
|
+ String openId = null;
|
|
|
|
+ String authCode = null;
|
|
|
|
+ String appid = null;
|
|
|
|
+ String transactionModel = null;
|
|
|
|
+ String tradeMerchantNo = null;
|
|
|
|
+ String buyerId = null;
|
|
|
|
+ String isAlt = "0";
|
|
|
|
+ String altType = null;
|
|
|
|
+ String altUrl = null;
|
|
|
|
+ BigDecimal marketingAmount = null;
|
|
|
|
+
|
|
|
|
+// com.hboxs.entity.Order order = new com.hboxs.entity.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);
|
|
|
|
+ Order order1 = new Order();
|
|
|
|
+ order1.setSn(sn);
|
|
|
|
+ order1.setType(orderType);
|
|
|
|
+ order1.setAgencyId(agencyId);
|
|
|
|
+ order1.setMerchantId(merchantId);
|
|
|
|
+ order1.setPersonageId(personageId);
|
|
|
|
+ order1.setAdminId(admin.getId());
|
|
|
|
+ order1.setProductName(productName);
|
|
|
|
+ order1.setPrice(price);
|
|
|
|
+ order1.setEquipmentId(equipmentId);
|
|
|
|
+ order1.setClientId(equipment.getClientId());
|
|
|
|
+ order1.setStatus(Order.Status.unpay);
|
|
|
|
+ order1.setFrp_code(frpCode);
|
|
|
|
+ orderService.create(order1);
|
|
|
|
+
|
|
|
|
+ JSONArray altInfo = new JSONArray();
|
|
|
|
+ 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("申请支付失败");
|
|
|
|
+ return "申请支付失败";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
+ // 汇聚支付支付申请返回支付二维码图片
|
|
|
|
+ String rd_Pic = resultJson.getString("rd_Pic");
|
|
|
|
+
|
|
|
|
+ if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
|
|
|
|
+ return "找不到支付图片";
|
|
|
|
+ }
|
|
|
|
+// ModelMap model = new ModelMap();
|
|
|
|
+ model.addAttribute("image", rd_Pic);
|
|
|
|
+ model.addAttribute("price", price);
|
|
|
|
+ return "/admin/promoCode/img";
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 支付成功回调
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/promoCodeNotify", method = RequestMethod.GET)
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public Object refund(HttpServletRequest request) {
|
|
|
|
+
|
|
|
|
+ String r6_Status = request.getParameter("r6_Status");
|
|
|
|
+
|
|
|
|
+ // 订单号
|
|
|
|
+ String sn = request.getParameter("r2_OrderNo");
|
|
|
|
+ //价格
|
|
|
|
+ String price = request.getParameter("r3_Amount");
|
|
|
|
+ //生成优惠码的个数
|
|
|
|
+ double num = Long.valueOf(price)/0.02;
|
|
|
|
+ int number = (int) num;
|
|
|
|
+ Order order = orderService.findBySn(sn);
|
|
|
|
+ if(order.getStatus()!=Order.Status.unpay){
|
|
|
|
+ return "success";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(JoinpayConstant.r6_Status_100.equals(r6_Status)){
|
|
|
|
+
|
|
|
|
+ // 已支付
|
|
|
|
+ order.setStatus(Order.Status.pay);
|
|
|
|
+
|
|
|
|
+ // 支付平台产生的流水号
|
|
|
|
+ String r7_TrxNo = request.getParameter("r7_TrxNo");
|
|
|
|
+ order.setTrxNo(r7_TrxNo);
|
|
|
|
+
|
|
|
|
+ // 格式:YYYY-MM-DD HH:mm:ss
|
|
|
|
+ String ra_PayTime = request.getParameter("ra_PayTime");
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ Date payDate = sdf.parse(URLDecoder.decode(ra_PayTime, "UTF-8"));
|
|
|
|
+ order.setPayDate(payDate);
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
+
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ orderService.update(order);
|
|
|
|
+ Admin admin = adminService.find(order.getAdminId());
|
|
|
|
+ JSONObject kindData = new JSONObject();
|
|
|
|
+ kindData.put("sn" , order.getSn());
|
|
|
|
+ kindData.put("productName" , order.getProductName());
|
|
|
|
+ List<String> codes =new ArrayList<>();
|
|
|
|
+ for(int i=0;i<number;i++){
|
|
|
|
+ String code = orderService.initSn(order.getEquipmentId());
|
|
|
|
+ StringBuffer str = new StringBuffer();
|
|
|
|
+ str.append(code.substring(0,4)).append(code.substring(code.length()-4,code.length()));
|
|
|
|
+ codes.add(str.toString());
|
|
|
|
+ }
|
|
|
|
+ for(String code : codes){
|
|
|
|
+ PromoCode promoCode = new PromoCode();
|
|
|
|
+ promoCode.setCode(Long.parseLong(code));
|
|
|
|
+ promoCode.setAdminId(String.valueOf(order.getAdminId()));
|
|
|
|
+ promoCode.setIsUse("0");
|
|
|
|
+ promoCode.setCreateDate(new Date());
|
|
|
|
+ promoCode.setUserName(admin.getUsername());
|
|
|
|
+ promoCodeService.save(promoCode);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// PushUtils.push(equipmentService.findByClientId(order.getClientId()).getGtClientId(), "支付成功", "您的订单支付成功", PushUtils.buildJson("pay_success", kindData.toString()).toString());
|
|
|
|
+
|
|
|
|
+ return "支付成功";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return "success";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/delete", method = RequestMethod.POST)
|
|
|
|
+ public
|
|
|
|
+ @ResponseBody
|
|
|
|
+ Message delete(Long[] ids) {
|
|
|
|
+ if (ids.length >= adminService.count()) {
|
|
|
|
+ return Message.error("admin.common.deleteAllNotAllowed");
|
|
|
|
+ }
|
|
|
|
+ adminService.delete(ids);
|
|
|
|
+ return SUCCESS_MESSAGE;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "/export")
|
|
|
|
+ public Object export(HttpServletResponse response, Long[] ids, String date) {
|
|
|
|
+
|
|
|
|
+ Admin admin = adminService.getCurrent();
|
|
|
|
+
|
|
|
|
+ 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<Filter> filters = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ switch (admin.getType()) {
|
|
|
|
+ case admin:
|
|
|
|
+ break;
|
|
|
|
+ case agency:
|
|
|
|
+ filters.add(Filter.in("adminId", lowerIds));
|
|
|
|
+ break;
|
|
|
|
+ case merchant:
|
|
|
|
+ filters.add(Filter.in("adminId", lowerIds));
|
|
|
|
+ break;
|
|
|
|
+ case personage:
|
|
|
|
+ filters.add(Filter.in("adminId", lowerIds));
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ if (StringUtils.isNotBlank(date)) {
|
|
|
|
+ String[] datestring = date.split(" - ");
|
|
|
|
+ Date startDate = new SimpleDateFormat("yyyy-MM-dd").parse(datestring[0]);
|
|
|
|
+ Date endDate = new SimpleDateFormat("yyyy-MM-dd").parse(datestring[1]);
|
|
|
|
+ filters.add(Filter.geDate("createDate", startDate));
|
|
|
|
+ filters.add(Filter.leDate("createDate", DateUtils.addDays(endDate, 1)));
|
|
|
|
+ }
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return JsonMessage.success("导出错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //List<Order> list = orderService.findList(ids);
|
|
|
|
+// List<Order> list = orderService.findList(null, filters, null);
|
|
|
|
+// List<OrderTarget> orderTargetList = orderService.findById(admin, list);
|
|
|
|
+ List<PromoCode> list = promoCodeService.findList(null, filters, null);
|
|
|
|
+ List<PromoCodeTarget> promoCodeTargets = promoCodeService.findById(list);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ ExportParams exportParams = new ExportParams("优惠码记录", "sheet1");
|
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcel(exportParams, PromoCodeTarget.class, promoCodeTargets);
|
|
|
|
+
|
|
|
|
+ if (workbook != null) {
|
|
|
|
+ OutputStream os = null;
|
|
|
|
+ try {
|
|
|
|
+ os = response.getOutputStream();
|
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("订单记录数据导出" + format.format(new Date()) + ".xls", "UTF-8"));
|
|
|
|
+ workbook.write(os);
|
|
|
|
+ return JsonMessage.success("导出成功");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return JsonMessage.success("导出错误");
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ os.close();
|
|
|
|
+ workbook.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return JsonMessage.success("导出错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|