FriendlyLinkService.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Author: lf
  4. * Blog: https://blog.feehi.com
  5. * Email: job@feehi.com
  6. * Created at: 2020-01-23 09:38
  7. */
  8. namespace common\services;
  9. use backend\models\search\FriendlyLinkSearch;
  10. use common\models\FriendlyLink;
  11. class FriendlyLinkService extends Service implements FriendlyLinkServiceInterface
  12. {
  13. public function getSearchModel(array $options=[])
  14. {
  15. return new FriendlyLinkSearch();
  16. }
  17. public function getModel($id, array $options=[])
  18. {
  19. return FriendlyLink::findOne($id);
  20. }
  21. public function newModel(array $options=[]){
  22. $model = new FriendlyLink();
  23. $model->loadDefaultValues();
  24. return $model;
  25. }
  26. public function getFriendlyLinks()
  27. {
  28. return FriendlyLink::find()->where(['status' => FriendlyLink::DISPLAY_YES])->orderBy(['sort' => SORT_ASC, 'id' => SORT_DESC])->all();
  29. }
  30. public function getFriendlyLinkCountByPeriod($startAt=null, $endAt=null)
  31. {
  32. $model = FriendlyLink::find();
  33. if( $startAt != null && $endAt != null ){
  34. $model->andWhere(["between", "created_at", $startAt, $endAt]);
  35. }else if ($startAt != null){
  36. $model->andwhere([">", "created_at", $startAt]);
  37. } else if($endAt != null){
  38. $model->andWhere(["<", "created_at", $endAt]);
  39. }
  40. return $model->count('id');
  41. }
  42. }