request->get(); $where = []; $where['mainId'] = $mainId; $searchTime = 'today'; if (!empty($searchTime)) { $startTime = $get['startTime'] ?? ''; $endTime = $get['endTime'] ?? ''; $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true); $where['time'] = ['between', [$period['startTime'], $period['endTime']]]; } //出库 $stockOut = StatStockOutClass::getSum($where); //采购入库 $cg = StatCgClass::getSum($where); //调拨入库 $stockIn = StatStockInClass::getSum($where); $totalOrderNum = 0; $todayDate = date('Y-m-d'); $todayStartTime = $todayDate . ' 00:00:00'; $todayEndTime = $todayDate . ' 23:59:59'; //批发开单 $pfIncome = 0; $pfSendCost = 0; $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]]; $where['payTime'] = ['between', [$todayStartTime, $todayEndTime]]; $ghsOrderList = OrderClass::getAllByCondition($where, null, '*'); if (!empty($ghsOrderList)) { foreach ($ghsOrderList as $ghsKey => $ghsOrder) { $actPrice = $ghsOrder['actPrice'] ?? 0; $sendCost = $ghsOrder['sendCost'] ?? 0; $pfIncome = bcadd($pfIncome, $actPrice, 2); $pfSendCost = bcadd($pfSendCost, $sendCost, 2); $totalOrderNum++; } } //零售开单 $lsIncome = 0; $lsSendCost = 0; $lsServiceFee = 0; $hdWhere = ['mainId' => $mainId, 'status' => ['in', [HdOrderClass::ORDER_STATUS_UN_SEND, HdOrderClass::ORDER_STATUS_SENDING, HdOrderClass::ORDER_STATUS_COMPLETE]]]; $hdWhere['payTime'] = ['between', [$todayStartTime, $todayEndTime]]; $hdOrderList = HdOrderClass::getAllByCondition($hdWhere, null, '*'); foreach ($hdOrderList as $hdKey => $hdOrder) { $actPrice = $hdOrder['actPrice'] ?? 0; $serviceFee = $hdOrder['serviceFee'] ?? 0; $sendCost = $hdOrder['sendCost'] ?? 0; $lsIncome = bcadd($actPrice, $lsIncome, 2); $lsSendCost = bcadd($lsSendCost, $sendCost, 2); $lsServiceFee = bcadd($lsServiceFee, $serviceFee, 2); $totalOrderNum++; } $condition = ['mainId' => $mainId, 'addTime' => ['between', [$todayStartTime, $todayEndTime]],]; $salary = 0; $salaryList = SalaryClass::getAllByCondition($condition, null, '*', null, true); if (!empty($salaryList)) { foreach ($salaryList as $item) { $salary = bcadd($salary, $item->amount, 2); } } $expendList = ExpendClass::getAllByCondition($condition, null, '*', null, true); $expendTypeMap = dict::getDict('expendTypeMap'); $expendAmount = []; if (!empty($expendList)) { foreach ($expendList as $item) { $type = $item->type ?? 0; $amount = $item->amount ?? 0; $name = $expendTypeMap[$type] ?? '暂无'; if (isset($expendAmount[$type]['amount']) == false) { $expendAmount[$type]['amount'] = 0; } $expendAmount[$type]['name'] = $name; $expendAmount[$type]['amount'] = floatval(bcadd($expendAmount[$type]['amount'], $amount, 2)); } } $income = [ ['name' => '批发销售', 'amount' => floatval($pfIncome)], ['name' => '零售销售', 'amount' => floatval($lsIncome)], ['name' => '调拨出库', 'amount' => floatval($stockOut)], ]; $expend = [ ['name' => '批发运费', 'amount' => floatval($pfSendCost)], ['name' => '零售运费', 'amount' => floatval($lsSendCost)], ['name' => '美团手续费', 'amount' => floatval($lsServiceFee)], ['name' => '采购', 'amount' => floatval($cg)], ['name' => '调拨入库', 'amount' => floatval($stockIn)], ['name' => '员工工资', 'amount' => floatval($salary)], ]; if (!empty($expendAmount)) { foreach ($expendAmount as $it) { $expend[] = $it; } } $balance = 0; foreach ($income as $it) { $amount = $it['amount'] ?? 0; $balance = bcadd($amount, $balance, 2); } foreach ($expend as $it) { $amount = $it['amount'] ?? 0; $balance = bcsub($balance, $amount, 2); } return ['income' => $income, 'expend' => $expend, 'balance' => floatval($balance), 'totalOrderNum' => $totalOrderNum]; } }