HelperService.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\Helper;
  7. /**
  8. * Class HelperService
  9. * @package addons\TinyShop\services\common
  10. * @author jianyan74 <751393839@qq.com>
  11. */
  12. class HelperService extends Service
  13. {
  14. /**
  15. * 获取下拉
  16. *
  17. * @param string $id
  18. * @return array
  19. */
  20. public function getDropDownForEdit($id = '')
  21. {
  22. $list = Helper::find()
  23. ->where(['>=', 'status', StatusEnum::DISABLED])
  24. ->andFilterWhere(['<>', 'id', $id])
  25. ->select(['id', 'title', 'pid', 'level'])
  26. ->orderBy('sort asc')
  27. ->asArray()
  28. ->all();
  29. $models = ArrayHelper::itemsMerge($list);
  30. $data = ArrayHelper::map(ArrayHelper::itemsMergeDropDown($models), 'id', 'title');
  31. return ArrayHelper::merge([0 => '顶级'], $data);
  32. }
  33. /**
  34. * @return array|\yii\db\ActiveRecord[]
  35. */
  36. public function findAll()
  37. {
  38. return Helper::find()
  39. ->where(['status' => StatusEnum::ENABLED])
  40. ->select(['id', 'title', 'pid', 'level'])
  41. ->orderBy('sort asc')
  42. ->asArray()
  43. ->all();
  44. }
  45. }
粤ICP备19079148号