package com.yc.sdk.shopping.action; import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.yc.action.BaseAction; import com.yc.action.grid.QrCodeRunable; import com.yc.entity.DataSourceEntity; import com.yc.factory.FactoryBean; import com.yc.multiData.MultiDataSource; import com.yc.multiData.SpObserver; import com.yc.sdk.miniapp.action.MaServiceInit; import com.yc.sdk.miniapp.service.MaUserIfc; import com.yc.sdk.password.action.ChangePassword; import com.yc.sdk.shopping.entity.*; import com.yc.sdk.shopping.service.CurrencyIfc; import com.yc.sdk.shopping.service.SettingIfc; import com.yc.sdk.shopping.service.address.AddressIfc; import com.yc.sdk.shopping.service.balance.BalanceIfc; import com.yc.sdk.shopping.service.register.AccountIfc; import com.yc.sdk.shopping.service.register.CltTypeIfc; import com.yc.sdk.shopping.service.register.OtherStaffIfc; import com.yc.sdk.shopping.service.register.SourceInfoIfc; import com.yc.sdk.shopping.service.wxpay.WxPayIfc; import com.yc.sdk.shopping.util.SettingKey; import com.yc.sdk.shopping.util.StringReplaceUtil; import com.yc.sdk.weixincp.action.CPUser; import com.yc.sdk.weixincp.action.CpServiceInit; import com.yc.sdk.weixincp.entity.MyWxCpUser; import com.yc.sdk.weixincp.service.AppIfc; import com.yc.sdk.weixincp.service.ERPUserIfc; import com.yc.sdk.weixinmp.entity.MyWxMpUser; import com.yc.sdk.weixinmp.service.MpUserIfc; import com.yc.service.demo.DemoIfc; import com.yc.utils.SessionKey; import me.chanjar.weixin.cp.api.WxCpService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map.Entry; import java.util.Set; @Controller @RequestMapping("/shopping/account.do") public class Account extends BaseAction { @Autowired AccountIfc accountIfc; @Autowired SettingIfc settingIfc; @Autowired DemoIfc demo; @Autowired CPUser user; @SuppressWarnings("rawtypes") @Autowired RedisTemplate redisTemplate ; @Autowired MpUserIfc mpUserIfc; @Autowired AppIfc appIfc ; @Autowired JedisPool jedisPool; @Autowired AddressIfc addressIfc; @Autowired WxPayIfc wxPayIfc; @Autowired CurrencyIfc currencyIfc; @Autowired BalanceIfc balanceIfc ; @Autowired MaUserIfc maUserIfc ; @Autowired SourceInfoIfc sourceInfoIfc; //客户来源下拉列表 @Autowired CltTypeIfc cltTypeIfc; //客户分类 @Autowired OtherStaffIfc otherStaffIfc; //获取外部人员列表 @Autowired ERPUserIfc erpUserIfc ; protected DataSourceEntity corpEntity; /** * 按 jsp 电话注册,需要有注册页面交互 * @param request * @param response */ @RequestMapping(params = "m=telreg") public void newCustomerByTel(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); String sessionId = session.getId(); //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID); String hostUrl = SettingKey.getHostUrl(request); // 将微信corpid组装成url String wxQueryString = SettingKey.getQueryStringByWx(request); boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request); JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); String reg = (request.getParameter("reg") == null ? "" : request.getParameter("reg")); CustomerEntity customerEntity = new CustomerEntity(); SettingEntity settingEntity = null; DataSourceEntity dataSourceEntity ; try { dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; }catch (DataAccessException e) { errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }catch (Exception e ){ errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } try { SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源 settingEntity = settingIfc.getSettingEntity(request); String telephone = request.getParameter("telephone") ; String password = request.getParameter("password") == null ? "" : request.getParameter("password"); String confirm = request.getParameter("confirm") == null ? "" : request.getParameter("confirm"); String code = request.getParameter("code") == null ? "" : request.getParameter("code"); String agree = request.getParameter("agree"); if (telephone == null || "".equals(telephone) || telephone.length() < 11) { errJson.addProperty("telephone", "客户电话必须在 1 至 11 字符之间!"); } if (settingEntity.isShowPassword() ) { if (password == null || "".equals(password)) errJson.addProperty("password", "密码 必须输入!"); if (confirm == null || "".equals(confirm)) errJson.addProperty("confirm", "确认密码 必须输入!"); if (password != null && confirm != null && !confirm.equals(password)) { errJson.addProperty("password", "2次输入的密码 必须相同!"); errJson.addProperty("confirm", "2次输入的密码 必须相同!"); } } if (agree == null || "".equals(agree)){ errJson.addProperty("warning", "警告:您未同意 隐私政策 条款 !"); } //验证码 String code2 = "" ; try { code2 = (String) redisTemplate.opsForValue().get(VerificationCodes.getCodeKey( telephone)); }catch(Exception e) { e.printStackTrace(); errJson.addProperty(SettingKey.CLTTEL, e.getMessage()); json.add("error", errJson); this.printJson(response, json.toString()); return ; } if (code == null || "".equals(code2)||code2 == null || "".equals(code2)|| ! code.equals(code2)){ errJson.addProperty("code", "验证码不正确!"); json.add("error", errJson); //this.printJson(response, json.toString()); //return ; } Set> it = errJson.entrySet(); if (!it.isEmpty() && it.size() != 0) { json.add("error", errJson); this.printJson(response, json.toString()); return; } String openId = request.getParameter(SessionKey.WEIXIN_OPENID); //从页面传递openid if (openId == null || openId.equals("")) { openId = (String) session.getAttribute(SessionKey.WEIXIN_OPENID); //从会话取openid } String hrCode = (String) session.getAttribute(SessionKey.HRCODE); // 是否ERP登录的用户 // 如果是微信过来的,则要给 USERCODE 赋值 String corpId = request.getParameter(SessionKey.WEIXIN_CORPID); String wx = request.getParameter(SessionKey.WEIXIN_FROM); if (corpId == null || "".equals(corpId)) { corpId = request.getParameter(SessionKey.WEIXIN_APPID); } customerEntity.setFromWx(wx); if (settingEntity.isShowPassword() ) { customerEntity.setPassword(ChangePassword.getEncryptPassword(password)); } if (customerEntity.getPassword()==null||"".equals(customerEntity.getPassword())) { customerEntity.setPassword(ChangePassword.getEncryptPassword()); //给个缺省密码 } customerEntity.setTel(telephone); customerEntity.setOpenId(openId); customerEntity.setCltType(settingEntity.getCltType()); //新客户分类 customerEntity.setReferralsType(settingEntity.getReferralsType()); //新客户推荐人所属 customerEntity.setMemberLevel(settingEntity.getDefaultMemberLevel()); //新客户会员级别 customerEntity.setCccode(settingEntity.getCcCode()) ; //新客户所在部门 customerEntity.setSourceInfo(settingEntity.getDefaultSourceInfo()); // 保存到数据库 customerEntity = accountIfc.saveNewCustomer(customerEntity, hrCode); // 1.首先判断是否微信过来的链接,如果是,则使用 CorpId 取数据源 //if (corpId != null && !"".equals(corpId) && wx != null && "1".equals(wx)) { // 仅限于微信号企业版 session.setAttribute(SessionKey.USERCODE, customerEntity.getCltCode()); session.setAttribute(SessionKey.USERNAME, customerEntity.getCltName()); //} session.setAttribute(SettingKey.CLTCODE, customerEntity.getCltCode()); session.setAttribute(SettingKey.CLTNAME, customerEntity.getCltName()); session.setAttribute(SettingKey.CLTTEL, customerEntity.getTel()); session.setAttribute(SettingKey.CLTEMAIL, customerEntity.getEmail()); session.setAttribute(SettingKey.COUNTRY, customerEntity.getCountryZoneId()); session.setAttribute(SettingKey.PROVINCE, customerEntity.getProvinceZoneId()); session.setAttribute(SettingKey.POSTCODE, customerEntity.getPostCode()); // 给匿名购物车设置“主人”,这个“主人”就是已经登录的客户名字 accountIfc.updateCartOwner(hrCode, sessionId, customerEntity.getCltCode(), customerEntity.getCltName(),openId); } catch (DataAccessException e) { errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }catch (Exception e ){ errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } finally { SpObserver.setDBtoInstance(); } //取第三方 service WxCpService openWxCpService = null ; try { openWxCpService = CpServiceInit.getWxCpService(dataSourceEntity.getCorpId(),"addressbook") ; }catch (Exception e) { e.printStackTrace(); errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } try { // 同步微信企业号用户 boolean isAddWxCpUser = false; if (settingEntity.isSyncWxCpUser()) { //DataSourceEntity corpEntity = MultiDataSource.getDataSourceMap(dbId); //DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源 if (corpEntity != null && corpEntity.getCorpId() != null && !"".equals(corpEntity.getCorpId())) { //user.setInit(wxCpConfigStorage, wxCpService, corpEntity); isAddWxCpUser = user.newUser(response, customerEntity.getCltCode(), customerEntity.getCltName(),openWxCpService); } } // 同步结束 SettingKey.setCartHintMsg(session, "成功 您的账户已注册成功。"); String redirect = (session.getAttribute(SettingKey.REDIRECT)==null?null:(String)session.getAttribute(SettingKey.REDIRECT)); if (redirect != null && !"".equals(redirect)) { String str = (redirect.indexOf("?") > 0?"&":"?") ; if (!(redirect.indexOf(SessionKey.WEIXIN_FROM+"=") > 0 && (redirect.indexOf(SessionKey.WEIXIN_CORPID+"=") > 0 ||redirect.indexOf(SessionKey.WEIXIN_APPID+"=") > 0 ))) { redirect += (wxQueryString == null||"".equals(wxQueryString)?"":str + wxQueryString) ; } }else if (reg != null && reg.equals("1")) { if (isAddWxCpUser) redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "account/regsuccess.jsp?sync=1" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "&" + wxQueryString); else redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "account/regsuccess.jsp" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString); } if (redirect == null || "".equals(redirect)) { redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "account/account.jsp" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString); } json.addProperty("redirect",redirect ); this.printJson(response, json.toString()); return; } catch (DataAccessException e) { errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }catch (Exception e ){ errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } finally { SpObserver.setDBtoInstance(); } } @RequestMapping(params = "m=getProfile") public void getProfile(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID); String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null ? "" : (String)session.getAttribute(SettingKey.CLTCODE)); JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); JsonObject cltcodeJson = new JsonObject(); SettingEntity settingEntity = null ; CustomerEntity customerEntity = null; List sourceInfoList = null ; List cltTypeList = null ; List otherStaffList = null; try { DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源 settingEntity = settingIfc.getSettingEntity(request) ; customerEntity = accountIfc.getLoginInfoByCltCode(cltCode,null,null) ; if (customerEntity == null) { cltcodeJson.addProperty("cltcode",""); json.add("list", cltcodeJson); json.addProperty("cltcode","") ; errJson.addProperty("warning", "客户未登录"); json.add("error", errJson); return ; } sourceInfoList = sourceInfoIfc.getSourceInfoEntity(-17000110); cltTypeList = cltTypeIfc.getCltTypeEntity(); otherStaffList = otherStaffIfc.getOtherStaffEntity(settingEntity.getReferralsType()) ; cltcodeJson.addProperty("cltcode", customerEntity.getCltCode()); //客户编号 cltcodeJson.addProperty("cltname", customerEntity.getCltName()); //您的姓名 cltcodeJson.addProperty("gender",customerEntity.getGender()); //称呼 1.先生/男士/帅哥 ,2.小姐/女士/美女 cltcodeJson.addProperty("telephone", customerEntity.getTel()); //手机号码 cltcodeJson.addProperty("email", customerEntity.getEmail()); //电子邮箱 cltcodeJson.addProperty("sourceinfo", customerEntity.getSourceInfo()); //客户来源 SourceInfoList cltcodeJson.addProperty("clttype", customerEntity.getCltType()); //客户分类 SourceInfoList cltcodeJson.addProperty("referralstype", customerEntity.getReferralsType()); //推荐人所属 SourceInfoList cltcodeJson.addProperty("referralscode", customerEntity.getReferralsCode()); //推荐人 OtherStaffList cltcodeJson.addProperty("fax", customerEntity.getFax()); //传真号码 json.add("list", cltcodeJson); JsonArray sourceInfoJsonArray = new JsonArray(); for(int i = 0 ;sourceInfoList != null&&sourceInfoList.size()>0&& i < sourceInfoList.size();i++) { JsonObject sourceInfoJsonObject = new JsonObject(); sourceInfoJsonObject.addProperty("InterValue", sourceInfoList.get(i).getInterValue()); sourceInfoJsonObject.addProperty("ShowValue", sourceInfoList.get(i).getDictvalue()); sourceInfoJsonArray.add(sourceInfoJsonObject); } json.add("SourceInfoList", sourceInfoJsonArray); JsonArray cltTypeJsonArray = new JsonArray(); for(int i = 0 ;cltTypeList != null&&cltTypeList.size()>0&& i < cltTypeList.size();i++) { JsonObject cltTypeJsonObject = new JsonObject(); cltTypeJsonObject.addProperty("InterValue", cltTypeList.get(i).getCltType() ); cltTypeJsonObject.addProperty("ShowValue", cltTypeList.get(i).getCltType() ); cltTypeJsonArray.add(cltTypeJsonObject); } json.add("CltTypeList", cltTypeJsonArray); JsonArray otherStaffListJsonArray = new JsonArray(); for(int i = 0 ;otherStaffList != null&&otherStaffList.size()>0&& i < otherStaffList.size();i++) { JsonObject otherStaffListJsonObject = new JsonObject(); otherStaffListJsonObject.addProperty("InterValue", otherStaffList.get(i).getCltCode() ); otherStaffListJsonObject.addProperty("ShowValue", otherStaffList.get(i).getCltName() ); otherStaffListJsonArray.add(otherStaffListJsonObject); } json.add("OtherStaffList", otherStaffListJsonArray); this.printJson(response, json.toString()); return; } catch (DataAccessException e) { e.printStackTrace(); errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } catch (Exception e ){ e.printStackTrace(); errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }finally { SpObserver.setDBtoInstance(); } } /** * 按 小程序 电话注册客户信息(自动注册,不需要页面交互) * @param request * @param response */ @RequestMapping(params = "m=telRegByAutoReg") public void newCustomerByTelByAutoReg(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); String sessionId = session.getId(); JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); //String signature=null; //String rawData = null ; String encryptedData = request.getParameter("encryptedData"); String iv = request.getParameter("iv") ; //String telephone = request.getParameter("telephone") == null ? "" : request.getParameter("telephone"); //电话 // if (telephone == null || "".equals(telephone) || telephone.length() < 11) { // errJson.addProperty("telephone", "客户电话必须在 1 至 11 字符之间!"); // } String referralsCode = request.getParameter("ReferralsCode") ; //传递过来的是企业微信的 userid String referralsName = request.getParameter("ReferralsName") ; //传递过来的是企业微信的 username Set> it = errJson.entrySet(); if (!it.isEmpty() && it.size() != 0) { json.add("error", errJson); this.printJson(response, json.toString()); return; } String openId = request.getParameter(SessionKey.WEIXIN_OPENID); //从页面传递openid if (openId == null || openId.equals("")) { openId = (String) session.getAttribute(SessionKey.WEIXIN_OPENID); //从会话取openid } // 如果是微信过来的,则要给 USERCODE 赋值 String corpId = request.getParameter(SessionKey.WEIXIN_CORPID); String wx = request.getParameter(SessionKey.WEIXIN_FROM); if (corpId == null || "".equals(corpId)) { corpId = request.getParameter(SessionKey.WEIXIN_APPID); } CustomerEntity customerEntity = new CustomerEntity(); SettingEntity settingEntity = null; DataSourceEntity dataSourceEntity = null ; try { dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; }catch (Exception e) { e.printStackTrace(); errJson.addProperty("warning", e.getCause()!=null?e.getCause().getMessage():e.getMessage()); json.add("error", errJson); this.printJson(response, json.toString()); return ; } //第三方托管方式写法 WxMaService wxService = null; try { wxService = MaServiceInit.getWxMaServiceByOpenComponentByAppId(dataSourceEntity.getMiniAppId()) ; if (wxService==null) { errJson.addProperty("warning","在数据源中没有找到该小程序的 AppId 参数设置(WxMaService),可能传递 AppId 【"+ corpId +"】参数不正确!【/shopping/account.do?m=telRegByAutoReg】"); json.add("error", errJson); this.printJson(response, json.toString()); return; } }catch (Exception e) { e.printStackTrace(); errJson.addProperty("warning",e.getCause()!=null?e.getCause().getMessage(): e.getMessage()+"【/shopping/account.do?m=telRegByAutoReg】"); json.add("error", errJson); this.printJson(response, json.toString()); return; } String hrCode = null ; if (wx !=null && "3".equals(wx)) { hrCode = request.getParameter(SettingKey.FROMUSERID) ; //取名片用户,主要用来获取名片上的部门信息 ,使新客户所在的部门与 名片用户一致(即在同一个部门),保证新客户下达的订单也在同一个部门 } if (hrCode == null || "".equals(hrCode)){ hrCode = (String) session.getAttribute(SessionKey.HRCODE); // 是否ERP登录的用户 } try (Jedis jedis = this.jedisPool.getResource()){ SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源 settingEntity = settingIfc.getSettingEntity(request); String sessionKey = jedis.get(SettingKey.SESSIONKEY.concat(":"+dataSourceEntity.getMiniAppId()).concat(":"+openId)); if (sessionKey == null || "".equals(sessionKey)) { sessionKey = request.getParameter(SettingKey.SESSIONKEY) ; } if (sessionKey == null || "".equals(sessionKey)) { errJson.addProperty("warning", "获取会话信息sessionKey失败,导致无法解密获取的电话号码,可能原因是会话已过期,请强制退出微信然后再重试【/shopping/account.do?m=telRegByAutoReg】"); json.add("error", errJson); this.printJson(response, json.toString()); return; } //解密数据获取电话号码 WxMaPhoneNumberInfo wxMaPhoneNumberInfo = wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv); Integer province = settingEntity.getProvinceZoneId()==null?0:settingEntity.getProvinceZoneId() ; Integer city = settingEntity.getCityZoneId()==null?0:settingEntity.getCityZoneId() ; Integer county = settingEntity.getCountyZoneId()==null?0:settingEntity.getCountyZoneId() ; Integer zoneId = county; if (zoneId == null || zoneId.equals(0)) zoneId = city; if (zoneId == null || zoneId.equals(0)) zoneId = province; if (zoneId == null || zoneId.equals(0)) zoneId = 0; customerEntity.setCltType(settingEntity.getCltType()); customerEntity.setSourceInfo(settingEntity.getDefaultSourceInfo()); customerEntity.setCountryZoneId(settingEntity.getCountryId()==null?0:settingEntity.getCountryId()) ; customerEntity.setProvinceZoneId(province); customerEntity.setCityZoneId(city); customerEntity.setCountyZoneId(county); customerEntity.setZoneId(zoneId); customerEntity.setTel(wxMaPhoneNumberInfo.getPhoneNumber()); customerEntity.setFax(null); customerEntity.setEmail(null); customerEntity.setPropertyId(null); customerEntity.setBuilding(null); customerEntity.setUnit(null); customerEntity.setHouse(null); customerEntity.setOpenId(openId); customerEntity.setPostCode(null); String password = ChangePassword.getEncryptPassword() ; customerEntity.setPassword(password); MyWxMpUser wxMpUser = maUserIfc.getUser(openId) ; customerEntity.setOrganization(null); customerEntity.setAddress(null); customerEntity.setCccode(settingEntity.getCcCode()); customerEntity.setWeiXinUserStatus(4); //customerEntity.setGender(wxMpUser != null? wxMpUser.getSex():0); customerEntity.setCltType(settingEntity.getCltType()); customerEntity.setReferralsType("企业微信"); //"企业微信" 是小程序的固定法写法, 不需要值 settingEntity.getReferralsType() customerEntity.setReferralsCode(referralsCode); customerEntity.setReferralsName(referralsName); customerEntity.setFromWx(wx); customerEntity.setOpenId(openId); if (StringUtils.isBlank(wxMpUser.getNickname())) { wxMpUser.setNickname("微信用户"); } customerEntity.setCltName(wxMpUser!=null?wxMpUser.getNickname():"微信用户"); // 保存到数据库 customerEntity = accountIfc.saveNewCustomer(customerEntity, hrCode); //--增加处理客户确认后生成二维码,线程处理 by danaus 2020/8/10 11:53 ThreadPoolTaskScheduler threadPoolTaskScheduler = (ThreadPoolTaskScheduler) FactoryBean.getBean("threadPoolTaskScheduler"); threadPoolTaskScheduler.execute(new QrCodeRunable(170001,16,customerEntity.getDocCode() ,(String) request.getSession().getAttribute(SessionKey.HRCODE) ,(String) request.getSession().getAttribute(SessionKey.HRNAME) ,dataSourceEntity.getDbId()+"" )); //---------- //将小程序拉取下来的电话号码保存起来 maUserIfc.updateTelephone(wxMaPhoneNumberInfo.getPhoneNumber(), openId ) ; // 1.首先判断是否微信过来的链接,如果是,则使用 CorpId 取数据源 if (corpId != null && !"".equals(corpId) && wx != null && "1".equals(wx)) { // 仅限于微信号企业版 session.setAttribute(SessionKey.USERCODE, customerEntity.getCltCode()); session.setAttribute(SessionKey.USERNAME, customerEntity.getCltName()); } session.setAttribute(SettingKey.CLTCODE, customerEntity.getCltCode()); session.setAttribute(SettingKey.CLTNAME, customerEntity.getCltName()); session.setAttribute(SettingKey.CLTTEL, customerEntity.getTel()); session.setAttribute(SettingKey.CLTEMAIL, customerEntity.getEmail()); session.setAttribute(SettingKey.COUNTRY, customerEntity.getCountryZoneId()); session.setAttribute(SettingKey.PROVINCE, customerEntity.getProvinceZoneId()); session.setAttribute(SettingKey.POSTCODE, customerEntity.getPostCode()); // 给匿名购物车设置“主人”,这个“主人”就是已经登录的客户名字 accountIfc.updateCartOwner(hrCode, sessionId, customerEntity.getCltCode(), customerEntity.getCltName(),openId); json.addProperty(SettingKey.CLTCODE, customerEntity.getCltCode()); json.addProperty(SettingKey.CLTNAME,customerEntity.getCltName()) ; json.addProperty(SettingKey.ReferralsType, customerEntity.getReferralsType()); //介绍人类别 json.addProperty(SettingKey.ReferralsCode, customerEntity.getReferralsCode()); //介绍人编号 json.addProperty(SettingKey.ReferralsName, customerEntity.getReferralsName()); //介绍人姓名 json.addProperty("Telephone", customerEntity.getTel()); //电话 json.addProperty("TelephoneMask",StringReplaceUtil.getTelephoneMask(customerEntity.getTel())); //电话 json.addProperty("state", "success"); this.printJson(response, json.toString()); return; }catch (DataAccessException e) { e.printStackTrace(); errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } catch (Exception e ){ e.printStackTrace(); errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }finally { SpObserver.setDBtoInstance(); } } /** * 按 jsp 页面注册 * @param request * @param response */ @SuppressWarnings("unchecked") @RequestMapping(params = "m=new") public void newCustomer(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); String sessionId = session.getId(); //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID); String hostUrl = SettingKey.getHostUrl(request); // 将微信corpid组装成url String wxQueryString = SettingKey.getQueryStringByWx(request); boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request); JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); String hrCode = (String) session.getAttribute(SessionKey.HRCODE); // 是否ERP登录的用户 String reg = (request.getParameter("reg") == null ? "" : request.getParameter("reg")); // String sessionId = session.getId(); // String userCode = (session.getAttribute(SessionKey.USERCODE) == null // ? "" : (String)session.getAttribute(SessionKey.USERCODE)); String cltName = request.getParameter("cltname") == null ? "" : request.getParameter("cltname");//姓名 String telephone = request.getParameter("telephone") == null ? "" : request.getParameter("telephone"); //电话 String fax = request.getParameter("fax") == null ? "" : request.getParameter("fax"); //传真 String email = request.getParameter("email") == null ? "" : request.getParameter("email"); String sourceInfo = request.getParameter("sourceinfo") == null ? "" : request.getParameter("sourceinfo"); //来源 String referralsType = request.getParameter("referralstype") == null ? "" : request.getParameter("referralstype"); //介绍人类型 String referralsCode = request.getParameter("referralscode") == null ? "" : request.getParameter("referralscode"); //介绍人代码 String password = request.getParameter("password") == null ? "" : request.getParameter("password"); //密码 String confirm = request.getParameter("confirm") == null ? "" : request.getParameter("confirm"); //确认密码 String countryId = request.getParameter("country_id") == null ? "" : request.getParameter("country_id"); // 国家 String province = request.getParameter("zone_id") == null ? "" : request.getParameter("zone_id"); // 省级 String city = request.getParameter("city") == null ? "" : request.getParameter("city"); // 城市 String county = request.getParameter("county") == null ? "" : request.getParameter("county"); // 区/县 String propertyId = request.getParameter("propertyid") == null ? "" : request.getParameter("propertyid"); //小区 (用于程序拼装地址) String building = request.getParameter("building") == null ? "" : request.getParameter("building"); //第几栋 (用于程序拼装地址) String unit = request.getParameter("unit") == null ? "" : request.getParameter("unit"); //第几单元 (用于程序拼装地址) String house = request.getParameter("house") == null ? "" : request.getParameter("house"); //门牌号 (用于程序拼装地址) String postCode = request.getParameter("postcode") == null ? "" : request.getParameter("postcode"); //邮编 String organization = request.getParameter("organization") == null ? "" : request.getParameter("organization"); //客户所属公司 String address = request.getParameter("address") == null ? "" : request.getParameter("address"); //地址(客户自己填写的) String gender = request.getParameter("gender") == null ? "" : request.getParameter("gender"); //性别 String cltType = request.getParameter("clttype") == null ? "" : request.getParameter("clttype"); //客户类型 String agree = request.getParameter("agree"); //同意隐私条款 String code = request.getParameter("code") == null ? "" : request.getParameter("code"); //验证码 // 如果是微信过来的,则要给 USERCODE 赋值 String corpId = request.getParameter(SessionKey.WEIXIN_CORPID); String wx = request.getParameter(SessionKey.WEIXIN_FROM); if (corpId == null || "".equals(corpId)) { corpId = request.getParameter(SessionKey.WEIXIN_APPID); } if (cltName == null || "".equals(cltName) || cltName.length() < 2) { errJson.addProperty("cltname", "客户姓名必须在2 至 32 字符之间!"); } if (gender == null || "".equals(gender)) { errJson.addProperty("gender", "称呼须输入!"); } //取第三方 service WxCpService openWxCpService = null ; DataSourceEntity dataSourceEntity = null ; try { dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; openWxCpService = CpServiceInit.getWxCpService(dataSourceEntity.getCorpId(),"addressbook") ; }catch (Exception e) { e.printStackTrace(); errJson.addProperty("warning", e.getCause()!=null?e.getCause().getMessage():e.getMessage()); json.add("error", errJson); this.printJson(response, json.toString()); return ; } CustomerEntity customerEntity = new CustomerEntity(); SettingEntity settingEntity = null; try { SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源 settingEntity = settingIfc.getSettingEntity(request); if (settingEntity.isShowTel() && settingEntity.isRequiredTel()) { if (telephone == null || "".equals(telephone) || telephone.length() < 11) { errJson.addProperty("telephone", "客户电话必须在 1 至 11 字符之间!"); } } if (settingEntity.isShowCltType() && settingEntity.isRequiredCltType()) { if (cltType == null || "".equals(cltType)) errJson.addProperty("clttype", "客户分类 必须输入!"); } if (settingEntity.isShowEmail() && settingEntity.isRequiredEmail()) { if (email == null || "".equals(email)) errJson.addProperty("email", "电子邮箱 必须输入!"); if (email != null && !"".equals(email) && !SettingKey.emailFormat(email)) errJson.addProperty("email", "电子邮箱 格式错误,请重新输入!"); } if (settingEntity.isShowSourceInfo() && settingEntity.isRequiredSourceInfo()) { if (sourceInfo == null || "".equals(sourceInfo)) errJson.addProperty("sourceinfo", "客户来源 必须输入!"); } if (!settingEntity.isShowSourceInfo()) { sourceInfo = settingEntity.getDefaultSourceInfo(); } if (settingEntity.isShowReferralsCode() && settingEntity.isRequiredReferralsCode()) { if (referralsType == null || "".equals(referralsType)) errJson.addProperty("referralstype", "推荐人所属 必须输入!"); } if (settingEntity.isShowReferralsCode() && settingEntity.isRequiredReferralsCode()) { if (referralsCode == null || "".equals(referralsCode)) errJson.addProperty("referralscode", "推荐人 必须输入!"); } if (settingEntity.isShowFax() && settingEntity.isRequiredFax()) { if (fax == null || "".equals(fax)) errJson.addProperty("fax", "传真号码 必须输入!"); } if (settingEntity.isShowPassword() && settingEntity.isRequiredPassword()) { if (password == null || "".equals(password)) errJson.addProperty("password", "密码 必须输入!"); if (confirm == null || "".equals(confirm)) errJson.addProperty("confirm", "确认密码 必须输入!"); if (password != null && confirm != null && !confirm.equals(password)) { errJson.addProperty("password", "2次输入的密码 必须相同!"); errJson.addProperty("confirm", "2次输入的密码 必须相同!"); } } if (settingEntity.isShowOrganization() && settingEntity.isRequiredOrganization()) { if (organization == null || "".equals(organization)) errJson.addProperty("organization", "公司名称 必须输入!"); } if (settingEntity.isShowCountryId() && settingEntity.isRequiredCountryId()) { if (countryId == null || "".equals(countryId)) errJson.addProperty("country_id", "国家 必须输入!"); } if (settingEntity.isShowProvinceZoneId() && settingEntity.isRequiredProvinceZoneId()) { if (province == null || "".equals(province)) errJson.addProperty("zone_id", "省份 必须输入!"); } if (settingEntity.isShowCityZoneId() && settingEntity.isRequiredCityZoneId()) { if (city == null || "".equals(city)) errJson.addProperty("city", "城市 必须输入!"); } if (settingEntity.isShowCountyZoneId() && settingEntity.isRequiredCountyZoneId()) { if (county == null || "".equals(county)) errJson.addProperty("county", "区/县 必须输入!"); } if (settingEntity.isShowPropertyId() && settingEntity.isRequiredPropertyId()) { if (propertyId == null || "".equals(propertyId)) errJson.addProperty("propertyid", "小区名称 必须输入!"); if (building == null || "".equals(building)) errJson.addProperty("building", "楼号 必须输入!"); } if (settingEntity.isShowAddress() && settingEntity.isRequiredAddress()) { if (address == null || "".equals(address)) errJson.addProperty("address", "地址 必须输入!"); } if (settingEntity.isShowPostcode() && settingEntity.isRequiredPostcode()) { if (postCode == null || "".equals(postCode)) errJson.addProperty("postcode", "邮编 必须输入!"); } boolean foundWarning = false ; if (settingEntity.getCcCode() == null || "".equals(settingEntity.getCcCode())) { foundWarning = true ; errJson.addProperty("warning", "请在 714001 功能号中预先设置【新客户所在部门】参数!"); } if (!foundWarning && (agree == null || "".equals(agree))) { errJson.addProperty("warning", "警告:您未同意同意 隐私政策 条款 !"); } Set> it = errJson.entrySet(); if (!it.isEmpty() && it.size() != 0) { json.add("error", errJson); this.printJson(response, json.toString()); return; } //验证码 String code2 = "" ; if (settingEntity.isShowTel() && settingEntity.isRequiredTel()) { try { code2 = (String) redisTemplate.opsForValue().get(VerificationCodes.getCodeKey( telephone)) ; }catch(Exception e) { e.printStackTrace(); errJson.addProperty(SettingKey.CLTTEL, e.getMessage()); json.add("error", errJson); this.printJson(response, json.toString()); return ; } if (code == null || "".equals(code2)||code2 == null || "".equals(code2)|| ! code.equals(code2)){ errJson.addProperty("code", "验证码不正确!"); json.add("error", errJson); this.printJson(response, json.toString()); return ; } } if ((province == null || "".equals(province))&& null != settingEntity.getProvinceZoneId()) { province = String.valueOf(settingEntity.getProvinceZoneId()); } if (province == null || "".equals(province)) { province = "0" ; } if (city == null || "".equals(city)) { city = "0" ; } String zoneId = county; if (zoneId == null || "".equals(zoneId) || "0".equals(zoneId)) zoneId = city; if (zoneId == null || "".equals(zoneId) || "0".equals(zoneId)) zoneId = province; if (zoneId == null || "".equals(zoneId) || "0".equals(zoneId)) zoneId = "0"; if (propertyId == null || "".equals(propertyId)) propertyId = "0"; if (county == null || "".equals(county)) county = "0"; if (propertyId == null || "".equals(propertyId)) propertyId = "0"; if (countryId == null || "".equals(countryId)) { countryId = "0" ; } customerEntity.setCltName(cltName); customerEntity.setCltType(settingEntity.getCltType()); customerEntity.setSourceInfo(sourceInfo); customerEntity.setCountryZoneId(countryId == null ? null : Integer.parseInt(countryId)); customerEntity.setProvinceZoneId(province == null ? null : Integer.parseInt(province)); customerEntity.setCityZoneId(city == null ? null : Integer.parseInt(city)); customerEntity.setCountyZoneId(county == null ? null : Integer.parseInt(county)); customerEntity.setZoneId(Integer.parseInt(zoneId)); customerEntity.setTel(telephone); customerEntity.setFax(fax); customerEntity.setEmail(email); customerEntity.setPropertyId(Integer.parseInt(propertyId)); customerEntity.setBuilding(building); customerEntity.setUnit(unit); customerEntity.setHouse(house); customerEntity.setPostCode(postCode); customerEntity.setPassword(ChangePassword.getEncryptPassword(password) ); customerEntity.setOrganization(organization); customerEntity.setAddress(address); customerEntity.setCccode(settingEntity.getCcCode()); customerEntity.setWeiXinUserStatus(4); customerEntity.setGender(Integer.parseInt(gender)); customerEntity.setCltType(cltType); customerEntity.setReferralsType(referralsType); customerEntity.setReferralsCode(referralsCode); customerEntity.setFromWx(wx); String openId = request.getParameter(SessionKey.WEIXIN_OPENID); //从页面传递openid if (openId == null || openId.equals("")) { openId = (String) session.getAttribute(SessionKey.WEIXIN_OPENID); //从会话取openid } customerEntity.setOpenId(openId); Integer telCount = accountIfc.getCltCodeCountByCltTel(telephone); if (telCount != null && telCount.intValue() > 0) { errJson.addProperty("telephone", "该电话已经注册,请使用另一个号码!"); json.add("error", errJson); this.printJson(response, json.toString()); return; } if (email != null && !"".equals(email)) { Integer emailCount = accountIfc.getCltCodeCountByEmail(email); if (emailCount != null && emailCount.intValue() > 0) { errJson.addProperty("email", "该电子邮件地址已经注册,请使用另一个邮箱地址!"); json.add("error", errJson); this.printJson(response, json.toString()); return; } } if (openId != null && !"".equals(openId)) { Integer emailCount = accountIfc.getCltCodeCountByOpenId(openId); if (emailCount != null && emailCount.intValue() > 0) { errJson.addProperty("warning", "当前微信用户已经注册,请刷新页面!"); json.add("error", errJson); this.printJson(response, json.toString()); return; } } // 保存到数据库 customerEntity = accountIfc.saveNewCustomer(customerEntity, hrCode); // 1.首先判断是否微信过来的链接,如果是,则使用 CorpId 取数据源 if (corpId != null && !"".equals(corpId) && wx != null && "1".equals(wx)) { // 仅限于微信号企业版 session.setAttribute(SessionKey.USERCODE, customerEntity.getCltCode()); session.setAttribute(SessionKey.USERNAME, customerEntity.getCltName()); } session.setAttribute(SettingKey.CLTCODE, customerEntity.getCltCode()); session.setAttribute(SettingKey.CLTNAME, customerEntity.getCltName()); session.setAttribute(SettingKey.CLTTEL, customerEntity.getTel()); session.setAttribute(SettingKey.CLTEMAIL, customerEntity.getEmail()); session.setAttribute(SettingKey.COUNTRY, customerEntity.getCountryZoneId()); session.setAttribute(SettingKey.PROVINCE, customerEntity.getProvinceZoneId()); session.setAttribute(SettingKey.POSTCODE, customerEntity.getPostCode()); //保存货币信息 session.setAttribute(SettingKey.currency,customerEntity.getCurrency()) ; session.setAttribute(SettingKey.currencyName,customerEntity.getCurrencyName()) ; session.setAttribute(SettingKey.currencySign,customerEntity.getCurrencySign()) ; // 给匿名购物车设置“主人”,这个“主人”就是已经登录的客户名字 accountIfc.updateCartOwner(hrCode, sessionId, customerEntity.getCltCode(), customerEntity.getCltName(),openId); // 同步微信企业号用户 boolean isAddWxCpUser = false; if (settingEntity.isSyncWxCpUser()) { //DataSourceEntity corpEntity = MultiDataSource.getDataSourceMap(dbId); //DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; if (corpEntity != null && corpEntity.getCorpId() != null && !"".equals(corpEntity.getCorpId())) { //user.setInit(wxCpConfigStorage, wxCpService, corpEntity); isAddWxCpUser = user.newUser(response, customerEntity.getCltCode(), customerEntity.getCltName(),openWxCpService); } } // 同步结束 String redirect = (session.getAttribute(SettingKey.REDIRECT)==null?null:(String)session.getAttribute(SettingKey.REDIRECT)); if (redirect != null && !"".equals(redirect)) { String str = (redirect.indexOf("?") > 0?"&":"?") ; if (!(redirect.indexOf(SessionKey.WEIXIN_FROM+"=") > 0 && (redirect.indexOf(SessionKey.WEIXIN_CORPID+"=") > 0 ||redirect.indexOf(SessionKey.WEIXIN_APPID+"=") > 0 ))) { redirect += (wxQueryString == null||"".equals(wxQueryString)?"":str + wxQueryString) ; } json.addProperty("redirect",redirect) ; }else if (reg != null && reg.equals("1")) { String url = ""; if (isAddWxCpUser) url = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "account/regsuccess.jsp?sync=1" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "&" + wxQueryString); else url = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "account/regsuccess.jsp" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString); json.addProperty("redirect", url); json.addProperty("status", "success"); } //删除验证码 redisTemplate.delete(VerificationCodes.getCodeKey( telephone)) ; this.printJson(response, json.toString()); return; } catch (DataAccessException e) { e.printStackTrace(); errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } catch (Exception e ){ e.printStackTrace(); errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }finally { SpObserver.setDBtoInstance(); } } @RequestMapping(params = "m=accountInfo") public void accountInfo(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID); String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null ? "" : (String)session.getAttribute(SettingKey.CLTCODE)); String cltName = (session.getAttribute(SettingKey.CLTNAME) == null ? "" : (String)session.getAttribute(SettingKey.CLTNAME)) ; String userCode = (session.getAttribute(SessionKey.USERCODE) == null ? "" : (String)session.getAttribute(SessionKey.USERCODE)); String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID) == null ? "" : (String) session.getAttribute(SessionKey.WEIXIN_OPENID) ) ; String nickName = (session.getAttribute(SessionKey.WEIXIN_NICKNAME) == null?"" :(String)session.getAttribute(SessionKey.WEIXIN_NICKNAME)) ; String headImgUrl = (session.getAttribute(SessionKey.WEIXIN_HEADIMGURL) == null?"" :(String)session.getAttribute(SessionKey.WEIXIN_HEADIMGURL)) ; String memberLevelDesc = (session.getAttribute(SettingKey.MEMBERLEVELDESC) == null?"":(String)session.getAttribute(SettingKey.MEMBERLEVELDESC)); String memberLevel = (session.getAttribute(SettingKey.MEMBERLEVEL) == null?"":(String)session.getAttribute(SettingKey.MEMBERLEVEL)); String fromUserId = request.getParameter(SettingKey.FROMUSERID) ; //System.out.println(this.getClass()+ " ,date:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))+ " ,openId:" + openId + ", sessionId:" + session.getId()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); DecimalFormat df = new DecimalFormat("0.00") ; JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); SettingEntity settingEntity = null; try { DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源 settingEntity = settingIfc.getSettingEntity(request); MemberInfoEntity memberInfoEntity =wxPayIfc.getMemberInfoByMemberLevel(memberLevel); JsonObject userInfo = new JsonObject(); MyWxMpUser myWxMpUser= maUserIfc.getUser(openId) ; //再次取数 int userCount = mpUserIfc.getUserCountByReferralsCode(openId); CurrencyEntity currencyEntity = new CurrencyEntity(request); String currency = currencyEntity.getCurrency(); BalanceEntity balanceEntity = balanceIfc.getBalance(currency, cltCode) ; String referralsName = (myWxMpUser!=null && myWxMpUser.getReferralsName()!=null&&!"".equals(myWxMpUser.getReferralsName())?myWxMpUser.getReferralsName(): (settingEntity.getMetaTitle()!=null&& !"".equals(settingEntity.getMetaTitle())?settingEntity.getMetaTitle():"无分享人")); userInfo.addProperty("CltCode", cltCode); //客户编号 userInfo.addProperty("CltName", cltName); //客户名称 userInfo.addProperty("NickName", nickName); //昵称 userInfo.addProperty("HeadImgUrl", headImgUrl); //头像 userInfo.addProperty("UserCount", userCount); //我的关注 //SubscribeTime 是unix timestamp时间戳 ,因此要转换为 日期时间 Date类型 Date subscribeTime = (myWxMpUser!=null&&myWxMpUser.getSubscribeTime()!=null?new Date(myWxMpUser.getSubscribeTime() * 1000L):null) ; userInfo.addProperty("SubscribeTime",subscribeTime!=null?sdf.format(subscribeTime):"") ; //关注时间 userInfo.addProperty("MemberLevel", memberLevel); //会员等级 userInfo.addProperty("MemberLevelDesc", memberLevelDesc); //会员等描述 userInfo.addProperty("MemberDocCode", memberInfoEntity!=null?memberInfoEntity.getDocCode():""); //显示 会员描述 链接用 userInfo.addProperty("AccumulationAmount",balanceEntity != null?df.format(balanceEntity.getAccumulationAmount()):"0" ) ; //累计积分 userInfo.addProperty("NotWithdrawAmount",balanceEntity != null?df.format(0.0-balanceEntity.getBalance()):"0"); //未提现积分 userInfo.addProperty("WithdrawAmount",balanceEntity != null?df.format((0.0 - balanceEntity.getBalance() * (1.0 - settingEntity.getWithdrawTaxRate()))):"0"); //可提现积分 //取出 我的客服人员名称 MyWxCpUser myWxCpUser = erpUserIfc.getWorkAppUser( fromUserId) ; String fromUserName = (myWxCpUser != null?myWxCpUser.getName():"") ; userInfo.addProperty("FromUserId", fromUserId) ; userInfo.addProperty("FromUserName", fromUserName) ; if (settingEntity.isStartupLeagueShopCcCode()) { userInfo.addProperty("ReferralsName", fromUserName); //介绍人 }else { userInfo.addProperty("ReferralsName", referralsName); //介绍人 } json.add("UserInfo", userInfo); //errJson.addProperty("warning",""); //不要显示空白错误提示,会导致页面有空白提示 //json.add("error", errJson); this.printJson(response, json.toString()); return; } catch (DataAccessException e) { e.printStackTrace(); errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } catch (Exception e ){ e.printStackTrace(); errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }finally { SpObserver.setDBtoInstance(); } } @RequestMapping(params = "m=updateprofile") public void updateProfile(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID); String hostUrl = SettingKey.getHostUrl(request); // 将微信corpid组装成url String wxQueryString = SettingKey.getQueryStringByWx(request); boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request); String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null ? "" : (String) session.getAttribute(SettingKey.CLTCODE)); String cltName = request.getParameter("cltname") == null ? "" : request.getParameter("cltname"); String telephone = request.getParameter("telephone") == null ? "" : request.getParameter("telephone"); String fax = request.getParameter("fax") == null ? "" : request.getParameter("fax"); String email = request.getParameter("email") == null ? "" : request.getParameter("email"); String sourceInfo = request.getParameter("sourceinfo") == null ? "" : request.getParameter("sourceinfo"); String referralsType = request.getParameter("referralstype") == null ? "" : request.getParameter("referralstype"); String referralsCode = request.getParameter("referralscode") == null ? "" : request.getParameter("referralscode"); String code = request.getParameter("code") == null ? "" : request.getParameter("code"); JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); if (cltName == null || "".equals(cltName) || cltName.length() < 2) { errJson.addProperty("cltname", "客户姓名必须在2 至 32 字符之间!"); } SettingEntity settingEntity = null; Integer ret = null; try { DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId()); settingEntity = settingIfc.getSettingEntity(request); if (settingEntity.isShowEmail() && settingEntity.isRequiredEmail()) { if (email == null || "".equals(email)) { errJson.addProperty("email", "电子邮箱 必须输入!"); } if (email != null && !"".equals(email) && !SettingKey.emailFormat(email)) { errJson.addProperty("email", "电子邮箱 格式错误,请重新输入!"); } } if (settingEntity.isShowSourceInfo() && settingEntity.isRequiredSourceInfo()) { if (sourceInfo == null || "".equals(sourceInfo)) { errJson.addProperty("sourceinfo", "客户来源 必须输入!"); } } if (settingEntity.isShowReferralsCode() && settingEntity.isRequiredReferralsCode()) { if (referralsType == null || "".equals(referralsType)) { errJson.addProperty("referralstype", "推荐人所属 必须输入!"); } } if (settingEntity.isShowReferralsCode() && settingEntity.isRequiredReferralsCode()) { if (referralsCode == null || "".equals(referralsCode)) { errJson.addProperty("referralscode", "推荐人 必须输入!"); } } if (settingEntity.isShowFax() && settingEntity.isRequiredFax()) { if (fax == null || "".equals(fax)) { errJson.addProperty("fax", "传真号码 必须输入!"); } } if (settingEntity.isShowTel() && settingEntity.isRequiredTel()) { if (telephone == null || "".equals(telephone)) { errJson.addProperty("telephone", "手机号码 必须输入!"); } } Set> it = errJson.entrySet(); if (!it.isEmpty() && it.size() != 0) { json.add("error", errJson); this.printJson(response, json.toString()); return; } //验证码 String code2 = "" ; if (settingEntity.isShowTel() && settingEntity.isRequiredTel()) { try { code2 = (String) redisTemplate.opsForValue().get(VerificationCodes.getCodeKey( telephone)) ; }catch(Exception e) { e.printStackTrace(); errJson.addProperty(SettingKey.CLTTEL, e.getMessage()); json.add("error", errJson); this.printJson(response, json.toString()); return ; } if (code == null || "".equals(code2)||code2 == null || "".equals(code2)|| ! code.equals(code2)){ errJson.addProperty("code", "验证码不正确!"); json.add("error", errJson); this.printJson(response, json.toString()); return ; } } // 保存到数据库 ret = accountIfc.updateCustomerProfile(cltCode, cltName, telephone, sourceInfo, referralsType, referralsCode, email, fax); if (ret != null && ret.equals(1)) { session.setAttribute(SettingKey.CLTNAME, cltName); session.setAttribute(SettingKey.CLTTEL, telephone); session.setAttribute(SettingKey.CLTEMAIL, email); SettingKey.setCartHintMsg(session, "成功 您的账户已更新。"); json.addProperty("redirect", hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "account/account.jsp" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString)); } this.printJson(response, json.toString()); return; } catch (DataAccessException e) { errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }catch (Exception e) { errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } finally { SpObserver.setDBtoInstance(); } } @RequestMapping(params = "m=updateaddress") public void updateAddress(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); // String dbId = (String) // session.getAttribute(SessionKey.SHOPPING_DBID); String hostUrl = SettingKey.getHostUrl(request); // 将微信corpid组装成url String wxQueryString = SettingKey.getQueryStringByWx(request); boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request); String seq = (request.getParameter(SettingKey.PAYMENTADDRESS) == null ||request.getParameter(SettingKey.PAYMENTADDRESS).equals("") ? "0" : request.getParameter(SettingKey.PAYMENTADDRESS)); String ac = (request.getParameter("ac") == null ? "new" : request.getParameter("ac")); String returnTo= request.getParameter("returnto"); //返回到哪个页面, String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null ? "" : (String) session.getAttribute(SettingKey.CLTCODE)); String linkMan = request.getParameter("linkman") == null ? "" : request.getParameter("linkman"); //联系人 String telephone = request.getParameter("telephone") == null ? "" : request.getParameter("telephone"); String organization = request.getParameter("organization") == null ? "" : request.getParameter("organization"); String countryId = request.getParameter("country_id") == null ? "0" : request.getParameter("country_id"); // 国家 String countryName = request.getParameter("countryname") == null ? "" : request.getParameter("countryname"); // 国家 String provinceZoneId = request.getParameter("zone_id") == null ? "0" : request.getParameter("zone_id"); // 省级 String provinceName = request.getParameter("provincename") == null ? "" : request.getParameter("provincename"); // 省级 String cityZoneId = request.getParameter("city") == null ? "0" : request.getParameter("city"); // 城市 String cityName = request.getParameter("cityname") == null ? "" : request.getParameter("cityname"); // 城市 String countyZoneId = request.getParameter("county") == null ? "0" : request.getParameter("county"); // 区/县 String countyName = request.getParameter("countyname") == null ? "" : request.getParameter("countyname"); // 区/县 String propertyId = request.getParameter("propertyid") == null ? "0" : request.getParameter("propertyid"); // 小区 String building = request.getParameter("building") == null ? "" : request.getParameter("building"); String unit = request.getParameter("unit") == null ? "" : request.getParameter("unit"); String house = request.getParameter("house") == null ? "" : request.getParameter("house"); String postCode = request.getParameter("postcode") == null ? "" : request.getParameter("postcode"); String addressName = request.getParameter("addressname") == null ? "" : request.getParameter("addressname"); String address = request.getParameter("address") == null ? "" : request.getParameter("address"); String street = request.getParameter("street") == null ? "" : request.getParameter("street"); String longitude = request.getParameter("longitude") == null ? "" :request.getParameter("longitude") ; String latitude = request.getParameter("latitude") == null ? "" :request.getParameter("latitude") ; JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); if (cltCode == null || "".equals(cltCode)) { SettingKey.setCartHintMsg(session, "请先登录,再修改地址!"); json.addProperty("redirect", hostUrl + "/shopping/account/login.jsp" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString)); errJson.addProperty("warning","请先登录,再修改地址!"); json.add("error", errJson); this.printJson(response, json.toString()); return; } if (linkMan == null || "".equals(linkMan) || linkMan.length() < 2) { errJson.addProperty("linkman", "联系人姓名必须在2 至 32 字符之间!"); errJson.addProperty("warning", "联系人姓名必须在2 至 32 字符之间!"); } SettingEntity settingEntity = null; Integer ret = null; try { DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源 settingEntity = settingIfc.getSettingEntity(request); if (settingEntity.isShowOrganization() && settingEntity.isRequiredOrganization()) { if (organization == null || "".equals(organization)) { errJson.addProperty("organization", "公司名称 必须输入!"); errJson.addProperty("warning","公司名称 必须输入!"); } } if (settingEntity.isShowCountryId() && settingEntity.isRequiredCountryId()) { if (countryId == null || "".equals(countryId)) { errJson.addProperty("country_id", "国家 必须输入!"); errJson.addProperty("warning", "国家 必须输入!"); } } if (settingEntity.isShowProvinceZoneId() && settingEntity.isRequiredProvinceZoneId()) { if (provinceZoneId == null || "".equals(provinceZoneId)) { errJson.addProperty("zone_id", "省份 必须输入!"); errJson.addProperty("warning", "省份 必须输入!"); } } if (settingEntity.isShowCityZoneId() && settingEntity.isRequiredCityZoneId()) { if (cityZoneId == null || "".equals(cityZoneId)) { errJson.addProperty("city", "城市 必须输入!"); errJson.addProperty("warning", "城市 必须输入!"); } } if (settingEntity.isShowCountyZoneId() && settingEntity.isRequiredCountyZoneId()) { if (countyZoneId == null || "".equals(countyZoneId)) { errJson.addProperty("county", "区/县 必须输入!"); errJson.addProperty("warning", "区/县 必须输入!"); } } if (settingEntity.isShowPropertyId() && settingEntity.isRequiredPropertyId()) { if (propertyId == null || "".equals(propertyId)) { errJson.addProperty("propertyid", "小区名称 必须输入!"); errJson.addProperty("warning", "小区名称 必须输入!"); } if (building == null || "".equals(building)) { errJson.addProperty("building", "楼号 必须输入!"); errJson.addProperty("warning", "楼号 必须输入!"); } } if (settingEntity.isShowAddress() && settingEntity.isRequiredAddress()) { if (street == null || "".equals(street)) { errJson.addProperty("address", "地址 必须输入!"); errJson.addProperty("warning", "地址 必须输入!"); } } if (settingEntity.isShowPostcode() && settingEntity.isRequiredPostcode()) { if (postCode == null || "".equals(postCode)) { errJson.addProperty("postcode", "邮编 必须输入!"); errJson.addProperty("warning", "邮编 必须输入!"); } } Set> it = errJson.entrySet(); if (!it.isEmpty() && it.size() != 0) { json.add("error", errJson); this.printJson(response, json.toString()); return; } if (countryId == null || "".equals(countryId)) { countryId = "0"; } if (provinceZoneId == null || "".equals(provinceZoneId)) { provinceZoneId = "0"; } if (cityZoneId == null || "".equals(cityZoneId)) { cityZoneId = "0"; } if (countyZoneId == null || "".equals(countyZoneId)) { countyZoneId = "0"; } if (propertyId == null || "".equals(propertyId)) { propertyId = "0"; } AddressEntity addressEntity = new AddressEntity() ; addressEntity.setSeq(Integer.parseInt(seq)); addressEntity.setCltCode(cltCode); addressEntity.setLinkMan(linkMan); addressEntity.setTelephone(telephone); addressEntity.setCountryId(Integer.parseInt(countryId)); addressEntity.setCountryName(countryName); addressEntity.setProvinceZoneId(Integer.parseInt(provinceZoneId)); addressEntity.setProvinceName(provinceName); addressEntity.setCityZoneId(Integer.parseInt(cityZoneId)); addressEntity.setCityName(cityName); addressEntity.setCountyZoneId(Integer.parseInt(countyZoneId)); addressEntity.setCountyName(countyName); addressEntity.setPropertyId(Integer.parseInt(propertyId)); addressEntity.setBuilding(building); addressEntity.setUnit(unit); addressEntity.setHouse(house); addressEntity.setPostCode(postCode); addressEntity.setOrganization(organization); addressEntity.setAddressName(addressName); addressEntity.setAddress(address); addressEntity.setStreet(street); addressEntity.setLongitude(longitude); addressEntity.setLatitude(latitude); if (ac != null && "edit".equals(ac)) { // 更新 update ret = addressIfc.updateAddress(addressEntity); } else { // 新增 new ret = addressIfc.newAddress(addressEntity); } if (ret != null ) { SettingKey.setCartHintMsg(session, "成功 您的地址已更新。"); String redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "account/address.jsp" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString) ; if (returnTo!= null&& "checkoutnew".equals(returnTo)) { redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "checkoutnew/address.jsp" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString) ; }else if (returnTo!= null&& "confirm".equals(returnTo)) { if (ret != null) { session.setAttribute(SettingKey.PAYMENTADDRESS,ret.toString()) ; //保存已经选择的地址 } redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "checkoutnew/" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString) ; }else if(returnTo!= null&&"membercheckout".equals(returnTo)){ String memberInfoDocCode=request.getParameter(SettingKey.DOCCODE)==null?"":request.getParameter(SettingKey.DOCCODE); redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "checkoutnew/membercheckout.jsp?" + SettingKey.DOCCODE + "=" + (memberInfoDocCode!=null?memberInfoDocCode:"") + (wxQueryString == null || "".equals(wxQueryString) ? "" : "&" + wxQueryString) ; } json.addProperty("redirect", redirect); } this.printJson(response, json.toString()); return; } catch (DataAccessException e) { errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage():e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }catch (Exception e) { errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage():e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } finally { SpObserver.setDBtoInstance(); } } @RequestMapping(params = "m=deladdress") public void delAddress(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID); String hostUrl = SettingKey.getHostUrl(request); // 将微信corpid组装成url String wxQueryString = SettingKey.getQueryStringByWx(request); boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request); String seq = (request.getParameter(SettingKey.PAYMENTADDRESS) == null ? "0" : request.getParameter(SettingKey.PAYMENTADDRESS)); String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null ? "" : (String) session.getAttribute(SettingKey.CLTCODE)); String returnTo= request.getParameter("returnto"); //返回到哪个页面, JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); if (cltCode == null || "".equals(cltCode)) { SettingKey.setCartHintMsg(session, "请先登录,再删除地址!"); this.print(response, ""); return; } Integer ret = null; try { DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源 // 保存到数据库 ret = addressIfc.delCustomerAddress(Integer.parseInt(seq), cltCode); //如果删除的地址是已经选择的,则要把选择的标记清空 String selectedSeq = (String)session.getAttribute(SettingKey.PAYMENTADDRESS) ; //已经选择的地址 if (seq!= null && seq.equals(selectedSeq)) { session.removeAttribute(SettingKey.PAYMENTADDRESS); } if (ret != null && ret.equals(1)) { SettingKey.setCartHintMsg(session, "成功 您的地址已删除。"); String redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "account/address.jsp" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString); if (returnTo!= null && "checkoutnew".equals(returnTo)) { redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "checkoutnew/address.jsp" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString); } json.addProperty("redirect", redirect); } String redirect = ""; if (returnTo!= null && "checkoutnew".equals(returnTo)) { redirect = ""; } this.print(response,redirect); return; } catch (DataAccessException e) { errJson.addProperty("warning", e.getCause().getMessage()); json.add("error", errJson); SettingKey.setCartHintMsg(session, e.getCause().getMessage()); // this.printJson(response, json.toString()); String redirect = ""; if (returnTo!= null && "checkoutnew".equals(returnTo)) { redirect = ""; }else if(returnTo!= null&&"membercheckout".equals(returnTo)){ String memberInfoDocCode=request.getParameter(SettingKey.DOCCODE)==null?"":request.getParameter(SettingKey.DOCCODE); redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "checkoutnew/membercheckout.jsp?" + SettingKey.DOCCODE + "=" + (memberInfoDocCode!=null?memberInfoDocCode:"") + (wxQueryString == null || "".equals(wxQueryString) ? "" : "&" + wxQueryString) ; } this.print(response,redirect); return; }catch (Exception e) { errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage():e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } finally { SpObserver.setDBtoInstance(); } } @RequestMapping(params = "m=getAddressList") public void getAddressList(HttpServletRequest request, HttpServletResponse response) { HttpSession session=request.getSession(); //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID); String cltCode = (session.getAttribute(SettingKey.CLTCODE)==null?"":(String)session.getAttribute(SettingKey.CLTCODE)); JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); String seq = session.getAttribute(SettingKey.PAYMENTADDRESS) == null?"0":(String) session.getAttribute(SettingKey.PAYMENTADDRESS) ; try { DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源 JsonArray addressListJsonArray = new JsonArray(); List addressList = addressIfc.getAddress(cltCode); for (int i = 0 ; addressList != null && i < addressList.size();i++) { AddressEntity addressEntity = addressList.get(i) ; JsonObject addressEntityJsonObject = new JsonObject(); addressEntityJsonObject.addProperty("Seq", addressEntity.getSeq()); addressEntityJsonObject.addProperty("LinkMan", addressEntity.getLinkMan()!= null&& ! "".equals(addressEntity.getLinkMan())?addressEntity.getLinkMan(): addressEntity.getCltName()); addressEntityJsonObject.addProperty("Telephone", addressEntity.getTelephone()!= null&& ! "".equals(addressEntity.getTelephone())?addressEntity.getTelephone() : ""); addressEntityJsonObject.addProperty("Organization", addressEntity.getOrganization()); addressEntityJsonObject.addProperty("AddressName",addressEntity.getAddressName() ); addressEntityJsonObject.addProperty("Address",addressEntity.getAddress() ); addressEntityJsonObject.addProperty("Street",addressEntity.getStreet() ); addressEntityJsonObject.addProperty("isSelected",seq.equals(addressEntity.getSeq().toString())); addressEntityJsonObject.addProperty("Longitude",addressEntity.getLongitude()); addressEntityJsonObject.addProperty("Latitude",addressEntity.getLatitude()); addressEntityJsonObject.addProperty("CountryId",addressEntity.getCountryId()); addressEntityJsonObject.addProperty("CountryName",addressEntity.getCountryName()); addressEntityJsonObject.addProperty("ProvinceZoneId",addressEntity.getProvinceZoneId()); addressEntityJsonObject.addProperty("ProvinceName",addressEntity.getProvinceName()); addressEntityJsonObject.addProperty("CityZoneId",addressEntity.getCityZoneId()); addressEntityJsonObject.addProperty("CityName",addressEntity.getCityName()); addressEntityJsonObject.addProperty("CountyZoneId",addressEntity.getCountyZoneId()); addressEntityJsonObject.addProperty("CountyName",addressEntity.getCountyName()); addressListJsonArray.add(addressEntityJsonObject); } json.add("list", addressListJsonArray); this.printJson(response, json.toString()); return; }catch(DataAccessException e ) { errJson.addProperty("warning", e.getCause() != null ?e.getCause().getMessage():e.getMessage()); json.add("error", errJson); this.printJson(response, json.toString()); return; }catch(Exception e){ errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }finally { SpObserver.setDBtoInstance(); } } @RequestMapping(params = "m=getAddressBySeq") public void getAddressBySeq(HttpServletRequest request, HttpServletResponse response) { HttpSession session=request.getSession(); //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID); String cltCode = (session.getAttribute(SettingKey.CLTCODE)==null?"":(String)session.getAttribute(SettingKey.CLTCODE)); String seq = (request.getParameter(SettingKey.PAYMENTADDRESS)== null?"0":request.getParameter(SettingKey.PAYMENTADDRESS)) ; String ac = (request.getParameter("ac")== null?"new":request.getParameter("ac")) ; JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); SettingEntity settingEntity = null; try { DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源 settingEntity = settingIfc.getSettingEntity(request); //JsonArray addressListJsonArray = new JsonArray(); JsonObject addressJsonObject = new JsonObject(); AddressEntity addressEntity = addressIfc.getAddressByAddressId(Integer.parseInt(seq), cltCode) ; Integer defaultCountryId = null ; //缺省国家 String defaultCountryName = null ; //缺省国家 Integer defaultProvinceZoneId = null ; //缺省省份 String defaultProvinceName = null ; //缺省省份 Integer defaultCityZoneId = null ; //缺省城市 String defaultCityName = null ; //缺省城市 Integer defaultCountyZoneId = null ; //缺省区/县 String defaultCountyName = null ; //缺省区/县 Integer defaultPropertyID = null ; //楼盘编号/小区名称 if ( ac != null && "edit".equals(ac) && addressEntity != null ) { defaultCountryId = addressEntity.getCountryId() ; defaultCountryName = addressEntity.getCountryName(); defaultProvinceZoneId = addressEntity.getProvinceZoneId(); defaultProvinceName = addressEntity.getProvinceName(); defaultCityZoneId = addressEntity.getCityZoneId(); defaultCityName = addressEntity.getCityName(); defaultCountyZoneId = addressEntity.getCountyZoneId(); defaultCountyName = addressEntity.getCountyName(); defaultPropertyID = addressEntity.getPropertyId() ; } else { defaultCountryId = settingEntity.getCountryId() ; defaultCountryName = settingEntity.getCountryName(); defaultProvinceZoneId = settingEntity.getProvinceZoneId(); defaultProvinceName = settingEntity.getProvinceName(); defaultCityZoneId = settingEntity.getCityZoneId(); defaultCityName = settingEntity.getCityName(); } addressJsonObject.addProperty("seq", seq); //seq addressJsonObject.addProperty("linkman", ac != null && "edit".equals(ac)?addressEntity.getLinkMan():""); //联系人姓名 addressJsonObject.addProperty("telephone", ac != null && "edit".equals(ac)?addressEntity.getTelephone():"" ); //联系人电话 addressJsonObject.addProperty("organization", ac != null && "edit".equals(ac)?addressEntity.getOrganization():""); //公司名称 addressJsonObject.addProperty("country_id", defaultCountryId); //国家 addressJsonObject.addProperty("countryname", defaultCountryName); //国家 addressJsonObject.addProperty("zone_id", defaultProvinceZoneId); //省份 addressJsonObject.addProperty("provincename", defaultProvinceName); //省份 addressJsonObject.addProperty("city", defaultCityZoneId); //城市 addressJsonObject.addProperty("cityname", defaultCityName); //城市 addressJsonObject.addProperty("county", defaultCountyZoneId); //区/县 addressJsonObject.addProperty("countyname", defaultCountyName); //区/县 addressJsonObject.addProperty("propertyid",ac != null && "edit".equals(ac)? defaultPropertyID:0); //小区ID addressJsonObject.addProperty("propertyname", ac != null && "edit".equals(ac)?addressEntity.getPropertyName():""); //小区名称 addressJsonObject.addProperty("building", ac != null && "edit".equals(ac)?addressEntity.getBuilding():""); //楼号 addressJsonObject.addProperty("unit", ac != null && "edit".equals(ac)?addressEntity.getUnit():""); //单元号 addressJsonObject.addProperty("house", ac != null && "edit".equals(ac)?addressEntity.getHouse():""); //房屋号 addressJsonObject.addProperty("street", ac != null && "edit".equals(ac)?addressEntity.getStreet():""); //街道地址 addressJsonObject.addProperty("addressname", ac != null && "edit".equals(ac)?addressEntity.getAddressName():""); //地址 addressJsonObject.addProperty("address", ac != null && "edit".equals(ac)?addressEntity.getAddress():""); //地址 addressJsonObject.addProperty("postcode", ac != null && "edit".equals(ac)?addressEntity.getPostCode():""); //邮编 addressJsonObject.addProperty("longitude", ac != null && "edit".equals(ac)?addressEntity.getLongitude():""); //地理经度(x) addressJsonObject.addProperty("latitude", ac != null && "edit".equals(ac)?addressEntity.getLatitude():""); //地理纬度(y) json.add("list", addressJsonObject); this.printJson(response, json.toString()); return; }catch(DataAccessException e ) { errJson.addProperty("warning", e.getCause() != null ?e.getCause().getMessage():e.getMessage()); json.add("error", errJson); this.printJson(response, json.toString()); return; }catch(Exception e){ errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }finally { SpObserver.setDBtoInstance(); } } @RequestMapping(params = "m=selectaddress") public void selectAddress(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID); String hostUrl = SettingKey.getHostUrl(request); String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null ? "" : (String) session.getAttribute(SettingKey.CLTCODE)); // 将微信corpid组装成url String wxQueryString = SettingKey.getQueryStringByWx(request); boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request); String returnTo= request.getParameter("returnto"); //返回到哪个页面: checkoutnew , account String seq = (request.getParameter(SettingKey.PAYMENTADDRESS) == null ? "0" : request.getParameter(SettingKey.PAYMENTADDRESS)); JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); boolean found ; try { DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源 // 保存到数据库 found = accountIfc.hasExistsAddress(cltCode,Integer.parseInt(seq)); if (found) { if (seq != null) { session.setAttribute(SettingKey.PAYMENTADDRESS,seq.toString()) ; //保存已经选择的地址 } String redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "checkoutnew/" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString); if (returnTo != null && "account".equals(returnTo)) { redirect = hostUrl +"/shopping/"+ (isMoblieBrowser?"mobile/":"") +"account/profile.jsp"+ (wxQueryString == null||"".equals(wxQueryString)?"":"?" + wxQueryString) ; }else if(returnTo!= null&&"membercheckout".equals(returnTo)){ String memberInfoDocCode=request.getParameter(SettingKey.DOCCODE)==null?"":request.getParameter(SettingKey.DOCCODE); redirect = hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "checkoutnew/membercheckout.jsp?" + SettingKey.DOCCODE + "=" + (memberInfoDocCode!=null?memberInfoDocCode:"") + (wxQueryString == null || "".equals(wxQueryString) ? "" : "&" + wxQueryString) ; } json.addProperty("redirect", redirect); } else { errJson.addProperty("warning", "地址不存在!"); json.add("error", errJson); } this.printJson(response,json.toString()); return; } catch (DataAccessException e) { errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage():e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; }catch (Exception e) { errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage():e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } finally { SpObserver.setDBtoInstance(); } } @RequestMapping(params = "m=password") public void updatePassword(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID); String hostUrl = SettingKey.getHostUrl(request); // 将微信corpid组装成url String wxQueryString = SettingKey.getQueryStringByWx(request); boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request); String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null ? "" : (String) session.getAttribute(SettingKey.CLTCODE)); String password = request.getParameter("password") == null ? "" : request.getParameter("password"); String confirm = request.getParameter("confirm") == null ? "" : request.getParameter("confirm"); JsonObject json = new JsonObject(); JsonObject errJson = new JsonObject(); if (password == null || "".equals(password) || password.length() < 4) errJson.addProperty("password", "输入密码必须在4到20字符之间!"); if (confirm == null || "".equals(confirm) || (password != null && confirm != null && !confirm.equals(password))) errJson.addProperty("confirm", "确认密码与输入密码不一致!"); Set> it = errJson.entrySet(); if (!it.isEmpty() && it.size() != 0) { json.add("error", errJson); this.printJson(response, json.toString()); return; } Integer ret = null; try { DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ; SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源 // 保存到数据库 ret = accountIfc.changePassword(cltCode, password); if (ret != null && ret.equals(1)) { SettingKey.setCartHintMsg(session, "成功 您的密码已更新。"); json.addProperty("redirect", hostUrl + "/shopping/" + (isMoblieBrowser?"mobile/":"") + "account/account.jsp" + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString)); } this.printJson(response, json.toString()); return; } catch (DataAccessException e) { errJson.addProperty("warning", (e.getCause()!=null? e.getCause().getMessage():e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } catch (Exception e) { errJson.addProperty("warning", (e.getCause()!=null? e.getCause().getMessage():e.getMessage())); json.add("error", errJson); this.printJson(response, json.toString()); return; } finally { SpObserver.setDBtoInstance(); } } }