diff --git a/bweb/src/main/java/com/bweb/config/AuthConfig.java b/bweb/src/main/java/com/bweb/config/AuthConfig.java index 52b84aa..ae32148 100644 --- a/bweb/src/main/java/com/bweb/config/AuthConfig.java +++ b/bweb/src/main/java/com/bweb/config/AuthConfig.java @@ -1,4 +1,4 @@ -package com.cweb.config; +package com.bweb.config; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; diff --git a/bweb/src/main/java/com/bweb/controller/file/FileController.java b/bweb/src/main/java/com/bweb/controller/file/FileController.java index ef5c13b..bbcc559 100644 --- a/bweb/src/main/java/com/bweb/controller/file/FileController.java +++ b/bweb/src/main/java/com/bweb/controller/file/FileController.java @@ -46,7 +46,7 @@ public class FileController { @RequestMapping(value="/getFileRecordsList",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询列表") - public ResponseData getFileRecordsList( HttpServletRequest request) { + public ResponseData getFileRecordsList(HttpServletRequest request) { try { SessionObject sessionObject = userCenter.getSessionObject(request); diff --git a/bweb/src/main/java/com/bweb/controller/goods/GoodPresentController.java b/bweb/src/main/java/com/bweb/controller/goods/GoodPresentController.java new file mode 100644 index 0000000..58cc84b --- /dev/null +++ b/bweb/src/main/java/com/bweb/controller/goods/GoodPresentController.java @@ -0,0 +1,130 @@ +package com.bweb.controller.goods; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.security.SessionObject; +import com.hfkj.common.security.UserCenter; +import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.entity.CouponDiscountPackage; +import com.hfkj.entity.GoodPresent; +import com.hfkj.entity.GoodsMsg; +import com.hfkj.entity.GoodsType; +import com.hfkj.model.ResponseData; +import com.hfkj.model.SecUserSessionObject; +import com.hfkj.service.discount.CouponDiscountPackageService; +import com.hfkj.service.goods.GoodPresentService; +import com.hfkj.sysenum.SecUserObjectTypeEnum; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@Controller +@RequestMapping(value="/goodPresent") +@Api(value="商品赠送") +public class GoodPresentController { + + private static final Logger log = LoggerFactory.getLogger(GoodPresentController.class); + + @Resource + private GoodPresentService goodPresentService; + + @Resource + private CouponDiscountPackageService discountPackageService; + + @Resource + private UserCenter userCenter; + + @RequestMapping(value="/createGoodPresent",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "创建商品赠送") + public ResponseData createGoodPresent(@RequestBody GoodPresent body, HttpServletRequest request) { + + try { + + SessionObject sessionObject = userCenter.getSessionObject(request); + SecUserSessionObject userModel = (SecUserSessionObject) sessionObject.getObject(); + + if (!userModel.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, ""); + } + + if (body == null + || body.getKey() == null + || body.getType() == null + || body.getSpecsId() == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + CouponDiscountPackage discountPackage = discountPackageService.findDiscountPackageByKey(body.getKey()); + if (discountPackage == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券包不存在"); + } + + body.setCreateTime(new Date()); + body.setUpdateTime(new Date()); + body.setStatus(1); + body.setName(discountPackage.getTitle()); + goodPresentService.create(body); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + + } + + @RequestMapping(value="/getListBrand",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询列表") + public ResponseData getListBrand(@RequestParam(value = "specsId" , required = false) Long specsId) { + try { + + Map map = new HashMap<>(); + map.put("specsId", specsId); + return ResponseMsgUtil.success(goodPresentService.getList(map)); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/delete",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "删除") + public ResponseData delete(@RequestParam(value = "id" , required = false) Long id, HttpServletRequest request) { + try { + + SessionObject sessionObject = userCenter.getSessionObject(request); + SecUserSessionObject userModel = (SecUserSessionObject) sessionObject.getObject(); + + if (!userModel.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, ""); + } + + goodPresentService.delete(id , false); + + return ResponseMsgUtil.success("删除成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/bweb/src/main/java/com/bweb/controller/goods/GoodsController.java b/bweb/src/main/java/com/bweb/controller/goods/GoodsController.java index bb6934f..70fa838 100644 --- a/bweb/src/main/java/com/bweb/controller/goods/GoodsController.java +++ b/bweb/src/main/java/com/bweb/controller/goods/GoodsController.java @@ -133,6 +133,7 @@ public class GoodsController { goodsMsg.setGoodsTypeParent(goodsType.getParentId()); goodsMsg.setGoodsTypeParentName(goodsTypeService.findGoodsType(goodsType.getParentId())); goodsMsg.setType(body.getType()); + goodsMsg.setShowType(body.getShowType()); goodsMsg.setGoodsBrand(body.getGoodsBrand()); goodsMsg.setStatus(body.getStatus()); goodsMsg.setTitle(body.getTitle()); @@ -256,7 +257,6 @@ public class GoodsController { // 判断必填项 if ( goodsSpecs.getId() == null || body.getValidDay() == null - || body.getType() == null || body.getSource() == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } @@ -271,7 +271,6 @@ public class GoodsController { goodsVpd.setSpecsId(goodsSpecs.getId()); goodsVpd.setValidDay(body.getValidDay()); - goodsVpd.setType(body.getType()); goodsVpd.setJumpType(body.getJumpType()); goodsVpd.setJumpUrl(body.getJumpUrl()); goodsVpd.setAppid(body.getAppid()); diff --git a/cweb/src/main/java/com/cweb/config/AuthConfig.java b/cweb/src/main/java/com/cweb/config/AuthConfig.java index 8814050..112bed5 100644 --- a/cweb/src/main/java/com/cweb/config/AuthConfig.java +++ b/cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -95,6 +95,7 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/starbucks/*") .excludePathPatterns("/meiTuan/*") .excludePathPatterns("/jd/*") + .excludePathPatterns("/output/*") ; } diff --git a/cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java b/cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java index 5025619..1fa6cee 100644 --- a/cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java +++ b/cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java @@ -69,20 +69,21 @@ public class CmsContentController { Map goodsMap = new HashMap<>(); goodsMap.put("status" , 1); + goodsMap.put("showType" , 1); List goodsMsgs = new ArrayList<>(); if (cmsContent.getShowType() == 1) { goodsMap.put("goodsType", cmsContent.getShowDataId()); - goodsMsgs = goodsMsgService.getList(goodsMap).stream().limit(2).collect(Collectors.toList()); + goodsMsgs = goodsMsgService.getListCrest(goodsMap).stream().limit(2).collect(Collectors.toList()); } if (cmsContent.getShowType() == 2) { goodsMap.put("goodsType", cmsContent.getShowDataId()); - goodsMsgs = goodsMsgService.getList(goodsMap).stream().limit(4).collect(Collectors.toList()); + goodsMsgs = goodsMsgService.getListCrest(goodsMap).stream().limit(4).collect(Collectors.toList()); } if (cmsContent.getShowType() == 3) { goodsMap.put("goodsType", cmsContent.getShowDataId()); - goodsMsgs = goodsMsgService.getList(goodsMap).stream().limit(10).collect(Collectors.toList()); + goodsMsgs = goodsMsgService.getListCrest(goodsMap).stream().limit(10).collect(Collectors.toList()); } for (GoodsMsg goodsMsg : goodsMsgs) { diff --git a/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java b/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java index 6822885..4d284f2 100644 --- a/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java +++ b/cweb/src/main/java/com/cweb/controller/discount/DiscountController.java @@ -1,5 +1,6 @@ package com.cweb.controller.discount; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @@ -10,9 +11,11 @@ import com.hfkj.common.security.SessionObject; import com.hfkj.common.security.UserCenter; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.entity.*; +import com.hfkj.haioil.HaiOilService; import com.hfkj.model.ResponseData; import com.hfkj.model.SecUserSessionObject; import com.hfkj.model.UserSessionObject; +import com.hfkj.model.discount.CouponDiscountUserRelModel; import com.hfkj.model.discount.DiscountGoodsModel; import com.hfkj.service.CommonService; import com.hfkj.service.SecDictionaryService; @@ -63,18 +66,71 @@ public class DiscountController { @RequestMapping(value = "/getListUserDiscount", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取用户优惠券列表") - public ResponseData getListUserDiscount(@RequestParam(value = "status", required = true) Integer status) { + public ResponseData getListUserDiscount( + @RequestParam(value = "status", required = true) Integer status, + @RequestParam(value = "source", required = true) Integer source + ) { try { // 用户session UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); - Map map = new HashMap<>(); + if (source == 1) { + Map map = new HashMap<>(); - map.put("userId", userSession.getUser().getId()); - map.put("status", status); + map.put("userId", userSession.getUser().getId()); + map.put("status", status); + + return ResponseMsgUtil.success(discountUserRelService.getList(map)); + + } else { + List list = new ArrayList<>(); + + if (userSession.getUser().getPhone() == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户未绑定手机号!"); + } + + Map map = new HashMap<>(); + if (status == 0) { + status = 3; + } + map.put("status" , status); + map.put("phone" , userSession.getUser().getPhone()); + JSONObject object = HaiOilService.queryListByPhone(map); + if (object.getString("return_code").equals("000000")) { + JSONArray array = object.getJSONObject("return_data").getJSONArray("dataList"); + for (int i = 0; i < array.size(); i++) { + JSONObject jsonObject = array.getJSONObject(i); + CouponDiscountUserRelModel rel = new CouponDiscountUserRelModel(); + rel.setSource(2); + rel.setUserId(userSession.getUser().getId()); + rel.setDiscountName(jsonObject.getString("discountName")); + rel.setDiscountType(jsonObject.getInteger("discountType")); + rel.setDiscountNo(jsonObject.getString("discountNo")); + rel.setDiscountCondition(jsonObject.getBigDecimal("discountCondition")); + if (jsonObject.getInteger("discountType") == 3) { + rel.setDiscountPercentage(jsonObject.getBigDecimal("discountPrice")); + } else { + rel.setDiscountPrice(jsonObject.getBigDecimal("discountPrice")); + } + if (jsonObject.getInteger("status") == 3) { + rel.setStatus(0); + }else { + rel.setStatus(jsonObject.getInteger("status")); + } + rel.setCreateTime(jsonObject.getDate("createTime")); + rel.setUseTime(jsonObject.getDate("useTime")); + rel.setUseEndTime(jsonObject.getDate("expirationTime")); + + list.add(rel); + } + return ResponseMsgUtil.success(list); + } else { + return ResponseMsgUtil.success(null); + } + + } - return ResponseMsgUtil.success(discountUserRelService.getList(map)); } catch (Exception e) { log.error("GoodsDetailController --> getListUser() error!", e); diff --git a/cweb/src/main/java/com/cweb/controller/goods/GoodsController.java b/cweb/src/main/java/com/cweb/controller/goods/GoodsController.java index eefcc10..2210acc 100644 --- a/cweb/src/main/java/com/cweb/controller/goods/GoodsController.java +++ b/cweb/src/main/java/com/cweb/controller/goods/GoodsController.java @@ -10,16 +10,14 @@ import com.hfkj.common.security.SessionObject; import com.hfkj.common.security.UserCenter; import com.hfkj.common.utils.PageUtil; import com.hfkj.common.utils.ResponseMsgUtil; -import com.hfkj.entity.GoodsMsg; -import com.hfkj.entity.GoodsSpecs; -import com.hfkj.entity.GoodsType; -import com.hfkj.entity.GoodsVpd; +import com.hfkj.entity.*; import com.hfkj.jd.JdService; import com.hfkj.model.ResponseData; import com.hfkj.model.SecUserSessionObject; import com.hfkj.model.goods.GoodsModel; import com.hfkj.model.goods.GoodsModelSpecs; import com.hfkj.model.goods.GoodsTypeModel; +import com.hfkj.service.discount.CouponDiscountService; import com.hfkj.service.goods.*; import com.hfkj.sysenum.SecUserObjectTypeEnum; import io.swagger.annotations.Api; @@ -59,9 +57,10 @@ public class GoodsController { @Resource private GoodsVpdService goodsVpdService; - @Resource private JdService jdService; + @Resource + private CouponDiscountService couponDiscountService; @RequestMapping(value="/getListGoodsType",method = RequestMethod.GET) @@ -114,6 +113,8 @@ public class GoodsController { @RequestParam(value = "title", required = false) String title, @RequestParam(value = "goodsTypeParent", required = false) Long goodsTypeParent, @RequestParam(value = "goodsType", required = false) Long goodsType, + @RequestParam(value = "showType", required = false) Integer showType, + @RequestParam(value = "discountId", required = false) Integer discountId, @RequestParam(value = "goodsBrand", required = false) Long goodsBrand, @RequestParam(value = "price", required = false) Integer price, @RequestParam(value = "saleNum", required = false) Integer saleNum, @@ -129,6 +130,7 @@ public class GoodsController { map.put("title", title); map.put("goodsType", goodsType); + map.put("showType", showType); map.put("goodsTypeParent", goodsTypeParent); map.put("goodsBrand", goodsBrand); map.put("saleNum", saleNum); @@ -141,6 +143,14 @@ public class GoodsController { List goodsModels = new ArrayList<>(); + // 查询优惠券可以用规格 + + Map mapSpecs = new HashMap<>(); + mapSpecs.put("discountId", discountId); + + // 查询规格可用优惠券 + List couponDiscountGoodsRel = couponDiscountService.getListGoodsRel(mapSpecs); + for (GoodsMsg goodsMsg : list) { GoodsModel goodsModel = new GoodsModel(); @@ -151,12 +161,29 @@ public class GoodsController { BigDecimal minPrice = goodsSpecs.get(0).getSalePrice(); BigDecimal minOriginalPrice = goodsSpecs.get(0).getOriginalPrice(); + for (GoodsSpecs specs : goodsSpecs) { if (specs.getSalePrice().compareTo(minPrice) < 0) { minPrice = specs.getSalePrice(); minOriginalPrice = specs.getOriginalPrice(); } + + if (discountId != null) { + CouponDiscountGoodsRel discountGoodsRel = couponDiscountGoodsRel.stream().filter(s -> s.getSpecsId().equals(specs.getId())).findFirst().orElse(null); + if (discountGoodsRel == null) { + specs.setExt1("0"); + } + } + + } + + // todo 删除没有绑定优惠券的 + goodsSpecs = goodsSpecs.stream().filter(s-> !s.getExt1().equals("0")).collect(Collectors.toList()); + + if (goodsSpecs.isEmpty()) { + continue; } + BeanUtils.copyProperties(goodsMsg, goodsModel); goodsModel.setOriginalPrice(minOriginalPrice); goodsModel.setPrice(minPrice); diff --git a/cweb/src/main/java/com/cweb/controller/output/OutputController.java b/cweb/src/main/java/com/cweb/controller/output/OutputController.java new file mode 100644 index 0000000..7804f8b --- /dev/null +++ b/cweb/src/main/java/com/cweb/controller/output/OutputController.java @@ -0,0 +1,101 @@ +package com.cweb.controller.output; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.api.ApiMerService; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.security.UserCenter; +import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.common.utils.SignatureUtil; +import com.hfkj.entity.*; +import com.hfkj.model.ResponseData; +import com.hfkj.model.UserSessionObject; +import com.hfkj.service.SecDictionaryService; +import com.hfkj.service.discount.CouponDiscountPackageService; +import com.hfkj.service.discount.CouponDiscountService; +import com.hfkj.service.discount.CouponDiscountUserRelService; +import com.hfkj.service.user.BsUserService; +import com.hfkj.sysenum.UserLoginPlatform; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +@Controller +@RequestMapping(value="/output") +@Api(value="输出外部接口") +public class OutputController { + + private static final Logger log = LoggerFactory.getLogger(OutputController.class); + + @Resource + private ApiMerService apiMerService; + + @Resource + private CouponDiscountUserRelService discountUserRelService; + @Resource + private BsUserService bsUserService; + + @RequestMapping(value = "/getListUserDiscount", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "获取用户优惠券列表") + public ResponseData getListUserDiscount(@RequestBody JSONObject body) { + try { + + if (body == null + || StringUtils.isBlank(body.getString("status")) + || StringUtils.isBlank(body.getString("phone")) + || StringUtils.isBlank(body.getString("sign")) + || StringUtils.isBlank(body.getString("appid")) + ) { + log.error("LoginController --> phone() error!", "请求参数校验失败"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + // 查询api商户信息 + ApiMer apiMer = apiMerService.queryDetail(body.getString("appid")); + + Map map = new HashMap<>(); + map.put("appid" , body.getString("appid")); + map.put("phone" , body.getString("phone")); + map.put("status" , body.getString("status")); + String sign = SignatureUtil.createSign(map , apiMer.getAppSecret()); + if (!body.getString("sign").equals(sign)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "签名校验失败!"); + } + + // 查询用户信息 + BsUser user = bsUserService.getUser(body.getString("phone")); + + if (user == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户不存在!"); + } + + Map mapPost = new HashMap<>(); + + mapPost.put("userId", user.getId()); + mapPost.put("status", body.getInteger("status")); + + return ResponseMsgUtil.success(discountUserRelService.getList(mapPost)); + + } catch (Exception e) { + log.error("GoodsDetailController --> getListUser() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + + + +} diff --git a/order/src/main/java/com/order/controller/business/BsOrderGoodsController.java b/order/src/main/java/com/order/controller/business/BsOrderGoodsController.java index 1c78e25..249317c 100644 --- a/order/src/main/java/com/order/controller/business/BsOrderGoodsController.java +++ b/order/src/main/java/com/order/controller/business/BsOrderGoodsController.java @@ -305,10 +305,6 @@ public class BsOrderGoodsController { BsOrderGoods goodsOrder = bsOrderGoodsService.queryDetail(body.getId()); - - - - if (goodsOrder == null) { throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "信息错误!"); } diff --git a/service/src/main/java/com/hfkj/dao/GoodsMsgMapperExt.java b/service/src/main/java/com/hfkj/dao/GoodsMsgMapperExt.java index 0663266..60357b3 100644 --- a/service/src/main/java/com/hfkj/dao/GoodsMsgMapperExt.java +++ b/service/src/main/java/com/hfkj/dao/GoodsMsgMapperExt.java @@ -42,7 +42,6 @@ public interface GoodsMsgMapperExt { " SELECT" + " id ," + " title as title," + - " title as title," + " list_img as listImg," + " third_id as thirdId," + " sale_num as saleNum" + @@ -51,6 +50,7 @@ public interface GoodsMsgMapperExt { " and goods_type_parent = #{param.goodsTypeParent} " + " and title like concat('%',#{param.title},'%') " + " and goods_type = #{param.goodsType} " + + " and show_type = #{param.showType} " + " and goods_brand = #{param.goodsBrand} " + " ORDER BY update_time desc" + " ORDER BY create_time desc" + diff --git a/service/src/main/java/com/hfkj/dao/GoodsSpecsMapperExt.java b/service/src/main/java/com/hfkj/dao/GoodsSpecsMapperExt.java index b7a09c9..79e85f4 100644 --- a/service/src/main/java/com/hfkj/dao/GoodsSpecsMapperExt.java +++ b/service/src/main/java/com/hfkj/dao/GoodsSpecsMapperExt.java @@ -17,6 +17,7 @@ public interface GoodsSpecsMapperExt { @Select("