request->get(); $mainId = $this->mainId; $export = $get['export'] ?? 0; $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : 0; $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']; $ghsList = GhsClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id'); $currentStartDate = date('Y-m-d', strtotime($start)); $currentEndDate = date('Y-m-d', strtotime($end)); $currentStartTime = $currentStartDate . ' 00:00:00'; $currentEndTime = $currentEndDate . ' 23:59:59'; $where = ['mainId' => $mainId]; if (!empty($debt)) { $where['debt'] = $debt; } $where['entryTime'] = ['between', [$currentStartTime, $currentEndTime]]; $orderList = PurchaseOrderClass::getAllByCondition($where, null, '*'); $list = []; $totalActPrice = 0; $totalOrderPrice = 0; $totalCarton = 0; $totalPack = 0; $totalFreight = 0; $totalTkPrice = 0; //增加项 $totalOnlyTkPrice = 0; $totalNum = 0; if (!empty($orderList)) { foreach ($orderList as $orderInfo) { $actPrice = $orderInfo['actPrice'] ?? 0; $orderPrice = $orderInfo['orderPrice'] ?? 0; $ghsId = $orderInfo['ghsId'] ?? 0; $status = $orderInfo['status'] ?? 0; $orderSn = $orderInfo['orderSn'] ?? ''; $tkPrice = $orderInfo['tkPrice'] ?? 0; if ($status != 4) { continue; } $carton = 0; $pack = 0; $freight = 0; $orderItemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*'); if (!empty($orderItemList)) { foreach ($orderItemList as $orderItem) { $num = $orderItem['xhNum'] ?? 0; $unitPrice = $orderItem['xhUnitPrice'] ?? 0; $refundNum = $orderItem['refundNum'] ?? 0; $classId = $orderItem['classId'] ?? 0; if (getenv('YII_ENV') == 'production') { if ($mainId == 23390) { $remainNum = bcsub($num, $refundNum); $amount = bcmul($remainNum, $unitPrice, 2); if ($classId == 73120) { $freight = bcadd($freight, $amount, 2); } } } } } //增加项 if ($tkPrice > 0) { $refundList = CgRefundClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true); if (!empty($refundList)) { foreach ($refundList as $refundInfo) { if (isset($refundInfo->refundType) && $refundInfo->refundType == 2) { $refundPrice = $refundInfo->refundPrice ?? 0; $totalOnlyTkPrice = bcadd($totalOnlyTkPrice, $refundPrice, 2); } } } } $totalCarton = bcadd($totalCarton, $carton, 2); $totalPack = bcadd($totalPack, $pack, 2); $totalFreight = bcadd($totalFreight, $freight, 2); $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2); $totalActPrice = bcadd($totalActPrice, $actPrice, 2); $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2); $totalNum++; if (isset($list[$ghsId])) { $list[$ghsId]['actPrice'] = bcadd($list[$ghsId]['actPrice'], $actPrice, 2); $list[$ghsId]['orderPrice'] = bcadd($list[$ghsId]['orderPrice'], $orderPrice, 2); $list[$ghsId]['num'] = bcadd($list[$ghsId]['num'], 1); $list[$ghsId]['carton'] = bcadd($list[$ghsId]['carton'], $carton, 2); $list[$ghsId]['pack'] = bcadd($list[$ghsId]['pack'], $pack, 2); $list[$ghsId]['freight'] = bcadd($list[$ghsId]['freight'], $freight, 2); $list[$ghsId]['tkPrice'] = bcadd($list[$ghsId]['tkPrice'], $tkPrice, 2); } else { $name = $ghsList[$ghsId] && $ghsList[$ghsId]['name'] ? $ghsList[$ghsId]['name'] : '未命名'; $mobile = $ghsList[$ghsId] && $ghsList[$ghsId]['mobile'] ? $ghsList[$ghsId]['mobile'] : '0'; $list[$ghsId] = [ 'id' => $ghsId, 'name' => $name, 'mobile' => $mobile, 'orderPrice' => $orderPrice, 'actPrice' => $actPrice, 'num' => 1, 'carton' => $carton, 'pack' => $pack, 'freight' => $freight, 'tkPrice' => $tkPrice, ]; } } foreach ($ghsList as $key => $ghs) { $ghsId = $ghs['id'] ?? 0; if (isset($list[$ghsId]) == false) { $list[$ghsId] = [ 'id' => $ghsId, 'name' => $ghs['name'], 'mobile' => $ghs['mobile'], 'actPrice' => 0, 'num' => 0, 'carton' => 0, 'pack' => 0, 'freight' => 0, 'tkPrice' => 0, 'orderPrice' => 0, ]; } } $list = array_values($list); } if ($export == 1) { if (empty($list)) { util::fail('没有数据需要导出'); } ini_set('memory_limit', '2045M'); set_time_limit(0); StatCgGhsClass::exportCgGhsYj($list, $mainId); util::stop(); } util::success([ 'list' => $list, 'totalActPrice' => $totalActPrice, 'totalOrderPrice' => $totalOrderPrice, 'totalCarton' => $totalCarton, 'totalNum' => $totalNum, 'totalPack' => $totalPack, 'totalFreight' => $totalFreight, 'totalTkPrice' => $totalTkPrice, //增加项 'totalOnlyTkPrice' => $totalOnlyTkPrice, ]); //[['amount','ghsId','ghsName','num','py']] } public function actionProfileOld() { $get = Yii::$app->request->get(); $where = []; $where['mainId'] = $this->mainId; $searchTime = $get['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']]]; } $list = StatCgGhsClass::getAllByCondition($where, null, '*'); $ghsIds = []; $arr = []; if (!empty($list)) { foreach ($list as $ke => $item) { $ghsId = $item['ghsId'] ?? 0; $num = $item['num'] ?? 0; $refundNum = $item['refundNum'] ?? 0; $amount = $item['amount'] ?? 0; $refundAmount = $item['refundAmount'] ?? 0; $ghsIds[$ghsId] = 1; if (isset($arr[$ghsId]['num'])) { $arr[$ghsId]['num'] = bcadd($arr[$ghsId]['num'], $num, 2); } else { $arr[$ghsId]['num'] = $num; } if (isset($arr[$ghsId]['refundNum'])) { $arr[$ghsId]['refundNum'] = bcadd($arr[$ghsId]['refundNum'], $refundNum, 2); } else { $arr[$ghsId]['refundNum'] = $refundNum; } if (isset($arr[$ghsId]['amount'])) { $arr[$ghsId]['amount'] = bcadd($arr[$ghsId]['amount'], $amount, 2); } else { $arr[$ghsId]['amount'] = $amount; } if (isset($arr[$ghsId]['refundAmount'])) { $arr[$ghsId]['refundAmount'] = bcadd($arr[$ghsId]['refundAmount'], $refundAmount, 2); } else { $arr[$ghsId]['refundAmount'] = $refundAmount; } } } $ghsIds = array_keys($ghsIds); $ghsData = GhsClass::getByIds($ghsIds); $cg = []; foreach ($ghsData as $ghs) { $ghsId = $ghs['id'] ?? 0; $ghsName = $ghs['name'] ?? ''; $ghsPy = $ghs['py'] ?? ''; $num = $arr[$ghsId]['num'] ?? 0; $refundNum = $arr[$ghsId]['refundNum'] ?? 0; $amount = $arr[$ghsId]['amount'] ?? 0; $refundAmount = $arr[$ghsId]['refundAmount'] ?? 0; $lastAmount = bcsub($amount, $refundAmount, 2); $lastNum = bcsub($num, $refundNum, 2); $cg[] = [ 'ghsId' => $ghsId, 'ghsName' => $ghsName, 'py' => $ghsPy, 'num' => $lastNum, 'amount' => $lastAmount, ]; } $cg = arrayUtil::arraySort($cg, 'num'); util::success(['list' => $cg]); } }