@RequestMapping(value = "/edit")
  public String orderEdit(Long id, String __VIEWSTATE, ModelMap map, HttpServletRequest req) {
    String username = (String) req.getSession().getAttribute("manager");
    if (null == username) {
      return "redirect:/Verwalter/login";
    }

    map.addAttribute("__VIEWSTATE", __VIEWSTATE);

    map.addAttribute("diy_site_list", tdDiySiteService.findByIsEnableTrue());

    List<TdCouponType> couponTypeList = null;

    couponTypeList = tdCouponTypeService.findAllOrderBySortIdAsc();

    map.addAttribute("coupon_type_list", couponTypeList);

    if (null != id) {
      map.addAttribute("coupon", tdCouponService.findOne(id));
      return "/site_mag/coupon_edit_hasId";
    }
    return "/site_mag/coupon_edit";
  }
  @RequestMapping(value = "/save")
  public String orderEdit(
      TdCoupon tdCoupon,
      String __VIEWSTATE,
      Long[] leftNumbers,
      Long typeId,
      ModelMap map,
      HttpServletRequest req) {
    String username = (String) req.getSession().getAttribute("manager");
    if (null == username) {
      return "redirect:/Verwalter/login";
    }

    map.addAttribute("__VIEWSTATE", __VIEWSTATE);

    if (null == tdCoupon.getId()) {
      tdManagerLogService.addLog("add", "用户修改优惠券", req);

      List<TdDiySite> tdDiySiteList = tdDiySiteService.findByIsEnableTrue();

      if (null != tdDiySiteList
          && tdDiySiteList.size() > 0
          && null != leftNumbers
          && leftNumbers.length > 0
          && null != typeId) {
        /** @author lc @注释:如果不是免费洗车券和免费打蜡券就不存在同盟店 */
        TdCouponType tdCouponType = tdCouponTypeService.findOne(typeId);

        if (tdCouponType.getTitle().equals("免费打蜡券") || tdCouponType.getTitle().equals("免费洗车券")) {
          for (int i = 0; i < tdDiySiteList.size(); i++) {
            TdDiySite tds = tdDiySiteList.get(i);

            if (null != tds && leftNumbers.length > i) {
              TdCoupon coupon =
                  tdCouponService.findTopByTypeIdAndDiySiteIdAndIsDistributtedFalse(
                      typeId, tds.getId());

              if (null == coupon) {
                coupon = new TdCoupon();
                coupon.setDiySiteId(tds.getId());
                coupon.setLeftNumber(leftNumbers[i]);
                coupon.setTypeId(typeId);
                coupon.setSortId(99L);
                coupon.setPrice(tdCouponType.getPrice());
              } else {
                coupon.setLeftNumber(coupon.getLeftNumber() + leftNumbers[i]);
              }

              tdCouponService.save(coupon);
            }
          }
        } else {
          TdCoupon coupon = tdCouponService.findByTypeId(typeId);

          if (null == coupon) {
            coupon = new TdCoupon();
            coupon.setLeftNumber(leftNumbers[0]);
            coupon.setTypeId(typeId);
            coupon.setSortId(99L);
            coupon.setPrice(tdCouponType.getPrice());
          } else {
            coupon.setLeftNumber(coupon.getLeftNumber() + leftNumbers[0]);
          }

          tdCouponService.save(coupon);
        }
      }

    } else {
      tdManagerLogService.addLog("edit", "用户修改优惠券", req);
      tdCouponService.save(tdCoupon);
    }

    return "redirect:/Verwalter/coupon/list";
  }