UserInfoAction.java 21.5 KB
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 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
package com.cjs.site.action.user.account;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.math.NumberUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cjs.site.biz.pub.CommonBiz;
import com.cjs.site.biz.user.account.PassportBiz;
import com.cjs.site.biz.user.account.RebindBiz;
import com.cjs.site.biz.user.account.UserBiz;
import com.cjs.site.biz.user.account.UserCenterBiz;
import com.cjs.site.biz.user.active.ActiveBiz;
import com.cjs.site.biz.user.entrust.EntrustBiz;
import com.cjs.site.dao.user.OrganInfoDao;
import com.cjs.site.dao.user.RebateclearDao;
import com.cjs.site.dao.user.account.AgentInfoDao;
import com.cjs.site.dao.user.account.ClientDao;
import com.cjs.site.dao.user.account.ClientInfoDao;
import com.cjs.site.dao.user.account.ExBindCardLogDao;
import com.cjs.site.dao.user.account.UserLevelDao;
import com.cjs.site.model.user.AgentInfo;
import com.cjs.site.model.user.account.ClientInfo;
import com.cjs.site.model.user.account.ExbindBankCardInfo;
import com.cjs.site.model.user.account.UserInfo;
import com.cjs.site.model.user.account.UserLevelInfo;
import com.cjs.site.util.lang.JsonUtil;
import com.cjs.site.util.lang.StringUtil;
import com.cjs.site.util.t2.T2Result;
import com.cjs.site.util.t2.T2Util;
import com.cjs.site.util.web.ActionUtil;
import com.cjs.site.util.web.PageUtils;

/**
 * 用户中心
 * 
 * @author tongxiaochuan
 *
 */
@Controller
@RequestMapping("/user")
public class UserInfoAction {
    @Autowired
    private EntrustBiz       entrustBiz;
    @Autowired
    private UserBiz          userBiz;
    @Autowired
    private RebindBiz        rebindBiz;
    @Autowired
    private CommonBiz        commonBiz;
    @Autowired
    private UserCenterBiz    centerBiz;
    @Autowired
    private ClientInfoDao    clientInfoDao;
    @Autowired
    private UserLevelDao     userLevelDao;
    @Autowired
    private ClientDao        clientDao;
    @Autowired
    private ActiveBiz        activeBiz;
    @Autowired
    private AgentInfoDao     agentDao;
    @Autowired
    private ExBindCardLogDao exBindCardLog;
    @Autowired
    private RebateclearDao   rebateclearDao;
    @Autowired
    private OrganInfoDao     organInfoDao;
    @Autowired
    private PassportBiz      passportBiz;

    private DateFormat       dateFormat = new SimpleDateFormat("yyyy年MM月dd日");
    private Logger           log        = LogManager.getLogger();

    /**会员中心*/
    @RequestMapping("/userCenter")
    public String userCenter(Model model) {
        String userId = ActionUtil.getUser().getFund_account();
        //会员显示
        model.addAttribute("userCenter", centerBiz.userCenter());

        //累计获得奖励
        model.addAttribute("rebateTotal", userBiz.queryRebateTotal(userId));
        model.addAttribute("currentDate", dateFormat.format(new Date()));
        return "/user/userCenter.jsp";
    }

    /**会员推广*/
    @RequestMapping("promotion")
    public String promotion(Model model) {
        return "user/promotion.jsp";
    }

    /**推广活动/推荐人详情*/
    @RequestMapping("promotions")
    public String promotions(Model model, @RequestParam Map<String, Object> params) {
        UserInfo userInfo = ActionUtil.getUser();
        String userLevel = clientDao.queryUserLevel(userInfo.getUserId());
        if (!params.containsKey("level")) {
            params.put("level", "-1");
        }
        //如果是银牌会员以上则跳转新页面
        if (!"1".equals(userLevel) && !"0".equals(userLevel)) {
            return "redirect:/user/promotions/new";
        }
        List<Map<String, Object>> promotions = userBiz.queryPromotionUsers(params, userInfo);
        for (Map<String, Object> map : promotions) {
            //会员等级
            String level = StringUtil.castString(map.get("ASSET_LEVEL"));
            if (NumberUtils.isNumber(level)) {
                //会员等级信息
                UserLevelInfo userLevelInfo = userLevelDao.queryByLevel(Integer.parseInt(level));
                map.put("ASSET_LEVEL", userLevelInfo.getLevelName());
            }
        }
        //查询所有等级信息
        List<UserLevelInfo> levelInfo = userLevelDao.queryAll();
        //查询所有下属会员数量
        params.put("_total", clientDao.queryUnderUserTotal(params));
        model.addAttribute("promotions", promotions);
        model.addAttribute("levelInfo", levelInfo);
        model.addAttribute("params", params);
        return "user/account/userActivityMember.jsp";
    }

