|
|
@@ -71,84 +71,82 @@ class StatItemController extends BaseController
|
|
|
$staffId = $get['staffId'] ?? 0;
|
|
|
|
|
|
$list = OrderClass::getAllByCondition($where, null, '*');
|
|
|
- if (empty($list)) {
|
|
|
- util::success(['list' => []]);
|
|
|
- }
|
|
|
$productInfo = ProductClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,name,py,cgStaffId', 'id');
|
|
|
$stat = [];
|
|
|
$totalAmount = 0;
|
|
|
$totalNum = 0;
|
|
|
$totalMl = 0;
|
|
|
- foreach ($list as $order) {
|
|
|
- $orderSn = $order['orderSn'] ?? '';
|
|
|
- $status = $order['status'] ?? 0;
|
|
|
- $book = $order['book'] ?? 0;
|
|
|
- $actPrice = $order['actPrice'] ?? 0;
|
|
|
- if ($status == 5 || $status == 1 || ($book == 1 && $status == 2)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if ($actPrice <= 0) {
|
|
|
- //如果全部退款的花材也不统计
|
|
|
- continue;
|
|
|
- }
|
|
|
- $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
- if (!empty($itemList)) {
|
|
|
- foreach ($itemList as $item) {
|
|
|
- $productId = $item->productId ?? 0;
|
|
|
- $name = $productInfo[$productId]['name'] ?? '';
|
|
|
- $py = $productInfo[$productId]['py'] ?? '';
|
|
|
+ if (!empty($list)) {
|
|
|
+ foreach ($list as $order) {
|
|
|
+ $orderSn = $order['orderSn'] ?? '';
|
|
|
+ $status = $order['status'] ?? 0;
|
|
|
+ $book = $order['book'] ?? 0;
|
|
|
+ $actPrice = $order['actPrice'] ?? 0;
|
|
|
+ if ($status == 5 || $status == 1 || ($book == 1 && $status == 2)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ($actPrice <= 0) {
|
|
|
+ //如果全部退款的花材也不统计
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
+ if (!empty($itemList)) {
|
|
|
+ foreach ($itemList as $item) {
|
|
|
+ $productId = $item->productId ?? 0;
|
|
|
+ $name = $productInfo[$productId]['name'] ?? '';
|
|
|
+ $py = $productInfo[$productId]['py'] ?? '';
|
|
|
|
|
|
- if (!empty($staffId)) {
|
|
|
- $currentCgStaffId = $productInfo[$productId]['cgStaffId'] ?? 0;
|
|
|
- if ($staffId != $currentCgStaffId) {
|
|
|
- continue;
|
|
|
+ if (!empty($staffId)) {
|
|
|
+ $currentCgStaffId = $productInfo[$productId]['cgStaffId'] ?? 0;
|
|
|
+ if ($staffId != $currentCgStaffId) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- $num = NextDayRefundClass::payDayRemainNum(
|
|
|
- $item['xhNum'] ?? 0,
|
|
|
- $item['refundNum'] ?? 0,
|
|
|
- $item['nextRefundNum'] ?? 0
|
|
|
- );
|
|
|
- $unitPrice = $item['xhUnitPrice'] ?? 0;
|
|
|
- $unitCost = $item['cost'] ?? 0;
|
|
|
- $unitGross = bcsub($unitPrice, $unitCost, 2);
|
|
|
- $currentAmount = bcmul($unitPrice, $num, 2);
|
|
|
- $currentGross = bcmul($unitGross, $num, 2);
|
|
|
+ $num = NextDayRefundClass::payDayRemainNum(
|
|
|
+ $item['xhNum'] ?? 0,
|
|
|
+ $item['refundNum'] ?? 0,
|
|
|
+ $item['nextRefundNum'] ?? 0
|
|
|
+ );
|
|
|
+ $unitPrice = $item['xhUnitPrice'] ?? 0;
|
|
|
+ $unitCost = $item['cost'] ?? 0;
|
|
|
+ $unitGross = bcsub($unitPrice, $unitCost, 2);
|
|
|
+ $currentAmount = bcmul($unitPrice, $num, 2);
|
|
|
+ $currentGross = bcmul($unitGross, $num, 2);
|
|
|
|
|
|
- $totalNum = bcadd($totalNum, $num, 2);
|
|
|
- $totalAmount = bcadd($totalAmount, $currentAmount, 2);
|
|
|
+ $totalNum = bcadd($totalNum, $num, 2);
|
|
|
+ $totalAmount = bcadd($totalAmount, $currentAmount, 2);
|
|
|
|
|
|
- $totalMl = bcadd($totalMl, $currentGross, 2);
|
|
|
+ $totalMl = bcadd($totalMl, $currentGross, 2);
|
|
|
|
|
|
- if ($currentGross < 0) {
|
|
|
- //noticeUtil::push($item->id . ' 毛利是负的', '15280215347');
|
|
|
- }
|
|
|
+ if ($currentGross < 0) {
|
|
|
+ //noticeUtil::push($item->id . ' 毛利是负的', '15280215347');
|
|
|
+ }
|
|
|
|
|
|
- $stat[$productId]['productId'] = $productId;
|
|
|
- $stat[$productId]['name'] = $name;
|
|
|
- $stat[$productId]['py'] = $py;
|
|
|
- if (isset($stat[$productId]['num'])) {
|
|
|
- $stat[$productId]['num'] = bcadd($stat[$productId]['num'], $num, 2);
|
|
|
- } else {
|
|
|
- $stat[$productId]['num'] = $num;
|
|
|
- }
|
|
|
- if (isset($stat[$productId]['amount'])) {
|
|
|
- $stat[$productId]['amount'] = bcadd($stat[$productId]['amount'], $currentAmount, 2);
|
|
|
- } else {
|
|
|
- $stat[$productId]['amount'] = $currentAmount;
|
|
|
- }
|
|
|
- if (isset($stat[$productId]['gross'])) {
|
|
|
- $stat[$productId]['gross'] = bcadd($stat[$productId]['gross'], $currentGross, 2);
|
|
|
- } else {
|
|
|
- $stat[$productId]['gross'] = $currentGross;
|
|
|
+ $stat[$productId]['productId'] = $productId;
|
|
|
+ $stat[$productId]['name'] = $name;
|
|
|
+ $stat[$productId]['py'] = $py;
|
|
|
+ if (isset($stat[$productId]['num'])) {
|
|
|
+ $stat[$productId]['num'] = bcadd($stat[$productId]['num'], $num, 2);
|
|
|
+ } else {
|
|
|
+ $stat[$productId]['num'] = $num;
|
|
|
+ }
|
|
|
+ if (isset($stat[$productId]['amount'])) {
|
|
|
+ $stat[$productId]['amount'] = bcadd($stat[$productId]['amount'], $currentAmount, 2);
|
|
|
+ } else {
|
|
|
+ $stat[$productId]['amount'] = $currentAmount;
|
|
|
+ }
|
|
|
+ if (isset($stat[$productId]['gross'])) {
|
|
|
+ $stat[$productId]['gross'] = bcadd($stat[$productId]['gross'], $currentGross, 2);
|
|
|
+ } else {
|
|
|
+ $stat[$productId]['gross'] = $currentGross;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 通过日:退货扣数量+金额;仅退款只扣金额(按原单花材占比分摊)
|
|
|
- // 支付日净销量已用 nextRefundNum(payDayRemainNum),无需再加回
|
|
|
+ // 通过日:退货扣数量+金额;仅退款只扣金额;无当日销量的花材也建负行
|
|
|
$deductMaps = [
|
|
|
NextDayRefundClass::sumItemByProduct($this->mainId, $currentStartTime, $currentEndTime),
|
|
|
NextDayRefundClass::sumMoneyOnlyAmountByProduct($this->mainId, $currentStartTime, $currentEndTime),
|
|
|
@@ -162,7 +160,14 @@ class StatItemController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
if (!isset($stat[$pid])) {
|
|
|
- continue;
|
|
|
+ $stat[$pid] = [
|
|
|
+ 'productId' => $pid,
|
|
|
+ 'name' => $productInfo[$pid]['name'] ?? '',
|
|
|
+ 'py' => $productInfo[$pid]['py'] ?? '',
|
|
|
+ 'num' => '0.00',
|
|
|
+ 'amount' => '0.00',
|
|
|
+ 'gross' => '0.00',
|
|
|
+ ];
|
|
|
}
|
|
|
$subNum = (string)($row['num'] ?? '0');
|
|
|
$subAmt = (string)($row['amount'] ?? '0');
|