MerchantService.php 2.7 KB

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