MerchantReconciliationOrderDao.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\store\order;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\order\MerchantReconciliationOrder as model;
  14. class MerchantReconciliationOrderDao extends BaseDao
  15. {
  16. public function getModel(): string
  17. {
  18. return model::class;
  19. }
  20. /**
  21. * 根据条件搜索数据。
  22. *
  23. * 本函数用于根据提供的条件搜索数据库中的记录。它支持两种条件:'reconciliation_id' 和 'type'。
  24. * 只有当条件存在且不为空时,才会在查询中添加相应的 WHERE 子句。
  25. *
  26. * @param array $where 包含搜索条件的数组。可能的条件键包括 'reconciliation_id' 和 'type'。
  27. * @return \Illuminate\Database\Eloquent\Builder|static 返回构建器对象,可用于进一步的查询操作或数据检索。
  28. */
  29. public function search($where)
  30. {
  31. // 获取模型对应的数据库实例
  32. return ($this->getModel()::getDB())->when(
  33. // 检查是否有 'reconciliation_id' 条件,并且它不是空的
  34. isset($where['reconciliation_id']) && $where['reconciliation_id'] !== '',
  35. function ($query) use ($where) {
  36. // 如果存在 'reconciliation_id',则在查询中添加对应的 WHERE 条件
  37. $query->where('reconciliation_id', $where['reconciliation_id']);
  38. }
  39. )->when(
  40. // 检查是否有 'type' 条件,并且它不是空的
  41. isset($where['type']) && $where['type'] !== '',
  42. function ($query) use ($where) {
  43. // 如果存在 'type',则在查询中添加对应的 WHERE 条件
  44. $query->where('type', $where['type']);
  45. }
  46. );
  47. }
  48. }