ProductUnitDao.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\product;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\product\ProductUnit;
  14. class ProductUnitDao extends BaseDao
  15. {
  16. /**
  17. * @return ProductUnit
  18. *
  19. * @date 2023/10/16
  20. * @author yyw
  21. */
  22. protected function getModel(): string
  23. {
  24. return ProductUnit::class;
  25. }
  26. /**
  27. * 搜索
  28. * @param array $where
  29. * @return \think\db\BaseQuery
  30. *
  31. * @date 2023/10/16
  32. * @author yyw
  33. */
  34. public function search(array $where = [])
  35. {
  36. return $this->getModel()::getDB()
  37. ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  38. $query->where('mer_id', $where['mer_id']);
  39. })
  40. ->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  41. $query->where('status', $where['status']);
  42. })
  43. ->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
  44. $query->where('is_del', $where['is_del']);
  45. })
  46. ->when(isset($where['value']) && $where['value'] !== '', function ($query) use ($where) {
  47. $query->whereLike('value', "%{$where['value']}%");
  48. })
  49. ->when(isset($where['product_unit_id']) && $where['product_unit_id'] !== '', function ($query) use ($where) {
  50. $query->whereLike($this->getPk(), $where['product_unit_id']);
  51. })
  52. ->order(['sort' => 'DESC', 'create_time' => 'DESC']);
  53. }
  54. }