| package com.matrix.system.hive.action; | 
|   | 
| import com.matrix.core.constance.MatrixConstance; | 
| import com.matrix.core.exception.GlobleException; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.core.pojo.PaginationVO; | 
| import com.matrix.core.tools.DateUtil; | 
| import com.matrix.core.tools.WebUtil; | 
| import com.matrix.system.common.bean.SysUsers; | 
| import com.matrix.system.constance.Dictionary; | 
| import com.matrix.system.constance.SystemConstance; | 
| import com.matrix.system.hive.bean.*; | 
| import com.matrix.system.hive.dao.MoneyCardUseDao; | 
| import com.matrix.system.hive.dao.MoneyCardUseFlowDao; | 
| import com.matrix.core.tools.DateUtil; | 
| import com.matrix.system.hive.pojo.CzXkVo; | 
| import com.matrix.system.hive.service.*; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.transaction.annotation.Transactional; | 
| import org.springframework.web.bind.annotation.RequestMapping; | 
| import org.springframework.web.bind.annotation.ResponseBody; | 
|   | 
| import javax.annotation.Resource; | 
| import javax.servlet.http.HttpServletRequest; | 
| import java.util.Arrays; | 
| import java.util.Date; | 
| import java.util.List; | 
|   | 
|   | 
| /** | 
|  * @author jiangyouyao | 
|  * @date 2016-09-20 10:17 | 
|  */ | 
| @Controller | 
| @RequestMapping(value = "admin/moneyCardUse") | 
| public class MoneyCardUseController extends BaseController { | 
|   | 
|     @Resource | 
|     private MoneyCardUseService cardUseService; | 
|     @Resource | 
|     private SysOrderService orderService; | 
|     @Resource | 
|     private SysOrderItemService orderItemService; | 
|     @Resource | 
|     private MoneyCardUseFreezeService moneyCardUseFreezeService; | 
|   | 
|     @Resource | 
|     private SysVipLevelService vipLevelService; | 
|     @Resource | 
|     private SysVipInfoService vipInfoService; | 
|   | 
|     @Autowired | 
|     private MoneyCardUseFlowDao moneyCardUseFlowDao; | 
|     @Autowired | 
|     private   MoneyCardUseDao moneyCardUseDao; | 
|     /** | 
|      * 跳转 充值页面 | 
|      * | 
|      * @author jyy | 
|      */ | 
|     @RequestMapping(value = "/editFormCz") | 
|     public String editFormCz() { | 
|         SysVipInfo info = | 
|                 (SysVipInfo) WebUtil.getSession().getAttribute(SystemConstance.CURRENT_CUSTOMER); | 
|         MoneyCardUse cardUseInfo = cardUseService.findByVipId(info.getId()); | 
|   | 
|         if (cardUseInfo == null) { | 
|             cardUseInfo = new MoneyCardUse(); | 
|             cardUseInfo.setVipId(info.getId()); | 
|             cardUseInfo.setCardName("储值卡"); | 
|             cardUseInfo.setIsVipCar(Dictionary.FLAG_YES_Y); | 
|             cardUseInfo.setRealMoney(0D); | 
|             cardUseInfo.setGiftMoney(0D); | 
|             cardUseInfo.setSource("-"); | 
|             cardUseInfo.setFailTime(DateUtil.stringToDate("2050-01-01 00:00",DateUtil.DATE_FORMAT_MM)); | 
|             cardUseInfo.setStatus(Dictionary.MONEYCARD_STATUS_YX); | 
|             moneyCardUseDao.insert(cardUseInfo); | 
|         } | 
|   | 
|         WebUtil.getRequest().setAttribute("obj", cardUseInfo); | 
|         return "admin/hive/beautySalon/cz-form"; | 
|     } | 
|   | 
|     /** | 
|      * 充值 | 
|      * | 
|      * @author 姜友瑶 | 
|      */ | 
|     @RequestMapping(value = "/cz") | 
|     public @ResponseBody | 
|     AjaxResult cz(CzXkVo czVo) { | 
|         SysOrder order=  orderService.updateAddCardMoney(czVo); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, "充值成功"); | 
|         result.putInMap("orderId",order.getId()); | 
|         return result; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 列表显示 | 
|      */ | 
|     @RequestMapping(value = "/showList") | 
|     public @ResponseBody | 
|     AjaxResult showList(MoneyCardUse moneyCardUse, PaginationVO pageVo) { | 
|   | 
|         return showList(cardUseService, moneyCardUse, pageVo); | 
|     } | 
|   | 
|     /** | 
|      * 列表显示 | 
|      */ | 
|     @RequestMapping(value = "/showCardFlowList") | 
|     public @ResponseBody | 
|     AjaxResult showCardFlowList(MoneyCardUseFlow moneyCardUseFlow, PaginationVO pageVo) { | 
|         List<MoneyCardUseFlow> dataList = moneyCardUseFlowDao.selectInPage(moneyCardUseFlow, pageVo); | 
|         return AjaxResult.buildSuccessInstance(dataList, moneyCardUseFlowDao.selectTotalRecord(moneyCardUseFlow)); | 
|     } | 
|   | 
|     /** | 
|      * 新增或者修改页面 | 
|      */ | 
|     @Transactional | 
|     @RequestMapping(value = "/modify") | 
|     public @ResponseBody | 
|     AjaxResult modify(MoneyCardUse moneyCardUse) { | 
|   | 
|         //设置卡项使用流水 | 
|         MoneyCardUse oldCard = cardUseService.findById(moneyCardUse.getId()); | 
|         SysUsers user = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); | 
|   | 
|         MoneyCardUseFlow moneyCardUseFlow = new MoneyCardUseFlow(); | 
|         moneyCardUseFlow.setTotal(moneyCardUse.getRealMoney() - oldCard.getRealMoney()); | 
|         moneyCardUseFlow.setGiftMoney(moneyCardUse.getGiftMoney() - oldCard.getGiftMoney()); | 
|         if(moneyCardUse.getLastCount()!=null){ | 
|             moneyCardUseFlow.setTimes(moneyCardUse.getLastCount() - oldCard.getLastCount()); | 
|         } | 
|   | 
|   | 
|         moneyCardUseFlow.setCarUseId(oldCard.getId()); | 
|         moneyCardUseFlow.setVipId(oldCard.getVipId()); | 
|         moneyCardUseFlow.setType(MoneyCardUseFlow.USE_TYPE_CARD_MODIFY); | 
|         moneyCardUseFlow.setCreateTime(new Date()); | 
|         moneyCardUseFlow.setOperationId(user.getSuId()); | 
|         moneyCardUseFlow.setContent(moneyCardUse.getChangeRemark()); | 
|         moneyCardUseFlow.setBalance(moneyCardUse.getGiftMoney()+moneyCardUse.getRealMoney()); | 
|         moneyCardUseFlowDao.insert(moneyCardUseFlow); | 
|         cardUseService.modify(moneyCardUse); | 
|         return AjaxResult.buildSuccessInstance("修改成功"); | 
|     } | 
|   | 
|     /** | 
|      * 进入修改界面 | 
|      */ | 
|     @RequestMapping(value = "/editForm") | 
|     public String editForm(Long id) { | 
|         MoneyCardUse moneyCardUse; | 
|         if (id != null) { | 
|             moneyCardUse = cardUseService.findById(id); | 
|             WebUtil.getRequest().setAttribute("obj", moneyCardUse); | 
|         } | 
|         return "admin/hive/vip/moneyCardUse-form"; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 查询会员卡最低充值金额 | 
|      * | 
|      * @author jyy | 
|      */ | 
|     @RequestMapping(value = "/fundMin") | 
|     public @ResponseBody | 
|     AjaxResult fundMin(Long id) { | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(vipLevelService.findById(id)), 0); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 跳转 补交页面 | 
|      * | 
|      * @author jyy | 
|      */ | 
|     @RequestMapping(value = "/toBj") | 
|     public String toBj(Long id, HttpServletRequest request) { | 
|         // 根据id查到对应的订单信息 | 
|         SysOrder order = orderService.findById(id); | 
|         WebUtil.getRequest().setAttribute("order", order); | 
|   | 
|         SysOrderItem item = new SysOrderItem(); | 
|         item.setOrderId(order.getId()); | 
|         item.setStatus(Dictionary.ORDER_STATU_QK); | 
|         order.setItems(orderItemService.findByModel(item)); | 
|   | 
|   | 
|         MoneyCardUse moneyCardUse = new MoneyCardUse(); | 
|         moneyCardUse.setVipId(order.getVipId()); | 
|         moneyCardUse.setStatus(Dictionary.MONEYCARD_STATUS_YX); | 
|         List<MoneyCardUse> cards = cardUseService.findByModel(moneyCardUse); | 
|   | 
|         WebUtil.getRequest().setAttribute("cards", cards); | 
|   | 
|         return "admin/hive/beautySalon/bj-form"; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 获取用户的可用充值卡 | 
|      * | 
|      * @author jyy | 
|      */ | 
|     @RequestMapping(value = "/getUseMoneyCard") | 
|     public @ResponseBody | 
|     AjaxResult getUseMoneyCard(Long vipId) { | 
|         MoneyCardUse moneyCardUse = new MoneyCardUse(); | 
|         moneyCardUse.setVipId(vipId); | 
|         moneyCardUse.setStatus(Dictionary.MONEYCARD_STATUS_YX); | 
|         List<MoneyCardUse> cards = cardUseService.findByModel(moneyCardUse); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, cards); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 补交 | 
|      * | 
|      * @throws GlobleException | 
|      * @author jyy | 
|      */ | 
|     @RequestMapping(value = "/bj") | 
|     public @ResponseBody | 
|     AjaxResult bj(SysOrder order) throws GlobleException { | 
|   | 
|         orderService.updateAfterMoney(order); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "补交成功"); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 跳转 续卡页面 | 
|      * | 
|      * @author jyy | 
|      */ | 
|     @RequestMapping(value = "/editFormXk") | 
|     public String editFormXk(Long id) { | 
|         SysVipInfo info = vipInfoService.findById(id); | 
|         MoneyCardUse cardInfo = cardUseService.findByVipId(info.getId()); | 
|         WebUtil.getRequest().setAttribute("obj", cardInfo); | 
|         return "admin/hive/beautySalon/xk-form"; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 删除 | 
|      */ | 
|     @RequestMapping(value = "/del") | 
|     public @ResponseBody | 
|     AjaxResult del(String keys) { | 
|   | 
|         return remove(cardUseService, keys); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 会员充值卡的列表显示 | 
|      */ | 
|     @RequestMapping(value = "/showVipMoneyCardList") | 
|     public @ResponseBody | 
|     AjaxResult showVipMoneyCardList(MoneyCardUse moneyCardUse, PaginationVO pageVo) { | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, cardUseService.findVipCardUseInPage( | 
|                 moneyCardUse, pageVo), cardUseService.findTotalVipCardUse(moneyCardUse)); | 
|     } | 
|   | 
|   | 
|   | 
|   | 
|     /** | 
|      * 这个action有2个功能 | 
|      * 将会员充值卡设置为有效 | 
|      * 或者修改有效期 | 
|      * | 
|      * @author jiangyouyao | 
|      * @date 2016-09-21 | 
|      */ | 
|     @RequestMapping(value = "/active") | 
|     public @ResponseBody | 
|     AjaxResult active(MoneyCardUse moneyCardUse) { | 
|         MoneyCardUse proj = moneyCardUseDao.selectById(moneyCardUse.getId()); | 
|         String status = proj.getStatus(); | 
|         Date failTime = proj.getFailTime(); | 
|         Date today = new Date(); | 
|         Date newDate = null; | 
|         newDate = moneyCardUse.getFailTime(); | 
|         // 状态为无效或者冻结的才能设置有效 | 
|         switch (status) { | 
|             case Dictionary.TAOCAN_STATUS_WX: | 
|                 // 如果到期,需要重新设置有效期 | 
|                 if (newDate != null && newDate.before(today)) { | 
|                     return new AjaxResult(AjaxResult.STATUS_FAIL, "有效期要大于当前日期"); | 
|                 } | 
|                 if (newDate == null && failTime.before(today)) { | 
|                     //如果是已过期界面会提醒重新设置有效期 | 
|                     return new AjaxResult(AjaxResult.STATUS_SUCCESS, "已过期"); | 
|                 } | 
|                 break; | 
|             //如果是冻结状态则要算出冻结的天数,延长有效期 | 
|             case Dictionary.TAOCAN_STATUS_DJ: | 
|                 MoneyCardUseFreeze freeze = new MoneyCardUseFreeze(); | 
|                 freeze = moneyCardUseFreezeService.findByMoneyCardUseId(proj.getId()); | 
|                 proj.setFailTime(DateUtil.nextNDate(failTime, freeze.getGapDays())); | 
|                 break; | 
|             default: | 
|                 return new AjaxResult(AjaxResult.STATUS_FAIL, "请选择无效或者冻结的充值卡"); | 
|         } | 
|         proj.setFailTime(moneyCardUse.getFailTime()); | 
|         cardUseService.active(proj); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "已设置为有效"); | 
|     } | 
|   | 
|     /** | 
|      * 将会员充值卡设置为无效 | 
|      * | 
|      * @author jiangyouyao | 
|      * @date 2016-09-21 | 
|      */ | 
|     @RequestMapping(value = "/invalid") | 
|     public @ResponseBody | 
|     AjaxResult invalidTc(MoneyCardUse moneyCardUse) { | 
|         MoneyCardUse proj = cardUseService.findById(moneyCardUse.getId()); | 
|         //以及转让或者退款的不能在设置为无效 | 
|         String status = proj.getStatus(); | 
|         switch (status) { | 
|             case Dictionary.TAOCAN_STATUS_TK: | 
|                 return new AjaxResult(AjaxResult.STATUS_FAIL, "充值卡已退款"); | 
|             case Dictionary.TAOCAN_STATUS_ZR: | 
|                 return new AjaxResult(AjaxResult.STATUS_FAIL, "充值卡已转让"); | 
|             case Dictionary.TAOCAN_STATUS_DJ: | 
|                 return new AjaxResult(AjaxResult.STATUS_FAIL, "充值卡已冻结"); | 
|         } | 
|         cardUseService.invalid(proj); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "已设置为无效"); | 
|     } | 
|   | 
|     /** | 
|      * 转让重置卡 | 
|      * | 
|      * @return | 
|      * @author jiangyouyao | 
|      * @date 2016-09-21 | 
|      * 转让信息 | 
|      * 被转让的会员id | 
|      */ | 
|     @RequestMapping(value = "/transfer") | 
|     public @ResponseBody | 
|     AjaxResult transfer(MoneyCardUse moneyCardUse, Long vipId2, Double money) { | 
|         cardUseService.transfer(moneyCardUse, vipId2, money); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "充值卡转让成功"); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 冻结充值卡 | 
|      * | 
|      * @param moneyCardUse | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/freeze") | 
|     public @ResponseBody | 
|     AjaxResult freeze(MoneyCardUse moneyCardUse) { | 
|         int i = cardUseService.freeze(moneyCardUse); | 
|         if (i > 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, "冻结成功"); | 
|         } | 
|         return new AjaxResult(AjaxResult.STATUS_FAIL, "冻结失败"); | 
|     } | 
|   | 
|     /** | 
|      * 退款 | 
|      * | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "getEffectCard") | 
|     public @ResponseBody | 
|     AjaxResult getEffectCard(MoneyCardUse moneyCardUse) { | 
|         AjaxResult result = AjaxResult.buildSuccessInstance(""); | 
|         //要退款的充值卡 | 
|         MoneyCardUse srcCardUse = cardUseService.findById(moneyCardUse.getId()); | 
|         if (!srcCardUse.getStatus().equals(Dictionary.TAOCAN_STATUS_YX)) { | 
|             throw new GlobleException("不是有效充值卡"); | 
|         } | 
|         //该会员是否有有效会籍卡 | 
|         MoneyCardUse targetCardUse = cardUseService.findByVipId(moneyCardUse.getVipId()); | 
|   | 
|         double money = srcCardUse.getRealMoney(); | 
|   | 
|         if (targetCardUse != null) { | 
|             targetCardUse.setRealMoney(money); | 
|             List<MoneyCardUse> list = Arrays.asList(targetCardUse); | 
|   | 
|             if (targetCardUse.getId().equals(srcCardUse.getId())) { | 
|                 result.setInfo("会籍卡退款只能退现金"); | 
|                 result.setRows(list); | 
|   | 
|             } else { | 
|                 result.setInfo("有有效会籍卡"); | 
|                 result.setRows(list); | 
|             } | 
|         } else { | 
|             //无会员卡则new一个,为了把钱传递到前台 | 
|             targetCardUse = new MoneyCardUse(); | 
|             targetCardUse.setRealMoney(money); | 
|             List<MoneyCardUse> list1 = Arrays.asList(targetCardUse); | 
|             result.setInfo("无有效会籍卡,退现金"); | 
|             result.setRows(list1); | 
|         } | 
|         return result; | 
|     } | 
|   | 
|     @RequestMapping(value = "/returnMoney") | 
|     public @ResponseBody | 
|     AjaxResult returnMoney(MoneyCardUse moneyCardUse, Long hjkId, String tcRemark, Long | 
|             shopId, Double money | 
|             , String tcName) { | 
|         int i = cardUseService.returnMoney(moneyCardUse, hjkId); | 
|         if (i > 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, "退款成功"); | 
|         } | 
|         return new AjaxResult(AjaxResult.STATUS_FAIL, "冻结失败"); | 
|     } | 
| } |