WorkClientFollowDao.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\work;
  12. use app\dao\BaseDao;
  13. use app\model\work\WorkClientFollow;
  14. use crmeb\traits\SearchDaoTrait;
  15. /**
  16. * 企业微信客户跟踪
  17. * Class WorkClientFollowDao
  18. * @package app\dao\wechat\work
  19. */
  20. class WorkClientFollowDao extends BaseDao
  21. {
  22. use SearchDaoTrait;
  23. /**
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return WorkClientFollow::class;
  29. }
  30. /**
  31. * 搜索
  32. * @param array $where
  33. * @param bool $authWhere
  34. * @return \crmeb\basic\BaseModel
  35. */
  36. public function searchWhere(array $where, bool $authWhere = true)
  37. {
  38. return $this->search($where)->when(!empty($where['user_name']), function ($query) use ($where) {
  39. $query->whereIn('client_id', function ($query) use ($where) {
  40. $query->name('work_client')->where('name', 'LIKE', '%' . $where['user_name'] . '%')->field(['id']);
  41. });
  42. })->when(!empty($where['state']), function ($query) use ($where) {
  43. $query->where('state', $where['state']);
  44. })->when(!empty($where['userid']), function ($query) use ($where) {
  45. if (is_array($where['userid'])) {
  46. $query->whereIn('userid', $where['userid']);
  47. } else {
  48. $query->where('userid', $where['userid']);
  49. }
  50. });
  51. }
  52. /**
  53. * 根据员工userid获取今日添加客户总数
  54. * @param array $userId
  55. * @param int $codeId
  56. * @return mixed
  57. */
  58. public function userIdByCilentCount(array $userId, int $codeId)
  59. {
  60. return $this->getModel()->whereIn('userid', $userId)->group('userid')->field(['userid', 'count(*) as sum'])->select()->toArray();
  61. }
  62. /**
  63. * 获取二维码添加客户数量
  64. * @param array $channeId
  65. * @return mixed
  66. */
  67. public function channelIdByCilentCount(array $channeId)
  68. {
  69. return $this->getModel()->whereDay('create_time')->whereIn('state', $channeId)->group('state')->field(['state', 'count(*) as sum'])->select()->toArray();
  70. }
  71. }