维护优惠券功能模块
This commit is contained in:
@@ -64,6 +64,7 @@ public class MybatisPlusConfig {
|
||||
"sys_dictionary",
|
||||
"sys_dictionary_data",
|
||||
"apps_test_data",
|
||||
"shop_users",
|
||||
"shop_order",
|
||||
"shop_order_info",
|
||||
"booking_user_invoice"
|
||||
|
||||
@@ -100,7 +100,7 @@ public class UsersController extends BaseController {
|
||||
@ApiOperation("修改")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Users users) {
|
||||
if (usersService.updateById(users)) {
|
||||
if (usersService.updateById(users)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
|
||||
@@ -4,18 +4,12 @@ import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.booking.entity.UserCard;
|
||||
import com.gxwebsoft.booking.service.UserCardService;
|
||||
import com.gxwebsoft.cms.entity.Website;
|
||||
import com.gxwebsoft.cms.entity.WebsiteField;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.entity.OrderInfo;
|
||||
import com.gxwebsoft.shop.entity.Payment;
|
||||
@@ -33,8 +27,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -145,6 +137,7 @@ public class WxPayNotifyController extends BaseController {
|
||||
}
|
||||
// 8.发放积分
|
||||
usersService.addIntegral(order);
|
||||
|
||||
return "SUCCESS";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,9 +62,11 @@ public class Users implements Serializable {
|
||||
@ApiModelProperty(value = "注册时间")
|
||||
private Integer createTime;
|
||||
|
||||
private String idcard;
|
||||
@ApiModelProperty(value = "身份证号码")
|
||||
private String idCard;
|
||||
|
||||
private String truename;
|
||||
@ApiModelProperty(value = "真实姓名")
|
||||
private String realName;
|
||||
|
||||
@ApiModelProperty(value = "是否管理员:1是;2否")
|
||||
private Integer isAdmin;
|
||||
|
||||
@@ -49,11 +49,11 @@
|
||||
<if test="param.createTimeEnd != null">
|
||||
AND a.create_time <= #{param.createTimeEnd}
|
||||
</if>
|
||||
<if test="param.idcard != null">
|
||||
AND a.idcard LIKE CONCAT('%', #{param.idcard}, '%')
|
||||
<if test="param.idCard != null">
|
||||
AND a.id_card LIKE CONCAT('%', #{param.idCard}, '%')
|
||||
</if>
|
||||
<if test="param.truename != null">
|
||||
AND a.truename LIKE CONCAT('%', #{param.truename}, '%')
|
||||
<if test="param.realName != null">
|
||||
AND a.real_name LIKE CONCAT('%', #{param.realName}, '%')
|
||||
</if>
|
||||
<if test="param.isAdmin != null">
|
||||
AND a.is_admin = #{param.isAdmin}
|
||||
|
||||
@@ -62,9 +62,11 @@ public class UsersParam extends BaseParam {
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private BigDecimal money;
|
||||
|
||||
private String idcard;
|
||||
@ApiModelProperty(value = "身份证号码")
|
||||
private String idCard;
|
||||
|
||||
private String truename;
|
||||
@ApiModelProperty(value = "真实姓名")
|
||||
private String realName;
|
||||
|
||||
@ApiModelProperty(value = "是否管理员:1是;2否")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
|
||||
@@ -41,4 +41,6 @@ public interface UsersService extends IService<Users> {
|
||||
Users getByIdRel(Integer id);
|
||||
|
||||
void addIntegral(Order order);
|
||||
|
||||
Users getByPhone(String phone);
|
||||
}
|
||||
|
||||
@@ -260,68 +260,87 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public Boolean payByBalance(Order order) {
|
||||
final User loginUser = order.getLoginUser();
|
||||
if (loginUser.getBalance().compareTo(order.getTotalPrice()) < 0) {
|
||||
final Users users = usersService.getByPhone(order.getPhone());
|
||||
if (users.getMoney().compareTo(order.getTotalPrice()) < 0) {
|
||||
throw new BusinessException("余额不足");
|
||||
}
|
||||
// 发起网络请求(更新余额接口)
|
||||
final RequestUtil requestUtil = new RequestUtil();
|
||||
requestUtil.setAccessToken(order.getAccessToken());
|
||||
requestUtil.setTenantId(order.getTenantId().toString());
|
||||
String api = "/system/user/updateUserBalance"; // 更新余额接口
|
||||
final BigDecimal subtract = loginUser.getBalance().subtract(order.getTotalPrice());
|
||||
// 发放积分
|
||||
usersService.addIntegral(order);
|
||||
// 修改订单状态
|
||||
order.setPayStatus(1);
|
||||
order.setPayTime(DateUtil.date());
|
||||
order.setExpirationTime(DateUtil.offset(DateUtil.date(), DateField.YEAR, 10));
|
||||
orderService.updateById(order);
|
||||
orderInfoService.update(new LambdaUpdateWrapper<OrderInfo>().eq(OrderInfo::getOrderId, order.getOrderId()).set(OrderInfo::getPayStatus, 1));
|
||||
// 更新会员卡状态
|
||||
if (order.getType().equals(2)) {
|
||||
final UserCard userCard = userCardService.getById(order.getCardId());
|
||||
userCard.setPayStatus(1);
|
||||
userCardService.updateById(userCard);
|
||||
}
|
||||
|
||||
loginUser.setBalance(subtract);
|
||||
return true;
|
||||
|
||||
|
||||
// 发起网络请求(更新余额接口)
|
||||
// final RequestUtil requestUtil = new RequestUtil();
|
||||
// requestUtil.setAccessToken(order.getAccessToken());
|
||||
// requestUtil.setTenantId(order.getTenantId().toString());
|
||||
// String api = "/system/user/updateUserBalance"; // 更新余额接口
|
||||
// final BigDecimal subtract = loginUser.getMoney().subtract(order.getTotalPrice());
|
||||
//
|
||||
// loginUser.setBalance(subtract);
|
||||
// 累加会员积分
|
||||
String key = "SiteInfo:" + order.getTenantId();
|
||||
final String siteInfo = redisUtil.get(key);
|
||||
// String key = "SiteInfo:" + order.getTenantId();
|
||||
// final String siteInfo = redisUtil.get(key);
|
||||
// 从缓存读取信息
|
||||
if(StrUtil.isNotBlank(siteInfo)){
|
||||
final Website website = JSONObject.parseObject(siteInfo, Website.class);
|
||||
final List<WebsiteField> fields = website.getFields();
|
||||
fields.forEach(d -> {
|
||||
if(d.getName().equals("integral_enabled") && d.getValue().equals("1")){
|
||||
loginUser.setPoints(loginUser.getPoints() + order.getPayPrice().intValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
final ApiResult<?> apiResult = requestUtil.updateUserBalance(api, loginUser);
|
||||
if (apiResult.getCode().equals(0)) {
|
||||
// 记录余额明细
|
||||
final UserBalanceLog balanceLog = new UserBalanceLog();
|
||||
balanceLog.setUserId(order.getUserId());
|
||||
balanceLog.setScene(20);
|
||||
balanceLog.setOrderNo(order.getOrderNo());
|
||||
balanceLog.setMoney(order.getPayPrice());
|
||||
balanceLog.setBalance(subtract);
|
||||
balanceLog.setRemark(order.getComments());
|
||||
balanceLog.setMerchantId(order.getMerchantId());
|
||||
userBalanceLogService.save(balanceLog);
|
||||
// 修改订单状态
|
||||
order.setPayStatus(1);
|
||||
order.setPayTime(DateUtil.date());
|
||||
order.setExpirationTime(DateUtil.offset(DateUtil.date(), DateField.YEAR, 10));
|
||||
orderService.updateById(order);
|
||||
orderInfoService.update(new LambdaUpdateWrapper<OrderInfo>().eq(OrderInfo::getOrderId,order.getOrderId()).set(OrderInfo::getPayStatus,1));
|
||||
// 更新会员卡状态
|
||||
if(order.getType().equals(2)){
|
||||
final UserCard userCard = userCardService.getById(order.getCardId());
|
||||
userCard.setPayStatus(1);
|
||||
userCardService.updateById(userCard);
|
||||
}
|
||||
// 发放积分
|
||||
usersService.addIntegral(order);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// if(StrUtil.isNotBlank(siteInfo)){
|
||||
// final Website website = JSONObject.parseObject(siteInfo, Website.class);
|
||||
// final List<WebsiteField> fields = website.getFields();
|
||||
// fields.forEach(d -> {
|
||||
// if(d.getName().equals("integral_enabled") && d.getValue().equals("1")){
|
||||
// loginUser.setPoints(loginUser.getPoints() + order.getPayPrice().intValue());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// final ApiResult<?> apiResult = requestUtil.updateUserBalance(api, loginUser);
|
||||
// if (apiResult.getCode().equals(0)) {
|
||||
// // 记录余额明细
|
||||
// final UserBalanceLog balanceLog = new UserBalanceLog();
|
||||
// balanceLog.setUserId(order.getUserId());
|
||||
// balanceLog.setScene(20);
|
||||
// balanceLog.setOrderNo(order.getOrderNo());
|
||||
// balanceLog.setMoney(order.getPayPrice());
|
||||
// balanceLog.setBalance(subtract);
|
||||
// balanceLog.setRemark(order.getComments());
|
||||
// balanceLog.setMerchantId(order.getMerchantId());
|
||||
// userBalanceLogService.save(balanceLog);
|
||||
// // 修改订单状态
|
||||
// order.setPayStatus(1);
|
||||
// order.setPayTime(DateUtil.date());
|
||||
// order.setExpirationTime(DateUtil.offset(DateUtil.date(), DateField.YEAR, 10));
|
||||
// orderService.updateById(order);
|
||||
// orderInfoService.update(new LambdaUpdateWrapper<OrderInfo>().eq(OrderInfo::getOrderId,order.getOrderId()).set(OrderInfo::getPayStatus,1));
|
||||
// // 更新会员卡状态
|
||||
// if(order.getType().equals(2)){
|
||||
// final UserCard userCard = userCardService.getById(order.getCardId());
|
||||
// userCard.setPayStatus(1);
|
||||
// userCardService.updateById(userCard);
|
||||
// }
|
||||
// // 发放积分
|
||||
// usersService.addIntegral(order);
|
||||
// return true;
|
||||
// }
|
||||
// return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public Boolean payByUserCard(Order order) {
|
||||
final Users users = usersService.getByPhone(order.getPhone());
|
||||
final User loginUser = order.getLoginUser();
|
||||
final UserCardLog userCardLog = new UserCardLog();
|
||||
if(order.getCardId() == null){
|
||||
if (order.getCardId() == null) {
|
||||
throw new BusinessException("会员卡ID不存在");
|
||||
}
|
||||
// 查询会员卡信息
|
||||
@@ -342,7 +361,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
if (userCard.getNum() <= 0) {
|
||||
throw new BusinessException("剩余次数不足");
|
||||
}
|
||||
userCardLog.setNum(userCard.getNum()-1);
|
||||
userCardLog.setNum(userCard.getNum() - 1);
|
||||
}
|
||||
userCardService.updateById(userCard);
|
||||
|
||||
@@ -363,7 +382,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
order.setExpirationTime(DateUtil.offset(DateUtil.date(), DateField.YEAR, 10));
|
||||
orderService.updateById(order);
|
||||
// 更新订单信息表的支付状态
|
||||
orderInfoService.update(new LambdaUpdateWrapper<OrderInfo>().eq(OrderInfo::getOrderId,order.getOrderId()).set(OrderInfo::getPayStatus,1));
|
||||
orderInfoService.update(new LambdaUpdateWrapper<OrderInfo>().eq(OrderInfo::getOrderId, order.getOrderId()).set(OrderInfo::getPayStatus, 1));
|
||||
// 发放积分
|
||||
usersService.addIntegral(order);
|
||||
return true;
|
||||
|
||||
@@ -77,4 +77,9 @@ public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements
|
||||
integralLogService.save(integralLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Users getByPhone(String phone) {
|
||||
return getOne(new LambdaUpdateWrapper<Users>().eq(Users::getPhone,phone).last("limit 1"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class OrderInfoTask extends BaseController {
|
||||
/**
|
||||
* 自动处理过期订单任务
|
||||
*/
|
||||
@Scheduled(cron="*/10 * * * * *")
|
||||
// @Scheduled(cron="*/10 * * * * *")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void settledExpirationOrder() {
|
||||
final Order order = new Order();
|
||||
@@ -57,7 +57,7 @@ public class OrderInfoTask extends BaseController {
|
||||
* 自动处理过期订单任务(游泳馆专用)
|
||||
* Scheduled(cron="0 30 21 * * ?")
|
||||
*/
|
||||
@Scheduled(cron="*/30 * * * * *")
|
||||
// @Scheduled(cron="*/30 * * * * *")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void settledExpirationOrderBy3028() {
|
||||
final Order order = new Order();
|
||||
|
||||
@@ -32,7 +32,7 @@ public class OrderTask extends BaseController {
|
||||
/**
|
||||
* 自动处理过期订单任务
|
||||
*/
|
||||
@Scheduled(fixedDelay = 2000, initialDelay = 2000)
|
||||
// @Scheduled(fixedDelay = 2000, initialDelay = 2000)
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void settledExpirationOrder() {
|
||||
final OrderParam p = new OrderParam();
|
||||
|
||||
Reference in New Issue
Block a user