fix: 推广员提成信息查询和导出. 商城提成

pull/6/head
tangqian 2023-05-31 12:00:24 +08:00
parent eadd9f2daa
commit 7619a9f220
7 changed files with 221 additions and 31 deletions

View File

@ -122,6 +122,19 @@ public class RechargeOrderController {
return success(pageResult);
}
@GetMapping("/promoterDraw-excel")
@Operation(summary = "导出推广员抽佣统计")
@PreAuthorize("@ss.hasPermission('shop:recharge-order:export')")
@OperateLog(type = EXPORT)
@TenantIgnore
public void getRechargeOrderExcel(@Valid PromoterDrawReqExcelVO excelVO, HttpServletResponse response) throws IOException {
if(!TenantContextHolder.ID_SYSTEM.equals(SecurityFrameworkUtils.getLoginUser().getTenantId())){
excelVO.setTenantId(SecurityFrameworkUtils.getLoginUser().getTenantId());
}
List<PromoterDrawExcelVO> list = rechargeOrderService.findPromoterDrawExcel(excelVO);
ExcelUtils.write(response, "推广员抽佣统计.xls", "数据", PromoterDrawExcelVO.class, list);
}
@GetMapping("/export-excel")
@Operation(summary = "导出订单 Excel")

View File

@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.shop.controller.admin.recharge.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
public class PromoterDrawExcelVO {
@ExcelProperty( "用户id")
private Long userId;
@ExcelProperty( "组织id")
private Long deptId;
@ExcelProperty( "商户id")
private Long tenantId;
@ExcelProperty( "组织名称")
private String deptName;
@ExcelProperty( "组织结构名称")
private String parentOrganizationName;
@ExcelProperty( "推广员名称")
private String nickname;
@ExcelProperty( "手机号")
private String mobile;
@ExcelProperty( "成为推广员时间")
private LocalDateTime createTime;
@ExcelProperty( "会员提成")
private Integer memberCommission;
@ExcelProperty( "商品提成")
private Integer goodsCommission;
@ExcelProperty( "成交定单数")
private BigDecimal orderCount;
@ExcelProperty( "可提现金额")
private BigDecimal drawAmount;
@ExcelProperty( "成交金额")
private BigDecimal dealAmount;
@ExcelProperty( "累计金额")
private BigDecimal totalAmount;
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.shop.controller.admin.recharge.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Data
public class PromoterDrawReqExcelVO implements Serializable {
private static final long serialVersionUID = -3999440180896951708L;
private Long tenantId;
@Schema(description = "商户名称")
private String deptName;
@Schema(description = "组织结构名称")
private String parentOrganizationName;
@Schema(description = "推广员名称")
private String nickname;
@Schema(description = "手机号")
private String mobile;
@Schema(description = "成为推广员时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -62,6 +62,7 @@ public interface RechargeOrderMapper extends BaseMapperX<RechargeOrderDO> {
IPage<RechargeOrderRespVO> findListPage(IPage<RechargeOrderRespVO> page, @Param("data") RechargeOrderPageReqVO data);
IPage<PromoterDrawVO> findPromoterDrawPage(IPage<PromoterDrawVO> page, @Param("data") PromoterDrawReqVO data);
List<PromoterDrawExcelVO> findPromoterDrawExcel(@Param("data") PromoterDrawReqExcelVO data);
List<PromoterDrawVO> findPromoterDrawCount(@Param("promoterIds") List<Long> promoterIds);
BigDecimal promoterOrderCount(@Param("startDate") LocalDateTime startDate, @Param("endDate")LocalDateTime endDate,@Param("promoterId") Long promoterId);

View File

@ -89,4 +89,6 @@ public interface RechargeOrderService {
Boolean memberChangeTie(MemberChangeTieRequest changeTieRequest);
ShoppingMemberOrderVO shoppingOrderCount(Integer type, Long loginUserId);
List<PromoterDrawExcelVO> findPromoterDrawExcel(PromoterDrawReqExcelVO excelVO);
}

View File

@ -132,31 +132,49 @@ public class RechargeOrderServiceImpl implements RechargeOrderService {
return new PageResult<>(page.getRecords(), page.getTotal());
}
@Override
public List<PromoterDrawExcelVO> findPromoterDrawExcel(PromoterDrawReqExcelVO excelVO) {
return rechargeOrderMapper.findPromoterDrawExcel(excelVO);
}
@Override
public PageResult<PromoterDrawVO> findPromoterDrawPage(PromoterDrawReqVO pageReqVO) {
Page<PromoterDrawVO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
rechargeOrderMapper.findPromoterDrawPage(page, pageReqVO);
List<PromoterDrawVO> list = page.getRecords();
if (list != null && list.size() > 0) {
List<Long> collect1 = list.stream().map(PromoterDrawVO::getUserId).collect(Collectors.toList());
List<PromoterDrawVO> promoterDrawVOList = rechargeOrderMapper.findPromoterDrawCount(collect1);
Map<Long, PromoterDrawVO> nameList = promoterDrawVOList.stream().collect(toMap(PromoterDrawVO::getUserId, value -> value, (value1, value2) -> value1));
// List<Long> collect1 = list.stream().map(PromoterDrawVO::getUserId).collect(Collectors.toList());
// List<PromoterDrawVO> promoterDrawVOList = rechargeOrderMapper.findPromoterDrawCount(collect1);
// Map<Long, PromoterDrawVO> nameList = promoterDrawVOList.stream().collect(toMap(PromoterDrawVO::getUserId, value -> value, (value1, value2) -> value1));
list.forEach(promoterDrawVO -> {
PromoterDrawVO promoterDrawNew = nameList.get(promoterDrawVO.getUserId());
if (promoterDrawNew != null) {
promoterDrawVO.setDealAmount(promoterDrawNew.getDealAmount());
promoterDrawVO.setTotalAmount(promoterDrawNew.getTotalAmount());
promoterDrawVO.setOrderCount(promoterDrawNew.getOrderCount());
if (promoterDrawVO.getMemberCommission() == null) {
promoterDrawVO.setMemberCommission(0);
}
promoterDrawVO.setDrawAmount(NumberUtil.mul(promoterDrawNew.getDealAmount(), NumberUtil.div(promoterDrawVO.getMemberCommission().toString(), "100"), 2));
} else {
promoterDrawVO.setDealAmount(new BigDecimal(0));
promoterDrawVO.setTotalAmount(new BigDecimal(0));
promoterDrawVO.setOrderCount(new BigDecimal(0));
if (promoterDrawVO.getMemberCommission() == null) {
promoterDrawVO.setMemberCommission(0);
promoterDrawVO.setDrawAmount(new BigDecimal(0));
}
if (promoterDrawVO.getTotalAmount() == null) {
promoterDrawVO.setTotalAmount(new BigDecimal(0));
}
if (promoterDrawVO.getDealAmount() == null) {
promoterDrawVO.setDealAmount(new BigDecimal(0));
}
if (promoterDrawVO.getOrderCount() == null) {
promoterDrawVO.setOrderCount(new BigDecimal(0));
}
promoterDrawVO.setDrawAmount(NumberUtil.mul(promoterDrawVO.getDealAmount(), NumberUtil.div(promoterDrawVO.getMemberCommission().toString(), "100"), 2));
// PromoterDrawVO promoterDrawNew = nameList.get(promoterDrawVO.getUserId());
// if (promoterDrawNew != null) {
// promoterDrawVO.setDealAmount(promoterDrawNew.getDealAmount());
// promoterDrawVO.setTotalAmount(promoterDrawNew.getTotalAmount());
// promoterDrawVO.setOrderCount(promoterDrawNew.getOrderCount());
// if (promoterDrawVO.getMemberCommission() == null) {
// promoterDrawVO.setMemberCommission(0);
// }
// promoterDrawVO.setDrawAmount(NumberUtil.mul(promoterDrawNew.getDealAmount(), NumberUtil.div(promoterDrawVO.getMemberCommission().toString(), "100"), 2));
// } else {
// promoterDrawVO.setDealAmount(new BigDecimal(0));
// promoterDrawVO.setTotalAmount(new BigDecimal(0));
// promoterDrawVO.setOrderCount(new BigDecimal(0));
// promoterDrawVO.setMemberCommission(0);
// promoterDrawVO.setDrawAmount(new BigDecimal(0));
// }
});
}
return new PageResult<>(list, page.getTotal());
@ -358,4 +376,5 @@ public class RechargeOrderServiceImpl implements RechargeOrderService {
return shoppingMemberOrderVO;
}
}

View File

@ -12,21 +12,28 @@
<select id="findPromoterDrawPage" resultType="cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.PromoterDrawVO">
SELECT
a.user_id,
a.dept_id,
a.tenant_id,
c.`name`as dept_name,
c.parent_organization_name,
d.nickname,
d.mobile,
a.create_time,
b.member_commission,
b.goods_commission
x1.*,
x2.order_count,
x2.deal_amount,
x2.total_amount
FROM
member_promoter a
LEFT JOIN system_dept c on c.id= a.dept_id
LEFT JOIN member_user d on d.id=a.user_id
LEFT JOIN system_tenant b on b.id=a.tenant_id
(
SELECT
a.user_id,
a.dept_id,
a.tenant_id,
c.`name` AS dept_name,
c.parent_organization_name,
d.nickname,
d.mobile,
a.create_time,
b.member_commission,
b.goods_commission
FROM
member_promoter a
LEFT JOIN system_dept c ON c.id = a.dept_id
LEFT JOIN member_user d ON d.id = a.user_id
LEFT JOIN system_tenant b ON b.id = a.tenant_id
<where>
<if test="data.tenantId!=null">
and a.tenant_id=#{data.tenantId}
@ -47,6 +54,18 @@
and a.create_time &lt;=#{data.createTime[1]}
</if>
</where>
) x1
LEFT JOIN (
SELECT
b.promoter_id AS user_id,
count( CASE b.paid = 1 WHEN 1 THEN 0 END ) AS order_count,
sum( CASE WHEN b.paid = 1 THEN b.pay_price ELSE 0 END ) AS deal_amount,
sum( CASE WHEN b.paid IN ( 1, 2 ) THEN b.pay_price ELSE 0 END ) AS total_amount
FROM
cy_recharge_order b
GROUP BY
b.promoter_id
) x2 ON x1.user_id = x2.user_id ORDER BY x2.total_amount DESC
</select>
<select id="findPromoterDrawCount" resultType="cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.PromoterDrawVO">
SELECT
@ -136,6 +155,65 @@
<include refid="baseWhere">
</include>
</select>
<select id="findPromoterDrawExcel"
resultType="cn.iocoder.yudao.module.shop.controller.admin.recharge.vo.PromoterDrawExcelVO">
SELECT
x1.*,
x2.order_count,
x2.deal_amount,
x2.total_amount
FROM
(
SELECT
a.user_id,
a.dept_id,
a.tenant_id,
c.`name` AS dept_name,
c.parent_organization_name,
d.nickname,
d.mobile,
a.create_time,
b.member_commission,
b.goods_commission
FROM
member_promoter a
LEFT JOIN system_dept c ON c.id = a.dept_id
LEFT JOIN member_user d ON d.id = a.user_id
LEFT JOIN system_tenant b ON b.id = a.tenant_id
<where>
<if test="data.tenantId!=null">
and a.tenant_id=#{data.tenantId}
</if>
<if test="data.parentOrganizationName!=null and data.parentOrganizationName!=''">
and c.parent_Organization_name like CONCAT('%',#{data.parentOrganizationName},'%')
</if>
<if test="data.mobile!=null and data.mobile!=''">
and d.mobile like CONCAT('%',#{data.mobile},'%')
</if>
<if test="data.nickname!=null and data.nickname!=''">
and d.nickname like CONCAT('%',#{data.nickname},'%')
</if>
<if test="data.createTime !=null and data.createTime.length>=1">
and a.create_time &gt;=#{data.createTime[0]}
</if>
<if test="data.createTime !=null and data.createTime.length>=2">
and a.create_time &lt;=#{data.createTime[1]}
</if>
</where>
) x1
LEFT JOIN (
SELECT
b.promoter_id AS user_id,
count( CASE b.paid = 1 WHEN 1 THEN 0 END ) AS order_count,
sum( CASE WHEN b.paid = 1 THEN b.pay_price ELSE 0 END ) AS deal_amount,
sum( CASE WHEN b.paid IN ( 1, 2 ) THEN b.pay_price ELSE 0 END ) AS total_amount
FROM
cy_recharge_order b
GROUP BY
b.promoter_id
) x2 ON x1.user_id = x2.user_id ORDER BY x2.total_amount DESC
</select>
<sql id="baseWhere">
<where>
<if test="data.orderId !=null and data.orderId!=''">