package com.cku.service;


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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cab.dao.CabThirdPartyMapper;
import com.cab.model.CabThirdParty;
import com.cku.core.ExecResultModel;
import com.cku.dao.CkuDvUserMapper;
import com.cku.dao.CkuUserMapper;
import com.cku.dao.SPOrderInfoMapper;
import com.cku.model.CkuDvUserModel;
import com.cku.model.CkuMatchSign;
import com.cku.model.CkuUser;


@Service("ckuMatchSignService")
public class CkuMatchSignServiceImpl {
	@Autowired
	public SPOrderInfoMapper sPOrderInfoMapper;
	
	@Autowired
	public CabThirdPartyMapper cabThirdPartyMapper;
	
	@Autowired
	public CkuDvUserMapper ckuDvUserMapper;
	
	@Autowired
	public CkuUserMapper ckuUserMapper;
	
	@Autowired
	public PublicService publicService;
	
	public Map checkSignUnfinished(Long userId){
		String dvUserId = "-1";
		String ckuId = "-1";
		Map<String,String> map = new HashMap<String,String>();
		//根据cab用户id查询出第三方表中对应的CKU账号信息
		CabThirdParty cabThirdParty = cabThirdPartyMapper.selectByUserId(new Long(userId).intValue());
		if(cabThirdParty != null){
			dvUserId = cabThirdParty.getCkuUserId();
		}
		//根据CKU账号id查询出CKU账号信息
		CkuDvUserModel ckuDvUserModel = ckuDvUserMapper.getckuMemberByUserId(dvUserId);
		if(ckuDvUserModel != null){
			ckuId = ckuDvUserModel.getCkuId();
		}
		int i=sPOrderInfoMapper.checkSignUnfinished(ckuId);
		//是否有未支付订单
		map.put("order", i>0?"yes":"no");
		List<CkuUser> eventIntroduce = ckuUserMapper.getUserMessage(ckuId);
		//是否是新会员
		map.put("newVip", eventIntroduce!=null&&"0".equals(eventIntroduce.get(0).getIsnewuser())?"yes":"no");
		boolean flag = publicService.memberStatus(ckuId);
		//会员是否有效
		map.put("rightVip", flag?"yes":"no");
		return map;
	}
	
	public String addSign(String userNo,String dogId,String trainId,Long matchId,Long projectId){
		ExecResultModel<CkuMatchSign> resultModel = new ExecResultModel<CkuMatchSign>();
		//ckuMatchSignMapper.insertSelective(record);
		
		resultModel.setItems(null);
		resultModel.setTotal((long) 0);
		resultModel.setRc(0);
		return resultModel.getToJson();
	}

}
