shopAdmin, $this->shop); $hasPower = 0; if (getenv('YII_ENV') == 'production') { //小向花卉 if ($this->mainId == 23390) { if (in_array($this->adminId, [31105])) { $hasPower = 1; } } } else { if ($this->mainId == 644) { if (in_array($this->adminId, [1230])) { $hasPower = 1; } } } if ($lookMoney == 0 && $hasPower == 0) { //盛丰员工可以看花材销售数据 if ($this->mainId != 44282) { util::fail('没有财务权限哦'); } } $get = Yii::$app->request->get(); $sort = $get['sort'] ?? 'num'; $where = []; $where['mainId'] = $this->mainId; $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'; $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]]; $staffId = $get['staffId'] ?? 0; $list = OrderClass::getAllByCondition($where, null, '*'); if (empty($list)) { util::success(['list' => []]); } $productInfo = ProductClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,name,py,cgStaffId', 'id'); $stat = []; $totalAmount = 0; $totalNum = 0; $totalMl = 0; foreach ($list as $order) { $orderSn = $order['orderSn'] ?? ''; $status = $order['status'] ?? 0; $book = $order['book'] ?? 0; $actPrice = $order['actPrice'] ?? 0; if ($status == 5 || $status == 1 || ($book == 1 && $status == 2)) { continue; } if ($actPrice <= 0) { //如果全部退款的花材也不统计 continue; } $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true); if (!empty($itemList)) { foreach ($itemList as $item) { $productId = $item->productId ?? 0; $name = $productInfo[$productId]['name'] ?? ''; $py = $productInfo[$productId]['py'] ?? ''; if (!empty($staffId)) { $currentCgStaffId = $productInfo[$productId]['cgStaffId'] ?? 0; if ($staffId != $currentCgStaffId) { continue; } } $num = bcsub($item['xhNum'], $item['refundNum'], 2); $unitPrice = $item['xhUnitPrice'] ?? 0; $unitCost = $item['cost'] ?? 0; $unitGross = bcsub($unitPrice, $unitCost, 2); $currentAmount = bcmul($unitPrice, $num, 2); $currentGross = bcmul($unitGross, $num, 2); $totalNum = bcadd($totalNum, $num, 2); $totalAmount = bcadd($totalAmount, $currentAmount, 2); $totalMl = bcadd($totalMl, $currentGross, 2); if ($currentGross < 0) { //noticeUtil::push($item->id . ' 毛利是负的', '15280215347'); } $stat[$productId]['productId'] = $productId; $stat[$productId]['name'] = $name; $stat[$productId]['py'] = $py; if (isset($stat[$productId]['num'])) { $stat[$productId]['num'] = bcadd($stat[$productId]['num'], $num, 2); } else { $stat[$productId]['num'] = $num; } if (isset($stat[$productId]['amount'])) { $stat[$productId]['amount'] = bcadd($stat[$productId]['amount'], $currentAmount, 2); } else { $stat[$productId]['amount'] = $currentAmount; } if (isset($stat[$productId]['gross'])) { $stat[$productId]['gross'] = bcadd($stat[$productId]['gross'], $currentGross, 2); } else { $stat[$productId]['gross'] = $currentGross; } } } } //增加毛利率 foreach ($stat as $key => $val) { $profit = $val['gross'] ?? 0; $price = $val['amount'] ?? 0; if ($price > 0) { $mll = bcdiv($profit, $price, 3); $mll = bcmul($mll, 100); $mll = round($mll, 1); } else { $mll = 0; } $stat[$key]['mll'] = $mll; } $rank = 'num'; if ($sort == 'gross') { $rank = 'gross'; } if ($sort == 'amount') { $rank = 'amount'; } if ($sort == 'mll') { $rank = 'mll'; } $stat = arrayUtil::arraySort($stat, $rank); $export = $get['export'] ?? 0; if ($export == 1) { $mainId = $this->mainId; StatSaleClass::exportItemSale($stat, $mainId); } util::success(['list' => $stat, 'totalAmount' => floatval($totalAmount), 'totalNum' => floatval($totalNum), 'totalMl' => $totalMl,]); } //花材销量 ssh 20211021 public function actionProfile() { //查看财务的权限 $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop); if ($lookMoney == 0) { util::fail('无法查看'); } $get = Yii::$app->request->get(); $where = []; $where['shopId'] = $this->shopId; if (isset($get['shopId']) && !empty($get['shopId'])) { $where['shopId'] = $get['shopId']; } $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 = StatItemClass::getAllByCondition($where, null, '*'); if (empty($list)) { util::success(['list' => $list]); } $ids = array_column($list, 'itemId'); $ids = array_unique(array_filter($ids)); $productInfo = ProductClass::getByIds($ids, null, 'id'); $stat = []; foreach ($list as $key => $val) { $itemId = $val['itemId'] ?? 0; $idsData[$itemId] = 0; $num = bcsub($val['num'], $val['refundNum'], 2); $amount = bcsub($val['amount'], $val['refundAmount'], 2); $name = $productInfo[$itemId]['name'] ?? ''; $py = $productInfo[$itemId]['py'] ?? ''; $stat[$itemId]['productId'] = $itemId; $stat[$itemId]['name'] = $name; $stat[$itemId]['py'] = $py; if (isset($stat[$itemId]['num'])) { $stat[$itemId]['num'] = bcadd($stat[$itemId]['num'], $num, 2); } else { $stat[$itemId]['num'] = $num; } if (isset($stat[$itemId]['amount'])) { $stat[$itemId]['amount'] = bcadd($stat[$itemId]['amount'], $amount, 2); } else { $stat[$itemId]['amount'] = $amount; } } $stat = arrayUtil::arraySort($stat, 'num'); util::success(['list' => $stat]); } }