ExpressDao.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\shipping;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\shipping\Express as model;
  14. class ExpressDao extends BaseDao
  15. {
  16. /**
  17. * @Author:Qinii
  18. * @Date: 2020/5/13
  19. * @return string
  20. */
  21. protected function getModel(): string
  22. {
  23. return model::class;
  24. }
  25. /**
  26. * @Author:Qinii
  27. * @Date: 2020/5/13
  28. * @param $field
  29. * @param $value
  30. * @param null $except
  31. * @return bool
  32. */
  33. public function merFieldExists($field, $value, $except = null, $id = null, $isUser = null)
  34. {
  35. return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
  36. $query->where($field, '<>', $except);
  37. })->when($id, function ($query) use ($id) {
  38. $query->where($this->getPk(), '<>', $id);
  39. })->when($isUser, function ($query) {
  40. $query->where('is_show', 1);
  41. })->where($field, $value)->count() > 0;
  42. }
  43. /**
  44. * @Author:Qinii
  45. * @Date: 2020/5/13
  46. * @param array $where
  47. * @return mixed
  48. */
  49. public function search(array $where)
  50. {
  51. $query = ($this->getModel()::getDB())
  52. ->when(isset($where['keyword']) && $where['keyword'],function($query) use ($where){
  53. $query->where('name|code','like','%'.$where['keyword'].'%');
  54. })
  55. ->where(isset($where['code']) && $where['code'],function($query)use($where){
  56. $query->where('code',$where['name']);
  57. })
  58. ->where(isset($where['is_show']) && $where['is_show'],function($query)use($where){
  59. $query->where('is_show',$where['is_show']);
  60. })
  61. ->where(isset($where['id']) && $where['id'],function($query)use($where){
  62. $query->where('id',$where['id']);
  63. });
  64. return $query->order('sort DESC');
  65. }
  66. }