ShippingTemplateDao.php 2.2 KB

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