|
@@ -0,0 +1,49 @@
|
|
|
+package cn.org.spring.wechar.controller;
|
|
|
+
|
|
|
+import cn.org.spring.common.util.StringUtil;
|
|
|
+import cn.org.spring.wechar.bean.Result;
|
|
|
+import cn.org.spring.wechar.utils.PrizeRandomUtil;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: 谢辉
|
|
|
+ * @date: 2021/5/18
|
|
|
+ * @email: xieh_mail@163.com
|
|
|
+ * @description: 抽奖
|
|
|
+ * @modifiedBy:
|
|
|
+ * @version: 1.0
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/v1/prize")
|
|
|
+public class PrizeController {
|
|
|
+
|
|
|
+ // String 可以为任意类型 也可以自定义类型
|
|
|
+ static Map<String, Integer> keyChanceMap = new HashMap<String, Integer>();
|
|
|
+
|
|
|
+ static {
|
|
|
+ //key值的是奖品名称或者id。value为中奖的概率
|
|
|
+ keyChanceMap.put("0", 10);// 谢谢惠顾
|
|
|
+ keyChanceMap.put("1", 200);// 中1元
|
|
|
+ keyChanceMap.put("3", 500);// 中3元
|
|
|
+ keyChanceMap.put("4", 3000);// 中4元
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 话费抽奖
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/getTelCharge")
|
|
|
+ public Result getTelCharge() {
|
|
|
+ String result = PrizeRandomUtil.chanceSelect(keyChanceMap);
|
|
|
+ if (StringUtil.isEmpty(result)) {
|
|
|
+ result = "0";
|
|
|
+ }
|
|
|
+ return Result.ok(result);
|
|
|
+ }
|
|
|
+}
|