| package com.matrix.system.hive.action; | 
|   | 
| import com.matrix.component.rabbitmq.RabiitMqTemplate; | 
| 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 com.matrix.system.shopXcx.mqTask.MQTaskRouting; | 
| import com.matrix.system.wechart.templateMsg.UniformMsgParam; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.beans.factory.annotation.Value; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.transaction.annotation.Transactional; | 
| import org.springframework.web.bind.annotation.RequestBody; | 
| 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; | 
|   | 
|     @Resource | 
|     private MoneyCardUseFlowDao moneyCardUseFlowDao; | 
|   | 
|     @Resource | 
|     private   MoneyCardUseDao moneyCardUseDao; | 
|   | 
|   | 
|     @Value("${evn}") | 
|     private  String evn; | 
|   | 
|     @Autowired | 
|     private RabiitMqTemplate rabiitMqTemplate; | 
|   | 
|   | 
|     /** | 
|      * 跳转 充值页面 | 
|      * | 
|      * @author jyy | 
|      */ | 
|     @RequestMapping(value = "/editFormCz") | 
|     public String editFormCz(Long id) { | 
|         MoneyCardUse cardUseInfo = cardUseService.findByVipId(id); | 
|         if (cardUseInfo == null) { | 
|             cardUseInfo=vipInfoService.addVipDefaultCard(id); | 
|         } | 
|         WebUtil.getRequest().setAttribute("obj", cardUseInfo); | 
|         return "admin/hive/beautySalon/cz-form"; | 
|     } | 
|   | 
|     /** | 
|      * 充值 | 
|      * | 
|      * @author 姜友瑶 | 
|      */ | 
|     @RequestMapping(value = "/cz") | 
|     public @ResponseBody | 
|     AjaxResult cz(@RequestBody CzXkVo czVo) { | 
|         SysOrder order=  orderService.updateAddCardMoney(czVo); | 
|         AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, "充值成功"); | 
|   | 
|         //发送微信公众号提醒 | 
|         UniformMsgParam uniformMsgParam=new UniformMsgParam(order.getCompanyId(),UniformMsgParam.GZH_CZCG); | 
|         uniformMsgParam.put("orderId",order.getId()); | 
|         rabiitMqTemplate.sendMsg(MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG+evn,uniformMsgParam.toJSONString()); | 
|   | 
|         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) { | 
|         // 根据id查到对应的订单信息 | 
|         SysOrder order = orderService.findById(id); | 
|         SysOrderItem item = new SysOrderItem(); | 
|         item.setOrderId(order.getId()); | 
|         List<SysOrderItem> items = orderItemService.findByModel(item); | 
|         order.setItems(items); | 
|         WebUtil.getRequest().setAttribute("order", order); | 
|   | 
|         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(@RequestBody 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 == 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, "冻结失败"); | 
|     } | 
|   | 
|   | 
|   | 
|   | 
| } |