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]); } }