MerchantRegionDao.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\system\merchant;
  12. use app\common\dao\BaseDao;
  13. use crmeb\traits\CategoresDao;
  14. use app\common\model\system\merchant\MerchantRegion;
  15. class MerchantRegionDao extends BaseDao
  16. {
  17. use CategoresDao;
  18. protected function getModel(): string
  19. {
  20. return MerchantRegion::class;
  21. }
  22. public function getAllOptions($mer_id = null,$status = 1,$level = null,$type = null)
  23. {
  24. $field = $this->getParentId().',name';
  25. $query = ($this->getModel()::getDB());
  26. $query->when(($mer_id !== null),function($query)use($mer_id){
  27. $query->where('mer_id', $mer_id);
  28. })
  29. ->when($status,function($query)use($status){
  30. $query->where($this->getStatus(),$status);
  31. })
  32. ->when(($level != '' && $level != null),function($query)use($level){
  33. $query->where($this->getLevel(),'<',$level);
  34. });
  35. $query->when(!is_null($type),function ($query) use($type){
  36. $query->where('type',$type);
  37. });
  38. return $query->order('sort DESC,'.$this->getPk().' DESC')->column($field, $this->getPk());
  39. }
  40. public function getLevel()
  41. {
  42. return 'lv';
  43. }
  44. public function getStatus(): string
  45. {
  46. return 'status';
  47. }
  48. }