feat: 多套餐
This commit is contained in:
@@ -66,6 +66,44 @@ CREATE TABLE `u_account` (
|
||||
-- Records of u_account
|
||||
-- ----------------------------
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for u_account_package
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `u_account_package`;
|
||||
CREATE TABLE `u_account_package` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`account_id` bigint(20) NULL DEFAULT NULL COMMENT '账户ID',
|
||||
`package_id` bigint(20) NULL DEFAULT NULL COMMENT '套餐ID',
|
||||
`traffic` bigint(20) NULL DEFAULT NULL COMMENT '流量',
|
||||
`duration` bigint(20) NULL DEFAULT NULL COMMENT '时长',
|
||||
`client_num` int(11) NULL DEFAULT NULL COMMENT '在线设备数',
|
||||
`expired_time` datetime NULL DEFAULT NULL COMMENT '失效时间',
|
||||
`package_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '套餐名称',
|
||||
`period_num` int(11) NULL DEFAULT NULL COMMENT '有效期数',
|
||||
`period_type` tinyint(4) NULL DEFAULT NULL COMMENT '有效期类型',
|
||||
`price` decimal(18, 4) NULL DEFAULT NULL COMMENT '价格',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
`rate_limit_enable` tinyint(1) NULL DEFAULT 0 COMMENT '带宽是否限制',
|
||||
`traffic_enable` tinyint(1) NULL DEFAULT 0 COMMENT '流量是否限制',
|
||||
`duration_enable` tinyint(1) NULL DEFAULT 0 COMMENT '时长是否限制',
|
||||
`client_num_enable` tinyint(1) NULL DEFAULT 0 COMMENT '在线设备数是否限制',
|
||||
`rate_limit_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '限速名称',
|
||||
`down_limit` bigint(20) NULL DEFAULT NULL COMMENT '下行限速',
|
||||
`down_limit_enable` tinyint(1) NULL DEFAULT 0 COMMENT '下行限速启用',
|
||||
`up_limit` bigint(20) NULL DEFAULT NULL COMMENT '上行限速',
|
||||
`up_limit_enable` tinyint(1) NULL DEFAULT 0 COMMENT '上行限速启用',
|
||||
`del_flag` tinyint(1) NULL DEFAULT 0 COMMENT '删除标志(0存在 1删除)',
|
||||
`create_by` bigint(20) NULL DEFAULT NULL COMMENT '创建人',
|
||||
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
|
||||
`update_by` bigint(20) NULL DEFAULT NULL COMMENT '更新人',
|
||||
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户平台-账户套餐表' ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of u_account_package
|
||||
-- ----------------------------
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for u_balance
|
||||
-- ----------------------------
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package org.wfc.user.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.wfc.common.core.web.controller.BaseController;
|
||||
import org.wfc.common.core.web.domain.AjaxResult;
|
||||
import org.wfc.common.core.web.page.TableDataInfo;
|
||||
import org.wfc.user.domain.UAccountPackage;
|
||||
import org.wfc.user.service.IUAccountPackageService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户平台-账户套餐表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author sys
|
||||
* @since 2025-02-10
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user/uAccountPackage")
|
||||
public class UAccountPackageController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IUAccountPackageService uAccountPackageService;
|
||||
|
||||
@GetMapping("/page")
|
||||
public TableDataInfo page(UAccountPackage uAccountPackage) {
|
||||
startPage();
|
||||
List<UAccountPackage> list = uAccountPackageService.list();
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public AjaxResult list(UAccountPackage uAccountPackage) {
|
||||
List<UAccountPackage> list = uAccountPackageService.list();
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getById(@PathVariable("id") Long id) {
|
||||
return success(uAccountPackageService.getById(id));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody UAccountPackage uAccountPackage) {
|
||||
return toAjax(uAccountPackageService.save(uAccountPackage));
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody UAccountPackage uAccountPackage) {
|
||||
return toAjax(uAccountPackageService.updateById(uAccountPackage));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
return toAjax(uAccountPackageService.removeByIds(CollUtil.newArrayList(ids)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.wfc.user.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.wfc.common.mybatis.domain.BaseData;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户平台-账户套餐表
|
||||
* </p>
|
||||
*
|
||||
* @author sys
|
||||
* @since 2025-02-10
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("u_account_package")
|
||||
@Schema(name = "UAccountPackage", description = "用户平台-账户套餐表")
|
||||
public class UAccountPackage extends BaseData {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "账户ID")
|
||||
private Long accountId;
|
||||
|
||||
@Schema(description = "套餐ID")
|
||||
private Long packageId;
|
||||
|
||||
@Schema(description = "流量")
|
||||
private Long traffic;
|
||||
|
||||
@Schema(description = "时长")
|
||||
private Long duration;
|
||||
|
||||
@Schema(description = "在线设备数")
|
||||
private Integer clientNum;
|
||||
|
||||
@Schema(description = "失效时间")
|
||||
private Date expiredTime;
|
||||
|
||||
@Schema(description = "套餐名称")
|
||||
private String packageName;
|
||||
|
||||
@Schema(description = "有效期数")
|
||||
private Integer periodNum;
|
||||
|
||||
@Schema(description = "有效期类型")
|
||||
private Integer periodType;
|
||||
|
||||
@Schema(description = "价格")
|
||||
private BigDecimal price;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "带宽是否限制")
|
||||
private Boolean rateLimitEnable;
|
||||
|
||||
@Schema(description = "流量是否限制")
|
||||
private Boolean trafficEnable;
|
||||
|
||||
@Schema(description = "时长是否限制")
|
||||
private Boolean durationEnable;
|
||||
|
||||
@Schema(description = "在线设备数是否限制")
|
||||
private Boolean clientNumEnable;
|
||||
|
||||
@Schema(description = "限速名称")
|
||||
private String rateLimitName;
|
||||
|
||||
@Schema(description = "下行限速")
|
||||
private Long downLimit;
|
||||
|
||||
@Schema(description = "下行限速启用")
|
||||
private Boolean downLimitEnable;
|
||||
|
||||
@Schema(description = "上行限速")
|
||||
private Long upLimit;
|
||||
|
||||
@Schema(description = "上行限速启用")
|
||||
private Boolean upLimitEnable;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.wfc.user.mapper;
|
||||
|
||||
import org.wfc.user.domain.UAccountPackage;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户平台-账户套餐表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author sys
|
||||
* @since 2025-02-10
|
||||
*/
|
||||
public interface UAccountPackageMapper extends BaseMapper<UAccountPackage> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.wfc.user.service;
|
||||
|
||||
import org.wfc.user.domain.UAccountPackage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户平台-账户套餐表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author sys
|
||||
* @since 2025-02-10
|
||||
*/
|
||||
public interface IUAccountPackageService extends IService<UAccountPackage> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.wfc.user.service.impl;
|
||||
|
||||
import org.wfc.user.domain.UAccountPackage;
|
||||
import org.wfc.user.mapper.UAccountPackageMapper;
|
||||
import org.wfc.user.service.IUAccountPackageService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户平台-账户套餐表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author sys
|
||||
* @since 2025-02-10
|
||||
*/
|
||||
@Service
|
||||
public class UAccountPackageServiceImpl extends ServiceImpl<UAccountPackageMapper, UAccountPackage> implements IUAccountPackageService {
|
||||
|
||||
}
|
||||
@@ -11,11 +11,13 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.wfc.common.core.exception.ServiceException;
|
||||
import org.wfc.common.security.utils.SecurityUtils;
|
||||
import org.wfc.user.api.IWifiApi;
|
||||
import org.wfc.user.api.omada.domain.convert.OmadaConvert;
|
||||
import org.wfc.user.api.omada.domain.dto.ClientRateLimitSettingDto;
|
||||
import org.wfc.user.domain.UAccount;
|
||||
import org.wfc.user.domain.UAccountPackage;
|
||||
import org.wfc.user.domain.UBill;
|
||||
import org.wfc.user.domain.UBillRule;
|
||||
import org.wfc.user.domain.UClient;
|
||||
@@ -25,6 +27,7 @@ import org.wfc.user.domain.URateLimit;
|
||||
import org.wfc.user.domain.constant.OrderStatusEnum;
|
||||
import org.wfc.user.domain.constant.OrderTypeEnum;
|
||||
import org.wfc.user.domain.constant.PeriodTypeEnum;
|
||||
import org.wfc.user.mapper.UAccountPackageMapper;
|
||||
import org.wfc.user.mapper.UBillMapper;
|
||||
import org.wfc.user.mapper.UBillRuleMapper;
|
||||
import org.wfc.user.mapper.UOrderMapper;
|
||||
@@ -69,14 +72,16 @@ public class UOrderServiceImpl extends ServiceImpl<UOrderMapper, UOrder> impleme
|
||||
@Autowired
|
||||
private UBillRuleMapper billRuleMapper;
|
||||
|
||||
@Autowired
|
||||
private UAccountPackageMapper accountPackageMapper;
|
||||
|
||||
@Autowired
|
||||
private IWifiApi wifiApi;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean paySuccess(Long orderId) {
|
||||
// 支付成功回调(预留)
|
||||
|
||||
// 支付成功回调
|
||||
// 更新当前订单状态为已支付
|
||||
UOrder order = this.getById(orderId);
|
||||
if (OrderStatusEnum.PAID.getCode().equals(order.getStatus())) {
|
||||
@@ -110,16 +115,14 @@ public class UOrderServiceImpl extends ServiceImpl<UOrderMapper, UOrder> impleme
|
||||
}
|
||||
if (OrderTypeEnum.PACKAGE.getCode().equals(order.getType())) {
|
||||
// 套餐
|
||||
callbackPackage(order, account);
|
||||
account.setTrafficUsed(0L);
|
||||
account.setDurationUsed(0L);
|
||||
account.setClientNumUsed(0);
|
||||
callbackPackage(order, account, false);
|
||||
} else if (OrderTypeEnum.RECHARGE.getCode().equals(order.getType())) {
|
||||
// 充值
|
||||
// 更新账户余额
|
||||
account.setBalance(order.getOrderAmount().add(Optional.ofNullable(account.getBalance()).orElse(BigDecimal.ZERO)));
|
||||
}
|
||||
account.setId(accountId);
|
||||
|
||||
accountService.saveOrUpdate(account);
|
||||
|
||||
// 授权当前用户的所有设备访问wifi
|
||||
@@ -139,26 +142,39 @@ public class UOrderServiceImpl extends ServiceImpl<UOrderMapper, UOrder> impleme
|
||||
return true;
|
||||
}
|
||||
|
||||
private void callbackPackage(UOrder order, UAccount account) {
|
||||
private void callbackPackage(UOrder order, UAccount account, boolean isValid) {
|
||||
if (ObjectUtil.isNull(order.getPackageId())) {
|
||||
return;
|
||||
}
|
||||
UAccountPackage accountPackage = new UAccountPackage();
|
||||
|
||||
UPackage uPackage = packageService.getById(order.getPackageId());
|
||||
Boolean rateLimitEnable = uPackage.getRateLimitEnable();
|
||||
rateLimitEnable = ObjectUtil.isNotNull(uPackage.getRateLimitId()) ? rateLimitEnable : false;
|
||||
if (rateLimitEnable) {
|
||||
URateLimit rateLimit = rateLimitService.getById(uPackage.getRateLimitId());
|
||||
BeanUtils.copyProperties(rateLimit, account);
|
||||
if (isValid) {
|
||||
BeanUtils.copyProperties(rateLimit, accountPackage);
|
||||
} else {
|
||||
BeanUtils.copyProperties(rateLimit, account);
|
||||
}
|
||||
}
|
||||
|
||||
if (isValid) {
|
||||
BeanUtils.copyProperties(uPackage, accountPackage);
|
||||
accountPackage.setPackageId(order.getPackageId());
|
||||
accountPackageMapper.insert(accountPackage);
|
||||
} else {
|
||||
BeanUtils.copyProperties(uPackage, account);
|
||||
account.setPackageId(order.getPackageId());
|
||||
account.setTrafficUsed(0L);
|
||||
account.setDurationUsed(0L);
|
||||
account.setClientNumUsed(0);
|
||||
Date current = new Date();
|
||||
DateTime endTime = getEndTime(uPackage, current);
|
||||
account.setStartTime(current);
|
||||
account.setEndTime(endTime);
|
||||
}
|
||||
BeanUtils.copyProperties(uPackage, account);
|
||||
account.setPackageId(order.getPackageId());
|
||||
account.setTrafficUsed(0L);
|
||||
account.setDurationUsed(0L);
|
||||
account.setClientNumUsed(0);
|
||||
Date current = new Date();
|
||||
DateTime endTime = getEndTime(uPackage, current);
|
||||
account.setStartTime(current);
|
||||
account.setEndTime(endTime);
|
||||
}
|
||||
|
||||
private static DateTime getEndTime(UPackage uPackage, Date current) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.wfc.user.mapper.UAccountPackageMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user