StatisticsController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace console\controllers;
  3. use common\logic\statistics\UserTeamStatisticsLogic;
  4. use yii\console\Controller;
  5. use yii\console\ExitCode;
  6. use common\models\mall\Mall;
  7. use common\models\statistics\GoodsStatistics;
  8. use common\models\statistics\GlobalStatistics;
  9. use common\models\statistics\UserStatistics;
  10. use common\models\statistics\RegionStatistics;
  11. use common\logic\statistics\AssetsStatisticsLogin;
  12. use Yii;
  13. class StatisticsController extends Controller
  14. {
  15. /**
  16. * 资产统计定时任务
  17. *
  18. * 30 * * * *
  19. * @author hpei
  20. * @return int
  21. */
  22. public function actionAssetsStatistics() {
  23. try {
  24. $object = new AssetsStatisticsLogin();
  25. $res = $object->execute();
  26. if($res == true) {
  27. echo 'success';
  28. return ExitCode::OK;
  29. }
  30. } catch (\Exception $e) {
  31. echo '定时任务统计资产' . $e->getMessage();
  32. $this->stderr('Error: ' . ExitCode::getReason(ExitCode::UNSPECIFIED_ERROR));
  33. return ExitCode::UNSPECIFIED_ERROR;
  34. }
  35. }
  36. /**
  37. * 生成统计缓存任务
  38. *
  39. * @param string type [global|user|goods|region]
  40. */
  41. public function actionCacheStatistics(string $type, int $mall_id) {
  42. if (empty($type) || empty($mall_id)) return;
  43. $mall = Mall::find()->select('name')->where(['id' => $mall_id, 'is_delete' => 0, 'is_recycle' => 0, 'is_disable' => 0])->one();
  44. if (empty($mall)) {
  45. echo 'id=' . $mall_id . '商城不存在';
  46. $this->stderr('Error: ' . ExitCode::getReason(ExitCode::UNSPECIFIED_ERROR));
  47. return ExitCode::UNSPECIFIED_ERROR;
  48. }
  49. try {
  50. switch ($type) {
  51. case 'global':
  52. $model = GlobalStatistics::class;
  53. break;
  54. case 'user':
  55. $model = UserStatistics::class;
  56. break;
  57. case 'goods':
  58. $model = GoodsStatistics::class;
  59. break;
  60. case 'region':
  61. $model = RegionStatistics::class;
  62. break;
  63. }
  64. $model::resetCache($mall_id);
  65. echo 'success';
  66. return ExitCode::OK;
  67. } catch (\Exception $e) {
  68. echo '生成' . $type . '缓存失败' . $e->getMessage();
  69. $this->stderr('Error: ' . ExitCode::getReason(ExitCode::UNSPECIFIED_ERROR));
  70. return ExitCode::UNSPECIFIED_ERROR;
  71. }
  72. }
  73. /**
  74. * 团队数据每日统计
  75. * @Author: lun
  76. * @DateTime: 2021/11/26 0026 9:16
  77. * @Copyright: copyright (c) 2021 广东七件事集团
  78. * @return int
  79. */
  80. public function actionUserTeamStatistics() {
  81. try {
  82. $mall_list = Mall::getEnableMallList(true);
  83. if(!empty($mall_list)){
  84. foreach ($mall_list as $mall){
  85. $logic = new UserTeamStatisticsLogic();
  86. $res = $logic->execute($mall['id']);
  87. if($res == false) {
  88. $this->stderr('Error: ' . ExitCode::getReason(ExitCode::UNSPECIFIED_ERROR));
  89. return ExitCode::UNSPECIFIED_ERROR;
  90. }
  91. }
  92. }
  93. echo 'success';
  94. return ExitCode::OK;
  95. } catch (\Exception $e) {
  96. echo '定时任务团队数据每日统计' . $e->getMessage();
  97. $this->stderr('Error: ' . ExitCode::getReason(ExitCode::UNSPECIFIED_ERROR));
  98. return ExitCode::UNSPECIFIED_ERROR;
  99. }
  100. }
  101. }