    /**推广活动/交易奖励*/
    @RequestMapping("/rebateReward")
    public String rebateReward(Model model) {
        //返佣
        model.addAttribute("current",
            userBiz.lastTradingDayRebate(ActionUtil.getUser().getUserId()));
        return "user/account/userActivity.jsp";
    }

    /**推广活动/交易记录*/
    @RequestMapping("/rebateRecord")
    public String rebateRecord(Map<String, Object> params, Model model) {
        PageUtils.processOralcePage(params);
        params.put("userId", ActionUtil.getUser().getFund_account());
        model.addAttribute("rebateAll", userBiz.queryRebate(params));
        model.addAttribute("rebateTotal", rebateclearDao.queryByUserTotal(params));
        model.addAttribute("params", params);
        return "user/account/userActivityHistory.jsp";
    }

    /**用户托管列表*/
    @RequestMapping("entrust/list")
    public String entrustList(@RequestParam Map<String, Object> params, Model model,
                              HttpSession session) {
        model.addAttribute("entrusts", entrustBiz.queryByUser(params, ActionUtil.getUser()));
        return "user/entrust.jsp";
    }

    @RequestMapping(value = "/changeBankCard", method = RequestMethod.GET)
    public String changeBankCard(HttpSession session, Model model) {
        UserInfo userInfo = ActionUtil.getUser();
        Map<String, String> bankInfo = clientInfoDao.queryForPnr(userInfo.getClient_id());
        model.addAttribute("bankInfo", bankInfo);
        model.addAttribute("mobileTel", bankInfo.get("MOBILE_TEL"));
        model.addAttribute("bankCode", StringUtil.replace(4, 3, bankInfo.get("BANK_ACCOUNT"), "*"));
        return "user/account/exbindBankCard.jsp";
    }

    /**
     * 换绑银行卡
     * @return
     */
    @RequestMapping(value = "/changeBankCard", method = RequestMethod.POST)
    public String changeBankCard(HttpSession session, ExbindBankCardInfo bankCardInfo,
                                 Model model) throws Exception {
        return rebindBiz.changeBankCard(session, bankCardInfo, model);
    }

    /**
    * 查询用户是否换绑成功
    * @param orderId
    * @return
    */
    @RequestMapping(value = "/checkChangeCard", method = RequestMethod.POST)
    public @ResponseBody String checkChangeCard(int id) {
        ExbindBankCardInfo bankCardInfo = exBindCardLog.queryById(id);
        if (bankCardInfo != null && bankCardInfo.getResult().equals("0")) {
            log.info("换绑信息" + bankCardInfo);
            return JsonUtil.toJson("result", "0");
        }
        return JsonUtil.toJson("result", "1");
    }

    /**
     * 跳转换绑结果页面
     * @return
     */
    @RequestMapping("/toSignResult")
    public String toSignResult(String resultCode, Model model) {
        if (Integer.parseInt(resultCode) == 0) {
            log.info(resultCode);
            model.addAttribute("resultCode", "0");
            model.addAttribute("msg", "尊敬的用户,您已更换银行卡成功!");
        } else {
            model.addAttribute("resultCode", "1");
            model.addAttribute("msg", "尊敬的用户,您更换银行卡操作失败!");
        }
        return "/user/signResult.jsp";
    }

