StoreServiceUserDao.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\service;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\service\StoreServiceUser;
  14. use app\common\repositories\system\ExtendRepository;
  15. use app\common\repositories\user\UserRepository;
  16. /**
  17. * Class StoreServiceDao
  18. * @package app\common\dao\store\service
  19. * @author xaboy
  20. * @day 2020/5/29
  21. */
  22. class StoreServiceUserDao extends BaseDao
  23. {
  24. /**
  25. * @return string
  26. * @author xaboy
  27. * @day 2020/5/29
  28. */
  29. protected function getModel(): string
  30. {
  31. return StoreServiceUser::class;
  32. }
  33. public function search(array $where)
  34. {
  35. return StoreServiceUser::getDB()->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
  36. $query->where('uid', $where['uid']);
  37. })->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  38. $query->where('mer_id', $where['mer_id']);
  39. })->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
  40. $query->where('service_id', $where['service_id']);
  41. })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  42. $uid = app()->make(UserRepository::class)->search(['keyword' => $where['keyword']])->limit(30)->column('uid');
  43. $uid = array_merge($uid, app()->make(ExtendRepository::class)->search([
  44. 'keyword' => $where['keyword'],
  45. 'type' => ExtendRepository::TYPE_SERVICE_USER_MARK,
  46. 'mer_id' => $where['mer_id'] ?? null
  47. ])->column('link_id'), [0]);
  48. $query->whereIn('uid', array_unique($uid));
  49. });
  50. }
  51. }