|
|
@@ -2,6 +2,9 @@
|
|
|
|
|
|
namespace hd\controllers;
|
|
|
|
|
|
+use bizHd\custom\classes\CustomClass;
|
|
|
+use bizHd\goods\classes\GoodsClass;
|
|
|
+use bizHd\order\classes\OrderClass;
|
|
|
use bizHd\stat\classes\StatOrderClass;
|
|
|
use bizHd\stat\classes\StatVisitClass;
|
|
|
use bizGhs\item\classes\ItemClass;
|
|
|
@@ -15,33 +18,62 @@ class ConsoleController extends BaseController
|
|
|
//总览
|
|
|
public function actionStat()
|
|
|
{
|
|
|
- $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost', null, true);
|
|
|
- $totalItemNum = 0;
|
|
|
- $totalCost = 0;
|
|
|
- if (!empty($itemList)) {
|
|
|
- foreach ($itemList as $item) {
|
|
|
- $stock = $item->stock ?? 0;
|
|
|
- $cost = $item->cost ?? 0;
|
|
|
- $totalItemNum = bcadd($stock, $totalItemNum, 2);
|
|
|
- $currentCost = bcmul($stock, $cost, 2);
|
|
|
- $totalCost = bcadd($currentCost, $totalCost, 2);
|
|
|
- }
|
|
|
- }
|
|
|
- $totalItemNum = floor($totalItemNum);
|
|
|
-
|
|
|
- $main = $this->main;
|
|
|
- $totalCustom = $main->totalUser ?? 0; // 总用户;总客户数
|
|
|
- $totalVisit = $main->totalVisit ?? 0;
|
|
|
- $totalOrder = $main->finishOrder ?? 0; // 完成订单数
|
|
|
- $overview = [
|
|
|
- ['name' => "花材数", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
|
|
|
- ['name' => "花材值", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
|
|
|
- ['name' => "花束", "url" => '/admin/custom/showTotalBalance', 'value' => 0, 'type' => 1],
|
|
|
- ['name' => "总客户", "url" => '/admin/stat/stock', 'value' => 0, 'type' => 1],
|
|
|
- ['name' => "总订单", "url" => '/admin/home/member', 'value' => 0, 'type' => 4],
|
|
|
- ['name' => "总赊账", "url" => '/admin/home/order', 'value' => 0, 'type' => 4],
|
|
|
- ];
|
|
|
- util::success(['overview' => $overview]);
|
|
|
+ $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', null, true);
|
|
|
+ $totalItemNum = 0;
|
|
|
+ $totalCost = 0;
|
|
|
+ if (!empty($itemList)) {
|
|
|
+ foreach ($itemList as $item) {
|
|
|
+ $stock = $item->stock ?? 0;
|
|
|
+ $cost = $item->cost ?? 0;
|
|
|
+ $totalItemNum = bcadd($stock, $totalItemNum, 2);
|
|
|
+ $currentCost = bcmul($stock, $cost, 2);
|
|
|
+ $totalCost = bcadd($currentCost, $totalCost, 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $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],
|
|
|
+ ['name' => "花束", "url" => '/admin/custom/showTotalBalance', 'value' => $goodsCount, 'type' => 1],
|
|
|
+ ['name' => "总客户", "url" => '/admin/stat/stock', 'value' => $customCount, 'type' => 1],
|
|
|
+ ['name' => "总订单", "url" => '/admin/home/member', '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]);
|
|
|
}
|
|
|
|
|
|
//概况 ssh 2019.12.19
|