Search in sources :

Example 1 with Sign

use of com.ikoori.vip.common.persistence.model.Sign in project vip by guangdada.

the class SignController method list.

/**
 * 获取签到规则列表
 */
@Permission
@RequestMapping(value = "/list")
@ResponseBody
public Object list(String condition) {
    Long userId = Long.valueOf(ShiroKit.getUser().getId());
    Merchant merchant = merchantService.getMerchantUserId(userId);
    Page<Sign> page = new PageFactory<Sign>().defaultPage();
    List<Map<String, Object>> result = signService.getSignList(page, null, page.getOrderByField(), page.isAsc(), merchant.getId());
    page.setRecords((List<Sign>) new SignWarpper(result).warp());
    return super.packForBT(page);
}
Also used : Merchant(com.ikoori.vip.common.persistence.model.Merchant) SignWarpper(com.ikoori.vip.server.modular.biz.warpper.SignWarpper) Sign(com.ikoori.vip.common.persistence.model.Sign) Map(java.util.Map) Permission(com.ikoori.vip.common.annotion.Permission) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with Sign

use of com.ikoori.vip.common.persistence.model.Sign in project vip by guangdada.

the class SignController method signUpdate.

/**
 * 跳转到修改签到规则
 */
@Permission
@RequestMapping("/sign_update/{signId}")
public String signUpdate(@PathVariable Long signId, Model model) {
    Sign sign = signService.selectById(signId);
    model.addAttribute(sign);
    return PREFIX + "sign_edit.html";
}
Also used : Sign(com.ikoori.vip.common.persistence.model.Sign) Permission(com.ikoori.vip.common.annotion.Permission) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Sign

use of com.ikoori.vip.common.persistence.model.Sign in project vip by guangdada.

the class SignApiImpl method signIn.

/**
 * 每日签到方法
 *
 * @Title: signIn
 * @param unionid
 * @return
 * @throws Exception
 * @date: 2017年9月29日 下午4:07:58
 * @author: chengxg
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
@Override
public JSONObject signIn(String unionid) throws Exception {
    log.info("进入signIn>>unionid=" + unionid);
    JSONObject obj = new JSONObject();
    obj.put("code", true);
    obj.put("msg", "签到成功");
    // unionid获得会员
    Member member = memberDao.getMemberByUnionid(unionid);
    if (member == null) {
        obj.put("msg", "您还不是会员哦");
        throw new Exception(obj.toJSONString());
    }
    // 当前时间
    Date nowDate = new Date();
    Date yesDate = DateUtil.getAfterDayDate(-1);
    String nowDateStr = DateUtil.getDay(new Date());
    String yesDateStr = DateUtil.getDay(yesDate);
    synchronized (unionid.intern()) {
        // 最后签到日期
        Date signDate = member.getSignDate();
        // 如果最后签到日期为null,表示历史第一次签到,修改连续签到天数=1,修改最后签到日期为今天
        if (signDate == null) {
            member.setSignDays(1);
        }
        String signDateStr = signDate == null ? "" : DateUtil.getDay(signDate);
        // 如果最后签到日期是今天,提示今天已经签到过, 不做后续处理
        if (nowDateStr.equals(signDateStr)) {
            obj.put("msg", "今天已经签到过了");
            throw new Exception(obj.toJSONString());
        } else {
            // 如果最后签到日期不是今天,保存今天的签到记录
            SignLog signLog = new SignLog();
            signLog.setMemberId(member.getId());
            signLog.setMerchantId(member.getMerchantId());
            signLogMapper.insert(signLog);
            // 如果最后签到日期是昨天,修改连续签到天数+1
            if (signDateStr.equals(yesDateStr)) {
                member.setSignDays(member.getSignDays() + 1);
            } else {
                // 如果最后签到日期不是昨天,修改连续签到天数=1
                member.setSignDays(1);
            }
            // 修改签到信息
            member.setSignDate(nowDate);
            member.setSignTotalDays(member.getSignTotalDays() + 1);
            memberMapper.updateById(member);
            // 连续签到天数
            Integer signDays = member.getSignDays();
            // 获得签到规则
            boolean getPoint = false;
            List<Sign> signs = getSignList(member.getMerchantId());
            for (Sign sign : signs) {
                if (!sign.isOnce()) {
                    Integer times = sign.getTimes();
                    Integer score = sign.getScore();
                    // times 等于1表示不需要连续, 每天签都能得积分
                    if (signDays % times == 0) {
                        boolean result = pointTradeService.savePointTrade(true, PointTradeType.MARK.getCode(), score, member.getId(), null, member.getMerchantId(), null, "签到");
                        if (!result) {
                            obj.put("msg", "签到失败!");
                            throw new Exception(obj.toJSONString());
                        }
                        // 连续签到为1天的情况, 可以同其他规则一起生效,不管是不是设置了“仅领一次”
                        if (times != 1) {
                            // 领取过后 , “仅领一次”的规则就不处理了
                            getPoint = true;
                        }
                    }
                }
            }
            // 处理“仅领一次”的规则
            if (!getPoint) {
                for (Sign sign : signs) {
                    if (sign.isOnce()) {
                        Integer times = sign.getTimes();
                        Integer score = sign.getScore();
                        if (signDays % times == 0) {
                            boolean result = pointTradeService.savePointTrade(true, PointTradeType.MARK.getCode(), score, member.getId(), null, member.getMerchantId(), null, "签到");
                            if (!result) {
                                obj.put("msg", "签到失败!");
                                throw new Exception(obj.toJSONString());
                            }
                            // 获取一次便退出
                            break;
                        }
                    }
                }
            }
        }
    }
    log.info("结束signIn" + unionid);
    return obj;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) SignLog(com.ikoori.vip.common.persistence.model.SignLog) Sign(com.ikoori.vip.common.persistence.model.Sign) Member(com.ikoori.vip.common.persistence.model.Member) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Sign (com.ikoori.vip.common.persistence.model.Sign)3 Permission (com.ikoori.vip.common.annotion.Permission)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Member (com.ikoori.vip.common.persistence.model.Member)1 Merchant (com.ikoori.vip.common.persistence.model.Merchant)1 SignLog (com.ikoori.vip.common.persistence.model.SignLog)1 SignWarpper (com.ikoori.vip.server.modular.biz.warpper.SignWarpper)1 Date (java.util.Date)1 Map (java.util.Map)1 Transactional (org.springframework.transaction.annotation.Transactional)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1