|
|
@@ -68,6 +68,160 @@ public class UserBillingController extends BaseController {
|
|
|
private IPosOrderRatingService posOrderRatingService;
|
|
|
@Autowired
|
|
|
private ICommissionRatesService commissionRatesService;
|
|
|
+ @Autowired
|
|
|
+ private IPosStoreService posStoreService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商家端账单列表
|
|
|
+ */
|
|
|
+ @Anonymous
|
|
|
+ @Auth
|
|
|
+ @GetMapping("/storeBillingList")
|
|
|
+ public AjaxResult storeBillingList(@RequestHeader String token,
|
|
|
+ @RequestParam Integer pageNum,
|
|
|
+ @RequestParam Integer pageSize,
|
|
|
+ @RequestParam(required = false) Long mdId,
|
|
|
+ @RequestParam(required = false) String type,
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
+ JwtUtil jwtUtil = new JwtUtil();
|
|
|
+ Long userId = Long.valueOf(jwtUtil.getusid(token));
|
|
|
+ InfoUser user = infoUserService.getById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ return error(MessageUtils.message("no.user.not.exist"));
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrapper<UserBilling> wrapper = new QueryWrapper<>();
|
|
|
+ String userType = user.getUserType();
|
|
|
+
|
|
|
+ if ("1".equals(userType)) {
|
|
|
+ // 商家:查自己名下所有门店的账单
|
|
|
+ wrapper.eq("user_id", userId);
|
|
|
+ if (mdId != null) {
|
|
|
+ wrapper.eq("md_id", mdId);
|
|
|
+ }
|
|
|
+ } else if ("4".equals(userType)) {
|
|
|
+ // 摊位主/门店:仅查自己关联门店的账单
|
|
|
+ Long storeId = user.getStoreId();
|
|
|
+ if (storeId == null) {
|
|
|
+ return error("未关联门店");
|
|
|
+ }
|
|
|
+ wrapper.eq("md_id", storeId);
|
|
|
+ } else {
|
|
|
+ return error("无权限访问");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type != null && !type.isEmpty()) {
|
|
|
+ wrapper.eq("type", type);
|
|
|
+ }
|
|
|
+ if (startDate != null && !startDate.isEmpty()) {
|
|
|
+ wrapper.apply("date_format(cretim,'%Y-%m-%d %H:%i:%s') >= date_format('" + startDate + " 00:00:00','%Y-%m-%d %H:%i:%s')");
|
|
|
+ }
|
|
|
+ if (endDate != null && !endDate.isEmpty()) {
|
|
|
+ wrapper.apply("date_format(cretim,'%Y-%m-%d %H:%i:%s') <= date_format('" + endDate + " 23:59:59','%Y-%m-%d %H:%i:%s')");
|
|
|
+ }
|
|
|
+ wrapper.orderByDesc("id");
|
|
|
+
|
|
|
+ Page<UserBilling> page = new Page<>(pageNum, pageSize);
|
|
|
+ IPage<UserBilling> pageResult = userBillingService.page(page, wrapper);
|
|
|
+
|
|
|
+ // 填充门店名称
|
|
|
+ List<UserBilling> records = pageResult.getRecords();
|
|
|
+ fillStoreName(records);
|
|
|
+
|
|
|
+ JSONObject org = new JSONObject();
|
|
|
+ org.put("list", records);
|
|
|
+ org.put("total", pageResult.getTotal());
|
|
|
+ org.put("pageNum", pageResult.getCurrent());
|
|
|
+ org.put("pageSize", pageResult.getSize());
|
|
|
+ return success(MessageUtils.message("no.success"), org);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商家端账单汇总
|
|
|
+ */
|
|
|
+ @Anonymous
|
|
|
+ @Auth
|
|
|
+ @GetMapping("/storeBillingSummary")
|
|
|
+ public AjaxResult storeBillingSummary(@RequestHeader String token,
|
|
|
+ @RequestParam(required = false) Long mdId,
|
|
|
+ @RequestParam(required = false) String type,
|
|
|
+ @RequestParam(required = false) String startDate,
|
|
|
+ @RequestParam(required = false) String endDate) {
|
|
|
+ JwtUtil jwtUtil = new JwtUtil();
|
|
|
+ Long userId = Long.valueOf(jwtUtil.getusid(token));
|
|
|
+ InfoUser user = infoUserService.getById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ return error(MessageUtils.message("no.user.not.exist"));
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrapper<UserBilling> wrapper = new QueryWrapper<>();
|
|
|
+ String userType = user.getUserType();
|
|
|
+
|
|
|
+ if ("1".equals(userType)) {
|
|
|
+ wrapper.eq("user_id", userId);
|
|
|
+ if (mdId != null) {
|
|
|
+ wrapper.eq("md_id", mdId);
|
|
|
+ }
|
|
|
+ } else if ("3".equals(userType)) {
|
|
|
+ Long storeId = user.getStoreId();
|
|
|
+ if (storeId == null) {
|
|
|
+ return error("未关联门店");
|
|
|
+ }
|
|
|
+ wrapper.eq("md_id", storeId);
|
|
|
+ } else {
|
|
|
+ return error("无权限访问");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type != null && !type.isEmpty()) {
|
|
|
+ wrapper.eq("type", type);
|
|
|
+ }
|
|
|
+ if (startDate != null && !startDate.isEmpty()) {
|
|
|
+ wrapper.apply("date_format(cretim,'%Y-%m-%d %H:%i:%s') >= date_format('" + startDate + " 00:00:00','%Y-%m-%d %H:%i:%s')");
|
|
|
+ }
|
|
|
+ if (endDate != null && !endDate.isEmpty()) {
|
|
|
+ wrapper.apply("date_format(cretim,'%Y-%m-%d %H:%i:%s') <= date_format('" + endDate + " 23:59:59','%Y-%m-%d %H:%i:%s')");
|
|
|
+ }
|
|
|
+
|
|
|
+ wrapper.select(
|
|
|
+ "IFNULL(SUM(amount),0) as amount",
|
|
|
+ "IFNULL(SUM(divvy),0) as divvy"
|
|
|
+ );
|
|
|
+
|
|
|
+ UserBilling summary = userBillingService.getOne(wrapper);
|
|
|
+ double totalAmount = summary != null && summary.getAmount() != null ? summary.getAmount() : 0;
|
|
|
+ double totalDivvy = summary != null && summary.getDivvy() != null ? summary.getDivvy() : 0;
|
|
|
+ double netIncome = totalAmount - totalDivvy;
|
|
|
+
|
|
|
+ JSONObject org = new JSONObject();
|
|
|
+ org.put("totalAmount", totalAmount);
|
|
|
+ org.put("totalDivvy", totalDivvy);
|
|
|
+ org.put("netIncome", netIncome);
|
|
|
+ return success(MessageUtils.message("no.success"), org);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充门店名称
|
|
|
+ */
|
|
|
+ private void fillStoreName(List<UserBilling> list) {
|
|
|
+ if (list == null || list.isEmpty()) return;
|
|
|
+ List<Integer> mdIds = list.stream()
|
|
|
+ .map(UserBilling::getMdId)
|
|
|
+ .filter(id -> id != null)
|
|
|
+ .map(Long::intValue)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (mdIds.isEmpty()) return;
|
|
|
+ List<PosStore> stores = posStoreService.listByIds(mdIds);
|
|
|
+ list.forEach(billing -> {
|
|
|
+ if (billing.getMdId() != null) {
|
|
|
+ stores.stream()
|
|
|
+ .filter(s -> Long.valueOf(s.getId()).equals(billing.getMdId()))
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(s -> billing.setMdName(s.getPosName()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 商家日账单数据
|
|
|
@@ -85,7 +239,8 @@ public class UserBillingController extends BaseController {
|
|
|
@RequestParam Long page,
|
|
|
@RequestParam Long size,
|
|
|
@RequestParam String riqi,
|
|
|
- @RequestParam(required = false) Boolean isCancel
|
|
|
+ @RequestParam(required = false) Boolean isCancel,
|
|
|
+ @RequestParam(required = false) Long mdId
|
|
|
) {
|
|
|
JwtUtil jwtUtil = new JwtUtil();
|
|
|
Long id = Long.valueOf(jwtUtil.getusid(token));
|
|
|
@@ -94,9 +249,9 @@ public class UserBillingController extends BaseController {
|
|
|
if (isCancel != null && isCancel) {
|
|
|
return getDayCancleOrderList(page, size, riqi, user);
|
|
|
}
|
|
|
- List<UserBilling> list = userBillingMapper.getdaylist(id, riqi, (page - 1) * size, size);
|
|
|
+ List<UserBilling> list = userBillingMapper.getdaylist(id, riqi, mdId, (page - 1) * size, size);
|
|
|
setYhInfo(list);
|
|
|
- BillDTO sum = userBillingMapper.getdaysum(id, riqi);
|
|
|
+ BillDTO sum = userBillingMapper.getdaysum(id, riqi, mdId);
|
|
|
JSONObject org = new JSONObject();
|
|
|
org.put("shul", sum.getSul());
|
|
|
org.put("sum", sum.getShouru());
|
|
|
@@ -113,7 +268,7 @@ public class UserBillingController extends BaseController {
|
|
|
if ("2".equals(user.getUserType())) {
|
|
|
setQsList(list, org);
|
|
|
} else {
|
|
|
- ShBillingDto shBillingDto = userBillingMapper.getShDaysum(id, riqi);
|
|
|
+ ShBillingDto shBillingDto = userBillingMapper.getShDaysum(id, riqi, mdId);
|
|
|
org.put("foodAmount", shBillingDto.getFoodAmount());
|
|
|
org.put("shYh", shBillingDto.getShYh());
|
|
|
setShList(list, org, user);
|
|
|
@@ -150,7 +305,8 @@ public class UserBillingController extends BaseController {
|
|
|
@RequestParam Long page,
|
|
|
@RequestParam Long size,
|
|
|
@RequestParam String riqi,
|
|
|
- @RequestParam(required = false) Boolean isCancel) {
|
|
|
+ @RequestParam(required = false) Boolean isCancel,
|
|
|
+ @RequestParam(required = false) Long mdId) {
|
|
|
JwtUtil jwtUtil = new JwtUtil();
|
|
|
Long id = Long.valueOf(jwtUtil.getusid(token));
|
|
|
InfoUser user = infoUserService.getById(id);
|
|
|
@@ -158,9 +314,9 @@ public class UserBillingController extends BaseController {
|
|
|
if (isCancel != null && isCancel) {
|
|
|
return getWeekCancleOrderList(page, size, riqi, user);
|
|
|
}
|
|
|
- List<UserBilling> list = userBillingMapper.getmeeklist(id, riqi, (page - 1) * size, size);
|
|
|
+ List<UserBilling> list = userBillingMapper.getmeeklist(id, riqi, mdId, (page - 1) * size, size);
|
|
|
setYhInfo(list);
|
|
|
- BillDTO sum = userBillingMapper.getmeeksum(id, riqi);
|
|
|
+ BillDTO sum = userBillingMapper.getmeeksum(id, riqi, mdId);
|
|
|
JSONObject org = new JSONObject();
|
|
|
org.put("shul", sum.getSul()); //数量
|
|
|
org.put("sum", sum.getShouru());
|
|
|
@@ -176,7 +332,7 @@ public class UserBillingController extends BaseController {
|
|
|
if ("2".equals(user.getUserType())) {
|
|
|
setQsList(list, org);
|
|
|
} else {
|
|
|
- ShBillingDto shBillingDto = userBillingMapper.getShMeeksum(id, riqi);
|
|
|
+ ShBillingDto shBillingDto = userBillingMapper.getShMeeksum(id, riqi, mdId);
|
|
|
org.put("foodAmount", shBillingDto.getFoodAmount());
|
|
|
org.put("shYh", shBillingDto.getShYh());
|
|
|
setShList(list, org, user);
|
|
|
@@ -299,16 +455,17 @@ public class UserBillingController extends BaseController {
|
|
|
@RequestParam Long page,
|
|
|
@RequestParam Long size,
|
|
|
@RequestParam String riqi,
|
|
|
- @RequestParam(required = false) Boolean isCancel) {
|
|
|
+ @RequestParam(required = false) Boolean isCancel,
|
|
|
+ @RequestParam(required = false) Long mdId) {
|
|
|
JwtUtil jwtUtil = new JwtUtil();
|
|
|
Long id = Long.valueOf(jwtUtil.getusid(token));
|
|
|
InfoUser user = infoUserService.getById(id);
|
|
|
if (isCancel != null && isCancel) {
|
|
|
return getMonthCancleOrderList(page, size, riqi, user);
|
|
|
}
|
|
|
- List<UserBilling> list = userBillingMapper.getmatlist(id, riqi, (page - 1) * size, size);
|
|
|
+ List<UserBilling> list = userBillingMapper.getmatlist(id, riqi, mdId, (page - 1) * size, size);
|
|
|
setYhInfo(list);
|
|
|
- BillDTO sum = userBillingMapper.getmatsum(id, riqi);
|
|
|
+ BillDTO sum = userBillingMapper.getmatsum(id, riqi, mdId);
|
|
|
JSONObject org = new JSONObject();
|
|
|
org.put("shul", sum.getSul());
|
|
|
org.put("sum", sum.getShouru());
|
|
|
@@ -324,7 +481,7 @@ public class UserBillingController extends BaseController {
|
|
|
if ("2".equals(user.getUserType())) {
|
|
|
setQsList(list, org);
|
|
|
} else {
|
|
|
- ShBillingDto shBillingDto = userBillingMapper.getshMonthsum(id, riqi);
|
|
|
+ ShBillingDto shBillingDto = userBillingMapper.getshMonthsum(id, riqi, mdId);
|
|
|
org.put("foodAmount", shBillingDto.getFoodAmount());
|
|
|
org.put("shYh", shBillingDto.getShYh());
|
|
|
setShList(list, org, user);
|