ShippingTemplateDao.php 2.8 KB

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