ShippingTemplateDao.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\common\dao\store\shipping;
  3. use think\facade\Db;
  4. use app\common\dao\BaseDao;
  5. use app\common\model\store\shipping\ShippingTemplate as model;
  6. class ShippingTemplateDao extends BaseDao
  7. {
  8. /**
  9. * @Author:Qinii
  10. * @Date: 2020/5/8
  11. * @return string
  12. */
  13. protected function getModel(): string
  14. {
  15. return model::class;
  16. }
  17. /**
  18. * @Author:Qinii
  19. * @Date: 2020/5/7
  20. * @param int $merId
  21. * @param array $where
  22. * @return mixed
  23. */
  24. public function search(int $merId,array $where)
  25. {
  26. $query = ($this->getModel()::getDB())->where('mer_id',$merId)->order('sort desc');
  27. if(isset($where['name']) && !empty($where['name']))
  28. $query->where('name','like','%'.$where['name'].'%');
  29. if(isset($where['type']) && !empty($where['type']))
  30. $query->where('type',$where['type']);
  31. return $query->order('sort DESC,create_time DESC');
  32. }
  33. /**
  34. * 查询是否存在
  35. * @Author:Qinii
  36. * @Date: 2020/5/7
  37. * @param int $merId
  38. * @param $field
  39. * @param $value
  40. * @param null $except
  41. * @return bool
  42. */
  43. public function merFieldExists(int $merId, $field, $value, $except = null)
  44. {
  45. return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
  46. $query->where($field, '<>', $except);
  47. })->where('mer_id', $merId)->where($field, $value)->count() > 0;
  48. }
  49. /**
  50. * 关联删除
  51. * @Author:Qinii
  52. * @Date: 2020/5/7
  53. * @param int $id
  54. * @return int|void
  55. */
  56. public function delete(int $id)
  57. {
  58. $result = $this->getModel()::with(['free','region','undelives'])->find($id);
  59. $result->together(['free','region','undelives'])->delete();
  60. }
  61. /**
  62. * 批量删除
  63. * @Author:Qinii
  64. * @Date: 2020/5/8
  65. * @param int $id
  66. * @return mixed
  67. */
  68. public function batchRemove(int $id)
  69. {
  70. return ($this->getModel())::getDB()->where($this->getPk(),'in',$id)->delete();
  71. }
  72. public function getList($merId)
  73. {
  74. return ($this->getModel())::getDB()->where('mer_id',$merId)->field('shipping_template_id,name')->order('sort DESC,create_time DESC')->select();
  75. }
  76. }