    /**快速开户用户绑卡页面*/
    @RequestMapping(value = "bind", method = RequestMethod.GET)
    public String bindBankCardView(Model model) {
        Map<String, Object> outMap = checkBind();
        if (outMap.get("resultCode").toString().equals("-1")) {
            model.addAttribute("resultMap", outMap);
            return "user/account/bindBankCard.jsp";
        } else if (outMap.get("resultCode").toString().equals("-2")) {
            model.addAttribute("resultMap", outMap);
            return "user/account/bindBankCardResult.jsp";
        }
        return "user/account/bindBankCard.jsp";
    }

    /**绑定操作检查*/
    @RequestMapping("bind/check")
    public @ResponseBody Map<String, Object> checkBind() {
        //检查时间限制
        Map<String, Object> outMap = new HashMap<String, Object>();
        if (!commonBiz.checkOpenTime()) {
            outMap.put("resultCode", "-1");
            outMap.put("resultMsg", "非交易时间,不可绑卡。");
            return outMap;
        }

        UserInfo userInfo = ActionUtil.getUser();

        outMap.clear();
        outMap.put("client_name", userInfo.getClient_name());
        if ("0".equals(userInfo.getOrgan_flag())) {
            outMap.put("id_kind", "0");
            Map<String, Object> userInfomation = rebindBiz
                .getUserInfomation(userInfo.getFund_account());
            outMap.put("id_no", userInfomation.get("id_no").toString());
        } else if ("1".equals(userInfo.getOrgan_flag())) {
            outMap.put("id_kind", "P");
            Map<String, String> query = organInfoDao.search(userInfo.getFund_account());
            outMap.put("id_no", query.get("ORGAN_CODE"));
        }
        T2Result result = T2Util.request(outMap, "619852");
        log.info(result);
        if (!result.getData().get(0).get("result_code").toString().equals("4")) {
            outMap.put("resultCode", "-2");
            outMap.put("resultMsg", "账户已经绑定银行卡,不可再次绑定。");
            return outMap;
        }
        outMap.put("resultCode", "0");
        return outMap;
    }

    /**快速开户用户绑卡*/
    @RequestMapping(value = "bind", method = RequestMethod.POST)
    public String bindBankCard(HttpServletRequest request, HttpSession session,
                               @RequestParam Map<String, Object> params,
                               Model model) throws Exception {
        UserInfo userInfo = ActionUtil.getUser();

        //检查时间限制
        Map<String, Object> outMap = new HashMap<String, Object>();
        if (!commonBiz.checkOpenTime()) {
            outMap.put("resultCode", "-1");
            outMap.put("resultMsg", "非交易时间,不可绑卡。");
            model.addAttribute("resultMap", outMap);
            return "user/account/bindBankCardResult.jsp";
        }

        //验证提交的参数格式正否正确
        Map<String, String> checkMap = rebindBiz.valiadateParams(params, session);
        if (checkMap.get("resultCode").equals("1")) {
            model.addAttribute("resultMap", checkMap);
            return "user/account/bindBankCardResult.jsp";
        }

        //验证是否可进行绑卡操作
        outMap.clear();
        outMap.put("client_name", userInfo.getClient_name());
        outMap.put("id_kind", "0");
        Map<String, Object> userInfomation = rebindBiz
            .getUserInfomation(userInfo.getFund_account());
        outMap.put("id_no", userInfomation.get("id_no").toString());
        T2Result result = T2Util.request(outMap, "619852");
        log.info(result);
        if (!result.getData().get(0).get("result_code").toString().equals("4")) {
            outMap.put("resultMsg", "账户已经绑定银行卡,不可再次绑定。");
            model.addAttribute("resultMap", outMap);
            return "user/account/bindBankCardResult.jsp";
        }

        params.put("fund_account", userInfo.getFund_account());
        params.put("client_id", userInfo.getClient_id());
        params.put("password", userInfo.getPassword());
        params.put("client_name", userInfo.getClient_name());
        params.put("id_kind", "0");
        params.put("id_no", userInfomation.get("id_no").toString());
        outMap = rebindBiz.bindBankCard(params);
        if (outMap.get("resultCode").toString().equals("-1")) {
            model.addAttribute("resultMap", outMap);
            return "user/account/bindBankCardResult.jsp";
        }

        Thread.sleep(10000);
        String resultMsg = rebindBiz.checkOpenAccount(userInfo,
            userInfomation.get("id_no").toString());

        outMap.clear();
        if (resultMsg.equals("0")) {
            outMap.put("resultCode", "1");
            outMap.put("resultMsg", "绑定银行卡成功,为了您的资金安全,请尽快登录交易客户端修改资金密码。");
            Map<String, Object> inmap = new HashMap<String, Object>();
            inmap.put("clientId", userInfo.getClient_id());
            //            inmap.put("idNo", userInfomation.get("id_no"));
            //            Map<String, Object> modelMap = passportBiz.active(inmap);
            //            if ("1".equals(modelMap.get("resultCode"))) {
            //                if (modelMap.get("giftCode") != null) {
            //                    outMap.put("giftResult", "1");
            //                    outMap.put("giftCode", modelMap.get("giftCode"));
            //                    outMap.put("giftAmount", modelMap.get("giftAmount"));
            //                } else {
            //                    outMap.put("giftResult", "0");
            //                }
            //            } else if ("-1".equals(modelMap.get("resultCode"))) {
            //                outMap.put("giftResult", "-1");
            //            }
            Map<String, Object> retmap = activeBiz.setPoint(inmap);
            if ("1".equals(retmap.get("resultCode"))) {
                outMap.put("pointCode", "1");
            } else {
                outMap.put("pointCode", "0");
            }
            log.info(retmap.get("resultMsg"));
        } else {
            outMap.put("resultCode", "0");
            outMap.put("resultMsg", "绑定银行卡失败,请您确认信息后重新换绑。如有疑问,详询400-969-0800。");
        }

        //为用户设置otc_account值,避免拦截器代码拦截
        Map<String, Object> userDetail = userBiz.queryUserEquity(userInfo.getClient_id(),
            userInfo.getPassword());
        userInfo.setOtc_account(StringUtil.castString(userDetail.get("otc_account")));
        request.getSession().setAttribute(UserInfo.USER, userInfo);
        request.setAttribute("bindMsg", "");

        model.addAttribute("resultMap", outMap);
        return "user/account/bindBankCardResult.jsp";
    }

