StoreService.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace services\store;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. use addons\TinyStore\common\models\store\Store;
  6. /**
  7. * Class StoreService
  8. * @package ${NAMESPACE}
  9. * @author jianyan74 <751393839@qq.com>
  10. */
  11. class StoreService
  12. {
  13. /**
  14. * @var int
  15. */
  16. protected $store_id = 0;
  17. /**
  18. * @return int
  19. */
  20. public function getId()
  21. {
  22. return $this->store_id;
  23. }
  24. /**
  25. * @param $store_id
  26. */
  27. public function setId($store_id)
  28. {
  29. $this->store_id = $store_id;
  30. }
  31. /**
  32. * @return int
  33. */
  34. public function getNotNullId(): int
  35. {
  36. return !empty($this->store_id) ? (int)$this->store_id : 0;
  37. }
  38. /**
  39. * 获取自动判断的商户ID
  40. *
  41. * @return int
  42. */
  43. public function getAutoId()
  44. {
  45. return 0;
  46. }
  47. /**
  48. * @param $store_id
  49. */
  50. public function addId($store_id)
  51. {
  52. !$this->store_id && $this->store_id = $store_id;
  53. }
  54. /**
  55. * @param $store
  56. * @return string
  57. */
  58. public function getTitle($store)
  59. {
  60. if (empty($store)) {
  61. return '---';
  62. }
  63. if (Yii::$app->services->devPattern->isB2C()) {
  64. return '平台';
  65. }
  66. return $store['title'];
  67. }
  68. /**
  69. * @param $condition
  70. * @return array|\yii\db\ActiveRecord|null
  71. */
  72. public function findByCondition($condition)
  73. {
  74. return Store::find()
  75. ->where($condition)
  76. ->andWhere(['status' => StatusEnum::ENABLED])
  77. ->one();
  78. }
  79. /**
  80. * @param $condition
  81. * @return array|\yii\db\ActiveRecord|null
  82. */
  83. public function findAllByCondition($condition)
  84. {
  85. return Store::find()
  86. ->where($condition)
  87. ->asArray()
  88. ->andWhere(['status' => StatusEnum::ENABLED])
  89. ->all();
  90. }
  91. /**
  92. * @param $id
  93. * @return array|\yii\db\ActiveRecord|null|Store
  94. */
  95. public function findById($id)
  96. {
  97. return Store::find()
  98. ->where(['id' => $id])
  99. ->one();
  100. }
  101. }
粤ICP备19079148号