推客
This commit is contained in:
parent
0aadd1d064
commit
34924ad351
120
src/main/java/com/ycwl/basic/biz/BrokerBiz.java
Normal file
120
src/main/java/com/ycwl/basic/biz/BrokerBiz.java
Normal file
@ -0,0 +1,120 @@
|
||||
package com.ycwl.basic.biz;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ycwl.basic.mapper.BrokerMapper;
|
||||
import com.ycwl.basic.mapper.BrokerRecordMapper;
|
||||
import com.ycwl.basic.mapper.StatisticsMapper;
|
||||
import com.ycwl.basic.model.pc.broker.entity.BrokerRecord;
|
||||
import com.ycwl.basic.model.pc.broker.resp.BrokerRespVO;
|
||||
import com.ycwl.basic.model.pc.order.entity.OrderEntity;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
|
||||
import com.ycwl.basic.repository.OrderRepository;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class BrokerBiz {
|
||||
@Autowired
|
||||
private BrokerMapper brokerMapper;
|
||||
@Autowired
|
||||
private BrokerRecordMapper brokerRecordMapper;
|
||||
@Autowired
|
||||
private OrderRepository orderRepository;
|
||||
@Autowired
|
||||
private ScenicRepository scenicRepository;
|
||||
@Autowired
|
||||
private StatisticsMapper statisticsMapper;
|
||||
|
||||
public void processOrder(Long orderId) {
|
||||
OrderEntity order = orderRepository.getOrder(orderId);
|
||||
if (order == null) {
|
||||
return;
|
||||
}
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(order.getScenicId());
|
||||
if (scenicConfig == null) {
|
||||
return;
|
||||
}
|
||||
int expireDay = 3;
|
||||
if (scenicConfig.getSampleStoreDay() != null) {
|
||||
expireDay = scenicConfig.getSampleStoreDay();
|
||||
}
|
||||
List<Long> brokerIdList = statisticsMapper.getBrokerIdListForUser(order.getMemberId(), DateUtil.offsetDay(DateUtil.beginOfDay(order.getCreateAt()), -expireDay), order.getCreateAt());
|
||||
List<BrokerRespVO> brokerInfoList = brokerIdList.stream().map(brokerId -> {
|
||||
BrokerRespVO broker = brokerMapper.getById(brokerId);
|
||||
if (broker == null) {
|
||||
return null;
|
||||
}
|
||||
if (Integer.valueOf(0).equals(broker.getStatus())) {
|
||||
return null;
|
||||
}
|
||||
if (Integer.valueOf(0).equals(broker.getBrokerEnable())) {
|
||||
return null;
|
||||
}
|
||||
return broker;
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
if (brokerInfoList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<BrokerRecord> brokerRecordList = new ArrayList<>();
|
||||
if (brokerInfoList.size() == 1) {
|
||||
// 直接算佣金
|
||||
String reason = "单人提成:";
|
||||
BrokerRespVO broker = brokerInfoList.get(0);
|
||||
BrokerRecord brokerRecord = new BrokerRecord();
|
||||
brokerRecord.setBrokerId(broker.getId());
|
||||
brokerRecord.setOrderId(orderId);
|
||||
if (broker.getBrokerRate() == null) {
|
||||
reason += "提成比例为空!";
|
||||
brokerRecord.setBrokerRate(BigDecimal.ZERO);
|
||||
}
|
||||
brokerRecord.setOrderPrice(order.getPayPrice());
|
||||
brokerRecord.setBrokerRate(broker.getBrokerRate());
|
||||
BigDecimal brokerRate = brokerRecord.getBrokerRate();
|
||||
BigDecimal brokerPrice = order.getPayPrice().multiply(brokerRate).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_DOWN);
|
||||
brokerRecord.setBrokerPrice(brokerPrice);
|
||||
reason += "金额:" + order.getPayPrice() + "元,提成比例:" + brokerRate + ",提成金额:" + brokerPrice + "元";
|
||||
brokerRecord.setReason(reason);
|
||||
brokerRecordList.add(brokerRecord);
|
||||
} else {
|
||||
BigDecimal totalRate = brokerInfoList.stream().map(BrokerRespVO::getBrokerRate).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BrokerRespVO broker = brokerInfoList.get(0);
|
||||
BigDecimal firstRate = broker.getBrokerRate();
|
||||
BigDecimal brokerPrice = order.getPayPrice().multiply(firstRate).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_DOWN);
|
||||
brokerInfoList.forEach(item -> {
|
||||
String reason = "多人提成:支付金额:" + order.getPayPrice() + "元,可提成比例:" + firstRate + ",可提成金额:" + brokerPrice + ":";
|
||||
BrokerRecord brokerRecord = new BrokerRecord();
|
||||
brokerRecord.setBrokerId(item.getId());
|
||||
brokerRecord.setOrderId(orderId);
|
||||
if (item.getBrokerRate() == null) {
|
||||
reason += "提成比例为空!";
|
||||
brokerRecord.setBrokerRate(BigDecimal.ZERO);
|
||||
}
|
||||
brokerRecord.setOrderPrice(order.getPayPrice());
|
||||
BigDecimal interBrokerRate = item.getBrokerRate().divide(totalRate, 2, RoundingMode.HALF_DOWN);
|
||||
brokerRecord.setBrokerRate(interBrokerRate);
|
||||
BigDecimal interBrokerPrice = order.getPayPrice().multiply(interBrokerRate).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_DOWN);
|
||||
brokerRecord.setBrokerPrice(interBrokerPrice);
|
||||
reason += "提成比例:" + item.getBrokerRate() + ",实际提成比例:" + interBrokerRate + ",提成金额:" + interBrokerPrice + "元";
|
||||
brokerRecord.setReason(reason);
|
||||
brokerRecordList.add(brokerRecord);
|
||||
});
|
||||
}
|
||||
revokeOrder(orderId);
|
||||
brokerRecordList.forEach(brokerRecord -> {
|
||||
brokerRecordMapper.add(brokerRecord);
|
||||
});
|
||||
}
|
||||
|
||||
public void revokeOrder(Long orderId) {
|
||||
brokerRecordMapper.deleteByOrderId(orderId);
|
||||
}
|
||||
}
|
@ -1,14 +1,29 @@
|
||||
package com.ycwl.basic.controller.pc;
|
||||
|
||||
import com.ycwl.basic.model.pc.broker.entity.BrokerEntity;
|
||||
import com.ycwl.basic.model.pc.broker.req.BrokerRecordReqQuery;
|
||||
import com.ycwl.basic.model.pc.broker.req.BrokerReqQuery;
|
||||
import com.ycwl.basic.model.pc.broker.resp.BrokerRecordRespVO;
|
||||
import com.ycwl.basic.model.pc.broker.resp.BrokerRespVO;
|
||||
import com.ycwl.basic.model.pc.broker.resp.DailySummaryRespVO;
|
||||
import com.ycwl.basic.service.pc.BrokerRecordService;
|
||||
import com.ycwl.basic.service.pc.BrokerService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import com.ycwl.basic.utils.WxMpUtil;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.storage.StorageFactory;
|
||||
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
||||
import com.ycwl.basic.model.pc.mp.MpConfigEntity;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/2 15:50
|
||||
@ -20,6 +35,12 @@ public class BrokerController {
|
||||
@Autowired
|
||||
private BrokerService brokerService;
|
||||
|
||||
@Autowired
|
||||
private BrokerRecordService brokerRecordService;
|
||||
|
||||
@Autowired
|
||||
private ScenicRepository scenicRepository;
|
||||
|
||||
@ApiOperation("分页查询")
|
||||
@PostMapping("/page")
|
||||
public ApiResponse page(@RequestBody BrokerReqQuery brokerReqQuery){
|
||||
@ -53,4 +74,64 @@ public class BrokerController {
|
||||
return ApiResponse.success(brokerService.updateStatus(id));
|
||||
}
|
||||
|
||||
@ApiOperation("修改状态")
|
||||
@PutMapping("/updateBrokerEnable/{id}")
|
||||
public ApiResponse updateBrokerEnable(@PathVariable("id") Long id){
|
||||
return ApiResponse.success(brokerService.updateBrokerEnable(id));
|
||||
}
|
||||
|
||||
@ApiOperation("推客记录分页查询")
|
||||
@PostMapping("/record/page")
|
||||
public ApiResponse pageRecord(@RequestBody BrokerRecordReqQuery brokerRecordReqQuery) {
|
||||
return ApiResponse.success(brokerRecordService.pageQuery(brokerRecordReqQuery));
|
||||
}
|
||||
|
||||
@ApiOperation("推客记录列表查询")
|
||||
@PostMapping("/record/list")
|
||||
public ApiResponse listRecord(@RequestBody BrokerRecordReqQuery brokerRecordReqQuery) {
|
||||
return ApiResponse.success(brokerRecordService.list(brokerRecordReqQuery));
|
||||
}
|
||||
|
||||
@ApiOperation("推客记录详情查询")
|
||||
@GetMapping("/record/getDetails/{id}")
|
||||
public ApiResponse getRecordDetails(@PathVariable("id") Long id) {
|
||||
return ApiResponse.success(brokerRecordService.getById(id));
|
||||
}
|
||||
|
||||
@ApiOperation("根据brokerId和时间范围查询每天的记录数量和orderPrice汇总")
|
||||
@GetMapping("/record/dailySummary")
|
||||
public ApiResponse<List<DailySummaryRespVO>> getDailySummaryByBrokerId(
|
||||
@RequestParam Long brokerId,
|
||||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
|
||||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
|
||||
return ApiResponse.success(brokerRecordService.getDailySummaryByBrokerId(brokerId, startTime, endTime));
|
||||
}
|
||||
|
||||
@ApiOperation("根据景区ID下载小程序二维码")
|
||||
@GetMapping("/{id}/QRCode")
|
||||
public ApiResponse<String> downloadQrCode(@PathVariable Long id) {
|
||||
BrokerRespVO broker = brokerService.getById(id);
|
||||
if (broker == null) {
|
||||
return ApiResponse.fail("推客不存在");
|
||||
}
|
||||
MpConfigEntity mpConfig = scenicRepository.getScenicMpConfig(broker.getScenicId());
|
||||
if (mpConfig == null) {
|
||||
return ApiResponse.fail("小程序配置不存在");
|
||||
}
|
||||
String appId = mpConfig.getAppId();
|
||||
String appSecret = mpConfig.getAppSecret();
|
||||
String appState = mpConfig.getState();
|
||||
String path = "pages/home/index?scenicId=" + broker.getScenicId() + "&morphId=" + id;
|
||||
String filePath = "qr_code_tk_" + id + ".jpg";
|
||||
try {
|
||||
WxMpUtil.generateWXAQRCode(appId, appSecret, appState, path, filePath);
|
||||
IStorageAdapter adapter = StorageFactory.use();
|
||||
File file = new File(filePath);
|
||||
String s = adapter.uploadFile(file, filePath);
|
||||
file.delete();
|
||||
return ApiResponse.success(s);
|
||||
} catch (Exception e) {
|
||||
return ApiResponse.fail("生成二维码失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.ycwl.basic.mapper;
|
||||
|
||||
import com.ycwl.basic.model.pc.broker.entity.BrokerEntity;
|
||||
import com.ycwl.basic.model.pc.broker.req.BrokerReqQuery;
|
||||
import com.ycwl.basic.model.pc.broker.resp.BrokerRespVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
@ -13,10 +14,11 @@ import java.util.List;
|
||||
*/
|
||||
@Mapper
|
||||
public interface BrokerMapper {
|
||||
List<BrokerEntity> list(BrokerReqQuery brokerReqQuery);
|
||||
BrokerEntity getById(Long id);
|
||||
List<BrokerRespVO> list(BrokerReqQuery brokerReqQuery);
|
||||
BrokerRespVO getById(Long id);
|
||||
int add(BrokerEntity broker);
|
||||
int deleteById(Long id);
|
||||
int update(BrokerEntity broker);
|
||||
int updateStatus(Long id);
|
||||
int updateBrokerEnable(Long id);
|
||||
}
|
||||
|
31
src/main/java/com/ycwl/basic/mapper/BrokerRecordMapper.java
Normal file
31
src/main/java/com/ycwl/basic/mapper/BrokerRecordMapper.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.ycwl.basic.mapper;
|
||||
|
||||
import com.ycwl.basic.model.pc.broker.entity.BrokerRecord;
|
||||
import com.ycwl.basic.model.pc.broker.req.BrokerRecordReqQuery;
|
||||
import com.ycwl.basic.model.pc.broker.resp.BrokerRecordRespVO;
|
||||
import com.ycwl.basic.model.pc.broker.resp.DailySummaryRespVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/12 10:00
|
||||
*/
|
||||
@Mapper
|
||||
public interface BrokerRecordMapper {
|
||||
List<BrokerRecordRespVO> list(BrokerRecordReqQuery brokerRecordReqQuery);
|
||||
|
||||
BrokerRecordRespVO getById(Long id);
|
||||
|
||||
int add(BrokerRecord brokerRecord);
|
||||
|
||||
int deleteById(Long id);
|
||||
|
||||
int deleteByOrderId(Long orderId);
|
||||
|
||||
int update(BrokerRecord brokerRecord);
|
||||
|
||||
List<DailySummaryRespVO> getDailySummaryByBrokerId(Long brokerId, Date startTime, Date endTime);
|
||||
}
|
@ -5,6 +5,8 @@ import com.ycwl.basic.model.mobile.statistic.req.StatisticsRecordAddReq;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
@ -87,4 +89,6 @@ public interface StatisticsMapper {
|
||||
BigDecimal countRefundAmount(CommonQueryReq query);
|
||||
|
||||
int addStatisticsRecord(StatisticsRecordAddReq req);
|
||||
|
||||
List<Long> getBrokerIdListForUser(Long memberId, Date startTime, Date endTime);
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.ycwl.basic.model.pc.broker.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@ -14,8 +16,9 @@ import java.util.Date;
|
||||
@Data
|
||||
@TableName("broker")
|
||||
public class BrokerEntity {
|
||||
@TableId
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
private Long scenicId;
|
||||
/**
|
||||
* 推客名称
|
||||
*/
|
||||
@ -29,10 +32,8 @@ public class BrokerEntity {
|
||||
* 状态,0禁用,1启用
|
||||
*/
|
||||
private Integer status;
|
||||
private Integer brokerEnable;
|
||||
private BigDecimal brokerRate;
|
||||
private Date createAt;
|
||||
private Date updateAt;
|
||||
private Integer brokerOrderCount;
|
||||
private Integer brokerOrderAmount;
|
||||
private Date firstBrokerDate;
|
||||
private Date lastBrokerDate;
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package com.ycwl.basic.model.pc.broker.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/12 10:00
|
||||
* 推客记录
|
||||
*/
|
||||
@Data
|
||||
@TableName("broker_record")
|
||||
public class BrokerRecord {
|
||||
@TableId
|
||||
private Long id;
|
||||
private Long brokerId;
|
||||
private Long orderId;
|
||||
private BigDecimal orderPrice;
|
||||
private BigDecimal brokerRate;
|
||||
private BigDecimal brokerPrice;
|
||||
private String reason;
|
||||
private Date createTime;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.ycwl.basic.model.pc.broker.req;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.ycwl.basic.model.common.BaseQueryParameterReq;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/12 10:00
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("查询推客记录请求参数")
|
||||
public class BrokerRecordReqQuery extends BaseQueryParameterReq {
|
||||
private Long brokerId;
|
||||
private Long orderId;
|
||||
@ApiModelProperty("开始时间")
|
||||
private Date startTime;
|
||||
@ApiModelProperty("结束时间")
|
||||
private Date endTime;
|
||||
}
|
@ -16,14 +16,15 @@ import java.util.Date;
|
||||
@ApiModel("查询推客列表请求参数")
|
||||
public class BrokerReqQuery extends BaseQueryParameterReq {
|
||||
private Long id;
|
||||
private Long scenicId;
|
||||
@ApiModelProperty("推客名称")
|
||||
private String name;
|
||||
@ApiModelProperty("手机号")
|
||||
private String phone;
|
||||
@ApiModelProperty("专属优惠码")
|
||||
private String promoCode;
|
||||
@ApiModelProperty("状态,0禁用,1启用")
|
||||
private Integer status;
|
||||
@ApiModelProperty("提成状态,0禁用,1启用")
|
||||
private Integer brokerEnable;
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.ycwl.basic.model.pc.broker.resp;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/12 10:00
|
||||
*/
|
||||
@Data
|
||||
public class BrokerRecordRespVO {
|
||||
private Long id;
|
||||
private Long brokerId;
|
||||
private Long orderId;
|
||||
private BigDecimal orderPrice;
|
||||
private BigDecimal brokerRate;
|
||||
private BigDecimal brokerPrice;
|
||||
private String reason;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
}
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@ -13,16 +14,26 @@ import java.util.Date;
|
||||
*/
|
||||
@Data
|
||||
public class BrokerRespVO {
|
||||
@TableId
|
||||
private Long id;
|
||||
private Long scenicId;
|
||||
private String scenicName;
|
||||
@ApiModelProperty("推客名称")
|
||||
private String name;
|
||||
@ApiModelProperty("专属优惠码")
|
||||
private String promoCode;
|
||||
private String phone;
|
||||
@ApiModelProperty("状态,0禁用,1启用")
|
||||
private Integer brokerEnable;
|
||||
private BigDecimal brokerRate;
|
||||
private Integer status;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createAt;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateAt;
|
||||
|
||||
private Long brokerScanCount;
|
||||
private Long brokerOrderCount;
|
||||
private BigDecimal brokerOrderAmount;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date firstBrokerDate;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date lastBrokerDate;
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.ycwl.basic.model.pc.broker.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/12 10:00
|
||||
*/
|
||||
@Data
|
||||
public class DailySummaryRespVO {
|
||||
private Date date;
|
||||
private Long recordCount;
|
||||
private BigDecimal totalOrderPrice;
|
||||
}
|
@ -203,7 +203,7 @@ public class ProfitSharingBiz {
|
||||
record.setCreateTime(new Date());
|
||||
records.add(record);
|
||||
}
|
||||
|
||||
revokeProfitSharing(scenicId, orderId, "重新分账");
|
||||
recordMapper.batchInsert(records);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,64 @@
|
||||
package com.ycwl.basic.service.impl.pc;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.mapper.BrokerRecordMapper;
|
||||
import com.ycwl.basic.model.pc.broker.entity.BrokerRecord;
|
||||
import com.ycwl.basic.model.pc.broker.req.BrokerRecordReqQuery;
|
||||
import com.ycwl.basic.model.pc.broker.resp.BrokerRecordRespVO;
|
||||
import com.ycwl.basic.model.pc.broker.resp.DailySummaryRespVO;
|
||||
import com.ycwl.basic.service.pc.BrokerRecordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/12 10:00
|
||||
*/
|
||||
@Service
|
||||
public class BrokerRecordServiceImpl implements BrokerRecordService {
|
||||
@Autowired
|
||||
private BrokerRecordMapper brokerRecordMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<BrokerRecordRespVO> pageQuery(BrokerRecordReqQuery brokerRecordReqQuery) {
|
||||
PageHelper.startPage(brokerRecordReqQuery.getPageNum(), brokerRecordReqQuery.getPageSize());
|
||||
List<BrokerRecordRespVO> list = brokerRecordMapper.list(brokerRecordReqQuery);
|
||||
PageInfo<BrokerRecordRespVO> pageInfo = new PageInfo<>(list);
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BrokerRecordRespVO> list(BrokerRecordReqQuery brokerRecordReqQuery) {
|
||||
return brokerRecordMapper.list(brokerRecordReqQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BrokerRecordRespVO getById(Long id) {
|
||||
return brokerRecordMapper.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int add(BrokerRecord brokerRecord) {
|
||||
return brokerRecordMapper.add(brokerRecord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
return brokerRecordMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(BrokerRecord brokerRecord) {
|
||||
return brokerRecordMapper.update(brokerRecord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DailySummaryRespVO> getDailySummaryByBrokerId(Long brokerId, Date startTime, Date endTime) {
|
||||
return brokerRecordMapper.getDailySummaryByBrokerId(brokerId, startTime, endTime);
|
||||
}
|
||||
|
||||
}
|
@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.mapper.BrokerMapper;
|
||||
import com.ycwl.basic.model.pc.broker.entity.BrokerEntity;
|
||||
import com.ycwl.basic.model.pc.broker.req.BrokerReqQuery;
|
||||
import com.ycwl.basic.model.pc.broker.resp.BrokerRespVO;
|
||||
import com.ycwl.basic.service.pc.BrokerService;
|
||||
import com.ycwl.basic.utils.SnowFlakeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -23,20 +24,20 @@ public class BrokerServiceImpl implements BrokerService {
|
||||
private BrokerMapper brokerMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<BrokerEntity> pageQuery(BrokerReqQuery brokerReqQuery) {
|
||||
public PageInfo<BrokerRespVO> pageQuery(BrokerReqQuery brokerReqQuery) {
|
||||
PageHelper.startPage(brokerReqQuery.getPageNum(),brokerReqQuery.getPageSize());
|
||||
List<BrokerEntity> list = brokerMapper.list(brokerReqQuery);
|
||||
PageInfo<BrokerEntity> pageInfo = new PageInfo(list);
|
||||
List<BrokerRespVO> list = brokerMapper.list(brokerReqQuery);
|
||||
PageInfo<BrokerRespVO> pageInfo = new PageInfo(list);
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BrokerEntity> list(BrokerReqQuery brokerReqQuery) {
|
||||
public List<BrokerRespVO> list(BrokerReqQuery brokerReqQuery) {
|
||||
return brokerMapper.list(brokerReqQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BrokerEntity getById(Long id) {
|
||||
public BrokerRespVO getById(Long id) {
|
||||
return brokerMapper.getById(id);
|
||||
}
|
||||
|
||||
@ -44,7 +45,6 @@ public class BrokerServiceImpl implements BrokerService {
|
||||
public int addOrUpdate(BrokerEntity broker) {
|
||||
Long id = broker.getId();
|
||||
if(id==null){
|
||||
broker.setId(SnowFlakeUtil.getLongId());
|
||||
return brokerMapper.add(broker);
|
||||
}else {
|
||||
return brokerMapper.update(broker);
|
||||
@ -60,4 +60,9 @@ public class BrokerServiceImpl implements BrokerService {
|
||||
public int updateStatus(Long id) {
|
||||
return brokerMapper.updateStatus(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateBrokerEnable(Long id) {
|
||||
return brokerMapper.updateBrokerEnable(id);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.ycwl.basic.service.pc;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.model.pc.broker.entity.BrokerRecord;
|
||||
import com.ycwl.basic.model.pc.broker.req.BrokerRecordReqQuery;
|
||||
import com.ycwl.basic.model.pc.broker.resp.BrokerRecordRespVO;
|
||||
import com.ycwl.basic.model.pc.broker.resp.DailySummaryRespVO;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/12 10:00
|
||||
*/
|
||||
public interface BrokerRecordService {
|
||||
PageInfo<BrokerRecordRespVO> pageQuery(BrokerRecordReqQuery brokerRecordReqQuery);
|
||||
|
||||
List<BrokerRecordRespVO> list(BrokerRecordReqQuery brokerRecordReqQuery);
|
||||
|
||||
BrokerRecordRespVO getById(Long id);
|
||||
|
||||
int add(BrokerRecord brokerRecord);
|
||||
|
||||
int delete(Long id);
|
||||
|
||||
int update(BrokerRecord brokerRecord);
|
||||
|
||||
List<DailySummaryRespVO> getDailySummaryByBrokerId(Long brokerId, Date startTime, Date endTime);
|
||||
}
|
@ -12,10 +12,11 @@ import java.util.List;
|
||||
* @Date:2024/12/2 15:54
|
||||
*/
|
||||
public interface BrokerService {
|
||||
PageInfo<BrokerEntity> pageQuery(BrokerReqQuery brokerReqQuery);
|
||||
List<BrokerEntity> list(BrokerReqQuery brokerReqQuery);
|
||||
BrokerEntity getById(Long id);
|
||||
PageInfo<BrokerRespVO> pageQuery(BrokerReqQuery brokerReqQuery);
|
||||
List<BrokerRespVO> list(BrokerReqQuery brokerReqQuery);
|
||||
BrokerRespVO getById(Long id);
|
||||
int addOrUpdate(BrokerEntity broker);
|
||||
int delete(Long id);
|
||||
int updateStatus(Long id);
|
||||
int updateBrokerEnable(Long id);
|
||||
}
|
||||
|
@ -2,10 +2,10 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ycwl.basic.mapper.BrokerMapper">
|
||||
<insert id="add">
|
||||
insert into broker(id, `name`, promo_code) values (#{id}, #{name}, #{promoCode})
|
||||
insert into broker(scenic_id, `name`, phone, status, broker_enable, broker_rate, create_at, update_at) values (#{scenicId}, #{name}, #{phone}, 0, #{brokerEnable}, #{brokerRate}, now(), now())
|
||||
</insert>
|
||||
<update id="update">
|
||||
update broker set `name` = #{name}, promo_code = #{promoCode} where id = #{id}
|
||||
update broker set `name` = #{name}, phone = #{phone}, broker_enable = #{brokerEnable}, broker_rate = #{brokerRate}, update_at = now() where id = #{id}
|
||||
</update>
|
||||
<update id="updateStatus">
|
||||
update broker
|
||||
@ -15,45 +15,56 @@
|
||||
0
|
||||
WHEN 0 THEN
|
||||
1
|
||||
ELSE null
|
||||
ELSE 1
|
||||
END)
|
||||
where id = #{id}
|
||||
</update>
|
||||
<update id="updateBrokerEnable">
|
||||
update broker
|
||||
set broker_enable = (CASE
|
||||
broker_enable
|
||||
WHEN 1 THEN
|
||||
0
|
||||
WHEN 0 THEN
|
||||
1
|
||||
ELSE 1
|
||||
END)
|
||||
where id = #{id}
|
||||
</update>
|
||||
<delete id="deleteById">
|
||||
delete from broker where id = #{id}
|
||||
</delete>
|
||||
<select id="list" resultType="com.ycwl.basic.model.pc.broker.entity.BrokerEntity">
|
||||
select id, `name`, phone, promo_code, status,
|
||||
(select count(1) from `order` where broker_id = broker.id) as broker_order_count,
|
||||
(select sum(pay_price) from `order` where broker_id = broker.id) as broker_order_amount,
|
||||
(select create_at from `order` where broker_id = broker.id and status = 1 order by create_at desc limit 1) as last_broker_date,
|
||||
(select create_at from `order` where broker_id = broker.id and status = 1 order by create_at asc limit 1) as first_broker_date,
|
||||
<select id="list" resultType="com.ycwl.basic.model.pc.broker.resp.BrokerRespVO">
|
||||
select b.id, scenic_id, s.name as scenicName, b.`name`, b.phone, b.broker_enable, b.broker_rate, b.status, b.create_at, b.update_at,
|
||||
(select count(1) from statistics s where s.type = 20 and s.morph_id = b.id) as broker_scan_count,
|
||||
(select count(1) from broker_record r where r.broker_id = b.id) as broker_order_count,
|
||||
(select sum(order_price) from broker_record r where r.broker_id = b.id) as broker_order_amount,
|
||||
create_at, update_at
|
||||
from broker
|
||||
from broker b left join scenic s on b.scenic_id = s.id
|
||||
<where>
|
||||
<if test="scenicId!= null">
|
||||
and b.scenic_id = #{scenicId}
|
||||
</if>
|
||||
<if test="name!= null and name!= ''">
|
||||
and `name` like concat('%', #{name}, '%')
|
||||
and b.`name` like concat('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="phone!= null and phone!= ''">
|
||||
and `phone` like concat('%', #{phone}, '%')
|
||||
</if>
|
||||
<if test="promoCode!= null and promoCode!= ''">
|
||||
and promo_code like concat('%', #{promoCode}, '%')
|
||||
and b.`phone` like concat('%', #{phone}, '%')
|
||||
</if>
|
||||
<if test="status!= null">
|
||||
and `status` = #{status}
|
||||
and b.`status` = #{status}
|
||||
</if>
|
||||
<if test="startTime!=null">
|
||||
and d.create_at >= #{startTime}
|
||||
and b.create_at >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime!=null">
|
||||
and d.create_at <= #{endTime}
|
||||
and b.create_at <= #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="getById" resultType="com.ycwl.basic.model.pc.broker.entity.BrokerEntity">
|
||||
select id, `name`, promo_code, status, create_at, update_at
|
||||
from broker
|
||||
where id = #{id}
|
||||
<select id="getById" resultType="com.ycwl.basic.model.pc.broker.resp.BrokerRespVO">
|
||||
select b.id, scenic_id, s.name as scenicName, b.`name`, b.phone, b.broker_enable, b.broker_rate, b.status, b.create_at, b.update_at
|
||||
from broker b left join scenic s on b.scenic_id = s.id
|
||||
where b.id = #{id}
|
||||
</select>
|
||||
</mapper>
|
86
src/main/resources/mapper/BrokerRecordMapper.xml
Normal file
86
src/main/resources/mapper/BrokerRecordMapper.xml
Normal file
@ -0,0 +1,86 @@
|
||||
<?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.ycwl.basic.mapper.BrokerRecordMapper">
|
||||
<select id="list" resultType="com.ycwl.basic.model.pc.broker.resp.BrokerRecordRespVO">
|
||||
select id, broker_id, order_id, order_price, broker_rate, broker_price, reason, create_time
|
||||
from broker_record
|
||||
<where>
|
||||
<if test="brokerId != null">
|
||||
and broker_id = #{brokerId}
|
||||
</if>
|
||||
<if test="orderId != null">
|
||||
and order_id = #{orderId}
|
||||
</if>
|
||||
<if test="startTime != null">
|
||||
and create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
and create_time <= #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<select id="getById" resultType="com.ycwl.basic.model.pc.broker.resp.BrokerRecordRespVO">
|
||||
select id, broker_id, order_id, order_price, broker_rate, broker_price, reason, create_time
|
||||
from broker_record
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getDailySummaryByBrokerId" resultType="com.ycwl.basic.model.pc.broker.resp.DailySummaryRespVO">
|
||||
SELECT date_series.date AS date,
|
||||
COALESCE(COUNT(br.id), 0) AS recordCount,
|
||||
COALESCE(SUM(br.order_price), 0) AS totalOrderPrice
|
||||
FROM (
|
||||
SELECT DATE_ADD(#{startTime}, INTERVAL (units.i + tens.i * 10 + hundreds.i * 100) DAY) AS date
|
||||
FROM (SELECT 0 AS i UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) units
|
||||
CROSS JOIN (SELECT 0 AS i UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) tens
|
||||
CROSS JOIN (SELECT 0 AS i UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) hundreds
|
||||
WHERE DATE_ADD(#{startTime}, INTERVAL (units.i + tens.i * 10) DAY) <= #{endTime}
|
||||
) date_series
|
||||
LEFT JOIN broker_record br ON DATE(br.create_time) = date_series.date AND br.broker_id = #{brokerId}
|
||||
GROUP BY date_series.date
|
||||
ORDER BY date_series.date
|
||||
</select>
|
||||
|
||||
<insert id="add">
|
||||
insert into broker_record(broker_id, order_id, order_price, broker_rate, broker_price, reason, create_time)
|
||||
values (#{brokerId}, #{orderId}, #{orderPrice}, #{brokerRate}, #{brokerPrice}, #{reason}, now())
|
||||
</insert>
|
||||
|
||||
<delete id="deleteById">
|
||||
delete from broker_record
|
||||
where id = #{id}
|
||||
</delete>
|
||||
<delete id="deleteByOrderId">
|
||||
delete from broker_record
|
||||
where order_id = #{orderId}
|
||||
</delete>
|
||||
|
||||
<update id="update">
|
||||
update broker_record
|
||||
<set>
|
||||
<if test="brokerId != null">
|
||||
broker_id = #{brokerId},
|
||||
</if>
|
||||
<if test="orderId != null">
|
||||
order_id = #{orderId},
|
||||
</if>
|
||||
<if test="orderPrice != null">
|
||||
order_price = #{orderPrice},
|
||||
</if>
|
||||
<if test="brokerRate != null">
|
||||
broker_rate = #{brokerRate},
|
||||
</if>
|
||||
<if test="brokerPrice != null">
|
||||
broker_price = #{brokerPrice},
|
||||
</if>
|
||||
<if test="reason != null">
|
||||
reason = #{reason},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
</mapper>
|
@ -247,4 +247,20 @@
|
||||
and create_at <= #{endTime}
|
||||
</if>
|
||||
</select>
|
||||
<select id="getBrokerIdListForUser" resultType="java.lang.Long">
|
||||
select morph_id
|
||||
from (
|
||||
select morph_id, max(create_time) as createTime
|
||||
from statistics
|
||||
where type = 20 and member_id = #{memberId}
|
||||
<if test="startTime!= null">
|
||||
and create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime!= null">
|
||||
and create_time <= #{endTime}
|
||||
</if>
|
||||
group by morph_id
|
||||
) a
|
||||
order by createTime desc
|
||||
</select>
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user