<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper 
PUBLIC 
	"-//mybatis.org//DTD Mapper 3.0//EN" 
	"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 命名，每一个映射对象不一样
	namespace:必须与对应的接口全类名一致
 -->
<mapper namespace="com.iamberry.wechat.service.mapper.AgentMemberMapper">

	<sql id="agentMemberAllField">
		u.user_id userId,
		u.user_openid userOpenid,
		u.user_head userHead,
		u.user_nickname userNickname,
		u.user_surplus_integral userSurplusIntegral,
		u.user_identity userIdentity,
		u.user_income userIncome,
		a.apply_is_read applyIsRead
	</sql>
	<select id="getMyOrderStatusCount" parameterType="String" resultType="java.util.HashMap">
		SELECT sales_status salesStatus,COUNT(sales_orderid) countAmount
		FROM tb_iamberry_shop_sales_order 
		WHERE sales_openid=#{id} 
		GROUP BY sales_status 
	</select>
	
	<!-- 根据 openid查询 通过审核的 微代理申请 -->
	<select id="getAgentMemberInfo" parameterType="String" resultType="AgentMemberDto">
		SELECT 
			<include refid="agentMemberAllField"></include>
		FROM tb_iamberry_user_userinfo u
		JOIN tb_iamberry_user_apply_logs a ON u.user_openid=a.apply_openid
		WHERE a.apply_status=3
		AND u.user_openid=#{id}
	</select>	

	<!-- 查询当前用户的待返还金额 -->
	<select id="getWillIncomeByOpenId" parameterType="String" resultType="Integer">
		SELECT SUM(REBACK_MONEY) SUNMONEY FROM TB_IAMBERRY_REBACK
		WHERE REBACK_TO_OPENID = #{openid}
		AND REBACK_STATUS = 1
		AND REBACK_USER_TYPE = 1
	</select>
	
</mapper>
