ExpressDao.php 1.9 KB

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