|
|
@@ -19,31 +19,16 @@ class ConsoleController extends BaseController
|
|
|
//总览
|
|
|
public function actionStat()
|
|
|
{
|
|
|
- $cacheKey = 'hd_console_stat_overview:' . $this->mainId . '_' . $this->shopId;
|
|
|
- $cache = \Yii::$app->redis->executeCommand('GET', [$cacheKey]);
|
|
|
- $cached = !empty($cache) ? json_decode($cache, true) : null;
|
|
|
- if (is_array($cached)
|
|
|
- && isset($cached['totalItemNum'], $cached['totalCost'], $cached['goodsCount'], $cached['customCount'], $cached['orderCount'], $cached['debtCount'])) {
|
|
|
- $overview = [
|
|
|
- ['name' => "花材数", "url" => '/admin/stat/stock', 'value' => $cached['totalItemNum'], 'type' => 1],
|
|
|
- ['name' => "花材值", "url" => '/admin/stat/stock', 'value' => $cached['totalCost'], 'type' => 1],
|
|
|
- ['name' => "花束", "url" => '/admin/custom/showTotalBalance', 'value' => $cached['goodsCount'], 'type' => 1],
|
|
|
- ['name' => "总客户", "url" => '/admin/stat/stock', 'value' => $cached['customCount'], 'type' => 1],
|
|
|
- ['name' => "总订单", "url" => '/admin/home/member', 'value' => $cached['orderCount'], 'type' => 4],
|
|
|
- ['name' => "总赊账", "url" => '/admin/home/order', 'value' => $cached['debtCount'], 'type' => 4],
|
|
|
- ];
|
|
|
- util::success(['overview' => $overview]);
|
|
|
- }
|
|
|
+ //不要用缓存!!!
|
|
|
|
|
|
- // 缓存未命中时计算
|
|
|
- $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost,virtualStock,delStatus', null, true);
|
|
|
+ $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,avCost,cost,virtualStock,delStatus', null, true);
|
|
|
$totalItemNum = 0;
|
|
|
$totalCost = 0;
|
|
|
if (!empty($itemList)) {
|
|
|
foreach ($itemList as $item) {
|
|
|
if ($item->virtualStock == 0 && $item->delStatus == 0) {
|
|
|
$stock = $item->stock ?? 0;
|
|
|
- $cost = $item->cost ?? 0;
|
|
|
+ $cost = $item->avCost ?? 0;
|
|
|
$totalItemNum = bcadd($stock, $totalItemNum, 2);
|
|
|
$currentCost = bcmul($stock, $cost, 2);
|
|
|
$totalCost = bcadd($currentCost, $totalCost, 2);
|
|
|
@@ -51,12 +36,10 @@ class ConsoleController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
$totalItemNum = floor($totalItemNum);
|
|
|
-
|
|
|
$goodsCount = GoodsClass::getCount(['mainId'=>$this->mainId]);
|
|
|
$customCount = CustomClass::getCount(['shopId'=>$this->shopId]);
|
|
|
$orderCount = OrderClass::getCount(['mainId'=>$this->mainId, 'status'=>4]);
|
|
|
$debtCount = OrderClass::debtCount($this->mainId);
|
|
|
-
|
|
|
$overview = [
|
|
|
['name' => "花材数", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
|
|
|
['name' => "花材值", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
|
|
|
@@ -65,17 +48,6 @@ class ConsoleController extends BaseController
|
|
|
['name' => "总订单", "url" => '/admin/home/order', 'value' => $orderCount, 'type' => 4],
|
|
|
['name' => "总赊账", "url" => '/admin/home/order', 'value' => $debtCount, 'type' => 4],
|
|
|
];
|
|
|
-
|
|
|
- $numbers = [
|
|
|
- 'totalItemNum' => $totalItemNum,
|
|
|
- 'totalCost' => $totalCost,
|
|
|
- 'goodsCount' => $goodsCount,
|
|
|
- 'customCount' => $customCount,
|
|
|
- 'orderCount' => $orderCount,
|
|
|
- 'debtCount' => $debtCount,
|
|
|
- ];
|
|
|
- // 缓存一小时
|
|
|
- \Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 3600, json_encode($numbers, JSON_UNESCAPED_UNICODE)]);
|
|
|
util::success(['overview' => $overview]);
|
|
|
}
|
|
|
|