UserStoreUserServices.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\store;
  13. use app\dao\store\UserStoreUserDao;
  14. use app\services\BaseServices;
  15. /**
  16. * Class UserStoreUserServices
  17. * @package app\services\store
  18. * @mixin UserStoreUserDao
  19. */
  20. class UserStoreUserServices extends BaseServices
  21. {
  22. /**
  23. * UserStoreUserServices constructor.
  24. * @param UserStoreUserDao $dao
  25. */
  26. public function __construct(UserStoreUserDao $dao)
  27. {
  28. $this->dao = $dao;
  29. }
  30. /**
  31. * 自定义简单查询总数
  32. * @param array $where
  33. * @return int
  34. */
  35. public function getCount(array $where): int
  36. {
  37. return $this->dao->getCount($where);
  38. }
  39. /**
  40. * 复杂条件搜索列表
  41. * @param array $where
  42. * @param string $field
  43. * @return array
  44. */
  45. public function getWhereUserList(array $where, string $field): array
  46. {
  47. [$page, $limit] = $this->getPageValue();
  48. $order_string = '';
  49. $order_arr = ['asc', 'desc'];
  50. if (isset($where['now_money']) && in_array($where['now_money'], $order_arr)) {
  51. $order_string = 'now_money ' . $where['now_money'];
  52. }
  53. $list = $this->dao->getListByModel($where, $field, $order_string, $page, $limit);
  54. $count = $this->dao->getCountByWhere($where);
  55. return [$list, $count];
  56. }
  57. /**
  58. * 门店搜索用户
  59. * @param array $data
  60. * @return array
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\DbException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. */
  65. public function storeSearch(array $data)
  66. {
  67. $where = [];
  68. if ($data['field_key']) {
  69. $where['u.' . $data['field_key']] = $data['keyword'];
  70. } else {
  71. $where['u.uid|u.phone'] = $data['keyword'];
  72. }
  73. $fields = 'u.*,w.country,w.province,w.city,w.sex,w.unionid,w.openid,w.user_type as w_user_type,w.groupid,w.tagid_list,w.subscribe,w.subscribe_time';
  74. $list = $this->dao->getList($where, $fields);
  75. $count = $this->dao->getCount($where);
  76. return compact('list', 'count');
  77. }
  78. }