ProductReservationDao.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\ProductReservation as model;
  14. class ProductReservationDao 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. * @return int 返回影响的行数,即被删除的属性记录数。
  28. */
  29. public function clear(int $productId)
  30. {
  31. // 初始化查询,根据产品ID查找属性记录
  32. return ($this->getModel())::where('product_id', $productId)->delete();
  33. }
  34. public function search(array $where)
  35. {
  36. $query = $this->getModel()::getDB()
  37. ->when(isset($where['product_id']) && $where['product_id'] !== '', function($query) use($where){
  38. $query->where('product_id', $where['product_id']);
  39. })
  40. ;
  41. $query->order('product_reservation_id ASC');
  42. return $query;
  43. }
  44. }