package com.iamberry.wechat.service.order;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.iamberry.wechat.core.entity.statictics.StatisticsSalesOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iamberry.app.tool.log.RatFWLogger;
import com.iamberry.wechat.core.entity.admin.ShopSystemRule;
import com.iamberry.wechat.core.entity.drp.PlaceInfo;
import com.iamberry.wechat.core.entity.drp.PlaceLogs;
import com.iamberry.wechat.core.entity.flow.TemplateFlowInfo;
import com.iamberry.wechat.core.entity.flow.TemplateReward;
import com.iamberry.wechat.core.entity.member.CashLog;
import com.iamberry.wechat.core.entity.member.Member;
import com.iamberry.wechat.core.entity.order.Order;
import com.iamberry.wechat.core.entity.order.OrderItem;
import com.iamberry.wechat.core.entity.order.OrderRebackMoney;
import com.iamberry.wechat.core.entity.reback.RebackInfo;
import com.iamberry.wechat.core.entity.relationship.DealerRelation;
import com.iamberry.wechat.core.entity.relationship.WdRelation;
import com.iamberry.wechat.core.entity.rewards.RewardsLog;
import com.iamberry.wechat.core.entity.rewards.SalesLog;
import com.iamberry.wechat.face.order.AdminOrderService;
import com.iamberry.wechat.service.mapper.RebackInfoMapper;
import com.iamberry.wechat.service.mapper.RewardsMapper;
import com.iamberry.wechat.service.mapper.SalesLogMapper;
import com.iamberry.wechat.service.mapper.TemplateFlowInfoMapper;
import com.iamberry.wechat.service.member.dao.CashLogDao;
import com.iamberry.wechat.service.order.dao.AdminOrderDao;
import com.iamberry.wechat.service.relationship.Dao.DealerRelationDao;
import com.iamberry.wechat.service.relationship.Dao.WdRelationDao;
import com.iamberry.wechat.tools.ResultInfo;


@Service
public class AdminOrderServiceImpl implements AdminOrderService {

	@Autowired
	private AdminOrderDao adminOrderDao;
	
	@Autowired
	private CashLogDao cashLogDao;
	
//	@Autowired
//	private WxService wxService;
	
	@Autowired
	private RebackInfoMapper  rebackInfoMapper;
	
	@Autowired
	private DealerRelationDao dealerRelationDao;
	
	@Autowired
	private WdRelationDao wdRelationDao;
	
	@Autowired
	private TemplateFlowInfoMapper templateFlowInfoMapper;
	
	@Autowired
	private RatFWLogger logger;
	
	@Autowired
	private SalesLogMapper salesLogMapper;
	
	@Autowired
	private RewardsMapper rewardsMapper;
	
	/**
	 * 根据订单编号，获取该订单的返利信息
	 * @param orderId  订单编号
	 * @return List<OrderRebackMoney> 返利信息
	 */
	public List<OrderRebackMoney> selectOrderRebackByOrderId(String orderId){
		return this.adminOrderDao.selectOrderRebackByOrderId(orderId);

	}
	
