MemberService.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\MemberModel;
  13. use App\Services\BaseService;
  14. /**
  15. * 会员管理-服务类
  16. * @author laravel开发员
  17. * @since 2020/11/11
  18. * Class MemberService
  19. * @package App\Services\Common
  20. */
  21. class MemberService extends BaseService
  22. {
  23. /**
  24. * 构造函数
  25. * @author laravel开发员
  26. * @since 2020/11/11
  27. * MemberService constructor.
  28. */
  29. public function __construct()
  30. {
  31. $this->model = new MemberModel();
  32. }
  33. /**
  34. * 获取列表
  35. * @param $params 参数
  36. * @param int $pageSize 分页大小:默认 15
  37. * @return array
  38. */
  39. public function getDataList($params, $pageSize = 10, $field=[])
  40. {
  41. $where = ['a.mark' => 1];
  42. $status = isset($params['status'])? $params['status'] : 0;
  43. if($status>0){
  44. $where['a.status'] = $status;
  45. }
  46. $list = $this->model->with(['level','parent','point'])
  47. ->from('member as a')
  48. ->leftJoin('member as b','b.id','a.parent_id')
  49. ->where($where)
  50. ->where(function($query) use($params){
  51. $trcUrl = isset($params['trc_url'])? trim($params['trc_url']) : '';
  52. if($trcUrl){
  53. $query->where('a.trc_url','like',"%{$trcUrl}%");
  54. }
  55. $parentUrl = isset($params['parent_trc_url'])? trim($params['parent_trc_url']) : '';
  56. if($parentUrl){
  57. $query->where('b.trc_url','like',"%{$parentUrl}%");
  58. }
  59. })
  60. ->where(function($query) use($params){
  61. $account = isset($params['account'])? trim($params['account']) : '';
  62. if($account){
  63. $query->where('a.username','like',"%{$account}%")->orWhere('a.nickname','like',"%{$account}%");
  64. }
  65. })
  66. ->select($field? $field : ['a.*','b.trc_url as parent_trc_url'])
  67. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  68. $list = $list? $list->toArray() :[];
  69. if($list){
  70. foreach($list['data'] as &$item){
  71. $item['create_time_text'] = $item['create_time']? datetime($item['create_time']):'';
  72. $item['avatar'] = $item['avatar']? get_image_url($item['avatar']): get_image_url('/images/member/logo.png');
  73. $item['invite_num'] = $this->model->where(['parent_id'=> $item['id'],'mark'=>1])->count('id');
  74. $item['team_num'] = $this->model->where(['mark'=>1])->whereRaw('FIND_IN_SET(?,parents)', $item['id'])->count('id');
  75. $item['point_num'] = $this->model->where(['point_id'=>$item['id'],'mark'=>1])->count('id');
  76. }
  77. }
  78. return [
  79. 'pageSize'=> $pageSize,
  80. 'total'=>isset($list['total'])? $list['total'] : 0,
  81. 'list'=> isset($list['data'])? $list['data'] : []
  82. ];
  83. }
  84. /**
  85. * 添加会编辑会员
  86. * @return array
  87. * @since 2020/11/11
  88. * @author laravel开发员
  89. */
  90. public function edit()
  91. {
  92. // 请求参数
  93. $data = request()->all();
  94. // 头像处理
  95. $avatar = trim($data['avatar']);
  96. if (strpos($avatar, "temp")) {
  97. $data['avatar'] = save_image($avatar, 'member');
  98. } else {
  99. $data['avatar'] = str_replace(IMG_URL, "", $data['avatar']);
  100. }
  101. // 出生日期
  102. if ($data['birthday']) {
  103. $data['birthday'] = strtotime($data['birthday']);
  104. }
  105. // 城市处理
  106. $city = isset($data['city']) ? $data['city'] : [3];
  107. if (!empty($data['city'])) {
  108. // 省份
  109. $data['province_id'] = $city[0];
  110. // 城市
  111. $data['city_id'] = $city[1];
  112. // 县区
  113. $data['district_id'] = $city[2];
  114. }
  115. unset($data['city']);
  116. return parent::edit($data); // TODO: Change the autogenerated stub
  117. }
  118. }