|  |  |  | 
|---|
|  |  |  | package com.matrix.system.shopXcx.action; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.matrix.biz.bean.BizUser; | 
|---|
|  |  |  | import com.matrix.biz.service.BizUserService; | 
|---|
|  |  |  | import com.matrix.core.anotations.RemoveRequestToken; | 
|---|
|  |  |  | import com.matrix.core.anotations.SaveRequestToken; | 
|---|
|  |  |  | import com.matrix.core.constance.MatrixConstance; | 
|---|
|  |  |  | import com.matrix.core.pojo.AjaxResult; | 
|---|
|  |  |  | import com.matrix.core.tools.StringUtils; | 
|---|
|  |  |  | import com.matrix.core.tools.WebUtil; | 
|---|
|  |  |  | import com.matrix.system.common.bean.SysUsers; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopScoreExchange; | 
|---|
|  |  |  | import com.matrix.system.hive.service.SysVipInfoService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.ShopScoreExchangeDao; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.pojo.ExchangeScorePOJO; | 
|---|
|  |  |  | 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 org.springframework.web.servlet.ModelAndView; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | public class ShopBizUserScoreAction { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BizUserService bizUserService; | 
|---|
|  |  |  | private SysVipInfoService sysVipInfoService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShopScoreExchangeDao shopScoreExchangeDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 记录编辑前的值Before_Edit_Value | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static final String BEV = "ShopBizUserScore_BEV"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 进入积分兑换界面 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @SaveRequestToken | 
|---|
|  |  |  | @RequestMapping(value = "/intoExchangePage") | 
|---|
|  |  |  | public ModelAndView exchangeScore(String userId) { | 
|---|
|  |  |  | BizUser bizUser = new BizUser(); | 
|---|
|  |  |  | ModelAndView modelAndView = new ModelAndView("admin/shop/user-score-exchange"); | 
|---|
|  |  |  | if (StringUtils.isNotBlank(userId)) { | 
|---|
|  |  |  | bizUser = bizUserService.findById(userId); | 
|---|
|  |  |  | if (bizUser.getCurrentScore() == null) { | 
|---|
|  |  |  | bizUser.setCurrentScore(0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | modelAndView.addObject("obj", bizUser); | 
|---|
|  |  |  | return modelAndView; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 兑换积分 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @RemoveRequestToken | 
|---|
|  |  |  | @RequestMapping(value = "/exchangeScore") | 
|---|
|  |  |  | public @ResponseBody | 
|---|
|  |  |  | AjaxResult exchangeScore(ExchangeScorePOJO pojo) { | 
|---|
|  |  |  | //校验参数中用户ID和用户兑换积分是否有效 | 
|---|
|  |  |  | if (pojo == null || StringUtils.isBlank(pojo.getUserId()) | 
|---|
|  |  |  | || pojo.getScore() == null || pojo.getScore() == 0) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "提交参数有误!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //兑换积分用户信息 | 
|---|
|  |  |  | BizUser bizUser = bizUserService.findById(pojo.getUserId()); | 
|---|
|  |  |  | if (bizUser == null) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "没有查询到相应用户!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (bizUser.getCurrentScore() == null) { | 
|---|
|  |  |  | bizUser.setCurrentScore(0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //如果兑换积分大于用户当前积分 | 
|---|
|  |  |  | if (pojo.getScore() > bizUser.getCurrentScore()) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "兑换积分大于用户当前积分!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //剩余积分 = 当前积分 - 兑换积分 | 
|---|
|  |  |  | Integer remainScore = bizUser.getCurrentScore() - pojo.getScore(); | 
|---|
|  |  |  | //当前操作用户信息 | 
|---|
|  |  |  | SysUsers loginUser = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|---|
|  |  |  | //修改用户剩余积分 | 
|---|
|  |  |  | BizUser updateModel = new BizUser(); | 
|---|
|  |  |  | updateModel.setUserId(bizUser.getUserId()); | 
|---|
|  |  |  | updateModel.setCurrentScore(remainScore); | 
|---|
|  |  |  | updateModel.setUpdateBy(loginUser.getSuName()); | 
|---|
|  |  |  | updateModel.setUpdateTime(new Date()); | 
|---|
|  |  |  | bizUserService.modifyByModel(updateModel); | 
|---|
|  |  |  | //添加积分兑换记录 | 
|---|
|  |  |  | ShopScoreExchange insertExchange = new ShopScoreExchange(); | 
|---|
|  |  |  | insertExchange.setCreateBy(loginUser.getSuName()); | 
|---|
|  |  |  | insertExchange.setUpdateBy(loginUser.getSuName()); | 
|---|
|  |  |  | insertExchange.setUserId(bizUser.getOpenId()); | 
|---|
|  |  |  | insertExchange.setExchangeScore(pojo.getScore()); | 
|---|
|  |  |  | insertExchange.setOperateId(loginUser.getSuId()); | 
|---|
|  |  |  | insertExchange.setRemark(pojo.getRemarks()); | 
|---|
|  |  |  | shopScoreExchangeDao.insert(insertExchange); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_SUCCESS, "兑换成功!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|