ExpressDao.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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['name']) && $where['name'],function($query) use ($where){
  53. $query->where('name|code','like','%'.$where['name'].'%');
  54. })->where(isset($where['code']) && $where['code'],function($query)use($where){
  55. $query->where('code',$where['name']);
  56. });
  57. return $query->order('sort DESC');
  58. }
  59. }