ShippingTemplateUndeliveryDao.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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 app\common\dao\BaseDao;
  13. use app\common\model\store\shipping\ShippingTemplateUndelivery as model;
  14. class ShippingTemplateUndeliveryDao extends BaseDao
  15. {
  16. /**
  17. * @Author:Qinii
  18. * @Date: 2020/5/8
  19. * @return string
  20. */
  21. protected function getModel(): string
  22. {
  23. return model::class;
  24. }
  25. /**
  26. * 检查指定字段是否存在特定值。
  27. *
  28. * 该方法用于查询数据库中指定字段的值是否与给定值匹配,
  29. * 并可以根据需要排除特定的值。
  30. *
  31. * @param string $field 要检查的字段名。
  32. * @param mixed $value 要匹配的值。
  33. * @param mixed $except 可选参数,用于指定需要排除的值。
  34. * @return bool 如果找到匹配的记录则返回true,否则返回false。
  35. */
  36. public function merFieldExists($field, $value, $except = null)
  37. {
  38. // 获取模型对应的数据库实例。
  39. $db = ($this->getModel())::getDB();
  40. // 如果指定了需要排除的值,则添加相应的where条件。
  41. $db->when($except, function ($query, $except) use ($field) {
  42. $query->where($field, '<>', $except);
  43. });
  44. // 添加字段等于给定值的where条件。
  45. $db->where($field, $value);
  46. // 统计符合条件的记录数,如果大于0则表示存在匹配的记录。
  47. return $db->count() > 0;
  48. }
  49. /**
  50. * 批量删除记录。
  51. * 本函数用于根据主键ID数组和临时ID数组批量删除数据库中的记录。
  52. * 它首先尝试根据主键ID删除记录,然后根据临时ID删除记录。
  53. * 这样做的目的是为了处理两种不同标识符下的数据清理需求,提高数据管理的灵活性。
  54. *
  55. * @param array $id 主键ID数组,用于删除对应ID的记录。
  56. * @param array $temp_id 临时ID数组,用于删除对应临时ID的记录。
  57. */
  58. public function batchRemove(array $id,array $temp_id)
  59. {
  60. // 如果主键ID数组不为空,尝试根据主键ID删除记录。
  61. if($id)
  62. ($this->getModel())::getDB()->where($this->getPk(),'in',$id)->delete();
  63. // 如果临时ID数组不为空,尝试根据临时ID删除记录。
  64. if($temp_id)
  65. ($this->getModel())::getDB()->where('temp_id','in',$temp_id)->delete();
  66. }
  67. }