StoreBranchProductDao.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\product\branch;
  12. use app\dao\BaseDao;
  13. use app\model\product\branch\StoreBranchProduct;
  14. /**
  15. * Class StoreBranchProductDao
  16. * @package app\dao\product\branch
  17. */
  18. class StoreBranchProductDao extends BaseDao
  19. {
  20. /**
  21. * @return string
  22. */
  23. protected function setModel(): string
  24. {
  25. return StoreBranchProduct::class;
  26. }
  27. /**
  28. * 收银台搜索
  29. * @param array $where
  30. * @return \crmeb\basic\BaseModel
  31. */
  32. public function getSerach(array $where)
  33. {
  34. return $this->search($where)->when(isset($where['store_name']) && $where['store_name'], function ($query) use ($where) {
  35. if (isset($where['field_key']) && $where['field_key'] && in_array($where['field_key'], ['product_id', 'store_name', 'bar_code'])) {
  36. $query->where($where['field_key'], $where['store_name']);
  37. } else {
  38. $query->where('product_id|store_name|bar_code|keyword', 'LIKE', '%' . $where['store_name'] . '%');
  39. }
  40. })->when(isset($where['ids']) && $where['ids'], function ($query) use ($where) {
  41. $query->whereIn('product_id', $where['ids']);
  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. });
  49. }
  50. /**
  51. * 订单搜索列表
  52. * @param array $where
  53. * @param array $field
  54. * @param int $page
  55. * @param int $limit
  56. * @param array $with
  57. * @return array
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. */
  62. public function getBranchProductList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = [], string $order = 'sort desc,stock desc,id desc')
  63. {
  64. return $this->search($where)->field($field)->when($with, function($query) use($with) {
  65. $query->with($with);
  66. })->when($page && $limit, function ($query) use ($page, $limit) {
  67. $query->page($page, $limit);
  68. })->order($order)->select()->toArray();
  69. }
  70. }