	public List<Order> selectShopOrder(Order order) {
		// TODO Auto-generated method stub
		order.getPage().initRecordBegin();
		/*if(order.getBeginDate()!=null){
			try {
				endDate=new Date(DateTimeUtil.getDayEnd(order.getBeginDate()));
			} catch (ParseException e) {
				endDate=DateTimeUtil.addDay(order.getBeginDate(), 1);
				e.printStackTrace();
			}
			order.setEndDate(endDate);
		}*/
		return this.adminOrderDao.selectShopOrder(order);
	}

	
	public List<Order> selectShopOrderByOrderId(Order order) {
		// TODO Auto-generated method stub
		return this.adminOrderDao.selectShopOrderByOrderId(order);
	}

	
	public Order getShopOrderByOrderId(String orderId) {
		// TODO Auto-generated method stub
		return this.adminOrderDao.getShopOrderByOrderId(orderId);
	}

	
	public List<OrderItem> getShopOrderItemByOrderId(String orderId) {
		// TODO Auto-generated method stub
		return this.adminOrderDao.getShopOrderItemByOrderId(orderId);
	}

	
	public Integer selectShopOrderCount(Order order) {
		// TODO Auto-generated method stub
		 int count = this.adminOrderDao.selectShopOrderCount(order);
		 return	count = count % order.getPage().getPageSize() == 0? count/order.getPage().getPageSize():(count/order.getPage().getPageSize())+1;
	}

	
	public Order selectOrderStatusByOrderId(String orderId) {
		// TODO Auto-generated method stub
		return this.adminOrderDao.selectOrderStatusByOrderId(orderId);
	}

	
	public boolean updateOrderStatusByOrderId(Order order) {
		// TODO Auto-generated method stub
		return this.adminOrderDao.updateOrderStatusByOrderId(order)>= 1 ? true : false;
	}

	
	public boolean deliverOrderByOrderId(Order order) {
		// TODO Auto-generated method stub
		return this.adminOrderDao.deliverOrderByOrderId(order) >= 1 ? true : false;
	}

	
	public Integer updateOrderDeliver(Order order) {
		// TODO Auto-generated method stub
		return adminOrderDao.updateOrderDeliver(order);
	}

	
	public boolean updateOrderAdminRemarkByOrderId(String remark,
			String orderId, Integer remarkColor) {
		// TODO Auto-generated method stub
		Order order = new Order();
		order.setSalesAdminRemark(remark);
		order.setSalesColorType(remarkColor);
		order.setSalesOrderid(orderId);
		return this.adminOrderDao.updateOrderAdminRemarkByOrderId(order) >= 1 ? true : false;
	}

	
	public List<Order> selectOrderByIntegral(Order order) {
		// TODO Auto-generated method stub
		return this.adminOrderDao.selectOrderByIntegral(order);
	}

	
	public void updateOrderIntegral(Order order, ShopSystemRule shopSystemRule) {
		// TODO Auto-generated method stub
		//（微代理，自己奖励积分公式：购买台数*每台奖励积分数）
		if (null == order) {
			return;
		}
		logger.info("——返利过程:返利start,订单号:" + order.getSalesOrderid() + "——");
		if (null == order.getSalesOpenid() || "".equals(order.getSalesOpenid())) {
			logger.info("——返利过程:此订单的openId为空,订单号:" + order.getSalesOrderid() + "——");
			return;
		}
		
		Member member = this.adminOrderDao.getUserByOpenId(order.getSalesOpenid());
		if (null == member) {
			logger.info("——返利过程:没有查到该用户,订单号:" + order.getSalesOrderid() + "——");
			return;
		}
		
		//修改订单是否入账的状态，将未入账变为已入账
		this.adminOrderDao.updateOrderIntegral(order.getSalesOrderid());
		
		//将返利表中待入账改为已入账
		RebackInfo rabackInfo = new RebackInfo();
		rabackInfo.setOrderId(order.getSalesOrderid());
		rabackInfo.setStatus(2);
		rebackInfoMapper.updateStatus(rabackInfo);
		
		//查询是否有微代理返利
		WdRelation wdRelation = wdRelationDao.getWdRelationByOpenid(order.getSalesOpenid());
		
		//一个订单中可能有多个产品，每个产品可能有一个单独的返利类型，所以需要循环判断产品类型，根据数量返利
		if (null != order.getOrderItemList() && order.getOrderItemList().size() > 0) {
			for (OrderItem orderItem : order.getOrderItemList()) {
				//将order重新封装，使根据产品返利更清晰，每次封装只封装一个产品类型
				List<OrderItem> orderItemList = new ArrayList<OrderItem>();
				orderItemList.add(orderItem);
				Order orderInfo = new Order();
				orderInfo.setSalesOrderid(order.getSalesOrderid());
				orderInfo.setSalesOpenid(order.getSalesOpenid());
				orderInfo.setItemSum(orderItem.getItemNum());
				orderInfo.setOrderItemList(orderItemList);

				//如果没有模板id，则是自己关注
				if ((null == member.getTemplateId() || "".equals(member.getTemplateId())) && member.getUserResType().intValue() != 3) {
					//如果是第一层级，则微代理返利表为空，不需要返利
					if (wdRelation == null) {
						return;
					}
					//获取返利模板id
					int templateId = shopSystemRule.getRuleNum().intValue();
					member.setTemplateId(templateId);
					//微代理返利
					this.agencyRebate(wdRelation, member, orderInfo);
				} else {
					int levelSum = 0;
					if (wdRelation != null && null != member.getTemplateId() && !"".equals(member.getTemplateId())) {
						//微代理返利
						this.agencyRebate(wdRelation, member, orderInfo);
						levelSum = wdRelation.getWdCount();
					}
					//查询商户层
					if (null != member.getUserDealers() && !"".equals(member.getUserDealers())) {
						DealerRelation dealerRelation = dealerRelationDao.getDealerRelationById(member.getUserDealers());
						if (dealerRelation != null) {
							this.commercialRebate(dealerRelation, member, orderInfo, levelSum);
						}
					}
				}
				logger.info("——返利过程:返利end,订单号:" + order.getSalesOrderid() + "——");
			}
		} else {
			logger.info("——返利过程:此订单的订单项为空,订单号:" + order.getSalesOrderid() + "——");
			return;
		}
		
		
	}
	
