SpecService.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace addons\TinyShop\services\common;
  3. use common\components\Service;
  4. use common\enums\StatusEnum;
  5. use common\helpers\ArrayHelper;
  6. use addons\TinyShop\common\models\common\Spec;
  7. /**
  8. * Class SpecService
  9. * @package addons\TinyShop\services\common
  10. * @author jianyan74 <751393839@qq.com>
  11. */
  12. class SpecService extends Service
  13. {
  14. /**
  15. * 根据id数组获取列表
  16. *
  17. * @param $ids
  18. * @return array|\yii\db\ActiveRecord[]
  19. */
  20. public function findByIds(array $ids)
  21. {
  22. return Spec::find()
  23. ->where(['status' => StatusEnum::ENABLED, 'is_tmp' => StatusEnum::DISABLED])
  24. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  25. ->andWhere(['in', 'id', $ids])
  26. ->with(['value'])
  27. ->asArray()
  28. ->all();
  29. }
  30. /**
  31. * @param $id
  32. * @return array|\yii\db\ActiveRecord|null
  33. */
  34. public function findById($id)
  35. {
  36. return Spec::find()
  37. ->where([
  38. 'id' => $id,
  39. 'status' => StatusEnum::ENABLED,
  40. ])
  41. ->asArray()
  42. ->one();
  43. }
  44. /**
  45. * @return array
  46. */
  47. public function getMap()
  48. {
  49. return ArrayHelper::map($this->findAll(), 'id', 'title');
  50. }
  51. /**
  52. * 获取列表
  53. *
  54. * @return array|\yii\db\ActiveRecord[]
  55. */
  56. public function findAll()
  57. {
  58. return Spec::find()
  59. ->where(['status' => StatusEnum::ENABLED])
  60. ->andWhere(['is_tmp' => StatusEnum::DISABLED])
  61. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  62. ->orderBy('sort asc, id desc')
  63. ->asArray()
  64. ->all();
  65. }
  66. }
粤ICP备19079148号