package com.iamberry.wechat.handles.drp;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

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.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iamberry.wechat.core.entity.drp.ApplyUserInfo;
import com.iamberry.wechat.face.drp.PlaceInfoService;

/**
 * @description 后台的分销管理
 * @author 欧阳明
 * @date 2016-4-21
 */

@Controller
@RequestMapping("/agent/drp")
public class DrpAgentHandler {
	@Autowired
	private PlaceInfoService placeInfoService;
	
	/**
	 * 我要代理
	 * 2016年12月14日10:04:55
	 * @param req
	 * @param res
	 */
	@ResponseBody
	@RequestMapping(value = "/addAgent", method = RequestMethod.POST)
	public String addAgent(HttpServletRequest request){
		String userName = request.getParameter("userName");
		String userTel = request.getParameter("userTel");
		String userMail = request.getParameter("userMail");
		String userCity = request.getParameter("userCity");
		String userTC = request.getParameter("userTC");
		ApplyUserInfo applyUserInfo = new ApplyUserInfo();
		
		if(userName == null || userName.equals("")){
			return "{\"status\":\"false\"}" ;
		}
		if(userTel == null || userTel.equals("")){
			return "{\"status\":\"false\"}" ;
		}
		if(userMail == null || userMail.equals("")){
			userMail = "mumu@qq,com";
		}
		if(userCity == null || userCity.equals("")){
			userCity = "深圳" ;
		}
		if(userTC == null || userTC.equals("")){
			userTC = "3" ;
		}
		applyUserInfo.setUserName(userName);
		applyUserInfo.setUserTel(userTel);
		applyUserInfo.setUserCity(userCity);
		applyUserInfo.setUserMail(userMail);
		applyUserInfo.setUserDate(new Date());
		applyUserInfo.setUserTc(userTC);
		Integer falg = placeInfoService.selectApplyAgentByTel(applyUserInfo.getUserTel());
		if(falg != null  ){
			if( falg > 0){
				return "{\"status\":\"false\",\"info\":\"已申请用户不能重复申请！\"}" ;
			}
		}
		Integer msg = placeInfoService.addApplyAgent(applyUserInfo);
		if(msg > 0){
			return "{\"status\":\"true\",\"info\":\"感谢您的加入！\"}" ;
		}else{
			return "{\"status\":\"false\",\"info\":\"申请失败！\"}" ;
		}
		
	}
}