修改计算余额方式

dev
wuwenxiong 2022-01-07 15:29:45 +08:00
parent 6c013d24fe
commit 7791a585b5
9 changed files with 93 additions and 57 deletions

View File

@ -141,7 +141,7 @@ public class PrepayService {
//获取账户可用余额
BigDecimal availableBalance = RefundDetailService.me.getAvailableBalance(prepayCustomer.getCustomerId(), prepayCustomer.getSurplus());
if (ordercluster.getSaleType() == 1) {
availableBalance = PresellOrderService.me.getPresellCustomerSurplusById(ordercluster.getPresellOrderId());
availableBalance = PresellOrderService.me.getPresellCustomerSurplusById(ordercluster.getCustomerId());
}
out.set("prepay_truck", true);
out.set("prepay_threshold", prepayCustomer.getThreshold());

View File

@ -163,21 +163,32 @@ public class PresellOrderService extends BaseService {
return PresellOrder.dao.find(sql, paraList.toArray());
}
public BigDecimal getPresellCustomerSurplusById(String id) {
String sql = "select t.presell_amount - ifnull(g.total_price, 0) surplus from presell_order t\n" +
" left join ( \n" +
"SELECT\n" +
" o.presell_order_id,\n" +
" SUM(d.total_price) total_price\n" +
"FROM\n" +
" `order_temp` d\n" +
"LEFT JOIN ordercluster o ON d.ordercluster_id = o.id\n" +
"WHERE\n" +
" d.sale_type = 1\n" +
"AND d.state = 5\n" +
"GROUP BY\n" +
" o.presell_order_id" + ") g on g.presell_order_id = t.id\n" +
"WHERE t.id = ?";
return Db.queryBigDecimal(sql, id);
public BigDecimal getPresellCustomerSurplusById(Integer id) {
List<Object> params = new ArrayList<>();
params.add(id);
params.add(id);
String sql = "SELECT\n" +
" (\n" +
" SELECT\n" +
" sum(t.presell_amount)\n" +
" FROM\n" +
" presell_order t\n" +
" WHERE\n" +
" t.del = 0\n" +
" AND t.customer_id = ?\n" +
" ) - (\n" +
" SELECT\n" +
" sum(\n" +
" t.total_weight * t.unit_price\n" +
" )\n" +
" FROM\n" +
" ordercluster t\n" +
" WHERE\n" +
" t.sale_type = 1\n" +
" AND t.state < 5\n" +
" AND t.customer_id = ?\n" +
" ) as surplus";
BigDecimal out = Db.queryBigDecimal(sql, params.toArray());
return out == null ? new BigDecimal(0) : out;
}
}

View File

@ -51,6 +51,7 @@ public class CustomerStatService {
" where t.customer_id is not null\n" +
" and t.create_time <= ? \n" +
" and t.state = 5\n" +
" and t.sale_type = 0\n" +
customerSql +
" group by t.customer_id\n";

View File

@ -3026,7 +3026,7 @@ public class OrderStatService {
" left join (\n" +
" select t.id, t.product_id, count(*) as orderCount, sum(t.total_price) as totalPrice, sum(t.weight) as weight\n" +
" from (\n" +
" select t.supermarket_id as id, t.paid, t.total_price, t.weight, t.product_id\n" +
" select t.supermarket_id as id, t.total_price, t.weight, t.product_id\n" +
" from order_temp t \n" +
" where t.sale_type = 0 \n" +
" and t.state = 5 \n" +
@ -3040,9 +3040,9 @@ public class OrderStatService {
List<Record> yhList = Db.find(
"SELECT\n" +
" t.supermarket_id id,\n" +
" count(*) as order_num,\n" +
" sum(t.weight) as weight,\n" +
" sum(t.total_price) total_price\n" +
" ifnull(count(*), 0) as order_num,\n" +
" ifnull(sum(t.weight), 0) as weight,\n" +
" ifnull(sum(t.total_price), 0) as total_price\n" +
"FROM\n" +
" order_temp t\n" +
"LEFT JOIN ordercluster c ON c.id = t.ordercluster_id\n" +
@ -3050,6 +3050,7 @@ public class OrderStatService {
"WHERE\n" +
" t.sale_type = 1\n" +
" AND t.state = 5\n" +
" AND p.del = 0\n" +
yhParams +
"GROUP BY\n" +
" t.supermarket_id", yhParamsList.toArray());
@ -3076,7 +3077,7 @@ public class OrderStatService {
double hj_yh_total_price = 0.0;
// 实售合并
if (shList.size() > 0) {
if (shList != null && !shList.isEmpty()) {
List<Record> shList2 = new ArrayList<>();
for (Record s : shList) {
int id = s.getInt("id");
@ -3095,6 +3096,16 @@ public class OrderStatService {
if ((s1_id == 1 && s2_id == 7) || (s1_id == 5 && s2_id == 9) ||s1_id == 6 && s2_id == 8) {
Record s3 = new Record();
int order_num;
int s1_order_num = s1.getInt("order_num") == null ? 0 : s1.getInt("order_num");
int s2_order_num = s2.getInt("order_num") == null ? 0 : s2.getInt("order_num");
order_num = s1_order_num + s2_order_num;
BigDecimal total_price;
BigDecimal s1_total_price = s1.getBigDecimal("total_price") == null ? new BigDecimal(0) : s1.getBigDecimal("total_price");
BigDecimal s2_total_price = s2.getBigDecimal("total_price") == null ? new BigDecimal(0) : s2.getBigDecimal("total_price");
total_price = s1_total_price.add(s2_total_price);
BigDecimal weight = s1.getBigDecimal("weight").add(s2.getBigDecimal("weight"));
if (weight.compareTo(new BigDecimal(0)) == 0) {
weight = new BigDecimal(0);
@ -3104,8 +3115,8 @@ public class OrderStatService {
s3.set("name", s1.getStr("name"));
s3.set("product_id", s1.getInt("product_id"));
s3.set("product_name", s1.getStr("product_name"));
s3.set("order_num", Math.addExact(s1.getInt("order_num"), s2.getInt("order_num")));
s3.set("total_price", s1.getBigDecimal("total_price").add(s2.getBigDecimal("total_price")));
s3.set("order_num", order_num);
s3.set("total_price", total_price);
s3.set("weight", weight);
shList1.add(s3);
break;
@ -3115,9 +3126,21 @@ public class OrderStatService {
} else if (shList2.size() == 1) {
shList1.addAll(shList2);
}
} else {
for (Record s : sups) {
Record p = new Record();
p.set("id", s.getInt("id"));
p.set("name", s.getStr("name"));
p.set("product_id", 1);
p.set("product_name", "黄砂");
p.set("order_num", 0);
p.set("weight", new BigDecimal(0));
p.set("total_price", new BigDecimal(0));
shList1.add(p);
}
}
// 预售合并
if (yhList.size() > 0) {
if (yhList != null && !yhList.isEmpty()) {
List<Record> yhList2 = new ArrayList<>();
for (Record s : yhList) {
int id = s.getInt("id");
@ -3133,18 +3156,28 @@ public class OrderStatService {
for (Record s2 : yhList2) {
int s1_id = s1.getInt("id");
int s2_id = s2.getInt("id");
if ((s1_id == 1 && s2_id == 7) || (s1_id == 5 && s2_id == 9) ||s1_id == 6 && s2_id == 8) {
if ((s1_id == 1 && s2_id == 7) || (s1_id == 5 && s2_id == 9) || s1_id == 6 && s2_id == 8) {
flag = true;
Record s3 = new Record();
int order_num;
int s1_order_num = s1.getInt("order_num") == null ? 0 : s1.getInt("order_num");
int s2_order_num = s2.getInt("order_num") == null ? 0 : s2.getInt("order_num");
order_num = s1_order_num + s2_order_num;
BigDecimal total_price;
BigDecimal s1_total_price = s1.getBigDecimal("total_price") == null ? new BigDecimal(0) : s1.getBigDecimal("total_price");
BigDecimal s2_total_price = s2.getBigDecimal("total_price") == null ? new BigDecimal(0) : s2.getBigDecimal("total_price");
total_price = s1_total_price.add(s2_total_price);
BigDecimal weight = s1.getBigDecimal("weight").add(s2.getBigDecimal("weight"));
if (weight.compareTo(new BigDecimal(0)) == 0) {
weight = new BigDecimal(0);
}
s3.set("id", s1_id);
s3.set("order_num", Math.addExact(s1.getInt("order_num"), s2.getInt("order_num")));
s3.set("total_price", s1.getBigDecimal("total_price").add(s2.getBigDecimal("total_price")));
s3.set("order_num", order_num);
s3.set("total_price", total_price);
s3.set("weight", weight);
yhList1.add(s3);
break;
@ -3159,7 +3192,11 @@ public class OrderStatService {
}
} else {
for (Record s : sups) {
Record p = new Record().set("id", s.getInt("id")).set("total_price", new BigDecimal(0));
Record p = new Record();
p.set("id", s.getInt("id"));
p.set("order_num", 0);
p.set("weight", new BigDecimal(0));
p.set("total_price", new BigDecimal(0));
yhList1.add(p);
}
}
@ -3182,9 +3219,9 @@ public class OrderStatService {
if (s_id == sl_id) {
flag = false;
Record r = new Record();
int order_num = sl.getInt("order_num");
BigDecimal weight = sl.getBigDecimal("weight");
BigDecimal total_price = sl.getBigDecimal("total_price");
int order_num = sl.getInt("order_num") == null ? 0 : sl.getInt("order_num");
BigDecimal weight = sl.getBigDecimal("weight") == null ? new BigDecimal(0) : sl.getBigDecimal("weight");
BigDecimal total_price = sl.getBigDecimal("total_price") == null ? new BigDecimal(0) : sl.getBigDecimal("total_price");
if (product_id == 1) {
hj_hs_sh_order_num += order_num;
@ -3249,9 +3286,9 @@ public class OrderStatService {
flag = false;
Record r = new Record();
int order_num = yl.getInt("order_num");
BigDecimal weight = yl.getBigDecimal("weight");
BigDecimal total_price = yl.getBigDecimal("total_price");
int order_num = yl.getInt("order_num") == null ? 0 : yl.getInt("order_num");
BigDecimal weight = yl.getBigDecimal("weight") == null ? new BigDecimal(0) : yl.getBigDecimal("weight");
BigDecimal total_price = yl.getBigDecimal("total_price") == null ? new BigDecimal(0) : yl.getBigDecimal("total_price");
hj_yh_order_num += order_num;
hj_yh_weight += weight.doubleValue();
hj_yh_total_price += total_price.doubleValue();
@ -3375,7 +3412,7 @@ public class OrderStatService {
Record total = new Record();
total.set("key", "total").set("name", "总合计").set("item_name", "-").set("product_name", "-")
.set("order_num", hj_hs_sh_order_num + hj_els_sh_order_num + hj_jzs_sh_order_num + hj_yh_order_num)
.set("weight", hj_hs_sh_weight + hj_els_sh_weight + hj_els_sh_weight + hj_yh_weight)
.set("weight", hj_hs_sh_weight + hj_els_sh_weight + hj_jzs_sh_weight + hj_yh_weight)
.set("total_price", hj_hs_sh_total_price + hj_els_sh_total_price + hj_jzs_sh_total_price + hj_yh_total_price);
retList.add(total);

View File

@ -1126,7 +1126,7 @@ public class OrderTempSyncService {
return Result.failed("没有找到客户预付费信息");
}
//账户可用余额
BigDecimal availableBalance = PresellOrderService.me.getPresellCustomerSurplusById(ordercluster.getPresellOrderId());
BigDecimal availableBalance = PresellOrderService.me.getPresellCustomerSurplusById(ordercluster.getCustomerId());
if (availableBalance == null || availableBalance.compareTo(min) <= 0) {
return Result.failed("客户余额不足");
}

View File

@ -322,11 +322,10 @@ public class OrderStatController extends BaseController {
String tm = get("tm");
int export = getInt("export", 0); // 是否导出为exce 0 不导出1 导出
Boolean stat_product = getBoolean("stat_product", false);
Integer sale_type = getInt("sale_type");
if (export == 0) {
renderJson(Result.object(OrderStatService.me.salestat(tm, sale_type)));
renderJson(Result.object(OrderStatService.me.statYearBySup(tm, 2)));
} else {
Workbook wb = OrderStatService.me.yearsalestatExport(tm, sale_type);
Workbook wb = OrderStatService.me.yearsalestatExportBySup(tm);
render(new ExcelRender("按砂站总销售汇总表_" + System.currentTimeMillis() + ".xlsx", wb));
}
}

View File

@ -114,14 +114,12 @@ public class InvoiceReceiveSyncService extends BaseSyncService {
}
receive.setSurplus(0);
SyncTask syncTask = new SyncTask();
boolean ret = Db.tx(new IAtom() {
@Override
public boolean run() {
try {
return receive.update()
&& SyncTaskService.me.save(syncTask.addUpdateData(receive), receive.getSupermarketId()) // 下发到指定的砂站
&& SyncTaskService.me.save(new SyncTask().addUpdateData(receive), receive.getSupermarketId()) // 下发到指定的砂站
&& ModifyLogService.me.save(receive, oldobj, Enums.DataOpType.UPDATE.getId(), user);
} catch (Exception e) {
log.error(e.getMessage(), e);
@ -130,10 +128,6 @@ public class InvoiceReceiveSyncService extends BaseSyncService {
}
});
if (ret) {
SyncTaskService.me.send(syncTask);
}
return ret ? Result.object(receive) : Result.failed(false, "回收失败");
}
}

View File

@ -585,7 +585,7 @@ public class OrderclusterSyncService extends BaseSyncService {
}
// 余额
BigDecimal pug_amount = PresellOrderService.me.getPresellCustomerSurplusById(model.getPresellOrderId());
BigDecimal pug_amount = PresellOrderService.me.getPresellCustomerSurplusById(model.getCustomerId());
BigDecimal surplus = presellOrder.getPresellAmount().subtract(pug_amount);
if (unitprice.multiply(model.getTotalWeight()).compareTo(surplus) > 0) {
@ -901,7 +901,7 @@ public class OrderclusterSyncService extends BaseSyncService {
return Result.failed(false, "未获取到订单信息");
}
// 余额
BigDecimal pug_amount = PresellOrderService.me.getPresellCustomerSurplusById(oldobj.getPresellOrderId());
BigDecimal pug_amount = PresellOrderService.me.getPresellCustomerSurplusById(oldobj.getCustomerId());
BigDecimal surplus = order.getPresellAmount().subtract(pug_amount);
if (plan_total_price.compareTo(surplus) > 0) {
return Result.failedstr("共计总配额达 %.2f元,客户余额(%.2f元)不足", plan_total_price, surplus);
@ -1128,7 +1128,7 @@ public class OrderclusterSyncService extends BaseSyncService {
} else {
PresellOrder order = PresellOrder.dao.findById(presell_order_id);
if (order != null) {
BigDecimal pug_amount = PresellOrderService.me.getPresellCustomerSurplusById(presell_order_id);
BigDecimal pug_amount = PresellOrderService.me.getPresellCustomerSurplusById(order.getCustomerId());
availableBalance = order.getPresellAmount().subtract(pug_amount);
maximumConfiguration = availableBalance.divide(new BigDecimal(unit_price), 2, BigDecimal.ROUND_DOWN);
}

View File

@ -111,14 +111,12 @@ public class TicketReceiveSyncService extends BaseSyncService {
}
receive.setSurplus(0);
SyncTask syncTask = new SyncTask();
boolean ret = Db.tx(new IAtom() {
@Override
public boolean run() {
try {
return receive.update()
&& SyncTaskService.me.save(syncTask.addUpdateData(receive), receive.getSupermarketId()) // 下发到指定的砂站
&& SyncTaskService.me.save(new SyncTask().addUpdateData(receive), receive.getSupermarketId()) // 下发到指定的砂站
&& ModifyLogService.me.save(receive, oldobj, Enums.DataOpType.UPDATE.getId(), user);
} catch (Exception e) {
log.error(e.getMessage(), e);
@ -127,10 +125,6 @@ public class TicketReceiveSyncService extends BaseSyncService {
}
});
if (ret) {
SyncTaskService.me.send(syncTask);
}
return ret ? Result.object(receive) : Result.failed(false, "回收失败");
}
}