UserStoreOrderServices.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. 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. * @mixin UserStoreOrderDao
  20. */
  21. class UserStoreOrderServices extends BaseServices
  22. {
  23. /**
  24. * UserStoreOrderServices constructor.
  25. * @param UserStoreOrderDao $dao
  26. */
  27. public function __construct(UserStoreOrderDao $dao)
  28. {
  29. $this->dao = $dao;
  30. }
  31. public function getUserSpreadCountList($uid, $orderBy = '', $keyword = '', $time = [])
  32. {
  33. if ($orderBy === '') {
  34. $orderBy = 'u.add_time desc';
  35. }
  36. $where = [];
  37. $where[] = ['u.uid', 'IN', $uid];
  38. if (strlen(trim($keyword))) {
  39. $where[] = ['u.nickname|u.phone', 'LIKE', "%$keyword%"];
  40. }
  41. if ($time[0] || $time[1]) {
  42. $where[] = ['spread_time', 'between', $time];
  43. }
  44. [$page, $limit] = $this->getPageValue();
  45. $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";
  46. $list = $this->dao->getUserSpreadCountList($where, $field, $orderBy, $page, $limit);
  47. /** @var UserServices $userServices */
  48. $userServices = app()->make(UserServices::class);
  49. foreach ($list as &$item) {
  50. $item['childCount'] = count($userServices->getUserSpredadUids($item['uid'], 1)) ?? 0;
  51. }
  52. return $list;
  53. }
  54. }