    /**白银及以上用户详情*/
    @RequestMapping("promotions/new")
    public String promotionsNew(Model model, @RequestParam Map<String, Object> params) {
        UserInfo userInfo = ActionUtil.getUser();
        if (!params.containsKey("level")) {
            params.put("level", "-1");
        }
        List<Map<String, Object>> promotions = userBiz.queryPromotionUsers(params, userInfo);
        for (Map<String, Object> map : promotions) {
            //会员等级
            String level = StringUtil.castString(map.get("ASSET_LEVEL"));
            if (!NumberUtils.isNumber(level)) {
                continue;
            }
            //会员等级信息
            UserLevelInfo userLevelInfo = userLevelDao.queryByLevel(Integer.parseInt(level));
            map.put("ASSET_LEVEL", userLevelInfo.getLevelName());
            Map<String, Object> searchMap = new HashMap<String, Object>();
            searchMap.put("assetLevel", level);
            searchMap.put("userId", map.get("CLIENT_ID").toString());

            AgentInfo agentInfo = agentDao.queryByFundAccount(map.get("CLIENT_ID").toString());
            if (agentInfo != null) {
                searchMap.put("userId", agentInfo.getAgentNo());
            }
            Integer underUserNum = clientDao.queryUnderCount(searchMap);
            //如果大于5个则不需要显示
            if (level.equals("1") && underUserNum > 5) {
                underUserNum = 5;
            } else if (!"1".equals(level.toString()) && underUserNum > 10) {
                underUserNum = 10;
            }

            if (level.equals("1")) {
                map.put("underUserNum", 5 - underUserNum);
            } else {
                map.put("underUserNum", 10 - underUserNum);
            }
        }
        //查询所有等级信息
        List<UserLevelInfo> levelInfo = userLevelDao.queryAll();
        //查询所有下属会员数量
        params.put("_total", clientDao.queryUnderUserTotal(params));
        model.addAttribute("promotions", promotions);
        model.addAttribute("levelInfo", levelInfo);
        model.addAttribute("params", params);
        return "user/account/userActivityMemberNew.jsp";
    }

