|
@@ -1,7 +1,22 @@
|
|
|
package com.iamberry.wechat.handles.agentInfo;
|
|
|
|
|
|
+import com.iamberry.wechat.core.entity.ResultMsg;
|
|
|
+import com.iamberry.wechat.core.entity.WechatUtils;
|
|
|
+import com.iamberry.wechat.core.entity.agentInfo.AgentTooth;
|
|
|
+import com.iamberry.wechat.core.entity.member.Member;
|
|
|
+import com.iamberry.wechat.face.agentInfo.AgentInfoService;
|
|
|
+import com.iamberry.wechat.face.member.MemberService;
|
|
|
+import com.iamberry.wechat.face.order.CodeService;
|
|
|
+import com.iamberry.wechat.tools.ResponseJson;
|
|
|
+import com.iamberry.wechat.tools.ResultInfo;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
/**
|
|
|
* 代理商逻辑处理类
|
|
|
* Created by liuzhiwei on 2017/10/11.
|
|
@@ -10,5 +25,93 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@RequestMapping("/wechat/agentTooth")
|
|
|
public class AgentToothHandler {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AgentInfoService agentInfoService;
|
|
|
+ @Autowired
|
|
|
+ private CodeService codeService;
|
|
|
+ @Autowired
|
|
|
+ private MemberService memberService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询代理商信息
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping("/select_agent_info")
|
|
|
+ public ResultMsg selectAgentInfo(HttpServletRequest request) throws Exception {
|
|
|
+ ResultMsg msg = new ResultMsg();
|
|
|
+ Member member = WechatUtils.getUserBySession(request);
|
|
|
+ //查询用户信息
|
|
|
+ Member user= memberService.getMemberByUserOpenId(member.getUserOpenid());
|
|
|
+ if (user == null) {
|
|
|
+ msg.setStatus(false);
|
|
|
+ msg.setMessage("未找到该用户!");
|
|
|
+ msg.setResultCode(ResultInfo.ERRORCODE);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ msg.setStatus(true);
|
|
|
+ msg.setResultCode(ResultInfo.SUCCESSCODE);
|
|
|
+ msg.setData(user);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 激活代理商信息
|
|
|
+ * @param request
|
|
|
+ * @param agentTooth
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping("/agent_activate")
|
|
|
+ public ResultMsg agentActivate(HttpServletRequest request, AgentTooth agentTooth) throws Exception {
|
|
|
+ ResultMsg msg = new ResultMsg();
|
|
|
+ Member member = WechatUtils.getUserBySession(request);
|
|
|
+ String phoneCode = request.getParameter("phoneCode"); //手机验证码
|
|
|
+ if (!StringUtils.isNotEmpty(agentTooth.getAgentTel())) {
|
|
|
+ msg.setResultCode(ResultInfo.ERRORCODE);
|
|
|
+ msg.setStatus(false);
|
|
|
+ msg.setMessage("电话号码不能为空!");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ //验证手机验证码是否正确
|
|
|
+ ResponseJson code = codeService.validCode(agentTooth.getAgentTel(),phoneCode);
|
|
|
+ if (code.getReturnCode() != 200) {
|
|
|
+ msg.setResultCode(ResultInfo.ERRORCODE);
|
|
|
+ msg.setStatus(false);
|
|
|
+ msg.setMessage("验证码不正确,请重新输入!");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ AgentTooth agent = new AgentTooth();
|
|
|
+ agent.setAgentTel(agentTooth.getAgentTel());
|
|
|
+ agent.setAgentStatus(1);
|
|
|
+ agent = agentInfoService.getAgentTooth(agent);
|
|
|
+ if (agent == null) {
|
|
|
+ msg.setResultCode(ResultInfo.ERRORCODE);
|
|
|
+ msg.setStatus(false);
|
|
|
+ msg.setMessage("未找到该代理商信息,请重新输入有效的电话号码!");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(agent.getAgentOpenid())) {
|
|
|
+ msg.setResultCode(ResultInfo.ERRORCODE);
|
|
|
+ msg.setStatus(false);
|
|
|
+ msg.setMessage("该代理商已被激活,无法再次激活!");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ agentTooth.setAgentOpenid(member.getUserOpenid());
|
|
|
+ //激活代理商信息
|
|
|
+ int num = agentInfoService.updateAgentOpenId(agentTooth);
|
|
|
+ if (num > 0) {
|
|
|
+ msg.setResultCode(ResultInfo.SUCCESSCODE);
|
|
|
+ msg.setStatus(true);
|
|
|
+ return msg;
|
|
|
+ } else {
|
|
|
+ msg.setResultCode(ResultInfo.ERRORCODE);
|
|
|
+ msg.setMessage("激活失败,请重新激活!");
|
|
|
+ msg.setStatus(false);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|