package com.iamberry.wechat.service.probation;

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

import com.iamberry.wechat.core.entity.order.ProbationOrder;
import com.iamberry.wechat.core.entity.probation.ProbationUserInfo;
import com.iamberry.wechat.core.entity.product.Product;
import com.iamberry.wechat.face.probation.ProbationService;
import com.iamberry.wechat.service.mapper.ProbationMapper;
import com.iamberry.wechat.service.mapper.ProductMapper;


@Service
public class ProbationServiceImpl implements ProbationService {

	@Autowired
	private ProbationMapper probationMapper;
	
	@Autowired
	private ProductMapper productMapper;
	
	
	public int addProbationUser(ProbationUserInfo prouserinfo) {
		// TODO Auto-generated method stub
		//添加订单
		ProbationOrder prouserorder = new ProbationOrder();
		
		prouserorder.setProbationOpenid(prouserinfo.getPuserOpenid());
		prouserorder.setProbationProductId(Integer.valueOf(prouserinfo.getPuserProductid()));
		//获取产品，信息
		Product product =  productMapper.selectProductByProductId(Integer.valueOf(prouserinfo.getPuserProductid()));
		prouserorder.setProbationAmount(product.getProductDiscount());
	
		prouserorder.setProbationStatus(1);
		
		probationMapper.addProbationUserOrder(prouserorder); //添加订单！
		
		return probationMapper.addProbationUser(prouserinfo);
	}
	
	/**
	 * 获取试用人，，订单
	 * @param openid 试用人信息
	 * @return
	 */
	public ProbationOrder getProbationOrderDetail(String orderid){
		return probationMapper.getProbationOrderDetail(orderid);
	}
	

}
