id ?? 0; $ghsMainId = $ghs->mainId ?? 0; $cacheKey = 'ghs_mall_visit_' . $ghsMainId . '_' . $date; $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $customId]); if (empty($exists)) { Yii::$app->redis->executeCommand('SADD', [$cacheKey, $customId]); $custom->visitTime = date("Y-m-d H:i:s"); $custom->save(); } } //批发保存访客数 public static function saveVisit($shop, $visitNum, $date = null) { $sjId = $shop->sjId ?? 0; $shopId = $shop->id ?? 0; $totalNum = $shop->totalVisit ?? 0; $date = isset($date) == false ? date("Ymd") : $date; $resource = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $date], true); //已经存过 if (!empty($resource)) { return false; } $data = [ 'time' => $date, 'riseNum' => 0, 'totalNum' => 0, 'shopId' => $shopId, 'sjId' => $sjId, 'createTime' => date("Y-m-d H:i:s") ]; $resource = self::add($data, true); $nowNum = bcadd($resource->riseNum, $visitNum, 2); $resource->riseNum = $nowNum; $resource->totalNum = $totalNum; $resource->save(); //每月 if ($date == null) { $time = date('Ym'); $year = date('Y'); $month = date('m'); } else { $timestamp = strtotime($date); $time = date('Ym', $timestamp); $year = date('Y', $timestamp); $month = date('m', $timestamp); } $stat = StatVisitMonthClass::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $time], true); if (empty($stat)) { $stat = StatVisitMonthClass::add(['shopId' => $shopId, 'sjId' => $sjId, 'time' => $time, 'year' => $year, 'month' => $month, 'createTime' => date("Y-m-d H:i:s")], true); } $currentNum = bcadd($stat->riseNum, $visitNum); $stat->riseNum = $currentNum; $stat->totalNum = $totalNum; $stat->save(); self::clearVisit($shop, $date); } //批发清空访客 public static function clearVisit($shop, $date = null) { $mainId = $shop->mainId ?? 0; $date = isset($date) == false ? date("Ymd") : $date; $cacheKey = 'ghs_mall_visit_' . $mainId . '_' . $date; Yii::$app->redis->executeCommand('DEL', [$cacheKey]); } //批发端获取访客数 ssh 2020.2.2 public static function getVisitNum($mainId, $date = null) { $date = isset($date) == false ? date("Ymd") : $date; $cacheKey = 'ghs_mall_visit_' . $mainId . '_' . $date; $num = Yii::$app->redis->executeCommand('SCARD', [$cacheKey]); return !empty($num) ? $num : 0; } //批发端获取访客ID public static function getVisitCustomIds($shop, $date = null) { $mainId = $shop->mainId ?? 0; $date = isset($date) == false ? date("Ymd") : $date; $cacheKey = 'ghs_mall_visit_' . $mainId . '_' . $date; $ids = Yii::$app->redis->executeCommand('SMEMBERS', [$cacheKey]); return $ids; } }