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); $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; $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/goods/list', 'value' => $goodsCount, 'type' => 1], ['name' => "总客户", "url" => '/admin/home/member', 'value' => $customCount, 'type' => 1], ['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]); } //概况 public function actionProfile() { //查看财务的权限 $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop); $lsIncome = 0; $orderCount = 0; $yesterdayIncome = 0; if ($lookMoney == 1) { $mainId = $this->mainId; $todayStr = date('Y-m-d'); // 今天零售订单总数与收入 $cacheKey = 'hd_console_profile:' . 'today_'.$todayStr.'_income_' . $this->shopId; $cache = \Yii::$app->redis->executeCommand('GET', [$cacheKey]); if ($cache) { $cacheData = json_decode($cache, true); $lsIncome = $cacheData['lsIncome']; $orderCount = $cacheData['orderCount']; } else { $period = dateUtil::formatTime('today', '', '', 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['time'] = ['between', [$start, $end]]; $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]]; $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]]; $orderCount = OrderClass::getCount($where); $lsIncome = 0; $hdOrderList = OrderClass::getAllByCondition($where, null, 'mainPay, forward, cash'); foreach ($hdOrderList as $hdKey => $hdOrder) { $actPrice = $hdOrder['mainPay'] ?? 0; $forward = $hdOrder['forward'] ?? 0; if ($forward == 1) { //零售售后付款 // $lsAfterSale = bcadd($lsAfterSale, $actPrice, 2); } else { $cash = $hdOrder['cash'] ?? 0; $lsIncome = bcadd($actPrice, $lsIncome, 2); $lsIncome = bcadd($lsIncome, $cash, 2); } } $cacheData = [ 'lsIncome' => $lsIncome, 'orderCount' => $orderCount, ]; \Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 1800, json_encode($cacheData, JSON_UNESCAPED_UNICODE)]); } // 昨天零售收入 $cacheKey = 'hd_console_profile:' . 'yesterday_'.$todayStr.'_income_' . $this->shopId; $cache = \Yii::$app->redis->executeCommand('GET', [$cacheKey]); if ($cache) { $cacheData = json_decode($cache, true); $yesterdayIncome = $cacheData['yesterdayIncome']; } else { $period = dateUtil::formatTime('yesterday', '', '', 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['time'] = ['between', [$start, $end]]; $where = ['mainId' => $mainId, 'status' => ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]]]; $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]]; $yesterdayIncome = 0; $hdOrderList = OrderClass::getAllByCondition($where, null, 'mainPay, forward, cash'); foreach ($hdOrderList as $hdKey => $hdOrder) { $actPrice = $hdOrder['mainPay'] ?? 0; $forward = $hdOrder['forward'] ?? 0; if ($forward == 1) { //零售售后付款 // $lsAfterSale = bcadd($lsAfterSale, $actPrice, 2); } else { $cash = $hdOrder['cash'] ?? 0; $yesterdayIncome = bcadd($actPrice, $yesterdayIncome, 2); $yesterdayIncome = bcadd($yesterdayIncome, $cash, 2); } } $cacheData = [ 'yesterdayIncome' => $yesterdayIncome, ]; \Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 86400, json_encode($cacheData, JSON_UNESCAPED_UNICODE)]); } } //访客数 $visitCustom = StatVisitClass::getVisitNum($this->shopId); // $wastage = \bizGhs\order\classes\StockWastageOrderClass::getTodayWaste($this->mainId); // $hsReturn = StatOrderClass::statHsNum($this->mainId); // $hsNum = $hsReturn['num'] ?? 0; $menu = [ ["name" => "商城", "img" => "ghs/home/shop2.png", "url" => "/admin/cg/mall", 'pf' => 1,], ["name" => "改价", "img" => "ghs/home/gj2.png", "url" => "/admin/changePrice/list2", 'pf' => 1,], ["name" => "花材绿植", "img" => "ghs/home/hcgl2.png", "url" => "/admin/item/list2", 'pf' => 1,], ["name" => "接花束", "img" => "ghs/home/shop2.png", "url" => "/admin/order/workOrder", 'pf' => 1,], ["name" => "拆散", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/part/list", 'pf' => 1,], ["name" => "损耗", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/breakage/list", 'pf' => 1,], ["name" => "任务", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/work/list", 'pf' => 1,], ["name" => "买花", "img" => "ghs/home/shop2.png", "url" => "/pagesPurchase/order", 'pf' => 1,], ["name" => "买花记录", "img" => "ghs/home/shop2.png", "url" => "/pagesPurchase/shopping", 'pf' => 1,], ["name" => "花束", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/goods/list", 'pf' => 1,], ["name" => "客户充值", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/recharge/rechargeCode", 'pf' => 1,], ]; $warning = ''; //$warning = '本月4号凌晨4点~5点系统升级,暂停使用'; util::success([ 'warning' => $warning, 'todayData' => [ 'visit' => $visitCustom, 'income' => $lsIncome, //$todaySale, 'order' => $orderCount, //$orderNum, // 'wastage' => $wastage, // 'bouquet' => $hsNum ], 'yesterdayIncome' => $yesterdayIncome, 'menu' => $menu, 'lookMoney' => $lookMoney, ]); } //常用初始化 public function actionInit() { $dict = dict::get($this->mainId); $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : []; util::success(['dict' => $dict, 'shop' => $shop]); } //系统收入、客服收入、欠款 public function actionStrokeCount() { if (empty($this->mainId)) { util::success([ 'systemIncome' => 0, 'systemCount' => 0, 'debtCount' => 0, 'debtIncome' => 0, 'kfWxCount' => 0, 'kfWxIncome' => 0, 'cashCount' => 0, 'cashIncome' => 0, ]); } $return = \bizGhs\stat\classes\StatKdClass::eachChannelIncome($this->mainId, $this->shop); $incomeList = $return['incomeList']; $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0; $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0; $systemIncome2 = $incomeList['system']['category']['pf']['amount'] ?? 0; $systemCount2 = $incomeList['system']['category']['pf']['num'] ?? 0; $systemCount = bcadd($systemCount1, $systemCount2); $systemIncome = bcadd($systemIncome1, $systemIncome2, 2); $debtIncome1 = $incomeList['debt']['category']['ls']['amount'] ?? 0; $debtCount1 = $incomeList['debt']['category']['ls']['num'] ?? 0; $debtIncome2 = $incomeList['debt']['category']['pf']['amount'] ?? 0; $debtCount2 = $incomeList['debt']['category']['pf']['num'] ?? 0; $debtIncome = bcadd($debtIncome1, $debtIncome2, 2); $debtCount = bcadd($debtCount1, $debtCount2); $kfWxIncome1 = $incomeList['kfWx']['category']['ls']['amount'] ?? 0; $kfWxCount1 = $incomeList['kfWx']['category']['ls']['num'] ?? 0; $kfWxIncome2 = $incomeList['kfWx']['category']['pf']['amount'] ?? 0; $kfWxCount2 = $incomeList['kfWx']['category']['pf']['num'] ?? 0; $kfWxIncome = bcadd($kfWxIncome1, $kfWxIncome2, 2); $kfWxCount = bcadd($kfWxCount1, $kfWxCount2); $cashIncome1 = $incomeList['cash']['category']['ls']['amount'] ?? 0; $cashCount1 = $incomeList['cash']['category']['ls']['num'] ?? 0; $cashIncome2 = $incomeList['cash']['category']['pf']['amount'] ?? 0; $cashCount2 = $incomeList['cash']['category']['pf']['num'] ?? 0; $cashIncome = bcadd($cashIncome1, $cashIncome2, 2); $cashCount = bcadd($cashCount1, $cashCount2); util::success([ 'systemIncome' => $systemIncome, 'systemCount' => $systemCount, 'debtCount' => $debtCount, 'debtIncome' => $debtIncome, 'kfWxCount' => $kfWxCount, 'kfWxIncome' => $kfWxIncome, 'cashCount' => $cashCount, 'cashIncome' => $cashIncome, ]); } }