| | |
| | | } |
| | | |
| | | // APP查询所有上架的会员卡 |
| | | @ResponseBody |
| | | @PostMapping("/listAll") |
| | | public List<Vip> listAll() { |
| | | List<Vip> list = vipService.lambdaQuery().eq(Vip::getStatus, 1).list(); |
| | | List<Coupon> coupons = couponClient.queryCouponAll(); |
| | | List<CouponCity> couponCityList = couponClient.queryAllCity(); |
| | | List<CouponStore> storeList = couponClient.queryAllStore(); |
| | | List<TStore> shopList = storeService.list(); |
| | | // 封装会员权益 |
| | | for (Vip vip : list) { |
| | | List<CouponVipResp> couponVipRespList = new ArrayList<>(); |
| | | List<TicketVipResp> ticketVipRespList = new ArrayList<>(); |
| | | String couponJson = vip.getCouponJson(); |
| | | JSONArray couponJsonArray = JSONArray.parseArray(couponJson); |
| | | for (Object o : couponJsonArray) { |
| | | JSONObject couponJsonObject = (JSONObject) o; |
| | | // 优惠券id |
| | | Integer id = Integer.valueOf(couponJsonObject.getString("id")); |
| | | // 优惠券数量 |
| | | Integer value = Integer.valueOf(couponJsonObject.getString("value")); |
| | | Coupon coupon = coupons.stream().filter(e -> e.getId().equals(id)).findFirst().orElse(new Coupon()); |
| | | CouponVipResp couponVipResp = new CouponVipResp(); |
| | | couponVipResp.setId(coupon.getId()); |
| | | couponVipResp.setName(coupon.getName()); |
| | | couponVipResp.setType(coupon.getType()); |
| | | couponVipResp.setUseCondition(coupon.getUseScope()); |
| | | couponVipResp.setCount(value); |
| | | switch (coupon.getUseScope()) { |
| | | case 1: |
| | | couponVipResp.setAvailable("全国通用"); |
| | | break; |
| | | case 2: |
| | | couponVipResp.setAvailable("指定城市可用"); |
| | | List<CouponCity> couponId = couponCityList.stream().filter(e -> e.getCouponId().equals(id)) |
| | | .collect(Collectors.toList()); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | for (CouponCity couponCity : couponId) { |
| | | stringBuilder.append(couponCity.getCity()); |
| | | } |
| | | couponVipResp.setCityOrStore(String.valueOf(stringBuilder)); |
| | | break; |
| | | case 3: |
| | | couponVipResp.setAvailable("指定门店可用"); |
| | | // 门店ids |
| | | List<Integer> storeIds = storeList.stream().filter(e -> e.getCouponId().equals(id)) |
| | | .map(CouponStore::getStoreId).collect(Collectors.toList()); |
| | | StringBuilder storeNames = new StringBuilder(""); |
| | | |
| | | if (!storeIds.isEmpty()) { |
| | | List<TStore> stores = shopList.stream().filter(e -> storeIds.contains(e.getId())).collect(Collectors.toList()); |
| | | for (TStore store : stores) { |
| | | storeNames.append(store.getName()).append(","); |
| | | } |
| | | // 去除最后一位 |
| | | StringBuilder res = storeNames.deleteCharAt(storeNames.length() - 1); |
| | | couponVipResp.setCityOrStore(res.toString()); |
| | | } else { |
| | | couponVipResp.setCityOrStore("无可用门店"); |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | couponVipResp.setInstructionsForUse(coupon.getIllustrate()); |
| | | ConponJsonRuleModel ruleModel = new ConponJsonRuleModel(); |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | switch (coupon.getType()) { |
| | | case 1: |
| | | // 满减券 |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | Double num2 = jsonObject.getDouble("deductionAmount"); |
| | | ruleModel.setConditionalAmount("满" + num1 + "可用"); |
| | | ruleModel.setDeductionAmount("¥ " + num2); |
| | | ruleModel.setExperienceName(""); |
| | | break; |
| | | case 2: |
| | | // 代金券 |
| | | Double jsonObjectDouble = jsonObject.getDouble("conditionalAmount"); |
| | | ruleModel.setConditionalAmount(""); |
| | | ruleModel.setDeductionAmount("¥ " + jsonObjectDouble); |
| | | ruleModel.setExperienceName(""); |
| | | break; |
| | | case 3: |
| | | // 体验券 |
| | | ruleModel.setConditionalAmount(""); |
| | | ruleModel.setDeductionAmount(""); |
| | | ruleModel.setExperienceName(jsonObject.getString("experienceName")); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | couponVipResp.setRuleModel(ruleModel); |
| | | |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | couponVipResp.setEffectiveTime(simpleDateFormat.format(coupon.getEndTime())); |
| | | couponVipRespList.add(couponVipResp); |
| | | } |
| | | vip.setCouponList(couponVipRespList); |
| | | String ticketJson = vip.getTicketJson(); |
| | | JSONArray ticketJsonArray = JSONArray.parseArray(ticketJson); |
| | | for (Object o : ticketJsonArray) { |
| | | JSONObject ticketJsonObject = (JSONObject) o; |
| | | TicketVipResp ticketVipResp = new TicketVipResp(); |
| | | ticketVipResp.setName(ticketJsonObject.getString("name")); |
| | | ticketVipResp.setTime(ticketJsonObject.getInteger("time")); |
| | | ticketVipResp.setCount(ticketJsonObject.getInteger("count")); |
| | | ticketVipRespList.add(ticketVipResp); |
| | | } |
| | | vip.setTicketList(ticketVipRespList); |
| | | } |
| | | return list; |
| | | } |
| | | @Autowired |
| | | private IProtocolService protocolService; |
| | | @ResponseBody |