Prechádzať zdrojové kódy

添加了激活代理商接口

liuzhiwei 7 rokov pred
rodič
commit
55a72f9720

+ 14 - 0
tooth-wechat-interface/src/main/java/com/iamberry/wechat/face/agentInfo/AgentInfoService.java

@@ -58,4 +58,18 @@ public interface AgentInfoService {
      * @return
      */
     AgentConfig getAgentConfig(AgentConfig config);
+
+    /**
+     * 修改代理商信息
+     * @param agentTooth
+     * @return
+     */
+    Integer updateAgentTooth(AgentTooth agentTooth);
+
+    /**
+     * 激活代理商
+     * @param agentTooth
+     * @return
+     */
+    Integer updateAgentOpenId(AgentTooth agentTooth);
 }

+ 10 - 0
tooth-wechat-service/src/main/java/com/iamberry/wechat/service/agentInfo/AgentInfoServiceImpl.java

@@ -53,4 +53,14 @@ public class AgentInfoServiceImpl implements AgentInfoService {
     public AgentConfig getAgentConfig(AgentConfig config) {
         return agentInfoMapper.getAgentConfig(config);
     }
+
+    @Override
+    public Integer updateAgentTooth(AgentTooth agentTooth) {
+        return agentInfoMapper.updateAgentTooth(agentTooth);
+    }
+
+    @Override
+    public Integer updateAgentOpenId(AgentTooth agentTooth) {
+        return agentInfoMapper.updateAgentOpenId(agentTooth);
+    }
 }

+ 14 - 0
tooth-wechat-service/src/main/java/com/iamberry/wechat/service/mapper/AgentInfoMapper.java

@@ -58,4 +58,18 @@ public interface AgentInfoMapper {
      * @return
      */
     AgentConfig getAgentConfig(AgentConfig config);
+
+    /**
+     * 修改代理商信息
+     * @param agentTooth
+     * @return
+     */
+    Integer updateAgentTooth(AgentTooth agentTooth);
+
+    /**
+     * 激活代理商
+     * @param agentTooth
+     * @return
+     */
+    Integer updateAgentOpenId(AgentTooth agentTooth);
 }

+ 53 - 0
tooth-wechat-service/src/main/java/com/iamberry/wechat/service/mapper/agentInfoMapper.xml

@@ -168,7 +168,60 @@
             <if test="agentId !=null and agentId !=''">
                 AND  agent_id = #{agentId}
             </if>
+            <if test="agentTel != null and agentTel != ''">
+                and agent_tel = #{agentTel}
+            </if>
+            <if test="agentStatus != null and agentStatus != ''">
+                and agent_status = #{agentStatus}
+            </if>
         </where>
     </select>
 
+    <!-- 修改代理商信息 -->
+    <update id="updateAgentTooth" parameterType="AgentTooth">
+      update
+        tb_iamberry_agent_agentinfo
+      <set>
+          <if test="agentName != null and agentName != ''">
+              agent_name = #{agentName},
+          </if>
+          <if test="agentAddr != null and agentAddr != ''">
+              agent_addr = #{agentAddr},
+          </if>
+          <if test="agentTel != null and agentTel != ''">
+              agent_tel = #{agentTel},
+          </if>
+          <if test="agentRoleId != null and agentRoleId != ''">
+              agent_role_id = #{agentRoleId},
+          </if>
+          <if test="agentStatus != null and agentStatus != ''">
+              agent_status = #{agentStatus},
+          </if>
+          <if test="agentStatus != null and agentStatus != ''">
+              agent_openid = #{agentOpenid}
+          </if>
+      </set>
+      <where>
+          <if test="agentId != null and agentId != ''">
+              agent_id = #{agentId}
+          </if>
+          <if test="agentTel != null and agentTel != ''">
+              and agent_tel = #{agentTel}
+          </if>
+      </where>
+    </update>
+
+    <!-- 激活代理商 -->
+    <update id="updateAgentOpenId" parameterType="AgentTooth">
+        update
+          tb_iamberry_agent_agentinfo
+        <set>
+            <if test="agentOpenid != null and agentOpenid != ''">
+                agent_openid = #{agentOpenid}
+            </if>
+        </set>
+        <where>
+              agent_tel = #{agentTel}
+        </where>
+    </update>
 </mapper>

+ 103 - 0
tooth-wechat-web/src/main/java/com/iamberry/wechat/handles/agentInfo/AgentToothHandler.java

@@ -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;
+        }
+    }
 }