mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-06-25 06:30:48 +08:00
充值功能 (未完成)
This commit is contained in:
@@ -1,25 +1,47 @@
|
||||
package com.mdd.front.controller;
|
||||
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.front.LikeFrontThreadLocal;
|
||||
import com.mdd.front.service.IRechargeService;
|
||||
import com.mdd.front.validate.RechargeValidate;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.models.auth.In;
|
||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/recharge")
|
||||
@Api(tags = "充值管理")
|
||||
public class RechargeController {
|
||||
|
||||
@Resource
|
||||
IRechargeService iRechargeService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public AjaxResult<Object> list() {
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
* @param rechargeValidate 参数
|
||||
* @return AjaxResult<Object>
|
||||
*/
|
||||
@PostMapping("/placeOrder")
|
||||
public AjaxResult<Object> placeOrder() {
|
||||
return AjaxResult.success();
|
||||
public AjaxResult<Object> placeOrder(@Validated @RequestBody RechargeValidate rechargeValidate) {
|
||||
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||
Integer terminal = LikeFrontThreadLocal.getTerminal();
|
||||
|
||||
Map<String, Object> result = iRechargeService.placeOrder(userId, terminal, rechargeValidate);
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.mdd.front.service;
|
||||
|
||||
import com.mdd.front.validate.RechargeValidate;
|
||||
import io.swagger.models.auth.In;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 充值余额接口服务类
|
||||
*/
|
||||
public interface IRechargeService {
|
||||
|
||||
Map<String, Object> placeOrder(Integer userId, Integer terminal, RechargeValidate rechargeValidate);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.mdd.front.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.common.entity.RechargeOrder;
|
||||
import com.mdd.common.mapper.RechargeOrderMapper;
|
||||
import com.mdd.common.util.TimeUtils;
|
||||
import com.mdd.common.util.ToolUtils;
|
||||
import com.mdd.front.service.IRechargeService;
|
||||
import com.mdd.front.validate.RechargeValidate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 充值余额服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class RechargeServiceImpl implements IRechargeService {
|
||||
|
||||
@Resource
|
||||
RechargeOrderMapper rechargeOrderMapper;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> placeOrder(Integer userId, Integer terminal, RechargeValidate rechargeValidate) {
|
||||
RechargeOrder order = new RechargeOrder();
|
||||
order.setUserId(userId);
|
||||
order.setOrderTerminal(terminal);
|
||||
order.setOrderSn(this.randMakeOrderSn());
|
||||
order.setPayWay(rechargeValidate.getPayWay());
|
||||
order.setPayStatus(0);
|
||||
order.setRefundStatus(0);
|
||||
order.setOrderAmount(rechargeValidate.getOrderAmount());
|
||||
order.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
order.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
order.setDeleteTime(System.currentTimeMillis() / 1000);
|
||||
rechargeOrderMapper.insert(order);
|
||||
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("id", order.getId());
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成唯一订单号
|
||||
*
|
||||
* @author fzr
|
||||
* @return String
|
||||
*/
|
||||
private String randMakeOrderSn() {
|
||||
String date = TimeUtils.timestampToDate(System.currentTimeMillis()/1000, "YmdHis");
|
||||
String sn;
|
||||
while (true) {
|
||||
sn = date + ToolUtils.randomInt(12);
|
||||
RechargeOrder snModel = rechargeOrderMapper.selectOne(
|
||||
new QueryWrapper<RechargeOrder>()
|
||||
.select("id")
|
||||
.eq("sn", sn)
|
||||
.last("limit 1"));
|
||||
if (snModel == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sn;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.mdd.front.validate;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@ApiModel("新用户更新信息参数")
|
||||
public class RechargeValidate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull(message = "payWay参数缺失")
|
||||
private Integer payWay;
|
||||
|
||||
@NotNull(message = "orderAmount参数缺失")
|
||||
private BigDecimal orderAmount;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user