PriceRuleDao.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\store;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\PriceRule;
  14. use app\common\repositories\system\RelevanceRepository;
  15. class PriceRuleDao extends BaseDao
  16. {
  17. protected function getModel(): string
  18. {
  19. return PriceRule::class;
  20. }
  21. public function search(array $where)
  22. {
  23. return PriceRule::getDB()->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  24. $query->whereLike('rule_name', "%{$where['keyword']}%");
  25. })->when(isset($where['is_show']) && $where['is_show'] !== '', function ($query) use ($where) {
  26. $query->where('is_show', $where['is_show']);
  27. })->when(isset($where['cate_id']) && $where['cate_id'] !== '', function ($query) use ($where) {
  28. $ids = app()->make(RelevanceRepository::class)->query([
  29. 'type' => RelevanceRepository::PRICE_RULE_CATEGORY
  30. ])->where(function ($query) use ($where) {
  31. if (is_array($where['cate_id'])) {
  32. $query->whereIn('right_id', $where['cate_id']);
  33. } else {
  34. $query->where('right_id', (int)$where['cate_id']);
  35. }
  36. })->group('left_id')->column('left_id');
  37. $ids[] = -1;
  38. $query->where(function ($query) use ($ids) {
  39. $query->whereIn('rule_id', $ids)->whereOr('is_default', 1);
  40. });
  41. });
  42. }
  43. }