admin
2020-05-14 03606c570bb14c7a0e52d83087d141f8f3e97a63
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package com.yeshi.fanli.controller;
 
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.JsonUtil;
 
import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.system.CustomerContent;
import com.yeshi.fanli.entity.system.CustomerName;
import com.yeshi.fanli.entity.system.SystemClientParams;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.share.ShareGoodsException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.CustomerContentService;
import com.yeshi.fanli.service.inter.config.CustomerNameService;
import com.yeshi.fanli.service.inter.config.SystemClientParamsService;
import com.yeshi.fanli.service.inter.config.SystemConfigService;
import com.yeshi.fanli.service.inter.goods.GoodsSecondClassService;
import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
import com.yeshi.fanli.service.inter.goods.TaoBaoCouponService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.user.ShamUserService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserInviteRecordService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.util.AESUtil;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.wx.WXLoginUtil;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
/**
 * 客户端网页接口与微信网页接口
 * 
 * @author Administrator
 *
 */
 
@Controller
@RequestMapping("/client")
public class ClientJspController {
 
    @Resource
    private GoodsSecondClassService goodsSecondClassService;
 
    @Resource
    private ConfigService configService;
 
    @Resource
    private HongBaoManageService hongBaoManageService;
 
    @Resource
    private ShamUserService shamUserService;
 
    @Resource
    private TaoBaoCouponService taoBaoCouponService;
 
    @Resource
    private ThreeSaleSerivce threeSaleSerivce;
 
    @Resource
    private UserInfoService userInfoService;
 
    @Resource
    private BusinessSystemService businessSystemService;
 
    @Resource
    private SystemConfigService systemConfigService;
 
    @Resource
    private SystemClientParamsService systemClientParamsService;
 
    @Resource
    private ShareGoodsService shareGoodsService;
 
    @Resource
    private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
 
    @Resource
    private UserInviteRecordService userInviteRecordService;
 
    @Resource
    private RedisManager redisManager;
 
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
 
    @Resource
    private CustomerNameService customerNameService;
 
    @Resource
    private CustomerContentService customerContentService;
 
    private static final String DOWNURL = "http://sj.qq.com/myapp/detail.htm?apkName="
            + Constant.systemCommonConfig.getAndroidPackageName();
 
    private static final String DOWNURL2 = "http://121.42.200.138/apk/fanliquan20180124.apk";
 
    @RequestMapping(value = "/new/{uid}")
    public String threeShareRepNew(@PathVariable String uid, String code, String state, String packages,
            String platform, String ios, HttpSession httpSession, HttpServletRequest request) {
 
        BusinessSystem system = businessSystemService.getBusinessSystem(platform, packages);
        String wxState = (String) httpSession.getAttribute("wxState");
        // 通过配置参数获取
        String down = DOWNURL2;
 
        SystemClientParams params = systemClientParamsService.getSystemClientParamsBySystemAndKey(system,
                "download_app_url");
        if (params != null)
            down = params.getValue();
 
        if (state!=null&&!state.equals(wxState)) {// 不是微信返回的!
            // request.setAttribute("error", "1");
            return "redirect:" + down;
        }
 
        // 保存邀请记录
        userInviteRecordService.saveInviteRecord(code, uid);
 
        return "redirect:" + down;
    }
 
