UserStoreOrderServices.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\services\user;
  13. use app\services\BaseServices;
  14. use app\dao\user\UserStoreOrderDao;
  15. /**
  16. *
  17. * Class UserStoreOrderServices
  18. * @package app\services\user
  19. */
  20. class UserStoreOrderServices extends BaseServices
  21. {
  22. /**
  23. * UserStoreOrderServices constructor.
  24. * @param UserStoreOrderDao $dao
  25. */
  26. public function __construct(UserStoreOrderDao $dao)
  27. {
  28. $this->dao = $dao;
  29. }
  30. public function getUserSpreadCountList($uid, $orderBy = '', $keyword = '')
  31. {
  32. if ($orderBy === '') {
  33. $orderBy = 'u.add_time desc';
  34. }
  35. $where = [];
  36. $where[] = ['u.uid', 'IN', $uid];
  37. if (strlen(trim($keyword))) {
  38. $where[] = ['u.nickname|u.phone', 'LIKE', "%$keyword%"];
  39. }
  40. [$page, $limit] = $this->getPageValue();
  41. $field = "u.uid,u.nickname,u.avatar,from_unixtime(u.add_time,'%Y/%m/%d') as time,u.spread_time,u.spread_count as childCount,p.orderCount,p.numberCount";
  42. $list = $this->dao->getUserSpreadCountList($where, $field, $orderBy, $page, $limit);
  43. /** @var UserServices $userServices */
  44. $userServices = app()->make(UserServices::class);
  45. foreach ($list as &$item) {
  46. $item['childCount'] = count($userServices->getUserSpredadUids($item['uid'], 1)) ?? 0;
  47. }
  48. return $list;
  49. }
  50. }