ProductDao.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\dao\store\product;
  12. use app\dao\BaseDao;
  13. use app\model\store\product\Product;
  14. /**
  15. * 商品dao
  16. * Class DeliveryServiceDao
  17. * @package app\dao\store
  18. */
  19. class ProductDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return Product::class;
  28. }
  29. /**
  30. * 收银台搜索
  31. * @param array $where
  32. * @return \crmeb\basic\BaseModel
  33. */
  34. public function getSerach(array $where)
  35. {
  36. return $this->getModel()->when(isset($where['store_name']) && $where['store_name'], function ($query) use ($where) {
  37. if (isset($where['field_key']) && $where['field_key'] && in_array($where['field_key'], ['product_id', 'store_name', 'bar_code'])) {
  38. $query->where($where['field_key'], $where['store_name']);
  39. } else {
  40. $query->where('store_name|bar_code|keyword', 'LIKE', '%' . $where['store_name'] . '%');
  41. }
  42. })->when(isset($where['cate_id']) && $where['cate_id'], function ($query) use ($where) {
  43. $query->whereIn('product_id', function ($query) use ($where) {
  44. $query->name('store_product_relation')->where('type', 1)->whereIn('relation_id', function ($query) use ($where) {
  45. $query->name('store_product_category')->where('pid', $where['cate_id'])->field('id')->select();
  46. })->field('product_id')->select();
  47. });
  48. })->when(isset($where['store_id']), function ($query) use ($where) {
  49. $query->where('store_id', $where['store_id']);
  50. });
  51. }
  52. }