package org.cs.web.user;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.cs.constants.Constants;
import org.cs.core.ctl.BaseCtl;
import org.cs.mgr.user.model.MgmInviteRecord;
import org.cs.mgr.user.model.MgmUser;
import org.cs.mgr.user.service.IMgmInviteRecordService;
import org.cs.mgr.user.service.IMgmUserService;
import org.cs.util.Pager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
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.alibaba.fastjson.JSONObject;


/**
 * 
 * @ClassName: MgmUser 
 * @Description:  
 * @author: sunny_shi
 * @date: 2018-06-09 13:28:55
 */
@Controller
@RequestMapping("web/mgmInviteRecordCtl")
public class MgmInviteRecordWebCtl extends BaseCtl {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	public IMgmInviteRecordService mgmInviteRecordUserService;
	
	
	@Autowired
	private IMgmUserService mgmUserService;
	/**
	 * 
	 * <p>邀请记录</p>
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("me_record")
	public String me_record(@RequestParam(required=false)String code,ModelMap mm){
		List<MgmInviteRecord> lists;
		BigDecimal sum;
		try {
			lists = mgmInviteRecordUserService.getMgmInviteRecordsList(code);
			mm.put("lists", lists);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "app/me/me_record";	
	}
	
	/**
	 * 
	 * <p>邀请好友</p>
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("me_invite")
	public String me_invite(HttpServletRequest request,ModelMap mm){
		Map<String, String> user = (Map<String, String>) this.get(Constants.SESSION_WEB_USER);
		String imgUrl=mgmUserService.getUserQRCode(request, user.get("id"));
		mm.put("IMG_URL", imgUrl);
		mm.put("USER", user);
		return "app/me/me_invite";	
	}
}