	//查询奖励金额
	public int getRewardMoney(Order orderInfo, Integer placeId, Integer roleId) {
		int rewardMoney = 0;
		//这次售出的该类型产品的总数
		int itemSum = orderInfo.getItemSum();
		//之前售出的该类型商品数量
		int salesNum = 0;
		//获取订单项的产品类型id
		OrderItem orderItem = orderInfo.getOrderItemList().get(0);
		Integer productType = orderItem.getItemProductType();
		SalesLog salesLog = new SalesLog();
		RewardsLog rewardsLog = new RewardsLog();
		salesLog.setSalesProductType(productType);
		salesLog.setSalesPlaceId(placeId);
		
		TemplateReward templateReward = new TemplateReward();
		templateReward.setRewardStatus(1);
		templateReward.setRewardProductType(productType);
		templateReward.setRewardRoleId(roleId);
		
		//查询购买人上线是否卖出过该类型商品
		salesLog = salesLogMapper.getSalesInfo(salesLog);
		if (salesLog == null) {
			salesNum = 0;
			templateReward.setRewardNum(0);
		} else {
			salesNum = salesLog.getSalesNum();
			templateReward.setRewardNum(salesLog.getSalesNum());
		}
		//按产品类型查询奖励信息，属于逻辑上要奖励的值
		TemplateReward templateRewardMin = templateFlowInfoMapper.selectRewardMin(templateReward);
		
		//按产品类型查询大于此数量的奖励信息
		List<TemplateReward> rewardList = templateFlowInfoMapper.selectRewardList(templateReward);
		
		//判断已卖出数量是否已经超过奖励任务限制的最大数量，如果是，则按最大奖励金额奖励
		if (templateRewardMin != null && (rewardList == null || rewardList.size() == 0)) {
			rewardMoney = templateRewardMin.getRewardMoney() * itemSum;
		}
		if (rewardList != null && rewardList.size() > 0) {
			for (int i = 0;i < rewardList.size();i++) {
				TemplateReward templateRewardMax = rewardList.get(i);
				//判断之前售出的和现在售出的之和是否比下一个奖励任务的数量大，如果小，则全部按这个任务奖励
				if (templateRewardMin != null && (salesNum + itemSum) < templateRewardMax.getRewardNum()) {
					rewardMoney += templateRewardMin.getRewardMoney() * itemSum;
					break;
					//判断之前售出的和现在售出的之和是否比下一个奖励任务的数量大，如果大，则部分数量按之前查出的金额奖励其余的按下一个任务奖励
				} else if (templateRewardMin != null && (salesNum + itemSum) >= templateRewardMax.getRewardNum() && (i +1) == rewardList.size()) {
					int num = templateRewardMax.getRewardNum() - salesNum;
					int sum = salesNum + itemSum - templateRewardMax.getRewardNum() + 1;
					rewardMoney += templateRewardMin.getRewardMoney() * (num - 1) + templateRewardMax.getRewardMoney() * sum;
					break;
				} else if (templateRewardMin != null && (salesNum + itemSum) >= templateRewardMax.getRewardNum()) {
					int num = templateRewardMax.getRewardNum() - salesNum;
					rewardMoney += templateRewardMin.getRewardMoney() * (num - 1) + templateRewardMax.getRewardMoney();
					salesNum += num;
					itemSum -= num;
					//第一轮奖励完成后，重新查询最小奖励金额，再进行下次循环奖励
					templateReward.setRewardStatus(1);
					templateReward.setRewardProductType(productType);
					templateReward.setRewardRoleId(roleId);
					templateReward.setRewardNum(salesNum);
					templateRewardMin = templateFlowInfoMapper.selectRewardMin(templateReward);
					//之前销售没有达到奖励任务，但加上这次销售的机器就达到奖励任务时，则先将没有达到的数量填满，这一轮只奖励一台
				} else if (templateRewardMin == null && (salesNum + itemSum) >= templateRewardMax.getRewardNum()) {
					int num = templateRewardMax.getRewardNum() - salesNum;
					rewardMoney += templateRewardMax.getRewardMoney();
					salesNum += num;
					itemSum -= num;
					//第一轮奖励完成后，重新查询最小奖励金额，再进行下次循环奖励
					templateReward.setRewardStatus(1);
					templateReward.setRewardProductType(productType);
					templateReward.setRewardRoleId(roleId);
					templateReward.setRewardNum(salesNum);
					templateRewardMin = templateFlowInfoMapper.selectRewardMin(templateReward);
					//判断之前售出的和现在售出的之和是否比下一个奖励任务的数量大，如果大，则部分数量按之前查出的金额奖励其余的按最大任务
				}
			}
		}
		rewardsLog.setLogsMoney(rewardMoney);
		rewardsLog.setLogsNum(orderInfo.getItemSum());
		rewardsLog.setLogsPlaceId(placeId);
		rewardsLog.setLogsProductType(productType);
		rewardsLog.setLogsDesc("订单" + orderInfo.getSalesOrderid() + "奖励任务奖励金额");
		
		//将该奖励插入奖励记录表
		rewardsMapper.insertRewardsLog(rewardsLog);
		
		SalesLog salesLogInfo = new SalesLog();
		salesLogInfo.setSalesPlaceId(placeId);
		salesLogInfo.setSalesProductType(productType);
		salesLogInfo.setSalesNum(orderInfo.getItemSum());
		if (salesLog == null) {
			salesLogMapper.insertSalesLog(salesLogInfo);
		} else {
			salesLogMapper.updateSalesLog(salesLogInfo);
		}
		return rewardMoney;
	}
	
