admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.yeshi.fanli.controller.client.v1.h5;
 
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.List;
 
import javax.annotation.Resource;
 
import com.yeshi.fanli.util.SystemInfoUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.JsonUtil;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.dto.GoodsMoneyConfigParamsDTO;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserRankings;
import com.yeshi.fanli.entity.goods.PullNewGoods;
import com.yeshi.fanli.service.inter.goods.PullNewGoodsService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
import com.yeshi.fanli.service.inter.user.QrCodeService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserRankingsService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.util.factory.goods.TaoBaoGoodsFactory;
import com.yeshi.fanli.vo.user.PullNewRuleVO;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("api/apph5/v1/pullNew")
public class AppH5PullNewController {
 
    @Resource
    private PullNewGoodsService pullNewGoodsService;
 
    @Resource
    private RedPackConfigService redPackConfigService;
 
    @Resource
    private UserRankingsService userRankingsService;
 
    @Resource
    private HongBaoManageService hongBaoManageService;
 
    @Resource
    private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
    
    @Resource
    private QrCodeService qrCodeService;
    
    @Resource
    private UserInfoService userInfoService;
 
    @Resource
    private UserInfoExtraService userInfoExtraService;
 
    
 
    /**
     * 拉新商品
     * 
     * @param acceptData
     * @param callback
     * @param uid
     * @param page
     * @param goodsType
     * @param out
     */
    @RequestMapping("getGoodsList")
    public void getGoodsList(AcceptData acceptData, String callback, Long uid, Integer page, PrintWriter out) {
        if (acceptData.getSystem() == null)
            acceptData.setSystem(SystemInfoUtil.getSystem(acceptData));
        JSONArray array = new JSONArray();
        List<PullNewGoods> list = pullNewGoodsService.listQuery((page-1)*Constant.PAGE_SIZE, Constant.PAGE_SIZE);
        if (list != null && list.size() > 0) {
            Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create();
            GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                    acceptData.getVersion(),acceptData.getSystem());
            paramsDTO.setBaseFanliRate(hongBaoManageService.getBaseFanliRate(acceptData.getSystem()));
            
            for (PullNewGoods goods : list) {
                array.add(gson.toJson(GoodsDetailVOFactory.convertTaoBao(TaoBaoGoodsFactory.create(goods),paramsDTO)));
            }
        }
        
 
        JSONObject data = new JSONObject();
        if (page == 1) {
            String ruleStr = redPackConfigService.getValueByKey("pullnew_activity_rule");
            if (!StringUtil.isNullOrEmpty(ruleStr)) {
                Type type = new TypeToken<PullNewRuleVO>() {
                }.getType();
                PullNewRuleVO rule = new Gson().fromJson(ruleStr, type);
                rule.setRuleName(DateUtil.getCurrentMonthChinese() + "月活动规则");
                data.put("rule", rule);
            }
            data.put("tip", redPackConfigService.getValueByKey("pullnew_page_tip"));
        }
        data.put("count", pullNewGoodsService.countQuery());
        data.put("list", array);
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
    }
 
    /**
     * 拉新排行榜
     * 
     * @param acceptData
     * @param callback
     * @param uid
     * @param page
     * @param out
     */
    @RequestMapping("getRankList")
    public void getRankList(AcceptData acceptData, String callback, Long uid, PrintWriter out) {
        if (acceptData.getSystem() == null)
            acceptData.setSystem(SystemInfoUtil.getSystem(acceptData));
        JSONArray array = new JSONArray();
        List<UserRankings> list = userRankingsService.getRankList(0, 10);
        if (list != null && list.size() > 0) {
            for (UserRankings rank : list) {
                JSONObject user = new JSONObject();
                user.put("nickName", rank.getNickName());
                user.put("portrait", rank.getPortrait());
                user.put("money", "¥ " + rank.getShareReward().setScale(2, BigDecimal.ROUND_DOWN));
                array.add(user);
            }
        }
        JSONObject data = new JSONObject();
        data.put("count", array.size());
        data.put("list", array);
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
    }
 
    /**
     * 创建分享图
     * 
     * @param acceptData
     * @param callback
     * @param uid
     * @param out
     */
    @RequestMapping("getShareImg")
    public void getShareImg(AcceptData acceptData, String callback, Long uid, PrintWriter out) {
        if (acceptData.getSystem() == null)
            acceptData.setSystem(SystemInfoUtil.getSystem(acceptData));
        if (uid == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户未登录"));
            return;
        }
 
        UserInfo userInfo = userInfoService.selectByPKey(uid);
        if (userInfo == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("该用户不存在"));
            return;
        }
        
        String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
        if (StringUtil.isNullOrEmpty(inviteCode)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("邀请码未激活"));
            return;
        }
        
        PullNewRuleVO rule = null;
        String ruleStr = redPackConfigService.getValueByKey("pullnew_activity_rule");
        if (!StringUtil.isNullOrEmpty(ruleStr)) {
            Type type = new TypeToken<PullNewRuleVO>() {
            }.getType();
            rule = new Gson().fromJson(ruleStr, type);
            rule.setRuleName(DateUtil.getCurrentMonthChinese() + "月活动规则");
        }
        
        String url = qrCodeService.drawPullNewPoster(uid, userInfo.getPortrait(), inviteCode, rule);
        if (StringUtil.isNullOrEmpty(url)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("生成分享图失败"));
            return;
        }
        
        JSONObject data = new JSONObject();
        data.put("imgUrl",url);
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
    }
}