    // 新版分享
    @RequestMapping("threeShareNew")
    public String threeShareNew(HttpServletRequest request, HttpSession session, HttpServletResponse response,
            long uid) {
        UserInfo userInfo = userInfoService.getUserById(uid);
        if (userInfo == null) {
            return "share/error";
        }
 
        try {
            String header = request.getHeader("User-Agent");// MicroMessenger:微信浏览器
            String ios = "ios=1";
            if (header.contains("iPhone")) {
                ios = "ios=2";
            }
            String redirect_uri = "http://" + Constant.wxGZConfig.getLoginHost() + "/"
                    + Constant.systemCommonConfig.getProjectName() + "/client/new/" + uid + "?packages="
                    + Constant.systemCommonConfig.getAndroidPackageName() + "&platform=ANDROID&" + ios;
            redirect_uri = URLEncoder.encode(redirect_uri, "utf-8");
 
            long currentTimeMillis = java.lang.System.currentTimeMillis();
            String md5 = StringUtil.Md5(currentTimeMillis + "");
            session.setAttribute("wxState", md5);
            String baseUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WXLoginUtil.WEXIN_APPID
                    + "&redirect_uri=" + redirect_uri + "&response_type=code&scope=snsapi_userinfo&state=" + md5
                    + "#wechat_redirect";
            response.sendRedirect(baseUrl);
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        return "share2/yaoqing";
    }
 
    @RequestMapping("getShareGoodsInfo")
    public void getShareGoodsInfo(HttpServletRequest request, long uid, long id, String sign, PrintWriter out) {
 
        if (!StringUtil.Md5("" + uid + id + Constant.WEBPAGE_SIGN_KEY).equalsIgnoreCase(sign)) {
            out.print(JsonUtil.loadFalseResult(-1, "签名错误"));
            return;
        }
 
        // 添加分享
        try {
            long startTime = java.lang.System.currentTimeMillis();
            UserShareGoodsHistory userShareGoodsHistory = shareGoodsService.addShareGoodsHistory(uid, id);
            LogHelper.test("生成分享图的总耗时为:" + (java.lang.System.currentTimeMillis() - startTime));
 
            JSONObject data = new JSONObject();
            JSONObject shareData = new JSONObject();
            JSONArray imgArr = new JSONArray();
            String pictures = userShareGoodsHistory.getPictures();
            JSONArray pictureArray = JSONArray.fromObject(pictures);
            for (int i = 0; i < pictureArray.size(); i++) {
                imgArr.add(pictureArray.optString(i));
            }
 
            TaoBaoGoodsBrief goods = redisManager.getTaoBaoGoodsBrief(userShareGoodsHistory.getGoodsId());
 
            shareData.put("type", "2");
            shareData.put("title", goods.getTitle());
            shareData.put("description", goods.getTitle());
            shareData.put("imgs", imgArr);
            try {
                data.put("wx", StringUtil.getBase64String(shareData.toString()));
                data.put("wxcircle", StringUtil.getBase64String(shareData.toString()));
                data.put("tkcode", StringUtil.getBase64String(userShareGoodsHistory.getTkCode()));
                data.put("qq", StringUtil.getBase64String(shareData.toString()));
                data.put("qqzone", StringUtil.getBase64String(shareData.toString()));
                data.put("sina", StringUtil.getBase64String(shareData.toString()));
                data.put("tishi", StringUtil.getBase64String("分享中..."));
                data.put("shareGoods", JsonUtil.getSimpleGson().toJson(userShareGoodsHistory));
                JSONObject goodsJSON = new JSONObject();
                goodsJSON.put("title", goods.getTitle());
                goodsJSON.put("zkPrice", goods.getZkPrice());
                // 有券
                if (!StringUtil.isNullOrEmpty(goods.getCouponInfo())) {
 
                    goodsJSON.put("finalPrice", TaoBaoUtil.getAfterUseCouplePrice(goods));
                }
                data.put("goods", goodsJSON);
 
                String link = String.format("http://%s/%s/client/html/sharegoods/share_detail.html?uid=%s&goodsId=%s",
                        Constant.systemCommonConfig.getProjectHost(), Constant.systemCommonConfig.getProjectName(),
                        AESUtil.encrypt(uid + ""), id + "");
                try {
                    String shortLink = HttpUtil.getShortLink(link);
                    data.put("link", shortLink);
                } catch (Exception e) {
                    data.put("link", link);
                }
                out.print(JsonUtil.loadTrueResult(data));
            } catch (Exception e) {
                JSONObject rdata = new JSONObject();
                rdata.put("uid", uid);
                rdata.put("id", id);
                LogHelper.errorDetailInfo(e, rdata.toString(), request.getRequestURI());
                out.print(JsonUtil.loadFalseResult(1001, "未知错误"));
            }
 
        } catch (ShareGoodsException e1) {
            JSONObject data = new JSONObject();
            data.put("uid", uid);
            data.put("id", id);
            LogHelper.errorDetailInfo(e1, data.toString(), request.getRequestURI());
            out.print(JsonUtil.loadFalseResult(e1.getCode(), e1.getMsg()));
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
 
    }
 
    // 获取帮助中心列表
 
    @RequestMapping("getHelpList")
    public void getHelpList(PrintWriter out) {
        List<CustomerName> totalList = new ArrayList<>();
        int page = 0;
        List<CustomerName> customerNameList = customerNameService.customerNameList(page, "", 1);
        if (customerNameList != null && customerNameList.size() > 0)
            totalList.addAll(customerNameList);
 
        while (customerNameList != null && customerNameList.size() == Constant.PAGE_SIZE) {
            page++;
            customerNameList = customerNameService.customerNameList(page, "", 1);
            if (customerNameList != null && customerNameList.size() > 0)
                totalList.addAll(customerNameList);
        }
 
        // 获取每个下面的详情
        for (CustomerName cn : totalList) {
            List<CustomerContent> contentList = customerContentService.getSecondProblemList(0, "", cn.getId());
            cn.setCustomerContentList(contentList);
        }
        out.print(JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(totalList)));
    }
 
    @RequestMapping("getHelpDetail")
    public void getHelpDetail(long id, PrintWriter out) {
        List<CustomerName> totalList = new ArrayList<>();
        CustomerContent customerContent = customerContentService.getCustomerContent(id);
        out.print(JsonUtil.loadTrueResult(customerContent.getContent().replace("\n", "<br>")));
    }
 
    /**
     * 获取邀请有奖的规则
     * 
     * @param callback
     * @param out
     */
    @RequestMapping("getinviteactivityrules")
    public void getInviteActivityRules(String callback, PrintWriter out) {
        String key = "activityRules"; // key值
        com.yeshi.fanli.entity.system.BusinessSystem system = new BusinessSystem();
        system.setCreatetime(java.lang.System.currentTimeMillis());
        system.setPlatform(1);
        system.setId(4L);
        SystemClientParams values = systemClientParamsService.getSystemClientParamsBySystemAndKey(system, key);
        // 转换换行符 给前端
        String valueN = values.getValue();
        String valueBr = valueN.replace("\n", "<br><br>");
        if (!StringUtil.isNullOrEmpty(callback)) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(valueBr)));
        } else {
            out.print(JsonUtil.loadTrueResult(valueBr));
        }
    }
 
}