ProductContentDao.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\product;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\product\ProductContent as model;
  14. class ProductContentDao extends BaseDao
  15. {
  16. protected function getModel(): string
  17. {
  18. return model::class;
  19. }
  20. /**
  21. * 清除指定产品的属性
  22. *
  23. * 此方法用于根据产品ID和可选的类型参数,从数据库中删除相应的属性记录。
  24. * 如果提供了类型参数,则只会删除与该类型匹配的属性记录。
  25. *
  26. * @param int $productId 产品的ID,用于确定要清除属性的产品。
  27. * @param int|null $type 属性的类型ID,可选参数。如果指定了类型,则只会删除指定类型的属性。
  28. * @return int 返回影响的行数,即被删除的属性记录数。
  29. */
  30. public function clearAttr(int $productId, ?int $type)
  31. {
  32. // 初始化查询,根据产品ID查找属性记录
  33. $query = ($this->getModel())::where('product_id', $productId);
  34. // 如果提供了类型参数,则进一步限制查询条件为指定的类型
  35. if (!is_null($type)) $query->where('type', $type);
  36. // 执行删除操作并返回删除的记录数
  37. return $query->delete();
  38. }
  39. }