|  |  |  | 
|---|
|  |  |  | import com.matrix.system.activity.entity.ActivitySignReceiveRecord; | 
|---|
|  |  |  | import com.matrix.system.activity.entity.ActivitySignRecord; | 
|---|
|  |  |  | import com.matrix.system.activity.entity.ActivitySignWriteoff; | 
|---|
|  |  |  | import com.matrix.system.common.constance.AppConstance; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysVipInfo; | 
|---|
|  |  |  | import com.matrix.system.score.entity.ScoreVipDetail; | 
|---|
|  |  |  | import com.matrix.system.score.service.ScoreVipDetailService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.dto.SeeAwardTextDto; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.dto.SignAwardDto; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.service.WxShopLogisticsQueryService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.tools.WxShopCouponUtil; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.vo.*; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopActivities; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopDeliveryInfo; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopLogisticsInfo; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopReceiveAddress; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.ShopActivitiesDao; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.ShopDeliveryInfoDao; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.ShopLogisticsInfoDao; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.ShopReceiveAddressDao; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.*; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.*; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.vo.SalesOrderVo; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WxShopLogisticsQueryService wxShopLogisticsQueryService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ScoreVipDetailService scoreVipDetailService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShopCouponDao shopCouponDao; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WxShopCouponUtil wxShopCouponUtil; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShopCouponRecordDao shopCouponRecordDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "获取签到基本信息", notes = "") | 
|---|
|  |  |  | @ApiResponses({ | 
|---|
|  |  |  | 
|---|
|  |  |  | * 查询是否有签到奖品 | 
|---|
|  |  |  | *       日常奖励和自定义奖品 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | SignSuccessVo signSuccessVo = new SignSuccessVo(); | 
|---|
|  |  |  | List<SignSuccessVo> signSuccessVos = new ArrayList<>(); | 
|---|
|  |  |  | //日常奖励,新增奖品领取记录 | 
|---|
|  |  |  | QueryWrapper<ActivitySignAwardSet> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("award_rule",ActivitySignAwardSet.AWARDRULE_NORMAL); | 
|---|
|  |  |  | 
|---|
|  |  |  | activitySignReceiveRecord.setUpdateTime(new Date()); | 
|---|
|  |  |  | activitySignReceiveRecordDao.insert(activitySignReceiveRecord); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SignSuccessVo signSuccessVo = new SignSuccessVo(); | 
|---|
|  |  |  | signSuccessVo.setType(1); | 
|---|
|  |  |  | signSuccessVo.setScoreCnt(activitySignAwardSetNormal.getScoreCnt()); | 
|---|
|  |  |  | signSuccessVo.setNormalAwardName(activitySignAwardSetNormal.getAwardName()); | 
|---|
|  |  |  | signSuccessVo.setNormalAwardImg(activitySignAwardSetNormal.getIntroduceImg()); | 
|---|
|  |  |  | signSuccessVo.setAwardName(activitySignAwardSetNormal.getAwardName()); | 
|---|
|  |  |  | signSuccessVo.setAwardImg(activitySignAwardSetNormal.getIntroduceImg()); | 
|---|
|  |  |  | signSuccessVos.add(signSuccessVo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //日常奖励积分,对应用户积分加减 | 
|---|
|  |  |  | int awardType = activitySignAwardSetNormal.getAwardType(); | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_SCORE == awardType){ | 
|---|
|  |  |  | int scoreCnt = activitySignAwardSetNormal.getScoreCnt(); | 
|---|
|  |  |  | if(scoreCnt > 0){ | 
|---|
|  |  |  | scoreVipDetailService.addScore(userId,null,null,scoreCnt, | 
|---|
|  |  |  | activitySignReceiveRecord.getId(), ScoreVipDetail.SCORE_VIP_TYPE_JOIN_ACTIVE,"签到积分"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //获取优惠券 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_COUPON == awardType){ | 
|---|
|  |  |  | //获取优惠券 | 
|---|
|  |  |  | int couponId = Integer.parseInt(activitySignAwardSetNormal.getCouponId()); | 
|---|
|  |  |  | ShopCoupon shopCoupon = shopCouponDao.selectById(couponId); | 
|---|
|  |  |  | // 如果没有找到该优惠券 | 
|---|
|  |  |  | if (shopCoupon == null) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "没有找到该优惠券!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 如果优惠券有数量限制并且已经领完 | 
|---|
|  |  |  | if (shopCoupon.getMaxQuantity() >= 0 && (shopCoupon.getMaxQuantity() <= shopCoupon.getQuantityReceive())) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "优惠券已领完!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | boolean newPeople = wxShopCouponUtil.verifyIsNewPeople(userId); | 
|---|
|  |  |  | // 如果改券是新人专属且当前用户不是新人 | 
|---|
|  |  |  | if (AppConstance.COUPON_GET_LIMT_NEW.equals(shopCoupon.getGetLimit()) && !newPeople) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "该优惠券为新人专享优惠券!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ShopCouponRecord insertRecord = new ShopCouponRecord(); | 
|---|
|  |  |  | insertRecord.setCreateBy(AppConstance.SYSTEM_USER); | 
|---|
|  |  |  | insertRecord.setUpdateBy(AppConstance.SYSTEM_USER); | 
|---|
|  |  |  | insertRecord.setCId(couponId); | 
|---|
|  |  |  | insertRecord.setUserId(userId); | 
|---|
|  |  |  | insertRecord.setIsUsing(2); | 
|---|
|  |  |  | int i = shopCouponRecordDao.insert(insertRecord); | 
|---|
|  |  |  | // 如果插入领取记录表失败 | 
|---|
|  |  |  | if (i < 0) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "优惠券领取失败!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | shopCoupon.setQuantityReceive(shopCoupon.getQuantityReceive() + 1); | 
|---|
|  |  |  | shopCouponDao.updateByModel(shopCoupon); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //获取当前累计天数 | 
|---|
|  |  |  | int cumulativeDay = getCumulativeDay(actId, userId, date, 0); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (ObjectUtil.isNotEmpty(activitySignReceiveRecordDone)) { | 
|---|
|  |  |  | String awardNameCumulativeDay = activitySignAwardSetCumulativeDay.getAwardName(); | 
|---|
|  |  |  | AjaxResult ajaxResult = AjaxResult.buildSuccessInstance(awardNameCumulativeDay+"已经领取过了"); | 
|---|
|  |  |  | ajaxResult.setData(signSuccessVo); | 
|---|
|  |  |  | ajaxResult.setData(signSuccessVos); | 
|---|
|  |  |  | return ajaxResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SignSuccessVo signSuccessVo = new SignSuccessVo(); | 
|---|
|  |  |  | signSuccessVo.setType(2); | 
|---|
|  |  |  | signSuccessVo.setAwardType(activitySignAwardSetCumulativeDay.getAwardType()); | 
|---|
|  |  |  | signSuccessVo.setAwardName(activitySignAwardSetCumulativeDay.getAwardName()); | 
|---|
|  |  |  | signSuccessVo.setAwardImg(activitySignAwardSetCumulativeDay.getIntroduceImg()); | 
|---|
|  |  |  | signSuccessVo.setAwardState(activitySignAwardSetCumulativeDay.getAwardState()); | 
|---|
|  |  |  | //新增奖品领取记录 | 
|---|
|  |  |  | ActivitySignReceiveRecord activitySignReceiveRecord = new ActivitySignReceiveRecord(); | 
|---|
|  |  |  | activitySignReceiveRecord.setUserId(userId); | 
|---|
|  |  |  | 
|---|
|  |  |  | * 获取对应奖品的领取方式(兑奖方式(1:线下兑换2:物流配送3:客服兑换) | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | signSuccessVo.setWriteOffCode(randomString); | 
|---|
|  |  |  | signSuccessVo.setAwardType(activitySignAwardSetCumulativeDay.getAwardType()); | 
|---|
|  |  |  | signSuccessVo.setAwardName(activitySignAwardSetCumulativeDay.getAwardName()); | 
|---|
|  |  |  | signSuccessVo.setAwardImg(activitySignAwardSetCumulativeDay.getIntroduceImg()); | 
|---|
|  |  |  | signSuccessVo.setAwardWay(activitySignAwardSetCumulativeDay.getAwardWay()); | 
|---|
|  |  |  | signSuccessVo.setAwardState(activitySignAwardSetCumulativeDay.getAwardState()); | 
|---|
|  |  |  | //2:物流配送 | 
|---|
|  |  |  | signSuccessVo.setOperationTip(activitySignAwardSetCumulativeDay.getOperationTip()); | 
|---|
|  |  |  | //1:线下兑换 | 
|---|
|  |  |  | 
|---|
|  |  |  | //3:优惠券 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_COUPON == activitySignAwardSetCumulativeDay.getAwardType()) { | 
|---|
|  |  |  | signSuccessVo.setCouponName(activitySignAwardSetCumulativeDay.getCouponName()); | 
|---|
|  |  |  | //获取优惠券 | 
|---|
|  |  |  | int couponId = Integer.parseInt(activitySignAwardSetCumulativeDay.getCouponId()); | 
|---|
|  |  |  | ShopCoupon shopCoupon = shopCouponDao.selectById(couponId); | 
|---|
|  |  |  | // 如果没有找到该优惠券 | 
|---|
|  |  |  | if (shopCoupon == null) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "没有找到该优惠券!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 如果优惠券有数量限制并且已经领完 | 
|---|
|  |  |  | if (shopCoupon.getMaxQuantity() >= 0 && (shopCoupon.getMaxQuantity() <= shopCoupon.getQuantityReceive())) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "优惠券已领完!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | boolean newPeople = wxShopCouponUtil.verifyIsNewPeople(userId); | 
|---|
|  |  |  | // 如果改券是新人专属且当前用户不是新人 | 
|---|
|  |  |  | if (AppConstance.COUPON_GET_LIMT_NEW.equals(shopCoupon.getGetLimit()) && !newPeople) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "该优惠券为新人专享优惠券!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ShopCouponRecord insertRecord = new ShopCouponRecord(); | 
|---|
|  |  |  | insertRecord.setCreateBy(AppConstance.SYSTEM_USER); | 
|---|
|  |  |  | insertRecord.setUpdateBy(AppConstance.SYSTEM_USER); | 
|---|
|  |  |  | insertRecord.setCId(couponId); | 
|---|
|  |  |  | insertRecord.setUserId(userId); | 
|---|
|  |  |  | insertRecord.setIsUsing(2); | 
|---|
|  |  |  | int i = shopCouponRecordDao.insert(insertRecord); | 
|---|
|  |  |  | // 如果插入领取记录表失败 | 
|---|
|  |  |  | if (i < 0) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "优惠券领取失败!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | shopCoupon.setQuantityReceive(shopCoupon.getQuantityReceive() + 1); | 
|---|
|  |  |  | shopCouponDao.updateByModel(shopCoupon); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | activitySignReceiveRecordDao.insert(activitySignReceiveRecord); | 
|---|
|  |  |  | //累计奖励积分,对应用户积分加减 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_SCORE == activitySignAwardSetCumulativeDay.getAwardType()) { | 
|---|
|  |  |  | int awardType = activitySignAwardSetCumulativeDay.getAwardType(); | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_SCORE == awardType){ | 
|---|
|  |  |  | int scoreCnt = activitySignAwardSetCumulativeDay.getScoreCnt(); | 
|---|
|  |  |  | if(scoreCnt > 0){ | 
|---|
|  |  |  | scoreVipDetailService.addScore(userId,null,null,scoreCnt, | 
|---|
|  |  |  | activitySignReceiveRecord.getId(), ScoreVipDetail.SCORE_VIP_TYPE_JOIN_ACTIVE,"签到积分"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //生成核销记录 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_CUSTOMIZE == activitySignAwardSetCumulativeDay.getAwardType()) { | 
|---|
|  |  |  | ActivitySignWriteoff activitySignWriteoff = new ActivitySignWriteoff(); | 
|---|
|  |  |  | 
|---|
|  |  |  | activitySignWriteoff.setUpdateTime(new Date()); | 
|---|
|  |  |  | activitySignWriteoffDao.insert(activitySignWriteoff); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | signSuccessVos.add(signSuccessVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("签到成功"); | 
|---|
|  |  |  | ajaxResult.setData(signSuccessVo); | 
|---|
|  |  |  | ajaxResult.setData(signSuccessVos); | 
|---|
|  |  |  | return ajaxResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | DateTime offsetDay = DateUtil.offsetDay(date, -i); | 
|---|
|  |  |  | return getCumulativeDay(actId,userId,offsetDay,i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取累计的签到奖品 | 
|---|
|  |  |  | * | 
|---|