	//给微代理返利
	public void agencyRebate(WdRelation wdRelation,Member member, Order order) {
		int itemSum = order.getItemSum();
		//判断返利第一层级是否为空，如果不为空则返利
		if (null != wdRelation.getWdFirst() && !"".equals(wdRelation.getWdFirst())) {
			this.updateAgencyRebate(order, wdRelation.getWdFirst(), member.getTemplateId(), 1, 2, itemSum, 1, 4, null);
		}
		//判断返利第二层级是否为空，如果不为空则返利
		if (null != wdRelation.getWdSecond() && !"".equals(wdRelation.getWdSecond())) {
			this.updateAgencyRebate(order, wdRelation.getWdSecond(), member.getTemplateId(), 2, 2, itemSum, 1, 4, null);
		}
		//判断返利第三层级是否为空，如果不为空则返利
		if (null != wdRelation.getWdThird() && !"".equals(wdRelation.getWdThird())) {
			this.updateAgencyRebate(order, wdRelation.getWdThird(), member.getTemplateId(), 3, 2, itemSum, 1, 4, null);
		}
		//判断返利第四层级是否为空，如果不为空则返利
		if (null != wdRelation.getWdFourth() && !"".equals(wdRelation.getWdFourth())) {
			this.updateAgencyRebate(order, wdRelation.getWdFourth(), member.getTemplateId(), 4, 2, itemSum, 1, 4, null);
		}
	}
	
