| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace common\services;
- use Yii;
- use common\components\dict;
- use common\components\stringUtil;
- use linslin\yii2\curl;
- use common\components\wxUtil;
- use common\components\util;
- use common\models\xhStatDealByDay;
- class xhStatDealByDayService {
-
- /**
- * 收集当天的订单
- */
- public static function gatherDeal($sjId)
- {
- $todayTime = strtotime(date("Y-m-d"));
- $dealKey = $sjId.dict::getCacheKey('statDealByDay').$todayTime;
- $num = Yii::$app->redis->executeCommand('INCR', [$dealKey]);//记录当天订单的增加
- return $num;
- }
- /**
- * 将昨天的订单数保存入库
- */
- public static function saveYesterdayDeal($sjId)
- {
- $yesTime = strtotime(date("Y-m-d",strtotime("-1 day")));
- $arr = xhStatDealByDay::getByCondition(['sjId' => $sjId,'time' => $yesTime]);
- if(!empty($arr)){
- return [];
- }
- $dealKey = $sjId.dict::getCacheKey('statDealByDay').$yesTime;
- $num = Yii::$app->redis->executeCommand('GET', [$dealKey]);
- $num = !empty($num) ? $num : 0;
- $totalNum = self::getYesterdayTotalNum($sjId);
- $data = ['time' => $yesTime,'riseNum' =>$num,'totalNum' => $totalNum,'sjId' => $sjId,'createTime' => date("Y-m-d H:i:s")];
- $saveData = self::add($data);
- return $saveData;
- }
- /**
- * 取昨天及以前的订单总数和
- */
- public static function getYesterdayTotalNum($sjId)
- {
- $totalNum = self::getTodayNum($sjId);
- $todayNum = self::getTodayNum($sjId);
- $num = $totalNum - $todayNum;
- return $num;
- }
- /**
- * 取总的订单数
- */
- public static function getTotalNum($sjId)
- {
- $asset = xhMerchantAssetService::getBySjId($sjId);
- $totalDeal = $asset['totalDeal'];
- return $totalDeal;
- }
- /**
- * 取今天的订单数
- */
- public static function getTodayNum($sjId)
- {
- $time = strtotime(date("Y-m-d"));
- $numKey = $sjId.dict::getCacheKey('statDealByDay').$time;
- $nowNum = Yii::$app->redis->executeCommand('GET', [$numKey]);//记录当天访问网站人数
- $nowNum = !empty($nowNum) ? $nowNum : 0;
- return $nowNum;
- }
- public static function add($data)
- {
- xhStatDealByDay::add($data);
- }
-
- /**
- * 获取昨天订单增加数
- */
- public static function getYesNum($sjId)
- {
- $yesTime = strtotime(date("Y-m-d",strtotime("-1 day")));
- $numKey = $sjId.dict::getCacheKey('statDealByDay').$yesTime;
- $nowNum = Yii::$app->redis->executeCommand('GET', [$numKey]);//记录当天访问网站人数
- return !empty($nowNum) ? $nowNum : 0;
- }
- /**
- * 清空昨天的订单增加数据(包括缓存与数据库)
- */
- public static function clearYesNum($sjId)
- {
- $yesTime = strtotime(date("Y-m-d",strtotime("-1 day")));
- $dealKey = $sjId.dict::getCacheKey('statDealByDay').$yesTime;
- $yesterdayVisitNum = Yii::$app->redis->executeCommand('DEL', [$dealKey]);
- xhStatDealByDay::deleteByCondition(['sjId' => $sjId,'time' => $yesTime]);
- }
- /**
- * 模拟创建昨天的订单数
- */
- public static function imitationCreateYesNum($sjId)
- {
- echo "\n模拟创建昨天的订单数……\n";
- $yesTime = strtotime(date("Y-m-d",strtotime("-1 day")));
- $dealKey = $sjId.dict::getCacheKey('statDealByDay').$yesTime;
- $num = rand(11,80);
- Yii::$app->redis->executeCommand('SET', [$dealKey,$num]);
- echo "\n创建完成\n";
- }
- }
|