LevelConfigService.php 1004 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace services\member;
  3. use common\components\Service;
  4. use common\models\member\LevelConfig;
  5. /**
  6. * Class LevelConfigService
  7. * @package services\member
  8. */
  9. class LevelConfigService extends Service
  10. {
  11. /**
  12. * @var array
  13. */
  14. protected $models = [];
  15. /**
  16. * @return array|\yii\db\ActiveRecord|null
  17. */
  18. public function findOne($merchant_id)
  19. {
  20. return LevelConfig::find()
  21. ->where(['merchant_id' => $merchant_id])
  22. ->one();
  23. }
  24. /**
  25. * @return LevelConfig
  26. */
  27. public function one($merchant_id)
  28. {
  29. if (!empty($this->models[$merchant_id])) {
  30. return $this->models[$merchant_id];
  31. }
  32. /* @var $model LevelConfig */
  33. if (empty($model = $this->findOne($merchant_id))) {
  34. $model = new LevelConfig();
  35. $model = $model->loadDefaultValues();
  36. $model->save();
  37. }
  38. $this->models[$merchant_id] = $model;
  39. return $model;
  40. }
  41. }
粤ICP备19079148号