| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace console\controllers;
- use common\logic\statistics\UserTeamStatisticsLogic;
- use yii\console\Controller;
- use yii\console\ExitCode;
- use common\models\mall\Mall;
- use common\models\statistics\GoodsStatistics;
- use common\models\statistics\GlobalStatistics;
- use common\models\statistics\UserStatistics;
- use common\models\statistics\RegionStatistics;
- use common\logic\statistics\AssetsStatisticsLogin;
- use Yii;
- class StatisticsController extends Controller
- {
- /**
- * 资产统计定时任务
- *
- * 30 * * * *
- * @author hpei
- * @return int
- */
- public function actionAssetsStatistics() {
- try {
- $object = new AssetsStatisticsLogin();
- $res = $object->execute();
- if($res == true) {
- echo 'success';
- return ExitCode::OK;
- }
- } catch (\Exception $e) {
- echo '定时任务统计资产' . $e->getMessage();
- $this->stderr('Error: ' . ExitCode::getReason(ExitCode::UNSPECIFIED_ERROR));
- return ExitCode::UNSPECIFIED_ERROR;
- }
- }
- /**
- * 生成统计缓存任务
- *
- * @param string type [global|user|goods|region]
- */
- public function actionCacheStatistics(string $type, int $mall_id) {
- if (empty($type) || empty($mall_id)) return;
- $mall = Mall::find()->select('name')->where(['id' => $mall_id, 'is_delete' => 0, 'is_recycle' => 0, 'is_disable' => 0])->one();
- if (empty($mall)) {
- echo 'id=' . $mall_id . '商城不存在';
- $this->stderr('Error: ' . ExitCode::getReason(ExitCode::UNSPECIFIED_ERROR));
- return ExitCode::UNSPECIFIED_ERROR;
- }
- try {
- switch ($type) {
- case 'global':
- $model = GlobalStatistics::class;
- break;
- case 'user':
- $model = UserStatistics::class;
- break;
- case 'goods':
- $model = GoodsStatistics::class;
- break;
- case 'region':
- $model = RegionStatistics::class;
- break;
- }
- $model::resetCache($mall_id);
- echo 'success';
- return ExitCode::OK;
- } catch (\Exception $e) {
- echo '生成' . $type . '缓存失败' . $e->getMessage();
- $this->stderr('Error: ' . ExitCode::getReason(ExitCode::UNSPECIFIED_ERROR));
- return ExitCode::UNSPECIFIED_ERROR;
- }
- }
- /**
- * 团队数据每日统计
- * @Author: lun
- * @DateTime: 2021/11/26 0026 9:16
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return int
- */
- public function actionUserTeamStatistics() {
- try {
- $mall_list = Mall::getEnableMallList(true);
- if(!empty($mall_list)){
- foreach ($mall_list as $mall){
- $logic = new UserTeamStatisticsLogic();
- $res = $logic->execute($mall['id']);
- if($res == false) {
- $this->stderr('Error: ' . ExitCode::getReason(ExitCode::UNSPECIFIED_ERROR));
- return ExitCode::UNSPECIFIED_ERROR;
- }
- }
- }
- echo 'success';
- return ExitCode::OK;
- } catch (\Exception $e) {
- echo '定时任务团队数据每日统计' . $e->getMessage();
- $this->stderr('Error: ' . ExitCode::getReason(ExitCode::UNSPECIFIED_ERROR));
- return ExitCode::UNSPECIFIED_ERROR;
- }
- }
- }
|