You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
863 B

  1. <?php
  2. namespace api\logic;
  3. use common\models\DailyActiveUser;
  4. use yii\base\Component;
  5. use Yii;
  6. /**
  7. * @author iron
  8. * @email weiriron@gmail.com
  9. * Class CartLogic
  10. * @package api\logic
  11. */
  12. class UserLogic extends Component
  13. {
  14. public function DailyActive()
  15. {
  16. $date = date('Y-m-d', time());
  17. $DAU = DailyActiveUser::find()
  18. ->where(['date' => $date])
  19. ->one();
  20. if ($DAU) {
  21. $ids = $DAU->user_ids;
  22. if (in_array(Yii::$app->user->id, $ids)) {
  23. return;
  24. }
  25. array_push($ids, Yii::$app->user->id);
  26. $DAU->user_id = $ids;
  27. $DAU->count += 1;
  28. } else {
  29. $DAU = new DailyActiveUser();
  30. $DAU->user_ids = array(Yii::$app->user->getId());
  31. $DAU->date = $date;
  32. }
  33. $DAU->save();
  34. }
  35. }