ExpressDao.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/13
  6. */
  7. namespace app\common\dao\store\shipping;
  8. use app\common\dao\BaseDao;
  9. use app\common\model\store\shipping\Express as model;
  10. class ExpressDao extends BaseDao
  11. {
  12. /**
  13. * @Author:Qinii
  14. * @Date: 2020/5/13
  15. * @return string
  16. */
  17. protected function getModel(): string
  18. {
  19. return model::class;
  20. }
  21. /**
  22. * @Author:Qinii
  23. * @Date: 2020/5/13
  24. * @param $field
  25. * @param $value
  26. * @param null $except
  27. * @return bool
  28. */
  29. public function merFieldExists($field, $value, $except = null, $id = null, $isUser = null)
  30. {
  31. return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
  32. $query->where($field, '<>', $except);
  33. })->when($id, function ($query) use ($id) {
  34. $query->where($this->getPk(), '<>', $id);
  35. })->when($isUser, function ($query) {
  36. $query->where('is_show', 1);
  37. })->where($field, $value)->count() > 0;
  38. }
  39. /**
  40. * @Author:Qinii
  41. * @Date: 2020/5/13
  42. * @param array $where
  43. * @return mixed
  44. */
  45. public function search(array $where)
  46. {
  47. $query = ($this->getModel()::getDB())
  48. ->when(isset($where['name']) && $where['name'],function($query) use ($where){
  49. $query->where('name','like','%'.$where['name'].'%');
  50. })->where(isset($where['code']) && $where['code'],function($query)use($where){
  51. $query->where('code',$where['name']);
  52. });
  53. return $query->order('sort DESC');
  54. }
  55. }