	//修改微代理返利
	public void updateAgencyRebate(Order order, int superiorId, int templateId, int flowLevel, 
			int flowType,int itemSum,int type,int resType, Integer rewardsMoney) {
		//获取订单项的产品类型id
		OrderItem orderItem = order.getOrderItemList().get(0);
		Integer productType = orderItem.getItemProductType();
		//获取返利金额
		Integer money = getRebateMoney(templateId, flowLevel, flowType, null, productType);
		if (money <= 0) {
			return;
		}
		//添加返利金额
		String openId = this.updateUserInfo(superiorId, money, itemSum, rewardsMoney);
		//将该操作添加到微代理返利金额记录表中
		this.addUserCashLogs(openId, money, type, order, resType, itemSum,rewardsMoney);
	}
	
	
	//根据条件获取返利金额
	public int getRebateMoney(int templateId, int flowLevel, int flowType, Integer flowRoleId, Integer productType) {
		TemplateFlowInfo templateFlowInfo = new TemplateFlowInfo();
		templateFlowInfo.setTemplateId(templateId);
		templateFlowInfo.setFlowLevel(flowLevel);
		templateFlowInfo.setFlowType(flowType);
		templateFlowInfo.setFlowProductType(productType);
		if (flowRoleId != null) {
			templateFlowInfo.setFlowRoleId(flowRoleId);
		}
		//查询返利节点表金额
		templateFlowInfo = templateFlowInfoMapper.getTemplateFlowInfo(templateFlowInfo);
		if (null == templateFlowInfo) {
			return 0;
		} else {
			return templateFlowInfo.getFlowMoney();
		}
	}
	
	//商户层返利
	public void updateCommercialRebate(int templateId, int flowLevel, int flowType, int itemSum, 
			int placeId, int type, int resType, Order order) {
		//获取订单项的产品类型id
		OrderItem orderItem = order.getOrderItemList().get(0);
		Integer productType = orderItem.getItemProductType();
		//根据id获取渠道信息
		PlaceInfo placeInfo = adminOrderDao.getOnePlaceInfo(placeId);
		int rewardMoney = this.getRewardMoney(order, placeId, placeInfo.getRoleId());
		//获取返利金额
		Integer money = this.getRebateMoney(templateId, flowLevel, flowType,placeInfo.getRoleId(),productType);
		if (money <= 0) {
			return;
		}
		//添加返利金额
		this.updatePlaceInfo(placeId, money, itemSum,rewardMoney);
		
		//添加日志时将奖励金额也保存到日志中
		money += rewardMoney;
		
		//将该操作添加到线下返利金额记录表中
		this.addPlaceLogs(placeId, money, type, order, resType, itemSum);
	}
	
	//商户层返利
	public void commercialRebate(DealerRelation dealerRelation, Member member, Order order, int levelSum) {
		int itemSum = order.getItemSum();
		int flowLevel = dealerRelation.getDealerCount() + levelSum;
		//判断返利第一层级是否为空，如果不为空则返利
		if (null != dealerRelation.getDealerFirst() && !"".equals(dealerRelation.getDealerFirst())) {
			this.updateCommercialRebate(member.getTemplateId(), flowLevel, 1, itemSum, dealerRelation.getDealerFirst(), 1, 1, order);
		}
		//判断返利第二层级是否为空，如果不为空则返利
		if (null != dealerRelation.getDealerSecond() && !"".equals(dealerRelation.getDealerSecond())) {
			this.updateCommercialRebate(member.getTemplateId(), flowLevel - 1, 1, itemSum, dealerRelation.getDealerSecond(), 1, 1, order);
		}
		//判断返利第三层级是否为空，如果不为空则返利
		if (null != dealerRelation.getDealerThird() && !"".equals(dealerRelation.getDealerThird())) {
			this.updateCommercialRebate(member.getTemplateId(), flowLevel - 2, 1, itemSum, dealerRelation.getDealerThird(), 1, 1, order);
		}
		//判断返利第四层级是否为空，如果不为空则返利
		if (null != dealerRelation.getDealerFourth() && !"".equals(dealerRelation.getDealerFourth())) {
			this.updateCommercialRebate(member.getTemplateId(), flowLevel - 3, 1, itemSum, dealerRelation.getDealerFourth(), 1, 1, order);
		}
		//判断返利第五层级是否为空，如果不为空则返利
		if (null != dealerRelation.getDealerFifth() && !"".equals(dealerRelation.getDealerFifth())) {
			this.updateCommercialRebate(member.getTemplateId(), flowLevel - 4, 1, itemSum, dealerRelation.getDealerFifth(), 1, 1, order);
		}
		//判断返利第六层级是否为空，如果不为空则返利
		if (null != dealerRelation.getDealerSixth() && !"".equals(dealerRelation.getDealerSixth())) {
			this.updateCommercialRebate(member.getTemplateId(), flowLevel - 5, 1, itemSum, dealerRelation.getDealerSixth(), 1, 1, order);
		}
	}
	
