ProductCopyDao.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\ProductCopy as model;
  14. class ProductCopyDao extends BaseDao
  15. {
  16. protected function getModel(): string
  17. {
  18. return model::class;
  19. }
  20. /**
  21. * 根据条件搜索数据。
  22. *
  23. * 本函数用于根据提供的条件数组搜索相关数据。它支持两个主要的搜索条件:'mer_id' 和 'type'。
  24. * 'mer_id' 用于指定商家ID,'type' 用于指定数据类型。其中,'type' 条件支持 'copy' 类型的数据,
  25. * 这种情况下,搜索将包括 'taobao'、'jd' 和 'copy' 类型的数据。
  26. *
  27. * @param array $where 包含搜索条件的数组。可能包含 'mer_id' 和 'type' 键。
  28. * @return \Illuminate\Database\Eloquent\Builder|static 返回数据库查询构建器实例,用于进一步的查询操作或数据获取。
  29. */
  30. public function search(array $where)
  31. {
  32. // 获取模型对应的数据库实例。
  33. return $this->getModel()::getDB()
  34. // 当 'mer_id' 条件存在且不为空时,添加 'mer_id' 的查询条件。
  35. ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  36. $query->where('mer_id', $where['mer_id']);
  37. })
  38. // 当 'type' 条件存在且不为空时,根据 'type' 的值添加相应的查询条件。
  39. ->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  40. if ($where['type'] == 'copy') {
  41. // 如果 'type' 为 'copy',则查询 'type' 为 'taobao'、'jd' 或 'copy' 的数据。
  42. $query->where('type', 'in', ['taobao', 'jd', 'copy']);
  43. } else {
  44. // 否则,直接查询指定 'type' 的数据。
  45. $query->where('type', $where['type']);
  46. }
  47. })
  48. // 按 'create_time' 降序排序。
  49. ->order('create_time DESC');
  50. }
  51. /**
  52. * 获取产品复制信息
  53. *
  54. * 本方法通过查询数据库,获取store_product_copy_id在398到467之间的产品复制信息。
  55. * 主要用于特定条件下的产品数据检索,以便于进一步的操作或展示。
  56. *
  57. * @return array 返回符合条件的产品复制信息数组。
  58. */
  59. public function get2()
  60. {
  61. // 根据条件查询产品复制信息,限定store_product_copy_id在398到467之间,并只返回info字段
  62. return $data = model::where('store_product_copy_id','>',398)
  63. ->where('store_product_copy_id','<',467)->field('info')->select();
  64. }
  65. }