门店号管理

dev_0531
LegnaYet 5 years ago
parent 255a45a04f
commit fc0297fdec

@ -647,8 +647,9 @@ public class CustomerViewService {
//店长
if(privilageRoleDO.getCode().equals(RoleEnum.ROLE_CODE_DZ.getRoleCode())) {
shopIdList = poiStoreStaffDOMapper.selectByUserId(userId);
Long storeAll = privilageCpUserDOMapper.selectStoresCountById(shopIdList);
Long storeDis = privilageCpUserDOMapper.selectDistinctStoresCountById(shopIdList);
String cpUserId = privilageCpUserStoreDOMapper.selectCpUserIdByStoreId(shopIdList.get(0));
Long storeAll = privilageCpUserDOMapper.selectStoreCount(cpUserId);
Long storeDis = privilageCpUserDOMapper.selectDistinctStoreCount(cpUserId);
result.setAllCustomer(storeAll);
result.setAllValidCustomer(storeDis);
@ -662,8 +663,9 @@ public class CustomerViewService {
//查询零售公司的门店
List<PoiStore> list1 = retailCompanyService.selectShopByCompany(pm.get(0).getOrgId());
shopIdList = list1.stream().map(PoiStore::getId).collect(Collectors.toList());
Long all = privilageCpUserDOMapper.selectStoresCountById(shopIdList);
Long dis = privilageCpUserDOMapper.selectDistinctStoresCountById(shopIdList);
List<String> cpUserIds = privilageCpUserStoreDOMapper.selectCpUserIdsByStoreIds(shopIdList);
Long all = privilageCpUserDOMapper.selectStoresCount(cpUserIds);
Long dis = privilageCpUserDOMapper.selectDistinctStoresCount(cpUserIds);
result.setAllCustomer(all);
result.setAllValidCustomer(dis);

@ -376,12 +376,12 @@ public class RetailCompanyService {
long count = opRelations.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count();
organizationalVO.setAllCustomer((int) count);
//组织成员的客户有效个数
QueryWrapper<OpSellerCustomerRelation> wrapper4 = new QueryWrapper<>();
wrapper4.in("store_id", stores);
wrapper4.eq("type", 1);
Integer countAble = opSellerCustomerRelationDOMapper.selectCount(wrapper4);
// long countAble = opRelations1.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count();
organizationalVO.setEffectiveCustomer(countAble);
// QueryWrapper<OpSellerCustomerRelation> wrapper4 = new QueryWrapper<>();
// wrapper4.in("store_id", stores);
// wrapper4.eq("type", 1);
// Integer countAble = opSellerCustomerRelationDOMapper.selectCount(wrapper4);
long countAble = opRelations.stream().filter(item -> item.getType() == 1).map(OpSellerCustomerRelation::getCustomerId).distinct().count();
organizationalVO.setEffectiveCustomer((int)countAble);
//计算新增客户数据
newCustomerStore(startTime, endTime, organizationalVO, stores);
@ -469,37 +469,23 @@ public class RetailCompanyService {
//最初时间的总客户人数
QueryWrapper<OpSellerCustomerRelation> wrapper2 = new QueryWrapper<>();
wrapper2.in("store_id", storeIds);
wrapper2.lt("create_time", startTime);
wrapper2.gt("create_time", startTime);
wrapper2.lt("create_time", l.plus(1, ChronoUnit.DAYS));
List<OpSellerCustomerRelation> opRelations = opSellerCustomerRelationDOMapper.selectList(wrapper2);
long count = opRelations.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count();
//最初时间的有效总客户人数
wrapper2.in("store_id", storeIds);
wrapper2.eq("type", 1);
wrapper2.lt("create_time", startTime);
List<OpSellerCustomerRelation> opRelations2 = opSellerCustomerRelationDOMapper.selectList(wrapper2);
long count2 = opRelations2.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count();
//最后时间的总客户人数
QueryWrapper<OpSellerCustomerRelation> wrapper3 = new QueryWrapper<>();
wrapper3.in("store_id", storeIds);
wrapper3.lt("create_time", l.plus(1, ChronoUnit.DAYS));
List<OpSellerCustomerRelation> opRelationsEnd = opSellerCustomerRelationDOMapper.selectList(wrapper3);
long countEnd = opRelationsEnd.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count();
//最后时间的有效总客户人数
wrapper3.in("store_id", storeIds);
wrapper3.eq("type", 1);
wrapper3.lt("create_time", l.plus(1, ChronoUnit.DAYS));
List<OpSellerCustomerRelation> opRelationsEnd2 = opSellerCustomerRelationDOMapper.selectList(wrapper3);
long countEnd2 = opRelationsEnd2.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count();
long count2 = opRelations.stream().filter(item -> item.getType() == 1).map(OpSellerCustomerRelation::getCustomerId).distinct().count();
//计算两个时间间隔用于计算平均值
LocalDate start = LocalDate.parse(startTime);
LocalDate end = LocalDate.parse(endTime);
long days = start.until(end, ChronoUnit.DAYS) + 1;
organizationalVO.setNewCustomer((int) (countEnd - count));
organizationalVO.setNewEffectiveCustomer((int) (countEnd2 - count2));
organizationalVO.setAvgNewCustomer(check1(countEnd - count, days));
organizationalVO.setAvgNewEffectiveCustomer(check1(countEnd2 - count2, days));
organizationalVO.setNewCustomer((int) count);
organizationalVO.setNewEffectiveCustomer((int) count2);
organizationalVO.setAvgNewCustomer(check1( count, days));
organizationalVO.setAvgNewEffectiveCustomer(check1(count2, days));
}
/**

@ -56,15 +56,13 @@
<!--客户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>
select t2.create_time as registerTime,
t2.type as validType,
t2.store_id as shopId
from op_seller_customer_relation t2
where
<if test="shopIds != null and shopIds.size > 0">
and t2.store_id in
t2.store_id in
<foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
#{item}
</foreach>
@ -81,10 +79,9 @@
</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
select count(t2.customer_id) as addCustomerNum,t2.store_id as storeId,t3.name as storeName,t3.code as storeCode
from op_seller_customer_relation t2,poi_store t3
where 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="(">
@ -92,23 +89,23 @@
</foreach>
</if>
<if test="startDate != null and startDate != ''">
and t1.create_time <![CDATA[ >= ]]> #{startDate}
and t2.create_time <![CDATA[ >= ]]> #{startDate}
</if>
<if test="endDate != null and endDate != ''">
and t1.create_time <![CDATA[ <= ]]> #{endDate}
and t2.create_time <![CDATA[ <= ]]> #{endDate}
</if>
group by t2.store_id
order by count(t1.id) desc
order by count(t2.customer_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
select count(t2.customer_id)
from op_seller_customer_relation t2
where
<if test="shopIds != null and shopIds.size > 0">
and t2.store_id in
t2.store_id in
<foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
#{item}
</foreach>
@ -117,10 +114,10 @@
and t2.type = #{type}
</if>
<if test="startDate != null and startDate != ''">
and t1.create_time <![CDATA[ >= ]]> #{startDate}
and t2.create_time <![CDATA[ >= ]]> #{startDate}
</if>
<if test="endDate != null and endDate != ''">
and t1.create_time <![CDATA[ <= ]]> #{endDate}
and t2.create_time <![CDATA[ <= ]]> #{endDate}
</if>
</select>

@ -139,12 +139,11 @@
t2.avatar_url AS avatar ,
t3. LEVEL AS vipFlag
FROM
op_seller_customer_relation t1
join op_customer t2 on t1.customer_id = t2.id
op_seller_customer_relation t1, op_customer t2
LEFT JOIN op_vip t3 ON t2.member_id = t3.id
AND t3. STATUS = 1
WHERE
1 = 1
t1.customer_id = t2.id
<if test="type == 1">
and t3.id is not null
</if>

@ -89,10 +89,10 @@
poi_store t1
LEFT JOIN op_seller_customer_relation t4 on t1.id = t4.store_id
<if test="startDate != null">
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startDate},'%Y-%m-%d')
and t4.create_time &gt;= #{startDate}
</if>
<if test="endDate != null">
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
and t4.create_time &lt;= #{endDate}
</if>,
poi_store_region t2
WHERE
@ -169,10 +169,10 @@
poi_store_staff t1
LEFT JOIN op_seller_customer_relation t2 ON t1.id = t2.user_id
<if test="startDate != null">
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startDate},'%Y-%m-%d')
and t4.create_time &gt;= #{startDate}
</if>
<if test="endDate != null">
and DATE_FORMAT(t4.create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
and t4.create_time &lt;= #{endDate}
</if>,
privilage_user t3,
poi_store_region t4
@ -290,29 +290,28 @@
</select>
<select id="selectWxSumCusNumByConditionShopManager" resultType="java.lang.Integer">
SELECT count(customer_id) from op_seller_customer_relation t, op_customer t2
SELECT count(t.customer_id) from op_seller_customer_relation t
WHERE t.store_id = #{storeId}
and t.customer_id = t2.id
<if test="startDate != null">
and date(t.create_time) &gt;= #{startDate}
and t.create_time &gt;= #{startDate}
</if>
<if test="endDate != null">
and date(t.create_time) &lt;= #{endDate}
and t.create_time &lt;= #{endDate}
</if>
group by store_id
group by t.store_id
</select>
<select id="selectWxSumCusNumByConditionStaff" resultType="java.lang.Integer">
SELECT count(customer_id) from op_seller_customer_relation t1, poi_store_staff t2, op_customer t3 where t1.customer_id = t3.id and t1.user_id = t2.id
SELECT count(customer_id) from op_seller_customer_relation t1, poi_store_staff t2 where t1.user_id = t2.id
and t2.type = 4
<if test="userId != null">
AND t2.user_id = #{userId}
</if>
<if test="startDate != null">
and date(t1.create_time) &gt;= #{startDate}
and t1.create_time &gt;= #{startDate}
</if>
<if test="endDate != null">
and date(t1.create_time) &lt;= #{endDate}
and t1.create_time &lt;= #{endDate}
</if>
group by t1.user_id
</select>
@ -326,15 +325,14 @@
user_id AS id,
count( customer_id ) AS cusNum
FROM
`op_seller_customer_relation` t,op_customer t2
`op_seller_customer_relation` t
WHERE
t.customer_id = t2.id
and t. store_id = #{storeId}
t. store_id = #{storeId}
<if test="startDate != null">
and date(t.create_time) &gt;= #{startDate}
and t.create_time &gt;= #{startDate}
</if>
<if test="endDate != null">
and date(t.create_time) &lt;= #{endDate}
and t.create_time &lt;= #{endDate}
</if>
GROUP BY
t.user_id
@ -365,23 +363,20 @@
(
SELECT
count( t2.customer_id ) AS newCusNum,
t1.id AS storeId
t2.store_id AS storeId
FROM
poi_store t1
JOIN `op_seller_customer_relation` t2 ON t1.id = t2.store_id
JOIN op_customer t3 on t2.customer_id = t3.id
`op_seller_customer_relation` t2
where 1=1
<if test="startDate != null">
and date(t2.create_time) &gt;= #{startDate}
and t2.create_time &gt;= #{startDate}
</if>
<if test="endDate != null">
and date(t2.create_time) &lt;= #{endDate}
and t2.create_time &lt;= #{endDate}
</if>
WHERE
t1.STATUS = 1
GROUP BY
storeId
t2.store_id
ORDER BY
newCusNum DESC, storeId DESC
newCusNum DESC, t2.store_id DESC
) a,
( SELECT @rank := 0 ) b
</select>
@ -392,18 +387,17 @@
@rank := @rank + 1 AS rankNo
FROM
( SELECT count( t2.customer_id ) AS newCusNum, t1.user_id AS userId FROM
poi_store_staff t1
LEFT JOIN `op_seller_customer_relation` t2 ON t1.id = t2.user_id
left join op_customer t3 on t2.customer_id = t3.id
poi_store_staff t1, `op_seller_customer_relation` t2
where t1.id = t2.user_id
<if test="startDate != null">
and date(t2.create_time) &gt;= #{startDate}
and t2.create_time &gt;= #{startDate}
</if>
<if test="endDate != null">
and date(t2.create_time) &lt;= #{endDate}
and t2.create_time &lt;= #{endDate}
</if>
where t1.store_id = #{storeId}
and t1.store_id = #{storeId}
and t1.type = 4
GROUP BY userId,t3.id ORDER BY newCusNum DESC, userId DESC ) a,
GROUP BY userId,t2.customer_id ORDER BY newCusNum DESC, userId DESC ) a,
( SELECT @rank := 0 ) b
</select>
<select id="selectLatestUpdateTime" resultType="java.util.Date">
@ -413,7 +407,7 @@
SELECT
t1.customer_id as customerId,t2.name as customerName,t2.external_userid as customerUserId,count( t1.store_id ) as count
FROM
op_seller_customer_relation t1 left join op_customer t2 on t1.customer_id = t2.id
op_seller_customer_relation t1 , op_customer t2 where t1.customer_id = t2.id
GROUP BY
t1.customer_id
HAVING

Loading…
Cancel
Save