| | |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.checkerframework.checker.units.qual.C; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | @Autowired |
| | | private DiscountLogMapper discountLogMapper; |
| | | @Autowired |
| | | private DiscountMapper discountMapper; |
| | | |
| | | @Autowired |
| | | GoodsorderJoinMapper goodsorderJoinMapper; |
| | |
| | | .eq("status",Constants.ZERO) |
| | | .orderByAsc("sortnum") |
| | | ));; |
| | | homeResponse.setDiscountList( |
| | | discountMapper.selectList(new QueryWrapper<Discount>().lambda() |
| | | .eq(Discount::getIsdeleted,Constants.ZERO) |
| | | .eq(Discount::getStatus,Constants.ZERO) |
| | | .orderByDesc(Discount::getId) |
| | | .last(" limit 3 ") |
| | | ) |
| | | ); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(homeResponse.getDiscountList())){ |
| | | for (Discount discount:homeResponse.getDiscountList()) { |
| | | discount.setDayPrice(discount.getPrice().divide(new BigDecimal(Integer.toString(discount.getUseDays())),2)); |
| | | } |
| | | } |
| | | if(!Objects.isNull(homeResponse.getAdList())&&homeResponse.getAdList().size()>Constants.ZERO){ |
| | | homeResponse.getAdList().forEach(i->{ |
| | | i.setImgfullurl(fullPath + i.getImgurl()); |
| | |
| | | goodsorder.setCreateDate(new Date()); |
| | | goodsorder.setIsdeleted(Constants.ZERO); |
| | | goodsorder.setCode(goodsorder.getId()); |
| | | goodsorder.setType(Constants.ZERO); |
| | | goodsorder.setMemberId(memberId); |
| | | goodsorder.setMoney(new BigDecimal(systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.RENT_DEPOSIT).getCode()).multiply(new BigDecimal(100))); |
| | | goodsorder.setStatus(Constants.goodsorderStatus.waitPay); |
| | |
| | | } catch (Exception e) { |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,发起支付失败~"); |
| | | } |
| | | |
| | | return response; |
| | | } |
| | | |
| | | private Object getWxPayResponse(Goodsorder goodsorder,String openid) throws Exception { |
| | | |
| | | @Override |
| | | public Object createDiscountOrderPay(String memberId,String discountId){ |
| | | Member member = memberMapper.selectById(memberId); |
| | | if(Objects.isNull(member)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到用户对象信息"); |
| | | } |
| | | Discount discount = discountMapper.selectById(discountId); |
| | | this.checkDiscountSaleDate(discount); |
| | | String discountMemberId = Constants.getUUID(); |
| | | String goodsorderId = Constants.getUUID(); |
| | | DiscountMember discountMember = new DiscountMember(); |
| | | BeanUtils.copyProperties(discount,discountMember); |
| | | discountMember.setCreator(null); |
| | | discountMember.setId(discountMemberId); |
| | | discountMember.setCreateDate(new Date()); |
| | | discountMember.setEditDate(new Date()); |
| | | discountMember.setEditor(null); |
| | | discountMember.setMemberId(memberId); |
| | | discountMember.setStatus(Constants.TWO); |
| | | discountMember.setGoodsorderId(goodsorderId); |
| | | discountMemberMapper.insert(discountMember); |
| | | |
| | | Goodsorder goodsorder = new Goodsorder(); |
| | | goodsorder.setId(goodsorderId); |
| | | goodsorder.setCreateDate(new Date()); |
| | | goodsorder.setIsdeleted(Constants.ZERO); |
| | | goodsorder.setCode(goodsorder.getId()); |
| | | goodsorder.setMemberId(memberId); |
| | | goodsorder.setType(Constants.ONE); |
| | | goodsorder.setMoney(discount.getPrice().multiply(new BigDecimal(100))); |
| | | goodsorder.setStatus(Constants.goodsorderStatus.waitPay); |
| | | goodsorder.setPreOrderid(goodsorder.getId()); |
| | | goodsorder.setPayStatus(Constants.goodsorderPayStatus.waitPay); |
| | | goodsorder.setPayWay(Constants.ZERO); |
| | | goodsorder.setObjType(Constants.ZERO); |
| | | goodsorder.setObjId(discount.getId()); |
| | | this.goodsorderMapper.insert(goodsorder); |
| | | //调起支付 |
| | | Object response = null; |
| | | Object response = null; |
| | | try { |
| | | response = getWxPayResponse(goodsorder,member.getOpenid()); |
| | | } catch (Exception e) { |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,发起支付失败~"); |
| | | } |
| | | return response; |
| | | |
| | | } |
| | | |
| | | public void checkDiscountSaleDate(Discount discount){ |
| | | if(Objects.isNull(discount)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到套餐信息"); |
| | | } |
| | | if(!(Constants.equalsInteger(discount.getIsdeleted(),Constants.ZERO) |
| | | ||Constants.equalsInteger(discount.getStatus(),Constants.ZERO))){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"套餐已下架,无法进行购买,请刷新查看"); |
| | | } |
| | | if(!(discount.getStartDate().getTime() < System.currentTimeMillis() |
| | | && Utils.Date.getEnd(discount.getEndDate()).getTime() > System.currentTimeMillis() )){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"套餐开放时间未到,无法进行购买"); |
| | | } |
| | | //验证是否超过今日可售卖数量 |
| | | if(Objects.nonNull(discount.getSaleDayLimit())){ |
| | | if(goodsorderMapper.selectCount(new QueryWrapper<Goodsorder>().lambda() |
| | | .eq(Goodsorder::getType,Constants.ONE) |
| | | .eq(Goodsorder::getObjId,discount.getId()) |
| | | .in(Goodsorder::getStatus,Constants.ZERO,Constants.ONE) |
| | | .apply(" EXTRACT(DAY FROM create_date) = EXTRACT(DAY FROM CURRENT_DATE) ") |
| | | )>=discount.getSaleDayLimit()){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"套餐今日发行量已售罄,请明日查看!"); |
| | | } |
| | | } |
| | | if(Objects.nonNull(discount.getSaleLimit())){ |
| | | if(goodsorderMapper.selectCount(new QueryWrapper<Goodsorder>().lambda() |
| | | .eq(Goodsorder::getType,Constants.ONE) |
| | | .eq(Goodsorder::getObjId,discount.getId()) |
| | | .in(Goodsorder::getStatus,Constants.ZERO,Constants.ONE) |
| | | .apply(" EXTRACT(YEAR FROM create_date) = EXTRACT(YEAR FROM CURRENT_DATE) ") |
| | | )>=discount.getSaleDayLimit()){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"套餐发行量已售罄!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | private Object getWxPayResponse(Goodsorder goodsorder,String openid){ |
| | | //调起支付 |
| | | Object response = null; |
| | | PrepayRequest request = new PrepayRequest(); |
| | | request.setAttach("createGoodsOrder"); |
| | | request.setDescription("森林公园自行车骑行押金支付"); |
| | | request.setDescription(Constants.equalsInteger(goodsorder.getType(),Constants.ZERO)?"森林公园自行车骑行押金支付":"森林公园自行车购买骑行套餐支付"); |
| | | request.setSpMchid(WxMiniConfig.wxProperties.getMchId()); |
| | | request.setSpAppid(WxMiniConfig.wxProperties.getAppId()); |
| | | request.setSubMchid(WxMiniConfig.wxProperties.getSubMchId()); |
| | |
| | | // 跟之前下单示例一样,填充预下单参数 |
| | | PrepayWithRequestPaymentResponse resParam = WxMiniConfig.jsapiExtService.prepayWithRequestPayment(request,WxMiniConfig.wxProperties.getSubAppId()); |
| | | response =resParam; |
| | | |
| | | return response; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | return ("处理成功!"); |
| | | } |
| | | goodsorder.setOnlineOrderid(paymentNo); |
| | | if(Constants.equalsInteger(goodsorder.getType(),Constants.ZERO)){ |
| | | this.dealGoodsOrderCallBack(goodsorder); |
| | | }else{ |
| | | this.dealDiscountOrderCallBack(goodsorder); |
| | | } |
| | | return ("处理成功!"); |
| | | } |
| | | |
| | | public void dealDiscountOrderCallBack(Goodsorder goodsorder){ |
| | | goodsorder.setPayStatus(Constants.goodsorderPayStatus.pay); |
| | | goodsorder.setStatus(Constants.goodsorderStatus.pay); |
| | | goodsorder.setPayDate(new Date()); |
| | | goodsorder.setEditDate(new Date()); |
| | | goodsorderMapper.updateById(goodsorder); |
| | | |
| | | DiscountMember discountMember = discountMemberMapper.selectOne(new QueryWrapper<DiscountMember>().lambda() |
| | | .eq(DiscountMember::getGoodsorderId,goodsorder.getId()).last(" limit 1 ")); |
| | | discountMemberMapper.update(null,new UpdateWrapper<DiscountMember>().lambda() |
| | | .set(DiscountMember::getStatus,Constants.ZERO) |
| | | .eq(DiscountMember::getId,discountMember.getId()) |
| | | ); |
| | | Constants.TRANSACTIONS_TYPE discountConstants = Constants.TRANSACTIONS_TYPE.DISCOUNT; |
| | | //存储交易流水表 |
| | | Transactions transactions = new Transactions(); |
| | | transactions.setMemberId(goodsorder.getMemberId()); |
| | | transactions.setCreateDate(new Date()); |
| | | transactions.setIsdeleted(Constants.ZERO); |
| | | transactions.setOrderId(goodsorder.getId()); |
| | | transactions.setMoney(goodsorder.getMoney()); |
| | | transactions.setType(discountConstants.getKey()); |
| | | transactions.setPreOrderid(goodsorder.getPreOrderid()); |
| | | transactions.setOnlineOrderid(goodsorder.getOnlineOrderid()); |
| | | transactions.setDoneDate(new Date()); |
| | | transactions.setTitle(discountConstants.getName()); |
| | | transactions.setContent(discountConstants.getInfo()); |
| | | //transactions.setContent(discountMember.getName() +" 有效期" + DateUtil.dateToString(discountMember.getUseStartDate(),"yyyy-MM-dd") +"-"+DateUtil.dateToString(discountMember.getUseEndDate(),"yyyy-MM-dd")); |
| | | transactions.setBalance(goodsorder.getMoney()); |
| | | transactions.setObjId(discountMember.getId()); |
| | | transactions.setObjType(Constants.TWO); |
| | | transactionsMapper.insert(transactions); |
| | | } |
| | | |
| | | |
| | | public void dealGoodsOrderCallBack(Goodsorder goodsorder){ |
| | | goodsorder.setPayStatus(Constants.goodsorderPayStatus.pay); |
| | | goodsorder.setStatus(Constants.goodsorderStatus.pay); |
| | | goodsorder.setPayDate(new Date()); |
| | |
| | | transactions.setObjId(goodsorder.getId()); |
| | | transactions.setObjType(Constants.ZERO); |
| | | transactionsMapper.insert(transactions); |
| | | return ("处理成功!"); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |