| @@ -1,15 +1,16 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.domain.po.WxCouponCar; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.po.WxPark; | |||
| import com.iformall.domain.vo.WxCouponCarVo; | |||
| import com.iformall.enums.EnumCarVendor; | |||
| import com.iformall.enums.EnumCouponStatus; | |||
| import com.iformall.enums.EnumETCPCode; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.*; | |||
| @@ -52,7 +52,7 @@ public class WxCreditHistory implements Serializable { | |||
| @io.swagger.annotations.ApiModelProperty(value="每笔积分明细",name="creditNum") | |||
| private Integer creditNum; | |||
| /**积分类型*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="积分类型 1每日登录,2消费,3绑车牌,4连接WIFI,5微信用户昵称授权,6微信用户手机授权,7完善个人信息,8积分导入,10增加积分,11积分兑换,12减少积分",name="creditType") | |||
| @io.swagger.annotations.ApiModelProperty(value="积分类型 1每日登录,2消费,3绑车牌,4连接WIFI,5微信用户昵称授权,6微信用户手机授权,7完善个人信息,8积分导入,10增加积分,11积分兑换,12减少积分 注:11积分兑换改为走订单接口",name="creditType") | |||
| private Integer creditType; | |||
| /**创建日期*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="创建日期",name="createDate") | |||
| @@ -15,6 +15,8 @@ public enum EnumCouponType { | |||
| COUPON_MULTIMCH(6, "通用券"), | |||
| COUPON_PRESS(8, "砍价券"), | |||
| COUPON_GROUP(9, "团购券"), | |||
| COUPON_CREDIT(50,"积分券"), | |||
| COUPON_CREDIT_PARK(51,"积分停车券"), | |||
| CARD_MULTIMCH(100, "消费卡"), | |||
| ; | |||
| @@ -10,7 +10,8 @@ public enum EnumOrderType { | |||
| COUPON(0,"券"), | |||
| MICROPAY(1,"B收款码支付"), | |||
| NATIVEPAY(2,"C扫码支付"), | |||
| PREPAIDCARD(3, "储值卡") | |||
| PREPAIDCARD(3, "储值卡"), | |||
| CREDIT(4,"积分支付") | |||
| ; | |||
| public static EnumOrderType getEnum(Integer code) { | |||
| @@ -1,12 +1,10 @@ | |||
| package com.iformall.service; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.WxCreditHistoryDto; | |||
| import com.iformall.domain.po.WxCreditHistory; | |||
| import com.iformall.domain.vo.WxCreditHistoryVo; | |||
| import org.springframework.web.bind.annotation.RequestParam; | |||
| import java.util.Map; | |||
| public interface WxCreditHistoryService { | |||
| @@ -43,7 +41,7 @@ public interface WxCreditHistoryService { | |||
| * | |||
| * @param record | |||
| */ | |||
| ResultData saveOrUpdate(WxCreditHistory record); | |||
| void saveOrUpdate(WxCreditHistory record); | |||
| /** | |||
| * 根据Id删除实体 | |||
| @@ -141,12 +141,12 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public ResultData saveOrUpdate(WxCreditHistory record) { | |||
| public void saveOrUpdate(WxCreditHistory record) { | |||
| WxCUser wxCUser = wxCUserMapper.selectByPrimaryKey(record.getCUserId()); | |||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectByPrimaryKey(record.getCUserId()); | |||
| if (wxCUser == null && wxCUserBasicInfo == null) { | |||
| //验证此用户是否存在 | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| //获取当前用户总积分 | |||
| //int currentCreditAmount = wxCreditHistoryMapper.creditAmount(record.getCUserId()); | |||
| @@ -162,10 +162,10 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| int creditChangeNum = creditIncrement(record); | |||
| if (creditChangeNum == 0) { | |||
| return new ResultData(ErrorCode.CREDIT_ZERO); | |||
| throw new MallinkException(ErrorCode.CREDIT_ZERO); | |||
| } | |||
| if (currentCreditAmount + creditChangeNum < 0) { | |||
| return new ResultData(ErrorCode.CREDIT_NOT_ENOUGH); | |||
| throw new MallinkException(ErrorCode.CREDIT_NOT_ENOUGH); | |||
| } | |||
| record.setCreditNum(creditChangeNum); | |||
| record.setCreditAmount(currentCreditAmount + creditChangeNum); | |||
| @@ -186,8 +186,6 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| } else { | |||
| //wxCreditHistoryMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "积分操作成功"); | |||
| } | |||
| @Override | |||
| @@ -313,72 +311,10 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| } | |||
| private int changeCredit(WxCreditHistory record) { | |||
| if (record == null || record.getCouponId() == null) { | |||
| log.error("券不存在"); | |||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| // 检查券状态 | |||
| String couponIdStr = String.valueOf(record.getCouponId()); | |||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(record.getCouponId()); | |||
| if (coupon == null) { | |||
| log.error("券不存在, couponId: " + couponIdStr); | |||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| if (coupon.getStatus() == EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()) { | |||
| log.error("券已下架, couponId: " + couponIdStr); | |||
| throw new MallinkException(ErrorCode.COUPON_IS_TAKE_OFF); | |||
| } | |||
| /*if (coupon.getSalePrice() != 0) { | |||
| log.error("券不免费, couponId: " + couponIdStr); | |||
| throw new MallinkException(ErrorCode.COUPON_IS_NOT_FREE); | |||
| }*/ | |||
| if (coupon.getValidEndDate() != null && coupon.getValidEndDate().before(new Date())) { | |||
| log.error("此券已过期, couponId: " + couponIdStr); | |||
| throw new MallinkException(ErrorCode.COUPON_IS_EXPIRED); | |||
| } | |||
| // 减库存操作 | |||
| try { | |||
| stockReduce(coupon, couponIdStr); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| } | |||
| int changeCredit = coupon.getCreditPrice(); | |||
| int changeCredit = record.getCreditNum(); | |||
| return -changeCredit; | |||
| } | |||
| private void stockReduce(WxCoupon coupon, String couponIdStr) { | |||
| long time = System.currentTimeMillis() + RedisLock.TIMEOUT; | |||
| String timeStr = String.valueOf(time); | |||
| // 库存加锁 | |||
| if (!redisLock.lock(couponIdStr, timeStr)) { | |||
| log.error("此券被锁定, couponId: " + couponIdStr); | |||
| throw new MallinkException(ErrorCode.TOO_MANY_REQUEST); | |||
| } | |||
| // 检查 优惠券 库存 | |||
| if (coupon.getRemainInventory() <= 0) { | |||
| //解锁 | |||
| redisLock.unlock(couponIdStr, timeStr); | |||
| log.error("此券库存为0, couponId: " + couponIdStr); | |||
| throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY); | |||
| } | |||
| try { | |||
| WxCoupon updateRecord = new WxCoupon(); | |||
| updateRecord.setId(coupon.getId()); | |||
| updateRecord.setRemainInventory(coupon.getRemainInventory() - 1); | |||
| updateRecord.setUpdateDate(new Date()); | |||
| // 减库存 | |||
| wxCouponMapper.updateByPrimaryKeySelective(updateRecord); | |||
| } catch (RuntimeException e) { | |||
| log.error("此券减库存失败, couponId: " + couponIdStr); | |||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||
| } finally { | |||
| //解锁 | |||
| redisLock.unlock(couponIdStr, timeStr); | |||
| } | |||
| } | |||
| private int payAddCredit(WxCreditHistory record) { | |||
| int addCreditNumber = 0; | |||
| // 订单金额为0时不计入 | |||
| @@ -102,6 +102,9 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Autowired | |||
| WxOrderGroupMapper wxOrderGroupMapper; | |||
| @Autowired | |||
| WxCreditHistoryService wxCreditHistoryService; | |||
| @Override | |||
| public PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxOrderMapper.findList(record)); | |||
| @@ -419,11 +422,35 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| record.setOrderNumber(orderNumber); | |||
| record.setCouponChannelId(couponChannelId); | |||
| record.setProductId(couponId); | |||
| record.setType(EnumOrderType.COUPON.getCode()); | |||
| //当salePrice为0时 则进行积分支付 | |||
| if (coupon.getCreditPrice() != null && coupon.getSalePrice() != null && coupon.getSalePrice() == 0 | |||
| && (coupon.getType() == EnumCouponType.COUPON_CREDIT.getCode() || coupon.getType() == EnumCouponType.COUPON_CREDIT_PARK.getCode())) { | |||
| //若用户剩余积分比积分售价低则不能支付 | |||
| if (user.getCredit() == null || user.getCredit() < coupon.getSalePrice()) { | |||
| throw new MallinkException(ErrorCode.CREDIT_NOT_ENOUGH); | |||
| } | |||
| //扣减积分操作记录 | |||
| WxCreditHistory creditHistory = new WxCreditHistory(); | |||
| creditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||
| creditHistory.setOperatorId(user.getId()); | |||
| creditHistory.setCreditNum(coupon.getCreditPrice()); | |||
| creditHistory.setCUserId(user.getId()); | |||
| creditHistory.setCreateDate(new Date()); | |||
| creditHistory.setTenantId(user.getTenantId()); | |||
| creditHistory.setCreditType(EnumScoreType.CHANGE_CREDIT.getCode()); | |||
| creditHistory.setCouponId(couponId); | |||
| wxCreditHistoryService.saveOrUpdate(creditHistory); | |||
| record.setType(EnumOrderType.CREDIT.getCode()); | |||
| //积分支付时 变更订单状态为已支付 | |||
| record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
| } else { | |||
| record.setType(EnumOrderType.COUPON.getCode()); | |||
| record.setOrderStatus(orderStatus); | |||
| } | |||
| record.setcUserId(user.getId()); | |||
| record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | |||
| record.setPayment(payment); | |||
| record.setOrderStatus(orderStatus); | |||
| //record.setOrderStatus(orderStatus); | |||
| record.setDetail(bodyStr); | |||
| record.setCreateDate(curr); | |||
| record.setUpdateDate(curr); | |||