request->get(); $where = []; $where['mainId'] = $this->mainId; $where['status'] = 4; $searchTime = $get['searchTime'] ?? 'today'; if (!empty($searchTime)) { $startTime = $get['startTime'] ?? ''; $endTime = $get['endTime'] ?? ''; $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true); $start = date("Y-m-d 00:00:00", strtotime($period['startTime'])); $end = date("Y-m-d 23:59:59", strtotime($period['endTime'])); $where['entryTime'] = ['between', [$start, $end]]; } $cgList = PurchaseOrderClass::getAllByCondition($where, 'entryTime ASC', '*', null, true); $packingCharge = 0; $shortCharge = 0; $longCharge = 0; $pickCharge = 0; $localCharge = 0; if (!empty($cgList)) { foreach ($cgList as $cg) { $pack = $cg->packingCharge ?? 0; $short = $cg->shortCharge ?? 0; $long = $cg->longCharge ?? 0; $pick = $cg->pickCharge ?? 0; $local = $cg->localCharge ?? 0; $packingCharge = bcadd($packingCharge, $pack, 2); $shortCharge = bcadd($shortCharge, $short, 2); $longCharge = bcadd($longCharge, $long, 2); $pickCharge = bcadd($pickCharge, $pick, 2); $localCharge = bcadd($localCharge, $local, 2); } } $total = [ 'packingCharge' => $packingCharge, 'shortCharge' => $shortCharge, 'longCharge' => $longCharge, 'pickCharge' => $pickCharge, 'localCharge' => $localCharge, 'num' => count($cgList) ]; util::success(['list' => $cgList, 'total' => $total]); } //按分类统计收入 ssh 20231111 public function actionClassProfit() { ini_set('memory_limit', '2045M'); set_time_limit(0); //查看财务的权限 $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop); $hasPower = 0; if (getenv('YII_ENV') == 'production') { //小向花卉 if ($this->mainId == 23390) { if (in_array($this->adminId, [28456, 31105, 52528])) { $hasPower = 1; } } } else { if ($this->mainId == 644) { if (in_array($this->adminId, [1230])) { $hasPower = 1; } } } if ($lookMoney == 0 && $hasPower == 0) { util::fail('没有财务权限哦'); } $mainId = $this->mainId; StatSaleClass::classProfile($mainId); } //配送业绩 ssh 20240824 public function actionSend() { ini_set('memory_limit', '2045M'); set_time_limit(0); $mainId = $this->mainId; $arr = StatSaleClass::send($mainId); util::success(['list' => $arr]); } public function actionIncomeOutItem() { ini_set('memory_limit', '2045M'); set_time_limit(0); //查看财务的权限 $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop); if ($lookMoney == 0) { util::fail('无法查看'); } $mainId = $this->mainId; StatSaleClass::incomeOutItem($mainId); } public function actionProfit() { ini_set('memory_limit', '2045M'); set_time_limit(0); //查看财务的权限 $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop); if ($lookMoney == 0) { util::fail('无法查看'); } $mainId = $this->mainId; $respond = StatSaleClass::profile($mainId); $income = $respond['income'] ?? 0; $expend = $respond['expend'] ?? 0; $balance = $respond['balance'] ?? 0; $payCodeIncome = $respond['payCodeIncome'] ?? 0; //由于损耗而造成少赚的钱 $wastageRespond = StatSaleClass::wastage($mainId); $wastagePrice = $wastageRespond['totalPrice'] ?? 0; $wastagePrice = floatval($wastagePrice); $wastageCost = $wastageRespond['totalCost'] ?? 0; $wastageCost = floatval($wastageCost); util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance), 'wastagePrice' => $wastagePrice,'wastageCost'=>$wastageCost, 'payCodeIncome' => $payCodeIncome]); } //按月统计损耗情况 public function actionWaste() { ini_set('memory_limit', '2045M'); set_time_limit(0); $mainId = $this->mainId; $list = StockWastageOrderClass::getAllByCondition(['mainId' => $mainId], null, '*'); $arr = []; $totalNum = 0; $totalCost = 0; $totalPrice = 0; if (!empty($list)) { foreach ($list as $order) { $addTime = $order['addTime']; $time = date("Ym", strtotime($addTime)); $date = date("Y年n月", strtotime($addTime)); $bigNum = $order['bigNum'] ?? 0; $cost = $order['cost'] ?? 0; $price = $order['price'] ?? 0; if (isset($arr[$time])) { $arr[$time]['num'] = bcadd($arr[$time]['num'], $bigNum); $arr[$time]['cost'] = bcadd($arr[$time]['cost'], $cost, 2); $arr[$time]['price'] = bcadd($arr[$time]['price'], $price, 2); $arr[$time]['time'] = $date; } else { $arr[$time]['num'] = $bigNum; $arr[$time]['cost'] = $cost; $arr[$time]['price'] = $price; $arr[$time]['time'] = $date; } $totalNum = bcadd($totalNum, $bigNum); $totalCost = bcadd($totalCost, $cost, 2); $totalPrice = bcadd($totalPrice, $price, 2); } } $totalCost = floatval($totalCost); $totalPrice = floatval($totalPrice); util::success(['list' => $arr, 'totalNum' => $totalNum, 'totalCost' => $totalCost, 'totalPrice' => $totalPrice]); } //损耗花材 public function actionWastage() { $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); $start = date("Y-m-d 00:00:00", strtotime($period['startTime'])); $end = date("Y-m-d 23:59:59", strtotime($period['endTime'])); $where['addTime'] = ['between', [$start, $end]]; } $wastageList = StockWastageOrderItemClass::getAllByCondition($where, null, '*', null, true); $stat = []; $totalCost = 0; $totalNum = 0; if (!empty($wastageList)) { foreach ($wastageList as $waste) { $name = $waste->name ?? ''; $shortCover = $waste->cover ?? ''; $cover = imgUtil::groupImg($shortCover); $num = $waste->itemNum ?? 0; $cost = $waste->itemCost ?? 0; $currentCost = bcmul($cost, $num, 2); $productId = $waste->productId ?? 0; if (isset($stat[$productId]) == false) { $stat[$productId]['name'] = $name; $stat[$productId]['cover'] = $cover; $stat[$productId]['num'] = 0; $stat[$productId]['amount'] = 0; } $stat[$productId]['num'] = bcadd($stat[$productId]['num'], $num, 2); $stat[$productId]['amount'] = bcadd($stat[$productId]['amount'], $currentCost, 2); $totalNum = bcadd($totalNum, $num, 2); $totalCost = bcadd($totalCost, $currentCost, 2); } $stat = array_values($stat); $stat = arrayUtil::arraySort($stat, 'num'); } util::success(['stat' => $stat, 'totalNum' => $totalNum, 'totalCost' => $totalCost]); } }