CateService.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace addons\RfDemo\services;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. use common\helpers\ArrayHelper;
  6. use addons\RfDemo\common\models\Cate;
  7. /**
  8. * Class CateService
  9. * @package addons\RfDemo\services
  10. * @author jianyan74 <751393839@qq.com>
  11. */
  12. class CateService
  13. {
  14. /**
  15. * 获取下拉
  16. *
  17. * @param string $id
  18. * @return array
  19. */
  20. public function getDropDownForEdit($id = '')
  21. {
  22. $list = Cate::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. * @param string $pid
  35. * @return array|\yii\db\ActiveRecord[]
  36. */
  37. public function findById($id)
  38. {
  39. return Cate::find()
  40. ->where(['id' => $id])
  41. ->andWhere(['status' => StatusEnum::ENABLED])
  42. ->asArray()
  43. ->one();
  44. }
  45. /**
  46. * @param string $pid
  47. * @return array|\yii\db\ActiveRecord[]
  48. */
  49. public function findAll()
  50. {
  51. $merchant_id = Yii::$app->services->merchant->getNotNullId();
  52. return Cate::find()
  53. ->select(['id', 'title', 'pid', 'level'])
  54. ->where(['status' => StatusEnum::ENABLED])
  55. ->andWhere(['merchant_id' => $merchant_id])
  56. ->orderBy('sort asc, id desc')
  57. ->asArray()
  58. ->all();
  59. }
  60. }
粤ICP备19079148号