| | |
| | | package com.xiaopeng.account.controller; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xiaopeng.account.model.dto.ReceiveCouponDto; |
| | | import com.xiaopeng.account.model.dto.SendCouponDto; |
| | | import com.xiaopeng.account.model.query.XpUserCouponListQuery; |
| | | import com.xiaopeng.account.model.vo.XpAppUserCouponListVo; |
| | | import com.xiaopeng.account.model.vo.XpAppUserCouponTotalVo; |
| | |
| | | import com.xiaopeng.account.service.IXpAppUserCouponService; |
| | | import com.xiaopeng.api.dto.account.GetUserCouponDto; |
| | | import com.xiaopeng.api.dto.account.UseUserCouponDto; |
| | | import com.xiaopeng.api.dto.account.UserResourcesDto; |
| | | import com.xiaopeng.api.feignClient.account.UserResourcesClient; |
| | | import com.xiaopeng.api.feignClient.account.XpAppUserClient; |
| | | import com.xiaopeng.api.feignClient.operation.XpOpenCityClient; |
| | | import com.xiaopeng.api.model.account.XpAppUserCoupon; |
| | | import com.xiaopeng.api.vo.account.UserCouponVo; |
| | |
| | | |
| | | private final IXpAppUserCouponService xpAppUserCouponService; |
| | | private final XpOpenCityClient xpOpenCityClient; |
| | | private final UserResourcesClient userResourcesClient; |
| | | |
| | | public XpAppUserCouponController(IXpAppUserCouponService xpAppUserCouponService, XpOpenCityClient xpOpenCityClient) { |
| | | |
| | | public XpAppUserCouponController(IXpAppUserCouponService xpAppUserCouponService, XpOpenCityClient xpOpenCityClient, UserResourcesClient userResourcesClient) { |
| | | this.xpAppUserCouponService = xpAppUserCouponService; |
| | | this.xpOpenCityClient = xpOpenCityClient; |
| | | this.userResourcesClient = userResourcesClient; |
| | | } |
| | | |
| | | |
| | | @PostMapping("/inner/appUserCoupon/getUserCoupon") |
| | | public R<UserCouponVo> getUserCoupon(@RequestBody GetUserCouponDto dto) { |
| | | String phone ="18888888888"; |
| | | if(dto.getUserId()>1){ |
| | | UserResourcesDto baseUserByUid = userResourcesClient.getBaseUserByUid(dto.getUserId().toString()); |
| | | if(baseUserByUid!=null){ |
| | | Object data = baseUserByUid.getData(); |
| | | phone = JSONObject.parseObject(data.toString()).getString("mobile"); |
| | | } |
| | | } |
| | | |
| | | |
| | | UserCouponVo userCouponVo = new UserCouponVo(); |
| | | // 获取用户所有优惠券 |
| | | List<XpAppUserCoupon> couponList = xpAppUserCouponService.list(new LambdaQueryWrapper<XpAppUserCoupon>().eq(XpAppUserCoupon::getStatus, 1).eq(XpAppUserCoupon::getAppUserId, dto.getUserId()).apply("FIND_IN_SET({0}, open_city_id)", dto.getOpenCityId()) ); |
| | | List<XpAppUserCoupon> couponList = xpAppUserCouponService.list(new LambdaQueryWrapper<XpAppUserCoupon>().eq(XpAppUserCoupon::getStatus, 1).eq(XpAppUserCoupon::getPhone,phone).apply("FIND_IN_SET({0}, open_city_id)", dto.getOpenCityId()) ); |
| | | if(couponList.isEmpty()){ |
| | | return R.ok(userCouponVo); |
| | | } |
| | |
| | | public R<XpAppUserCouponVo> list(@RequestBody XpUserCouponListQuery query, HttpServletRequest request) { |
| | | // uid已通过拦截器otp校验,可以直接使用 |
| | | String uid = request.getHeader("XP-Uid"); |
| | | XpAppUserCouponVo vo = xpAppUserCouponService.userCouponList(query, uid); |
| | | String phone ="18888888888"; |
| | | UserResourcesDto baseUserByUid = userResourcesClient.getBaseUserByUid(uid); |
| | | if(baseUserByUid!=null){ |
| | | Object data = baseUserByUid.getData(); |
| | | phone = JSONObject.parseObject(data.toString()).getString("mobile"); |
| | | } |
| | | |
| | | XpAppUserCouponVo vo = xpAppUserCouponService.userCouponList(query, phone); |
| | | return R.ok(vo); |
| | | } |
| | | |
| | |
| | | public R<XpAppUserCouponListVo> detail(@PathVariable("couponId") Long couponId, HttpServletRequest request) { |
| | | // uid已通过拦截器otp校验,可以直接使用 |
| | | String uid = request.getHeader("XP-Uid"); |
| | | String phone ="18888888888"; |
| | | UserResourcesDto baseUserByUid = userResourcesClient.getBaseUserByUid(uid); |
| | | if(baseUserByUid!=null){ |
| | | Object data = baseUserByUid.getData(); |
| | | phone = JSONObject.parseObject(data.toString()).getString("mobile"); |
| | | } |
| | | XpAppUserCoupon coupon = xpAppUserCouponService.getById(couponId); |
| | | if(uid.equals(coupon.getAppUserId().toString())){ |
| | | if(phone.equals(coupon.getPhone())){ |
| | | XpAppUserCouponListVo vo = new XpAppUserCouponListVo(); |
| | | vo.setCouponId(coupon.getId().toString()); |
| | | vo.setTitle(coupon.getCouponName()); |
| | | vo.setExpireTime(coupon.getExpirationTime()); |
| | | vo.setTimeRule(coupon.getTimeJson()); |
| | | if("0".equals(vo.getCouponId())){ |
| | | vo.setApplicableCities(Arrays.asList("不限")); |
| | | }else { |
| | |
| | | public R<XpAppUserCouponTotalVo> total(HttpServletRequest request) { |
| | | // uid已通过拦截器otp校验,可以直接使用 |
| | | String uid = request.getHeader("XP-Uid"); |
| | | XpAppUserCouponTotalVo vo = xpAppUserCouponService.userCouponTotal(uid); |
| | | String phone ="18888888888"; |
| | | UserResourcesDto baseUserByUid = userResourcesClient.getBaseUserByUid(uid); |
| | | if(baseUserByUid!=null){ |
| | | Object data = baseUserByUid.getData(); |
| | | phone = JSONObject.parseObject(data.toString()).getString("mobile"); |
| | | } |
| | | XpAppUserCouponTotalVo vo = xpAppUserCouponService.userCouponTotal(phone); |
| | | return R.ok(vo); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发放优惠券 |
| | | */ |
| | | @PostMapping("/api/v1/appUserCoupon/send") |
| | | @ApiOperation(value = "发放优惠券", tags = {"管理后台-发放优惠券"}) |
| | | public R<String> send(@RequestBody SendCouponDto dto) { |
| | | return xpAppUserCouponService.send(dto); |
| | | } |
| | | |
| | | |
| | | } |