You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bsdgy-server/src/main/resources/mapper/OpCustomerDOMapper.xml

197 lines
8.5 KiB
XML

<?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, t2.create_time as createTime
from op_seller_customer_relation t1
left join poi_store t0 on t0.id = t1.store_id
left join poi_store_staff t5 ON t5.store_id = t0.id and t1.user_id = t5.id
LEFT JOIN op_customer t2 ON t2.id = t1.customer_id
LEFT JOIN op_vip t3 ON t3.id = t2.member_id
LEFT JOIN privilage_user t4 ON t4.id = t5.user_id where 1 =1
<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 t2.create_time >= #{startDate}
</if>
<if test="endDate != null">
and t2.create_time <![CDATA[ < ]]> #{endDate}
</if>
order by t2.create_time desc,t2.id desc,t1.user_id desc
</select>
<select id="selectCustomerInfoBySellerId" 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, t2.create_time as createTime
from op_seller_customer_relation t1
left join poi_store t0 on t0.id = t1.store_id
left join poi_store_staff t5 ON t5.store_id = t0.id and t1.user_id = t5.id
LEFT JOIN op_customer t2 ON t2.id = t1.customer_id
LEFT JOIN op_vip t3 ON t3.id = t2.member_id
LEFT JOIN privilage_user t4 ON t4.id = t5.user_id where 1 =1
and t1.user_id = #{sellerId}
<if test="startDate != null">
and t2.create_time >= #{startDate}
</if>
<if test="endDate != null">
and t2.create_time <![CDATA[ < ]]> #{endDate}
</if>
GROUP BY t2.id
order by t2.create_time desc,t2.id desc
</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,
t1.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="selectAddCustomerTopShop" resultType="com.kiisoo.ic.ls.bean.StoreAddDTO">
select count(t1.id) as addCustomerNum,t2.store_id as storeId,t3.name as storeName,t3.code as storeCode
from op_customer t1, op_seller_customer_relation t2,poi_store t3
where t1.id=t2.customer_id
and t2.store_id = t3.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="startDate != null and startDate != ''">
and t1.create_time <![CDATA[ >= ]]> #{startDate}
</if>
<if test="endDate != null and endDate != ''">
and t1.create_time <![CDATA[ <= ]]> #{endDate}
</if>
group by t2.store_id
order by count(t1.id) desc
limit 10
</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 t1.create_time <![CDATA[ >= ]]> #{startDate}
</if>
<if test="endDate != null and endDate != ''">
and t1.create_time <![CDATA[ <= ]]> #{endDate}
</if>
</select>
<!--店铺ids→客户组织-->
<select id="selectCustomerOrgByShopIds" resultType="com.kiisoo.ic.customer.entity.ShopOrgInfoVO">
select t1.id as customerId,t1.`name` as customerName, t1.parent_id as companyId, t3.entity_id as shopId, ifnull(t4.`abbreviation`,t4.`name`) as shopName
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>
<if test="level != null">
and t1.`level`=#{level}
</if>
</select>
<!--店铺ids→零售公司信息-->
<select id="selectOrgInfoByShopIds" resultType="com.kiisoo.ic.customer.entity.CustomerViewZeroExtendVO">
SELECT distinct region.id as regionId,region.name as region,company.id as companyId,company.name as company,
customer.id as customerId,customer.name as customer ,shop.id as shopId, shop.`code` as shopCode, shop.name as shopName
FROM `privilage_organizational` region,`privilage_organizational` company,`privilage_organizational` customer,
privilage_organizational_domain t4, privilage_domain_entity t5,poi_store shop
where company.parent_id=region.id
and customer.parent_id = company.id
and region.`level`=1
and company.`level`=2
and customer.`level`=3
and customer.id = t4.org_id
and t4.domain_id=t5.domain_id
and t5.type=3
and t5.entity_id=shop.id
<choose>
<when test="shopIds != null and shopIds.size > 0 ">
and shop.id in
<foreach collection="shopIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</when>
<otherwise>
and 1 = 0
</otherwise>
</choose>
<if test="regionId != null and regionId != 0">
and region.id = #{regionId}
</if>
<if test="companyId != null and companyId != 0">
and company.id = #{companyId}
</if>
<if test="customerId != null and customerId != 0">
and customer.id = #{customerId}
</if>
</select>
<select id="countCustomerByDate" resultType="java.lang.Integer">
SELECT count(1)
from op_seller_customer_relation t1
join poi_store t0 on t0.id = t1.store_id
left join poi_store_staff t5 ON t5.store_id = t0.id and t1.user_id = t5.id
JOIN op_customer t2 ON t2.id = t1.customer_id
where t1.create_time >= #{startDate}
and t1.create_time &lt;= #{endDate}
<if test="shopIds != null and shopIds.size > 0">
and t1.store_id in
<foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
#{item}
</foreach>
</if>
</select>
</mapper>