<?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">
<mapper namespace= "com.kiisoo.ic.customer.mapper.OpCustomerDOMapper" >
<select id= "selectCustomerInfoByShopIds" resultType= "com.kiisoo.ic.customer.bean.OpCustomerDTO" >
select
t2.id,t2.`name`,
t2.member_id as idCard,t0.name as shopName,t0.code as shopCode,
t4.name as sellerName, t3.birthday, t2.phone,
t3.name as vipName,t3.phone as vipPhone, t5.staff_code as sellerCode, t1.create_time as createTime
from
poi_store t0,
op_seller_customer_relation t1 LEFT JOIN privilage_user t4 on t1.user_id = t4.id left join poi_store_staff t5 on t4.id = t5.user_id,
op_customer t2 LEFT JOIN op_vip t3 on t2.member_id = t3.id
where t0.id = t1.store_id and t1.customer_id = t2.id
<choose >
<when test= "shopId != null and shopId.size > 0 " >
and t1.store_id in
<foreach collection= "shopId" index= "index" item= "item" open= "(" separator= "," close= ")" >
#{item}
</foreach>
</when>
<otherwise >
and 1 = 0
</otherwise>
</choose>
<if test= "startDate != null" >
and t1.create_time >= #{startDate}
</if>
<if test= "endDate != null" >
and t1.create_time <![CDATA[ <= ]]> #{endDate}
</if>
order by t2.id,t1.user_id asc
</select>
<select id= "selectCustomerInfoBySellerId" resultType= "com.kiisoo.ic.customer.bean.OpCustomerDTO" >
select
t2.id,t2.`name`,t2.member_id as idCard,GROUP_CONCAT(DISTINCT t0.`name`) as shopName, GROUP_CONCAT(DISTINCT t4.`name`) as sellerName, t3.birthday, t2.phone
,t3.name as vipName,t3.phone as vipPhone
from
poi_store t0,
op_seller_customer_relation t1 LEFT JOIN privilage_user t4 on t1.user_id = t4.id,
op_customer t2 LEFT JOIN op_vip t3 on t2.member_id = t3.id
where t0.id = t1.store_id and t1.customer_id = t2.id
and t1.user_id = #{sellerId}
<if test= "startDate != null" >
and t1.create_time >= #{startDate}
</if>
<if test= "endDate != null" >
and t1.create_time <![CDATA[ <= ]]> #{endDate}
</if>
GROUP BY t2.id
order by t2.id asc
</select>
<!-- 客户list -->
<select id= "selectCustomerList" resultType= "com.kiisoo.ic.customer.entity.OpCustomer" >
select t1.id as id, t1.`name` as name, t1.member_id as memberId, t1.phone as phone,
t2.create_time as registerTime, t2.type as validType, t2.store_id as shopId
from op_customer t1, op_seller_customer_relation t2
where t1.id=t2.customer_id
<if test= "memberId != null" >
and t1.member_id = #{memberId}
</if>
<if test= "shopIds != null and shopIds.size > 0" >
and t2.store_id in
<foreach collection= "shopIds" separator= "," item= "item" index= "index" close= ")" open= "(" >
#{item}
</foreach>
</if>
<if test= "sellerId != null" >
and t2.user_id=#{sellerId}
</if>
<if test= "startDate != null and startDate != ''" >
and t2.create_time <![CDATA[ >= ]]> #{startDate}
</if>
<if test= "endDate != null and endDate != ''" >
and t2.create_time <![CDATA[ <= ]]> #{endDate}
</if>
</select>
<!-- 客户总数 -->
<select id= "selectCustomerCount" resultType= "Long" >
select count(t1.id)
from op_customer t1, op_seller_customer_relation t2
where t1.id=t2.customer_id
<if test= "shopIds != null and shopIds.size > 0" >
and t2.store_id in
<foreach collection= "shopIds" separator= "," item= "item" index= "index" close= ")" open= "(" >
#{item}
</foreach>
</if>
<if test= "type != null" >
and t2.type = #{type}
</if>
<if test= "startDate != null and startDate != ''" >
and t2.create_time <![CDATA[ >= ]]> #{startDate}
</if>
<if test= "endDate != null and endDate != ''" >
and t2.create_time <![CDATA[ <= ]]> #{endDate}
</if>
</select>
<!-- 店铺ids→零售公司 -->
<select id= "selectOrgByShopIds" resultType= "com.kiisoo.ic.customer.entity.CustomerViewShopVO" >
select t1.id as orgId,t1.`name` as orgName, t3.entity_id as shopId
from privilage_organizational t1, privilage_organizational_domain t2, privilage_domain_entity t3
where t1.id = t2.org_id
and t2.domain_id = t3.domain_id
and t3.type = 3
and t3.entity_id in
<foreach collection= "shopIds" separator= "," item= "item" index= "index" close= ")" open= "(" >
#{item}
</foreach>
</select>
<!-- 店铺ids→零售公司 -->
<select id= "selectOrgInfoByShopIds" resultType= "com.kiisoo.ic.customer.entity.CustomerViewZeroExtendVO" >
select t1.id as orgId,t1.`name` as orgName, t3.entity_id as shopId, t4.name as shopName, t4.code as shopCode
from privilage_organizational t1, privilage_organizational_domain t2, privilage_domain_entity t3, poi_store t4
where t1.id = t2.org_id
and t2.domain_id = t3.domain_id
and t3.type = 3 and t3.entity_id = t4.id
and t3.entity_id in
<foreach collection= "shopIds" separator= "," item= "item" index= "index" close= ")" open= "(" >
#{item}
</foreach>
order by t3.entity_id,t1.id asc
</select>
</mapper>