CenterService.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace addons\OperationCenter\common\services;
  3. use addons\OperationCenter\common\models\ApplyList;
  4. use addons\OperationCenter\common\models\MallUser;
  5. use addons\OperationCenter\common\models\UserCenter;
  6. /**
  7. * CenterService
  8. * @package addons\OperationCenter\common\services
  9. */
  10. class CenterService extends BaseService
  11. {
  12. /**
  13. * 获取分页列表
  14. *
  15. * @param array $params
  16. * @return array
  17. */
  18. public function getPageList(array $params = [])
  19. {
  20. $name = $params['name'] ?? '';
  21. $mobile = $params['mobile'] ?? '';
  22. $user_id = $params['user_id'] ?? '';
  23. $user_keyword = $params['user_keyword'] ?? '';
  24. return UserCenter::getPageList(
  25. $this->getPage($params), $this->getLimit($params), function ($query)
  26. use ($name, $mobile, $user_id, $user_keyword)
  27. {
  28. $query->andWhere(['mall_id' => $this->mall_id]);
  29. // 会员ID
  30. if (!empty($user_id)) {
  31. $query->andWhere(['user_id' => $user_id]);
  32. }
  33. // 会员名称
  34. if (!empty($name)) {
  35. $query->andWhere(['user_id' => ApplyList::getUserIdByName(
  36. $this->mall_id, $name
  37. )]);
  38. }
  39. // 联系电话
  40. if (!empty($mobile)) {
  41. $query->andWhere(['user_id' => ApplyList::getUserIdByMobile(
  42. $this->mall_id, $mobile
  43. )]);
  44. }
  45. // 会员信息查询
  46. if (!empty($user_keyword)) {
  47. $query->andWhere(['user_id' => MallUser::getUserIdByUserKeyWord(
  48. $this->mall_id, $user_keyword
  49. )]);
  50. }
  51. $query->with([
  52. 'user' => function ($query) {
  53. $query->select(['id', 'nickname', 'username', 'mobile', 'avatar_url']);
  54. },
  55. 'level' => function ($query) {
  56. $query->select(['id', 'mall_id', 'name', 'level']);
  57. },
  58. 'applyInfo' => function ($query) {
  59. $query->select(['id', 'user_id', 'mobile', 'name', 'center_name', 'operation_address', 'idcard_front', 'idcard_reverse']);
  60. },
  61. ]);
  62. }
  63. );
  64. }
  65. /**
  66. * 删除会员
  67. *
  68. * @param integer $id
  69. * @return boolean
  70. */
  71. public function delUser(int $id)
  72. {
  73. $user = UserCenter::getCenterById($this->mall_id, $id);
  74. if (empty($user)) return $this->error('运营中心不存在');
  75. $user->delete();
  76. return true;
  77. }
  78. }