id ?? 0; $lsShopId = $shop->lsShopId ?? 0; //批发开单 pf 零售开单 ls 批发结账 pfJz 零售尾款 lsWk $get = Yii::$app->request->get(); $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today'; $startTime = $get['startTime'] ?? ''; $endTime = $get['endTime'] ?? ''; $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true); $start = $period['startTime']; $end = $period['endTime']; $currentStartDate = date('Y-m-d', strtotime($start)); $currentEndDate = date('Y-m-d', strtotime($end)); $currentStartTime = $currentStartDate . ' 00:00:00'; $currentEndTime = $currentEndDate . ' 23:59:59'; $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId, 'isPt' => 0], null, '*', 'id', true); $kf = []; if (!empty($staffList)) { foreach ($staffList as $staff) { $name = $staff->name ?? ''; $staffId = $staff->id ?? 0; $kf[$staffId]['name'] = $name; $kf[$staffId]['key'] = $staffId; $kf[$staffId]['num'] = 0; $kf[$staffId]['amount'] = 0; $kf[$staffId]['itemList']['pf'] = ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0]; $kf[$staffId]['itemList']['ls'] = ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0]; $kf[$staffId]['itemList']['pfJz'] = ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0]; $kf[$staffId]['itemList']['lsWk'] = ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0]; } } $incomeList = [ //系统收入 'system' => [ 'amount' => 0, 'num' => 0, 'name' => '系统收款', 'category' => [ 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0], 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0], 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0], 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0], ], ], 'kfWx' => [ 'amount' => 0, 'num' => 0, 'name' => '线下微信', 'class' => $kf, 'category' => [ 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0], 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0], 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0], 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0], ] ], 'debt' => [ 'amount' => 0, 'num' => 0, 'name' => '挂账(未结)', 'category' => [ 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0], 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0], ], ], 'debtClear' => [ 'amount' => 0, 'num' => 0, 'name' => '挂账(已结)', 'category' => [ 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0], 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0], ], ], 'balancePay' => [ 'amount' => 0, 'name' => '余额支付', 'num' => 0, 'category' => [ 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0], 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0], 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0], 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0], ], ], 'cash' => [ 'amount' => 0, 'name' => '现金', 'num' => 0, 'category' => [ 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0], 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0], 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0], 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0], ], ], 'aliPay' => [ 'amount' => 0, 'num' => 0, 'name' => '线下支付宝', 'category' => [ 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0], 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0], 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0], 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0], ], ], 'bankCard' => [ 'amount' => 0, 'name' => '银行卡', 'num' => 0, 'category' => [ 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0], 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0], 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0], 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0], ], ], 'mt' => ['amount' => 0, 'num' => 0, 'name' => '美团'], 'other' => [ 'amount' => 0, 'num' => 0, 'name' => '其它', 'category' => [ 'pf' => ['name' => '批发', 'key' => 'pf', 'num' => 0, 'amount' => 0], 'ls' => ['name' => '零售', 'key' => 'ls', 'num' => 0, 'amount' => 0], 'pfJz' => ['name' => '批发结账', 'key' => 'pfJz', 'num' => 0, 'amount' => 0], 'lsWk' => ['name' => '零售尾款', 'key' => 'lsWk', 'num' => 0, 'amount' => 0], ], ], ]; $staffAmountList = []; //批发开单 $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]]; $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]]; $ghsOrderList = OrderClass::getAllByCondition($where, null, '*'); if (!empty($ghsOrderList)) { foreach ($ghsOrderList as $ghsKey => $ghsOrder) { $payWay = $ghsOrder['payWay'] ?? 0; $actPrice = $ghsOrder['actPrice'] ?? 0; $getStaffId = $ghsOrder['getStaffId'] ?? 0; $debtPrice = $ghsOrder['debtPrice'] ?? 0; $remainDebtPrice = $ghsOrder['remainDebtPrice'] ?? 0; $onlinePay = $ghsOrder['onlinePay'] ?? dict::getDict('onlinePay', 'not'); $status = $ghsOrder['status'] ?? 0; $book = $ghsOrder['book'] ?? 0; $staffId = $ghsOrder['shopAdminId'] ?? 0; $staffName = $ghsOrder['shopAdminName'] ?? ''; if ($staffId == 0) { $staffName = '系统'; } if ($status == 0 || $status == 5) { continue; } if ($book == 1 && $status == 2) { continue; } if (isset($staffAmountList[$staffId])) { $staffAmountList[$staffId]['num'] = bcadd($staffAmountList[$staffId]['num'], 1); $staffAmountList[$staffId]['amount'] = bcadd($staffAmountList[$staffId]['amount'], $actPrice, 2); } else { $staffAmountList[$staffId] = ['num' => 1, 'amount' => $actPrice, 'staffName' => $staffName, 'staffId' => $staffId]; } if ($debtPrice > 0) { if ($remainDebtPrice > 0) { $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $actPrice, 2); $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1); $incomeList['debt']['category']['pf']['amount'] = bcadd($incomeList['debt']['category']['pf']['amount'], $actPrice, 2); $incomeList['debt']['category']['pf']['num'] = bcadd($incomeList['debt']['category']['pf']['num'], 1); } else { $incomeList['debtClear']['amount'] = bcadd($incomeList['debtClear']['amount'], $actPrice, 2); $incomeList['debtClear']['num'] = bcadd($incomeList['debtClear']['num'], 1); $incomeList['debtClear']['category']['pf']['amount'] = bcadd($incomeList['debtClear']['category']['pf']['amount'], $actPrice, 2); $incomeList['debtClear']['category']['pf']['num'] = bcadd($incomeList['debtClear']['category']['pf']['num'], 1); } } else { if ($onlinePay == dict::getDict('onlinePay', 'yes')) { //使用在线支付 $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $actPrice, 2); $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1); $incomeList['system']['category']['pf']['amount'] = bcadd($incomeList['system']['category']['pf']['amount'], $actPrice, 2); $incomeList['system']['category']['pf']['num'] = bcadd($incomeList['system']['category']['pf']['num'], 1); } else { //使用非在线支付 switch ($payWay) { case dict::getDict('payWay', 'wxPay'): //员工微信总共收了多少笔多少钱 $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $actPrice, 2); $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1); //批发开单、零售开单、批发结账、零售尾款各收了多少现金 $incomeList['kfWx']['category']['pf']['amount'] = bcadd($incomeList['kfWx']['category']['pf']['amount'], $actPrice, 2); $incomeList['kfWx']['category']['pf']['num'] = bcadd($incomeList['kfWx']['category']['pf']['num'], 1); //每个客服总共收了多少笔多少钱 if (isset($incomeList['kfWx']['class'][$getStaffId])) { $incomeList['kfWx']['class'][$getStaffId]['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $actPrice, 2)); $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1); } //每个客服收的明细 if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf'])) { $incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['amount'], $actPrice, 2)); $incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['pf']['num'], 1); } break; case dict::getDict('payWay', 'alipay'): $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $actPrice, 2); $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1); $incomeList['aliPay']['category']['pf']['amount'] = bcadd($incomeList['aliPay']['category']['pf']['amount'], $actPrice, 2); $incomeList['aliPay']['category']['pf']['num'] = bcadd($incomeList['aliPay']['category']['pf']['num'], 1); break; case dict::getDict('payWay', 'cash'): $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $actPrice, 2); $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1); $incomeList['cash']['category']['pf']['amount'] = bcadd($incomeList['cash']['category']['pf']['amount'], $actPrice, 2); $incomeList['cash']['category']['pf']['num'] = bcadd($incomeList['cash']['category']['pf']['num'], 1); break; case dict::getDict('payWay', 'balancePay'): $incomeList['balancePay']['amount'] = bcadd($incomeList['balancePay']['amount'], $actPrice, 2); $incomeList['balancePay']['num'] = bcadd($incomeList['balancePay']['num'], 1); $incomeList['balancePay']['category']['pf']['amount'] = bcadd($incomeList['balancePay']['category']['pf']['amount'], $actPrice, 2); $incomeList['balancePay']['category']['pf']['num'] = bcadd($incomeList['balancePay']['category']['pf']['num'], 1); break; case dict::getDict('payWay', 'bankCard'): $incomeList['bankCard']['amount'] = bcadd($incomeList['bankCard']['amount'], $actPrice, 2); $incomeList['bankCard']['num'] = bcadd($incomeList['bankCard']['num'], 1); $incomeList['bankCard']['category']['pf']['amount'] = bcadd($incomeList['bankCard']['category']['pf']['amount'], $actPrice, 2); $incomeList['bankCard']['category']['pf']['num'] = bcadd($incomeList['bankCard']['category']['pf']['num'], 1); break; case dict::getDict('payWay', 'unknown'): $incomeList['other']['amount'] = bcadd($incomeList['other']['amount'], $actPrice, 2); $incomeList['other']['num'] = bcadd($incomeList['other']['num'], 1); $incomeList['other']['category']['pf']['amount'] = bcadd($incomeList['other']['category']['pf']['amount'], $actPrice, 2); $incomeList['other']['category']['pf']['num'] = bcadd($incomeList['other']['category']['pf']['num'], 1); break; default: } } } } } //零售开单 $payCodeIncome = 0; $lsAfterSale = 0; $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]]; $hdWhere['payTime'] = ['between', [$currentStartTime, $currentEndTime]]; $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*'); foreach ($hdOrderList as $hdKey => $hdOrder) { $payWay = $hdOrder['payWay'] ?? 0; $mainPay = $hdOrder['mainPay'] ?? 0; $cash = $hdOrder['cash'] ?? 0; $actPrice = $hdOrder['mainPay'] ?? 0; $getStaffId = $hdOrder['getStaffId'] ?? 0; $debtPrice = $hdOrder['debtPrice'] ?? 0; $remainDebtPrice = $hdOrder['remainDebtPrice'] ?? 0; $onlinePay = $hdOrder['onlinePay'] ?? 0; $fromType = $hdOrder['fromType'] ?? 0; $staffId = $hdOrder['shopAdminId'] ?? 0; $staffName = $hdOrder['shopAdminName'] ?? ''; $repeat = $hdOrder['repeat'] ?? 0; $forward = $hdOrder['forward'] ?? 0; $tkPrice = $hdOrder['tkPrice'] ?? 0; $mainPay = bcsub($mainPay, $tkPrice, 2); if ($forward == 1) { //售后付款属于支出 $lsAfterSale = bcadd($lsAfterSale, $mainPay, 2); continue; } $currentAmount = 0; if ($onlinePay == dict::getDict('onlinePay', 'yes')) { $incomeList['system']['amount'] = bcadd($incomeList['system']['amount'], $mainPay, 2); $incomeList['system']['num'] = bcadd($incomeList['system']['num'], 1); $incomeList['system']['category']['ls']['amount'] = bcadd($incomeList['system']['category']['ls']['amount'], $mainPay, 2); $incomeList['system']['category']['ls']['num'] = bcadd($incomeList['system']['category']['ls']['num'], 1); if ($repeat == 1) { $payCodeIncome = bcadd($payCodeIncome, $mainPay, 2); } if ($cash > 0) { $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $cash, 2); $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1); $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $cash, 2); $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1); } $currentAmount = bcadd($mainPay, $cash, 2); } else { if ($fromType == dict::getDict('fromType', 'mt')) { //美团!!! $incomeList['mt']['amount'] = bcadd($incomeList['mt']['amount'], $actPrice, 2); $incomeList['mt']['num'] = bcadd($incomeList['mt']['num'], 1); } else { if ($debtPrice > 0) { if ($remainDebtPrice > 0) { $incomeList['debt']['amount'] = bcadd($incomeList['debt']['amount'], $remainDebtPrice, 2); $incomeList['debt']['num'] = bcadd($incomeList['debt']['num'], 1); $incomeList['debt']['category']['ls']['amount'] = bcadd($incomeList['debt']['category']['ls']['amount'], $remainDebtPrice, 2); $incomeList['debt']['category']['ls']['num'] = bcadd($incomeList['debt']['category']['ls']['num'], 1); } $clearDebt = bcsub($debtPrice, $remainDebtPrice, 2); if ($clearDebt > 0) { $incomeList['debtClear']['amount'] = bcadd($incomeList['debtClear']['amount'], $clearDebt, 2); $incomeList['debtClear']['num'] = bcadd($incomeList['debtClear']['num'], 1); $incomeList['debtClear']['category']['ls']['amount'] = bcadd($incomeList['debtClear']['category']['ls']['amount'], $clearDebt, 2); $incomeList['debtClear']['category']['ls']['num'] = bcadd($incomeList['debtClear']['category']['ls']['num'], 1); } $currentAmount = bcadd($remainDebtPrice, $clearDebt, 2); } else { $currentAmount = $mainPay; } if ($currentAmount > 0) { //使用非在线支付 switch ($payWay) { case dict::getDict('payWay', 'wxPay'): //员工微信总共收了多少笔多少钱 $incomeList['kfWx']['amount'] = bcadd($incomeList['kfWx']['amount'], $currentAmount, 2); $incomeList['kfWx']['num'] = bcadd($incomeList['kfWx']['num'], 1); //批发开单、零售开单、批发结账、零售尾款各收了多少现金 $incomeList['kfWx']['category']['ls']['amount'] = bcadd($incomeList['kfWx']['category']['ls']['amount'], $currentAmount, 2); $incomeList['kfWx']['category']['ls']['num'] = bcadd($incomeList['kfWx']['category']['ls']['num'], 1); //客1 客2 客3各收了多少钱 if (isset($incomeList['kfWx']['class'][$getStaffId])) { $incomeList['kfWx']['class'][$getStaffId]['amount'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['amount'], $currentAmount, 2); $incomeList['kfWx']['class'][$getStaffId]['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['num'], 1); } //每个客服收的明细 if (isset($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls'])) { $incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['amount'] = floatval(bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['amount'], $actPrice, 2)); $incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['num'] = bcadd($incomeList['kfWx']['class'][$getStaffId]['itemList']['ls']['num'], 1); } break; case dict::getDict('payWay', 'alipay'): $incomeList['aliPay']['amount'] = bcadd($incomeList['aliPay']['amount'], $currentAmount, 2); $incomeList['aliPay']['num'] = bcadd($incomeList['aliPay']['num'], 1); $incomeList['aliPay']['category']['ls']['amount'] = bcadd($incomeList['aliPay']['category']['ls']['amount'], $currentAmount, 2); $incomeList['aliPay']['category']['ls']['num'] = bcadd($incomeList['aliPay']['category']['ls']['num'], 1); break; case dict::getDict('payWay', 'cash'): $incomeList['cash']['amount'] = bcadd($incomeList['cash']['amount'], $currentAmount, 2); $incomeList['cash']['num'] = bcadd($incomeList['cash']['num'], 1); $incomeList['cash']['category']['ls']['amount'] = bcadd($incomeList['cash']['category']['ls']['amount'], $currentAmount, 2); $incomeList['cash']['category']['ls']['num'] = bcadd($incomeList['cash']['category']['ls']['num'], 1); break; case dict::getDict('payWay', 'balancePay'): $incomeList['balancePay']['amount'] = bcadd($incomeList['balancePay']['amount'], $currentAmount, 2); $incomeList['balancePay']['num'] = bcadd($incomeList['balancePay']['num'], 1); $incomeList['balancePay']['category']['ls']['amount'] = bcadd($incomeList['balancePay']['category']['ls']['amount'], $currentAmount, 2); $incomeList['balancePay']['category']['ls']['num'] = bcadd($incomeList['balancePay']['category']['ls']['num'], 1); break; case dict::getDict('payWay', 'bankCard'): $incomeList['bankCard']['amount'] = bcadd($incomeList['bankCard']['amount'], $currentAmount, 2); $incomeList['bankCard']['num'] = bcadd($incomeList['bankCard']['num'], 1); $incomeList['bankCard']['category']['ls']['amount'] = bcadd($incomeList['bankCard']['category']['ls']['amount'], $currentAmount, 2); $incomeList['bankCard']['category']['ls']['num'] = bcadd($incomeList['bankCard']['category']['ls']['num'], 1); break; case dict::getDict('payWay', 'unknown'): $incomeList['other']['amount'] = bcadd($incomeList['other']['amount'], $currentAmount, 2); $incomeList['other']['num'] = bcadd($incomeList['other']['num'], 1); $incomeList['other']['category']['ls']['amount'] = bcadd($incomeList['other']['category']['ls']['amount'], $currentAmount, 2); $incomeList['other']['category']['ls']['num'] = bcadd($incomeList['other']['category']['ls']['num'], 1); break; default: } } } } //员工业绩 if (isset($staffAmountList[$staffId])) { $staffAmountList[$staffId]['num'] = bcadd($staffAmountList[$staffId]['num'], 1); $staffAmountList[$staffId]['amount'] = bcadd($staffAmountList[$staffId]['amount'], $currentAmount, 2); } else { $staffAmountList[$staffId] = ['num' => 1, 'amount' => $currentAmount, 'staffName' => $staffName]; } } // 跨天售后:按原单入账渠道扣减金额(只减金额不减笔数);批发 pf + 零售 ls self::deductNextDayFromChannelIncome($incomeList, $mainId, $currentStartTime, $currentEndTime); return ['incomeList' => $incomeList, 'staffAmountList' => $staffAmountList, 'payCodeIncome' => $payCodeIncome, 'lsAfterSale' => $lsAfterSale]; } /** * 渠道收入对冲跨天售后金额(ghs 批发 + hd 零售共用财务) * 挂账已结扣 debtClear 等;批发记 pf、零售记 ls */ protected static function deductNextDayFromChannelIncome(&$incomeList, $mainId, $startTime, $endTime) { // ghs 批发售后 → 扣 category.pf self::applyNextDayRowsToChannelIncome( $incomeList, NextDayRefundClass::listForChannelIncomeDeduct($mainId, $startTime, $endTime), 'pf' ); // hd 零售售后 → 扣 category.ls(与开单入账口径一致) self::applyNextDayRowsToChannelIncome( $incomeList, HdNextDayRefundClass::listForChannelIncomeDeduct($mainId, $startTime, $endTime), 'ls' ); } /** * 将跨天售后行按渠道扣减金额 * @param array $incomeList * @param array $rows listForChannelIncomeDeduct 结果 * @param string $categoryKey pf|ls */ protected static function applyNextDayRowsToChannelIncome(&$incomeList, $rows, $categoryKey) { if (empty($rows)) { return; } foreach ($rows as $row) { $amount = bcadd((string)($row['amount'] ?? '0'), '0', 2); if (bccomp($amount, '0', 2) <= 0) { continue; } $channel = self::resolveNextDayIncomeChannel($row); if (empty($channel) || !isset($incomeList[$channel])) { $channel = 'other'; } $incomeList[$channel]['amount'] = bcsub((string)$incomeList[$channel]['amount'], $amount, 2); if (isset($incomeList[$channel]['category'][$categoryKey])) { $incomeList[$channel]['category'][$categoryKey]['amount'] = bcsub( (string)$incomeList[$channel]['category'][$categoryKey]['amount'], $amount, 2 ); } } } /** 与开单入账分支一致,映射渠道 key;无原单按售后 payWay / 是否已返充归类 */ protected static function resolveNextDayIncomeChannel($row) { $debtPrice = bcadd((string)($row['debtPrice'] ?? '0'), '0', 2); $remainDebt = bcadd((string)($row['remainDebtPrice'] ?? '0'), '0', 2); $orderId = intval($row['orderId'] ?? 0); $payWay = intval($row['orderPayWay'] ?? ($row['payWay'] ?? ($row['refundPayWay'] ?? 0))); $onlinePay = intval($row['onlinePay'] ?? ($row['refundOnlinePay'] ?? dict::getDict('onlinePay', 'not'))); // 无关联销售单:已返充记 balancePay,否则按线下 payWay;未落地资金归 other if ($orderId <= 0) { if (intval($row['returnBalance'] ?? 0) === 1) { return 'balancePay'; } if (intval($row['hasReturn'] ?? 0) !== 1) { return 'other'; } $refundPayWay = intval($row['refundPayWay'] ?? $payWay); switch ($refundPayWay) { case dict::getDict('payWay', 'wxPay'): return 'kfWx'; case dict::getDict('payWay', 'alipay'): return 'aliPay'; case dict::getDict('payWay', 'cash'): return 'cash'; case dict::getDict('payWay', 'bankCard'): return 'bankCard'; default: return 'other'; } } if ($orderId > 0 && bccomp($debtPrice, '0', 2) > 0) { return bccomp($remainDebt, '0', 2) > 0 ? 'debt' : 'debtClear'; } if ($onlinePay == dict::getDict('onlinePay', 'yes')) { return 'system'; } switch ($payWay) { case dict::getDict('payWay', 'wxPay'): return 'kfWx'; case dict::getDict('payWay', 'alipay'): return 'aliPay'; case dict::getDict('payWay', 'cash'): return 'cash'; case dict::getDict('payWay', 'balancePay'): return 'balancePay'; case dict::getDict('payWay', 'bankCard'): return 'bankCard'; case dict::getDict('payWay', 'debtPay'): return 'debtClear'; default: return 'other'; } } }