|
@@ -201,17 +201,39 @@ class StatSaleClass extends BaseClass
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- // 隔天售后扣客户采购金额(笔数不减)
|
|
|
|
|
- $fwdMap = NextDayRefundClass::sumAmountGroupByCustom($mainId, $currentStartTime, $currentEndTime);
|
|
|
|
|
- foreach ($fwdMap as $cid => $amt) {
|
|
|
|
|
- if (!isset($arr[$cid])) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- $arr[$cid]['amount'] = bcsub((string)$arr[$cid]['amount'], (string)$amt, 2);
|
|
|
|
|
- $arr[$cid]['profit'] = bcsub((string)$arr[$cid]['profit'], (string)$amt, 2);
|
|
|
|
|
- $totalAmount = bcsub((string)$totalAmount, (string)$amt, 2);
|
|
|
|
|
- $totalProfit = bcsub((string)$totalProfit, (string)$amt, 2);
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ // 隔天售后:按通过日扣金额/扎数;无当日开单也建负行(笔数不减)
|
|
|
|
|
+ $fwdMap = NextDayRefundClass::sumAmountGroupByCustom($mainId, $currentStartTime, $currentEndTime);
|
|
|
|
|
+ $qtyMap = NextDayRefundClass::sumItemQtyByCustom($mainId, $currentStartTime, $currentEndTime);
|
|
|
|
|
+ $cidKeys = array_unique(array_merge(array_keys($fwdMap), array_keys($qtyMap)));
|
|
|
|
|
+ foreach ($cidKeys as $cid) {
|
|
|
|
|
+ $amt = $fwdMap[$cid] ?? '0';
|
|
|
|
|
+ $qty = $qtyMap[$cid] ?? '0';
|
|
|
|
|
+ if (bccomp((string)$amt, '0', 2) == 0 && bccomp((string)$qty, '0', 2) == 0) {
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!isset($arr[$cid])) {
|
|
|
|
|
+ $arr[$cid] = [
|
|
|
|
|
+ 'customId' => $cid,
|
|
|
|
|
+ 'customName' => $customList[$cid]['name'] ?? '',
|
|
|
|
|
+ 'py' => $customList[$cid]['py'] ?? '',
|
|
|
|
|
+ 'num' => 0,
|
|
|
|
|
+ 'count' => '0.00',
|
|
|
|
|
+ 'amount' => '0.00',
|
|
|
|
|
+ 'levelName' => '',
|
|
|
|
|
+ 'orderPrice' => 0,
|
|
|
|
|
+ 'tkPrice' => 0,
|
|
|
|
|
+ 'cost' => 0,
|
|
|
|
|
+ 'profit' => '0.00',
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ $arr[$cid]['amount'] = bcsub((string)$arr[$cid]['amount'], (string)$amt, 2);
|
|
|
|
|
+ $arr[$cid]['profit'] = bcsub((string)$arr[$cid]['profit'], (string)$amt, 2);
|
|
|
|
|
+ $arr[$cid]['count'] = bcsub((string)($arr[$cid]['count'] ?? 0), (string)$qty, 2);
|
|
|
|
|
+ $totalAmount = bcsub((string)$totalAmount, (string)$amt, 2);
|
|
|
|
|
+ $totalProfit = bcsub((string)$totalProfit, (string)$amt, 2);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!empty($arr)) {
|
|
|
$arr = arrayUtil::arraySort($arr, 'profit');
|
|
$arr = arrayUtil::arraySort($arr, 'profit');
|
|
|
}
|
|
}
|
|
|
$totalAmount = floatval($totalAmount);
|
|
$totalAmount = floatval($totalAmount);
|
|
@@ -1471,15 +1493,14 @@ class StatSaleClass extends BaseClass
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 隔天售后:数量已用 nextRefundNum;通过日再扣数量/金额
|
|
|
|
|
- self::applyNextDayAdjustToSendStaffRows(
|
|
|
|
|
- $arr,
|
|
|
|
|
- $mainId,
|
|
|
|
|
- $currentStartTime,
|
|
|
|
|
- $currentEndTime
|
|
|
|
|
- );
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ // 隔天售后:数量已用 nextRefundNum;通过日再扣(无当日配送也建负行)
|
|
|
|
|
+ self::applyNextDayAdjustToSendStaffRows(
|
|
|
|
|
+ $arr,
|
|
|
|
|
+ $mainId,
|
|
|
|
|
+ $currentStartTime,
|
|
|
|
|
+ $currentEndTime
|
|
|
|
|
+ );
|
|
|
if (!empty($arr)) {
|
|
if (!empty($arr)) {
|
|
|
$arr = array_values($arr);
|
|
$arr = array_values($arr);
|
|
|
}
|
|
}
|
|
@@ -1570,18 +1591,39 @@ class StatSaleClass extends BaseClass
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- // 隔天售后按客户扣金额后归到片区(笔数不减;无当日开单的片区不新建行)
|
|
|
|
|
- $fwdMap = NextDayRefundClass::sumAmountGroupByCustom($mainId, $currentStartTime, $currentEndTime);
|
|
|
|
|
- foreach ($fwdMap as $cid => $amt) {
|
|
|
|
|
- $distId = $customList[$cid]['distId'] ?? 0;
|
|
|
|
|
- if (!isset($arr[$distId])) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- $arr[$distId]['amount'] = bcsub((string)$arr[$distId]['amount'], (string)$amt, 2);
|
|
|
|
|
- $arr[$distId]['profit'] = bcsub((string)$arr[$distId]['profit'], (string)$amt, 2);
|
|
|
|
|
- $totalAmount = bcsub((string)$totalAmount, (string)$amt, 2);
|
|
|
|
|
- $totalProfit = bcsub((string)$totalProfit, (string)$amt, 2);
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ // 隔天售后按客户归到片区扣金额/扎数;无当日开单的片区也建负行
|
|
|
|
|
+ $fwdMap = NextDayRefundClass::sumAmountGroupByCustom($mainId, $currentStartTime, $currentEndTime);
|
|
|
|
|
+ $qtyMap = NextDayRefundClass::sumItemQtyByCustom($mainId, $currentStartTime, $currentEndTime);
|
|
|
|
|
+ $cidKeys = array_unique(array_merge(array_keys($fwdMap), array_keys($qtyMap)));
|
|
|
|
|
+ foreach ($cidKeys as $cid) {
|
|
|
|
|
+ $amt = $fwdMap[$cid] ?? '0';
|
|
|
|
|
+ $qty = $qtyMap[$cid] ?? '0';
|
|
|
|
|
+ if (bccomp((string)$amt, '0', 2) == 0 && bccomp((string)$qty, '0', 2) == 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $distId = $customList[$cid]['distId'] ?? 0;
|
|
|
|
|
+ if (!isset($arr[$distId])) {
|
|
|
|
|
+ $arr[$distId] = [
|
|
|
|
|
+ 'distId' => $distId,
|
|
|
|
|
+ 'distName' => isset($distMap[$distId]) ? $distMap[$distId]['name'] : '未划片区',
|
|
|
|
|
+ 'num' => 0,
|
|
|
|
|
+ 'count' => '0.00',
|
|
|
|
|
+ 'amount' => '0.00',
|
|
|
|
|
+ 'levelName' => '',
|
|
|
|
|
+ 'orderPrice' => 0,
|
|
|
|
|
+ 'tkPrice' => 0,
|
|
|
|
|
+ 'cost' => 0,
|
|
|
|
|
+ 'profit' => '0.00',
|
|
|
|
|
+ ];
|
|
|
}
|
|
}
|
|
|
|
|
+ $arr[$distId]['amount'] = bcsub((string)$arr[$distId]['amount'], (string)$amt, 2);
|
|
|
|
|
+ $arr[$distId]['profit'] = bcsub((string)$arr[$distId]['profit'], (string)$amt, 2);
|
|
|
|
|
+ $arr[$distId]['count'] = bcsub((string)($arr[$distId]['count'] ?? 0), (string)$qty, 2);
|
|
|
|
|
+ $totalAmount = bcsub((string)$totalAmount, (string)$amt, 2);
|
|
|
|
|
+ $totalProfit = bcsub((string)$totalProfit, (string)$amt, 2);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!empty($arr)) {
|
|
|
$arr = arrayUtil::arraySort($arr, 'profit');
|
|
$arr = arrayUtil::arraySort($arr, 'profit');
|
|
|
}
|
|
}
|
|
|
$totalAmount = floatval($totalAmount);
|
|
$totalAmount = floatval($totalAmount);
|
|
@@ -1614,10 +1656,7 @@ class StatSaleClass extends BaseClass
|
|
|
if (bccomp($deltaAmt, '0', 2) == 0 && bccomp($deltaNum, '0', 2) == 0) {
|
|
if (bccomp($deltaAmt, '0', 2) == 0 && bccomp($deltaNum, '0', 2) == 0) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- // 通过日扣减时:当日无该花材开单则不新建行(与花材销量一致)
|
|
|
|
|
- if ($sign < 0 && !isset($arr[$pid])) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 通过日扣减:当日无该花材开单也建负行(收入/数量可为负)
|
|
|
if (!isset($arr[$pid])) {
|
|
if (!isset($arr[$pid])) {
|
|
|
$arr[$pid] = [
|
|
$arr[$pid] = [
|
|
|
'name' => $productList[$pid]['name'] ?? '已删除',
|
|
'name' => $productList[$pid]['name'] ?? '已删除',
|
|
@@ -1648,7 +1687,7 @@ class StatSaleClass extends BaseClass
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 配送业绩:支付日数量已用 nextRefundNum;通过日再扣数量/金额(仅退款只减金额)。
|
|
* 配送业绩:支付日数量已用 nextRefundNum;通过日再扣数量/金额(仅退款只减金额)。
|
|
|
- * 仅调整当日已有配送员行,不因纯售后新建行。
|
|
|
|
|
|
|
+ * 无当日配送单的配送员也会建负行业绩行。
|
|
|
*
|
|
*
|
|
|
* @param array $arr sendStaffId => 业绩行(引用修改 itemNum/amount)
|
|
* @param array $arr sendStaffId => 业绩行(引用修改 itemNum/amount)
|
|
|
* @param int $mainId
|
|
* @param int $mainId
|
|
@@ -1663,11 +1702,20 @@ class StatSaleClass extends BaseClass
|
|
|
) {
|
|
) {
|
|
|
$applyDelta = function ($staffMap, $sign) use (&$arr) {
|
|
$applyDelta = function ($staffMap, $sign) use (&$arr) {
|
|
|
foreach ($staffMap as $sid => $row) {
|
|
foreach ($staffMap as $sid => $row) {
|
|
|
- if (!isset($arr[$sid])) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
$deltaNum = bcmul((string)($row['num'] ?? '0'), (string)$sign, 2);
|
|
$deltaNum = bcmul((string)($row['num'] ?? '0'), (string)$sign, 2);
|
|
|
$deltaAmt = bcmul((string)($row['amount'] ?? '0'), (string)$sign, 2);
|
|
$deltaAmt = bcmul((string)($row['amount'] ?? '0'), (string)$sign, 2);
|
|
|
|
|
+ if (bccomp($deltaAmt, '0', 2) == 0 && bccomp($deltaNum, '0', 2) == 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!isset($arr[$sid])) {
|
|
|
|
|
+ $arr[$sid] = [
|
|
|
|
|
+ 'staffName' => '未记名',
|
|
|
|
|
+ 'orderNum' => 0,
|
|
|
|
|
+ 'itemNum' => '0.00',
|
|
|
|
|
+ 'amount' => '0.00',
|
|
|
|
|
+ 'staffId' => $sid,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
$arr[$sid]['itemNum'] = bcadd((string)($arr[$sid]['itemNum'] ?? 0), $deltaNum, 2);
|
|
$arr[$sid]['itemNum'] = bcadd((string)($arr[$sid]['itemNum'] ?? 0), $deltaNum, 2);
|
|
|
$arr[$sid]['amount'] = bcadd((string)($arr[$sid]['amount'] ?? 0), $deltaAmt, 2);
|
|
$arr[$sid]['amount'] = bcadd((string)($arr[$sid]['amount'] ?? 0), $deltaAmt, 2);
|
|
|
}
|
|
}
|