	//修改用户可用金额信息
	public String updateUserInfo(int userId, double num, int itemSum, Integer rewardsMoney) {
		//根据推荐人id查询该推荐人
		Member referUser = this.adminOrderDao.getUserByUserRefereeid(userId);
		if (referUser != null) {
			//微代理对象
			Member agentMember = new Member();
			//微代理奖励金额
			int agentIntegral = 0;
			//计算微代理奖励金额，如果有销售奖励，则加上该奖励金额
			if (null != rewardsMoney) {
				agentIntegral = (int)(itemSum * num) + rewardsMoney.intValue();
			} else {
				agentIntegral = (int)(itemSum * num);
			}
			agentMember.setUserIncome(agentIntegral);
			agentMember.setUserId(userId);
			//给微代理奖励金额
			this.adminOrderDao.updateUserByUserId(agentMember);
			return referUser.getUserOpenid();
		}
		return "";
	}
	
	//封装在用户现金记录表中插入一条数据
	public void addUserCashLogs(String openid, double num, int type, Order order, int resType,int itemSum, Integer rewardsMoney) {
		CashLog cashLog = new CashLog();
		cashLog.setCashLogsOpenid(openid);
		//如果存在销售奖励金额，则添加
		if (null == rewardsMoney) {
			cashLog.setCashLogsNum((int)(num*itemSum));
		} else {
			cashLog.setCashLogsNum((int)(num*itemSum) + rewardsMoney.intValue());
		}
		
		cashLog.setCashLogsType(type);
		String rebateOrder = rebateOrderTemplate(order.getSalesOpenid(),order.getSalesOrderid(),
				openid,String.valueOf(cashLog.getCashLogsNum()));
		cashLog.setCashLogsIntroduction(rebateOrder);
		cashLog.setCashLogsResType(resType);
		cashLog.setCashLogsCreateDate(new Date());
		cashLog.setCashLogsOrderid(order.getSalesOrderid());
		this.cashLogDao.addCashLog(cashLog);
	}
	
	//修改线下渠道的返利金额
	public void updatePlaceInfo(int placeId, double num, int itemSum, double rewardMoney) {
		PlaceInfo placeInfo = new PlaceInfo();
		placeInfo.setId(placeId);
		placeInfo.setAmount((int)(num*itemSum + rewardMoney));
		//修改金额
		this.adminOrderDao.updatePlaceInfo(placeInfo);
	}
	