    /** 推荐人的间接信息*/
    @RequestMapping("promotions/indirect")
    public String promotions(Model model, UserInfo userInfo,
                             @RequestParam Map<String, Object> params) {
        if (!params.containsKey("level")) {
            params.put("level", "-1");
        }
        Map<String, Object> checkMap = new HashMap<String, Object>();
        //判断查询的是否属于下级会员
        UserInfo clientInfo = ActionUtil.getUser();
        checkMap.put("clientId", clientInfo.getClient_id());
        checkMap.put("underClient", userInfo.getClient_id());
        List<Map<String, Object>> list = clientDao.checkUnderInfo(checkMap);
        if (list.size() == 0) {
            return "redirect:/user/promotions/new";
        }

        List<Map<String, Object>> promotions = userBiz.queryPromotionUsers(params, userInfo);
        for (Map<String, Object> map : promotions) {
            //会员等级
            String level = StringUtil.castString(map.get("ASSET_LEVEL"));
            if (NumberUtils.isNumber(level)) {
                //会员等级信息
                UserLevelInfo userLevelInfo = userLevelDao.queryByLevel(Integer.parseInt(level));
                map.put("ASSET_LEVEL", userLevelInfo.getLevelName());
                Map<String, Object> searchMap = new HashMap<String, Object>();
                searchMap.put("assetLevel", level);
                searchMap.put("userId", map.get("CLIENT_ID").toString());
                //查询是否是代理商
                AgentInfo agentInfo = agentDao.queryByFundAccount(map.get("CLIENT_ID").toString());
                if (agentInfo != null) {
                    searchMap.put("userId", agentInfo.getAgentNo());
                }
                Integer underUserNum = clientDao.queryUnderCount(searchMap);

                if (level.equals("1") && underUserNum > 5) {
                    underUserNum = 5;
                } else if (!"1".equals(level.toString()) && underUserNum > 10) {
                    underUserNum = 10;
                }
                //如果大于5个则不需要显示
                if (level.equals("1")) {
                    map.put("underUserNum", 5 - underUserNum);
                } else {
                    map.put("underUserNum", 10 - underUserNum);
                }
            }
        }
        //查询所有等级信息
        List<UserLevelInfo> levelInfo = userLevelDao.queryAll();
        //查询所有下属会员数量
        ClientInfo info = clientInfoDao.queryByClientId(userInfo.getClient_id());
        params.put("_total", clientDao.queryUnderUserTotal(params));
        model.addAttribute("promotions", promotions);
        model.addAttribute("levelInfo", levelInfo);
        model.addAttribute("params", params);
        model.addAttribute("clientInfo", info);
        return "user/account/userActivityMemberIndirect.jsp";
    }

    /**
     * 买卖记录
     * @return
     */
    @RequestMapping(value = "/sales/record", method = RequestMethod.GET)
    public String salesRecord() {
        return "user/salesRecord.jsp";
    }

    /**
     * 绑卡
     * @param model
     * @return
     */
    @RequestMapping(value = "/bindcard", method = RequestMethod.GET)
    public String pnrBindView(Model model) {
        UserInfo userInfo = ActionUtil.getUser();
        if ("1".equals(userInfo.getOrgan_flag())) {
            return "user/account/bindOrganBankCard.jsp";
        } else {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("client_id", userInfo.getClient_id());
            params.put("fund_account", userInfo.getFund_account());
            T2Result result = T2Util.request(params, "619829");
            String mobile_tel = result.getData().get(0).get("mobile_tel").toString();

            model.addAttribute("mobileTel", mobile_tel);
            model.addAttribute("resultMap", passportBiz.checkBind());
            return "user/account/bindBankCard.jsp";
        }
    }

    /**
     * 绑卡
     * @param request
     * @param session
     * @param params
     * @param model
     * @return
     */
    @RequestMapping(value = "/bindcard", method = RequestMethod.POST)
    public String bind(HttpServletRequest request, HttpSession session,
                       @RequestParam Map<String, Object> params, Model model) {
        log.info("绑卡页面提交信息:" + params);
        return rebindBiz.bindCard(params, model, session);
    }
}