抽奖
This commit is contained in:
@@ -28,9 +28,10 @@ import io.swagger.annotations.*;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import reactor.util.annotation.Nullable;
|
||||||
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
@@ -127,14 +128,17 @@ public class DiscSpinningController {
|
|||||||
@Login
|
@Login
|
||||||
@GetMapping("/app/discSpinning/drawCount")
|
@GetMapping("/app/discSpinning/drawCount")
|
||||||
@ApiOperation("获取大转盘抽奖次数")
|
@ApiOperation("获取大转盘抽奖次数")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "source", value = "`task`任务拉起抽奖 或者 `order` 订单拉起抽奖", dataTypeClass = String.class, paramType = "body"),
|
||||||
|
})
|
||||||
@ApiResponses({
|
@ApiResponses({
|
||||||
@ApiResponse(code = 200, message = "{\"sum\":\"总抽奖次数\",\"count\":\"剩余抽奖次数\"}"),
|
@ApiResponse(code = 200, message = "{\"sum\":\"总抽奖次数\",\"count\":\"剩余抽奖次数\"}"),
|
||||||
})
|
})
|
||||||
public Result drawCount(@RequestAttribute("userId") Long userId, @RequestBody Map maps) {
|
public Result drawCount(@ApiIgnore @RequestAttribute("userId") Long userId,@Nullable @ApiIgnore @RequestBody Map maps) {
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
|
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
|
||||||
map.put("sum", drawCount);
|
map.put("sum", drawCount);
|
||||||
if (maps.containsKey("source") && "task".equals(maps.get("source"))) {
|
if (maps!=null && maps.containsKey("source") && "task".equals(maps.get("source"))) {
|
||||||
//任务可抽奖次数
|
//任务可抽奖次数
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -150,11 +154,14 @@ public class DiscSpinningController {
|
|||||||
|
|
||||||
@Login
|
@Login
|
||||||
@GetMapping("/app/discSpinning/draw")
|
@GetMapping("/app/discSpinning/draw")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "source", value = "`task`任务拉起抽奖 或者 `order` 订单拉起抽奖", dataTypeClass = String.class, paramType = "body"),
|
||||||
|
})
|
||||||
@ApiOperation("抽取大转盘")
|
@ApiOperation("抽取大转盘")
|
||||||
public Result draw(@RequestAttribute("userId") Long userId, @RequestBody Map maps) {
|
public Result draw(@ApiIgnore @RequestAttribute("userId") Long userId,@Nullable @ApiIgnore @RequestBody Map maps) {
|
||||||
double amount = 0;
|
double amount = 0;
|
||||||
Long orderId = null;
|
Long orderId = null;
|
||||||
if (!maps.containsKey("source") && !"task".equals(maps.get("source"))) {
|
if (maps!=null && !maps.containsKey("source") && !"task".equals(maps.get("source"))) {
|
||||||
//任务抽奖
|
//任务抽奖
|
||||||
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
|
int drawCount = Integer.parseInt(commonRepository.findOne(901).getValue());
|
||||||
Integer i = recordService.countDraw(userId);
|
Integer i = recordService.countDraw(userId);
|
||||||
@@ -168,7 +175,8 @@ public class DiscSpinningController {
|
|||||||
return Result.error("无可抽奖机会");
|
return Result.error("无可抽奖机会");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Result().put("data", draws(amount, orderId, userId));
|
return new Result().put("data",
|
||||||
|
draws(amount, orderId, userId, maps.get("source") == null ? "order" : maps.get("source").toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/app/discSpinning/receive")
|
@PostMapping("/app/discSpinning/receive")
|
||||||
@@ -258,7 +266,7 @@ public class DiscSpinningController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public DiscSpinningRecord draws(double orderAmount, Long orderId, Long userId) {
|
public DiscSpinningRecord draws(double orderAmount, Long orderId, Long userId, String source) {
|
||||||
DiscSpinning result = new DiscSpinning("谢谢惠顾", 1, null);
|
DiscSpinning result = new DiscSpinning("谢谢惠顾", 1, null);
|
||||||
List<DiscSpinning> prizes = discSpinningService.list(new QueryWrapper<DiscSpinning>().orderByAsc("odds"));
|
List<DiscSpinning> prizes = discSpinningService.list(new QueryWrapper<DiscSpinning>().orderByAsc("odds"));
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
@@ -303,7 +311,7 @@ public class DiscSpinningController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DiscSpinningRecord record = new DiscSpinningRecord(result.getName(), orderId, userId, result.getType(),
|
DiscSpinningRecord record = new DiscSpinningRecord(result.getName(), orderId, userId, result.getType(),
|
||||||
result.getNumber(), DateUtils.formatYMD(new Date()), DateUtils.format(new Date()));
|
result.getNumber(), DateUtils.formatYMD(new Date()), DateUtils.format(new Date()), source);
|
||||||
recordService.save(record);
|
recordService.save(record);
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 大转盘抽奖记录(DiscSpinningRecord)表实体类
|
* 大转盘抽奖记录(DiscSpinningRecord)表实体类
|
||||||
@@ -39,11 +40,14 @@ public class DiscSpinningRecord extends Model<DiscSpinningRecord> {
|
|||||||
private String drawDay;
|
private String drawDay;
|
||||||
//创建时间
|
//创建时间
|
||||||
private String createTime;
|
private String createTime;
|
||||||
|
//来源 task 任务 order 订单
|
||||||
|
private String source = "order";
|
||||||
|
|
||||||
public DiscSpinningRecord() {
|
public DiscSpinningRecord() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscSpinningRecord(String name, Long orderId, Long userId, Integer type, BigDecimal number, String drawDay, String createTime) {
|
public DiscSpinningRecord(String name, Long orderId, Long userId, Integer type, BigDecimal number,
|
||||||
|
String drawDay, String createTime, String source) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.orderId = orderId;
|
this.orderId = orderId;
|
||||||
@@ -51,6 +55,9 @@ public class DiscSpinningRecord extends Model<DiscSpinningRecord> {
|
|||||||
this.number = number;
|
this.number = number;
|
||||||
this.drawDay = drawDay;
|
this.drawDay = drawDay;
|
||||||
this.createTime = createTime;
|
this.createTime = createTime;
|
||||||
|
if (StringUtils.isNotBlank(source)) {
|
||||||
|
this.source = source;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.sqx.modules.pay.controller.app;
|
package com.sqx.modules.pay.controller.app;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.sqx.common.utils.DateUtils;
|
import com.sqx.common.utils.DateUtils;
|
||||||
@@ -229,8 +230,7 @@ public class WuyouController {
|
|||||||
userMoneyDetails.setMoney(new BigDecimal(amount));
|
userMoneyDetails.setMoney(new BigDecimal(amount));
|
||||||
userMoneyDetails.setUserId(sourceUser.getUserId());
|
userMoneyDetails.setUserId(sourceUser.getUserId());
|
||||||
userMoneyDetails.setByUserId(user.getUserId());
|
userMoneyDetails.setByUserId(user.getUserId());
|
||||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
userMoneyDetails.setCreateTime(DateUtil.now());
|
||||||
userMoneyDetails.setCreateTime(simpleDateFormat.format(new Date()));
|
|
||||||
userMoneyDetails.setContent("分享达标奖励" + amount + "元");
|
userMoneyDetails.setContent("分享达标奖励" + amount + "元");
|
||||||
userMoneyDetails.setTitle("分享达标奖励");
|
userMoneyDetails.setTitle("分享达标奖励");
|
||||||
userMoneyDetails.setState(2);
|
userMoneyDetails.setState(2);
|
||||||
@@ -241,8 +241,5 @@ public class WuyouController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
|
|
||||||
|
|
||||||
<select id="countDraw" resultType="int">
|
<select id="countDraw" resultType="int">
|
||||||
SELECT count(1) FROM `disc_spinning_record` where user_id = 99 and draw_day = DATE_FORMAT(CURDATE(), '%Y-%m-%d');
|
SELECT count(1) FROM `disc_spinning_record` where user_id = #{userId} and draw_day = DATE_FORMAT(CURDATE(), '%Y-%m-%d');
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user