	//封装在线下代理现金记录表中插入一条数据
	public void addPlaceLogs(int placeId, double num, int type, Order order, int resType, int itemSum) {
		try {
			PlaceLogs placeLogs = new PlaceLogs();
			placeLogs.setPlaceId(placeId);
			placeLogs.setNums((int)(num*itemSum));
			placeLogs.setType(type);
			String rebateOrder = rebateOrderTemplate(order.getSalesOpenid(),order.getSalesOrderid(),
					String.valueOf(placeLogs.getPlaceId()),String.valueOf(placeLogs.getNums()));
			placeLogs.setIntroduction(rebateOrder);
			placeLogs.setResType(resType);
			placeLogs.setCreateDate(new Date());
			this.adminOrderDao.insertPlaceLogs(placeLogs);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 构建简介模板
	 * @param str1   用户openid
	 * @param str2	orderid
	 * @param str3	返利对象openid或是id
	 * @param str4	多少钱
	 * @return
	 */
	public String rebateOrderTemplate(String str1, String str2, String str3, String str4) {
		String rebateOrder = ResultInfo.rebateOrderText;
		try {
			if (null != rebateOrder && !"".equals(rebateOrder)) {
				rebateOrder = rebateOrder.replace("{1}", str1);
				rebateOrder = rebateOrder.replace("{2}", str2);
				rebateOrder = rebateOrder.replace("{3}", str3);
				rebateOrder = rebateOrder.replace("{4}", str4);
			}
			return rebateOrder;
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}

	
	@Override
	public Integer getOrderNum(Order order) {
		// TODO Auto-generated method stub
		return this.adminOrderDao.getOrderNum(order);
	}

	@Override
	public ShopSystemRule getReluByRid(int rId) {
		// TODO Auto-generated method stub
		return this.adminOrderDao.getReluByRid(rId);
	}

	@Override
	public String selectSalesOpenIdByOrderId(String orderId) {
		// TODO Auto-generated method stub
		return adminOrderDao.selectSalesOpenIdByOrderId(orderId);
	}

	@Override
	public List<Order> getOrderByCreateTime(Order order) {
		// TODO Auto-generated method stub
		return adminOrderDao.getOrderByCreateTime(order);
	}
	@Override
	public List<Order> getOrderByCreateTimeAndFiveMinutes(Order order) {
		// TODO Auto-generated method stub
		return adminOrderDao.getOrderByCreateTimeAndFiveMinutes(order);
	}
	
	@Override
	public Integer updateOrderByOrderId(List<String> list) {
		// TODO Auto-generated method stub
		return adminOrderDao.updateOrderByOrderId(list);
	}

	@Override
	public Integer updateOrderStatusByOrderIdAndToStatus(Order order) {
		// TODO Auto-generated method stub
		return adminOrderDao.updateOrderStatusByOrderIdAndToStatus(order);
	}

	@Override
	public List<OrderItem> getItemsNumByOrderId(String orderId) {
		// TODO Auto-generated method stub
		return adminOrderDao.getItemsNumByOrderId(orderId);
	}

	@Override
	public List<Order> getOrderList(Order order) {
		// TODO Auto-generated method stub
		return adminOrderDao.getOrderList(order);
	}

	@Override
	public Integer updateOrderListStatus(List<Order> list) {
		// TODO Auto-generated method stub
		return adminOrderDao.updateOrderListStatus(list);
	}

	@Override
	public Integer updateUserByUserId(Member member) {
		// TODO Auto-generated method stub
		return adminOrderDao.updateUserByUserId(member);
	}

	@Override
	public Integer addCashLog(CashLog cashLog) {
		// TODO Auto-generated method stub
		return cashLogDao.addCashLog(cashLog);
	}

	/**
	 * 获取销售数量
	 * @param map
	 * @return
	 */
	public Integer getSalesVolumes(Map map){
		return  adminOrderDao.getSalesVolumes(map);
	}

	/**
	 * 获取个人已购买的机器台数
	 * @param map
	 * @return
	 */
	public Integer getPersonalPurchase(Map map){
		return  adminOrderDao.getPersonalPurchase(map);
	}

	/**
	 * 获取个人消费总额
	 * @param map
	 * @return
	 */
	public Integer getTotalConsume(Map map){
		return  adminOrderDao.getTotalConsume(map);
	}

	/**
	 * 获取已购买的总人数
	 * @param member
	 * @return
	 */
	public Integer getAlreadyNumber(Member member){
		return  adminOrderDao.getAlreadyNumber(member);
	}

	/**
	 * 获取购买的机器台数
	 * @param member
	 * @return
	 */
	public Integer getUnitsNumber(Member member){
		return  adminOrderDao.getUnitsNumber(member);
	}

	/**
	 * 获取总的消费金额
	 * @param member
	 * @return
	 */
	public Integer getTotalAmount(Member member){
		return  adminOrderDao.getTotalAmount(member);
	}

	@Override
	public List<StatisticsSalesOrder> listWeekNum() {
		return adminOrderDao.listWeekNum();
	}

	@Override
	public List<StatisticsSalesOrder> listLastWeekNum() {
		return adminOrderDao.listLastWeekNum();
	}

	@Override
	public List<StatisticsSalesOrder> listMonthNum(StatisticsSalesOrder salesOrder) {
		return adminOrderDao.listMonthNum(salesOrder);
	}

	@Override
	public List<StatisticsSalesOrder> listYearNum(StatisticsSalesOrder salesOrder) {
		return adminOrderDao.listYearNum(salesOrder);
	}
}
