|
|
@@ -9,9 +9,6 @@ use bizGhs\order\classes\NextDayRefundClass;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
use bizGhs\shop\classes\ShopAdminClass;
|
|
|
use bizGhs\stat\classes\StatSaleClass;
|
|
|
-use bizHd\order\classes\OrderClass as HdOrderClass;
|
|
|
-use bizHd\order\classes\OrderItemClass as HdOrderItemClass;
|
|
|
-use bizHd\refund\classes\HdNextDayRefundClass;
|
|
|
use common\components\arrayUtil;
|
|
|
use common\components\dateUtil;
|
|
|
use common\components\noticeUtil;
|
|
|
@@ -74,7 +71,7 @@ class StatItemController extends BaseController
|
|
|
$staffId = $get['staffId'] ?? 0;
|
|
|
|
|
|
$list = OrderClass::getAllByCondition($where, null, '*');
|
|
|
- $productInfo = ProductClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,name,py,cgStaffId,cost,avCost', 'id');
|
|
|
+ $productInfo = ProductClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,name,py,cgStaffId', 'id');
|
|
|
$stat = [];
|
|
|
$totalAmount = 0;
|
|
|
$totalNum = 0;
|
|
|
@@ -149,95 +146,11 @@ class StatItemController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 零售开单花材:与批发共用库存花材 id(xhOrderItem.itemId = Product.id)
|
|
|
- $hdWhere = [
|
|
|
- 'mainId' => $this->mainId,
|
|
|
- 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]],
|
|
|
- 'payTime' => ['between', [$currentStartTime, $currentEndTime]],
|
|
|
- ];
|
|
|
- $hdList = HdOrderClass::getAllByCondition($hdWhere, null, '*');
|
|
|
- if (!empty($hdList)) {
|
|
|
- foreach ($hdList as $hdOrder) {
|
|
|
- if (intval($hdOrder['forward'] ?? 0) === 1) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $mainPay = bcsub(
|
|
|
- (string)($hdOrder['mainPay'] ?? '0'),
|
|
|
- (string)($hdOrder['tkPrice'] ?? '0'),
|
|
|
- 2
|
|
|
- );
|
|
|
- $cash = bcadd((string)($hdOrder['cash'] ?? '0'), '0', 2);
|
|
|
- if (bccomp(bcadd($mainPay, $cash, 2), '0', 2) <= 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $orderSn = $hdOrder['orderSn'] ?? '';
|
|
|
- $itemList = HdOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
- if (empty($itemList)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- foreach ($itemList as $item) {
|
|
|
- $productId = intval($item->itemId ?? 0);
|
|
|
- if ($productId <= 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $name = $productInfo[$productId]['name'] ?? '';
|
|
|
- $py = $productInfo[$productId]['py'] ?? '';
|
|
|
- if (!empty($staffId)) {
|
|
|
- $currentCgStaffId = $productInfo[$productId]['cgStaffId'] ?? 0;
|
|
|
- if ($staffId != $currentCgStaffId) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- $num = HdNextDayRefundClass::payDayRemainNum(
|
|
|
- $item->num ?? 0,
|
|
|
- $item->refundNum ?? 0,
|
|
|
- $item->nextRefundNum ?? 0
|
|
|
- );
|
|
|
- if (bccomp((string)$num, '0', 2) <= 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $unitPrice = $item->unitPrice ?? 0;
|
|
|
- $unitCost = $item->cost ?? null;
|
|
|
- if ($unitCost === null || $unitCost === '') {
|
|
|
- $unitCost = $productInfo[$productId]['avCost']
|
|
|
- ?? ($productInfo[$productId]['cost'] ?? 0);
|
|
|
- }
|
|
|
- $unitGross = bcsub((string)$unitPrice, (string)$unitCost, 2);
|
|
|
- $currentAmount = bcmul((string)$unitPrice, (string)$num, 2);
|
|
|
- $currentGross = bcmul($unitGross, (string)$num, 2);
|
|
|
-
|
|
|
- $totalNum = bcadd($totalNum, $num, 2);
|
|
|
- $totalAmount = bcadd($totalAmount, $currentAmount, 2);
|
|
|
- $totalMl = bcadd($totalMl, $currentGross, 2);
|
|
|
-
|
|
|
- $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;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 通过日:退货扣数量+金额;仅退款只扣金额;无当日销量的花材也建负行(批发+零售)
|
|
|
+ // 通过日:退货扣数量+金额;仅退款只扣金额;无当日销量的花材也建负行
|
|
|
+ $nextDayDeduct = '0.00';
|
|
|
$deductMaps = [
|
|
|
NextDayRefundClass::sumItemByProduct($this->mainId, $currentStartTime, $currentEndTime),
|
|
|
NextDayRefundClass::sumMoneyOnlyAmountByProduct($this->mainId, $currentStartTime, $currentEndTime),
|
|
|
- HdNextDayRefundClass::sumItemByProduct($this->mainId, $currentStartTime, $currentEndTime),
|
|
|
- HdNextDayRefundClass::sumMoneyOnlyAmountByProduct($this->mainId, $currentStartTime, $currentEndTime),
|
|
|
];
|
|
|
foreach ($deductMaps as $deductMap) {
|
|
|
foreach ($deductMap as $pid => $row) {
|
|
|
@@ -265,14 +178,15 @@ class StatItemController extends BaseController
|
|
|
$totalNum = bcsub((string)$totalNum, $subNum, 2);
|
|
|
$totalAmount = bcsub((string)$totalAmount, $subAmt, 2);
|
|
|
$totalMl = bcsub((string)$totalMl, $subAmt, 2);
|
|
|
+ $nextDayDeduct = bcadd($nextDayDeduct, $subAmt, 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //增加毛利率
|
|
|
+ //增加毛利率(金额为负时不计算毛利率,避免除零/误导)
|
|
|
foreach ($stat as $key => $val) {
|
|
|
$profit = $val['gross'] ?? 0;
|
|
|
$price = $val['amount'] ?? 0;
|
|
|
- if ($price > 0) {
|
|
|
+ if (bccomp((string)$price, '0', 2) > 0) {
|
|
|
$mll = bcdiv($profit, $price, 3);
|
|
|
$mll = bcmul($mll, 100);
|
|
|
$mll = round($mll, 1);
|
|
|
@@ -291,7 +205,7 @@ class StatItemController extends BaseController
|
|
|
if ($sort == 'mll') {
|
|
|
$rank = 'mll';
|
|
|
}
|
|
|
- $stat = arrayUtil::arraySort($stat, $rank);
|
|
|
+ $stat = array_values(arrayUtil::arraySort($stat, $rank));
|
|
|
|
|
|
$export = $get['export'] ?? 0;
|
|
|
if ($export == 1) {
|
|
|
@@ -299,7 +213,13 @@ class StatItemController extends BaseController
|
|
|
StatSaleClass::exportItemSale($stat, $mainId);
|
|
|
}
|
|
|
|
|
|
- util::success(['list' => $stat, 'totalAmount' => floatval($totalAmount), 'totalNum' => floatval($totalNum), 'totalMl' => $totalMl,]);
|
|
|
+ util::success([
|
|
|
+ 'list' => $stat,
|
|
|
+ 'totalAmount' => floatval($totalAmount),
|
|
|
+ 'totalNum' => floatval($totalNum),
|
|
|
+ 'totalMl' => floatval($totalMl),
|
|
|
+ 'nextDayDeduct' => floatval($nextDayDeduct),
|
|
|
+ ]);
|
|
|
|
|
|
}
|
|
|
|