| | |
| | |
|
| | | String prize = generateAward();
|
| | | if (prize == null) {
|
| | | prize = "抽中一张福利免单券";
|
| | | prize = "一张福利免单券";
|
| | | }
|
| | |
|
| | | dataInfo.put("pic", shamUser.getPicUrl());
|
| | |
| | | return prize;
|
| | | }
|
| | |
|
| | | |
| | |
|
| | | /**
|
| | | * 获取抽奖广告列表
|
| | | * |
| | | * @param callback
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getDailyRadioList")
|
| | | public void getDailyRadioList(String callback, PrintWriter out) {
|
| | |
|
| | | try {
|
| | | // 随机20条数据
|
| | | List<ShamUser> listUser = shamUserService.listRandUser(20);
|
| | |
|
| | | JSONArray array = new JSONArray();
|
| | | for (ShamUser shamUser : listUser) {
|
| | | JSONObject dataInfo = new JSONObject();
|
| | |
|
| | | String name = shamUser.getName();
|
| | | if (name.length() == 1) {
|
| | | name = "Jx****" + name;
|
| | | } else {
|
| | | name = name.substring(0, 1) + "****" + name.substring(name.length() - 2, name.length() - 1);
|
| | | }
|
| | |
|
| | | String prize = dailyGenerateAward();
|
| | | if (prize == null) {
|
| | | prize = "两张返利奖励券";
|
| | | }
|
| | |
|
| | | dataInfo.put("pic", shamUser.getPicUrl());
|
| | | dataInfo.put("content", name + ",抽中" + prize);
|
| | | array.add(dataInfo);
|
| | | }
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("result_list", array);
|
| | |
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
| | |
|
| | | } catch (Exception e) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 生成奖项-天天抽
|
| | | * |
| | | * @return
|
| | | */
|
| | | public String dailyGenerateAward() {
|
| | |
|
| | | RandomGift randomGift1 = new RandomGift();
|
| | | randomGift1.prize = "抽中华为手机20一台";
|
| | | randomGift1.probability = 2;
|
| | |
|
| | | RandomGift randomGift2 = new RandomGift();
|
| | | randomGift2.prize = "现金红包¥188";
|
| | | randomGift2.probability = 5;
|
| | |
|
| | | RandomGift randomGift3 = new RandomGift();
|
| | | randomGift3.prize = "现金红包¥88";
|
| | | randomGift3.probability = 13;
|
| | |
|
| | | RandomGift randomGift4 = new RandomGift();
|
| | | randomGift4.prize = "两张返利奖励券";
|
| | | randomGift4.probability = 40;
|
| | |
|
| | | RandomGift randomGift5 = new RandomGift();
|
| | | randomGift5.prize = "一张返利奖励券";
|
| | | randomGift5.probability = 40;
|
| | |
|
| | | List<RandomGift> giftList = new ArrayList<RandomGift>();
|
| | | giftList.add(randomGift1);
|
| | | giftList.add(randomGift2);
|
| | | giftList.add(randomGift3);
|
| | | giftList.add(randomGift4);
|
| | | giftList.add(randomGift5);
|
| | |
|
| | | long result = (1 + Math.round(Math.random() * (99)));
|
| | |
|
| | | int minRange = 0;
|
| | | int maxRange = 0;
|
| | |
|
| | | String prize = null;
|
| | |
|
| | | for (int i = 0; i < giftList.size(); i++) {
|
| | | RandomGift obj2 = giftList.get(i);
|
| | | int probability = obj2.probability;
|
| | |
|
| | | maxRange = maxRange + probability;
|
| | | minRange = 100 - maxRange;
|
| | |
|
| | | if (probability != 0) {
|
| | | if (result > minRange && result <= maxRange) {
|
| | | prize = obj2.prize;
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return prize;
|
| | | }
|
| | | |
| | | class RandomGift {
|
| | | public String prize;// 奖项
|
| | | public int probability; // 概率
|