shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能查看'); } //惠雅鲜花员工不能看利润表 $shopAdmin = $this->shopAdmin; $adminId = $shopAdmin->adminId ?? 0; if (in_array($adminId, [3405, 2812, 4004,2812])) { util::fail('暂无权限'); } $mainId = $this->mainId; $respond = StatSaleClass::profile($mainId); $income = $respond['income'] ?? 0; $expend = $respond['expend'] ?? 0; $balance = $respond['balance'] ?? 0; util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance)]); } 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]); } }