gorden hai 1 mes
pai
achega
768456a8d5

+ 18 - 0
app/admin/controller/member/MemberController.php

@@ -378,6 +378,24 @@ class MemberController
         return MemberService::welfareInfo($request);
     }
 
+    /**
+     * @Desc 我的粉丝列表
+     * @Author Gorden
+     * @Date 2024/9/20 10:22
+     *
+     * @param Request $request
+     * @return \support\Response
+     */
+    public function fansList(Request $request)
+    {
+        $memberId = $request->get('member_id');
+        if (!$memberId) {
+            return json_fail("参数错误");
+        }
+
+        return MemberService::fansList($request);
+    }
+
     public function clearWelfare(Request $request)
     {
         $memberId = $request->post('member_id', '');

+ 138 - 8
app/admin/service/member/MemberService.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\service\member;
 
+use app\common\Tree;
 use app\model\ClientPoints;
 use app\model\CouponDetail;
 use app\model\Device;
@@ -23,6 +24,7 @@ use app\model\SysUser;
 use support\Db;
 use support\exception\BusinessException;
 use support\Request;
+use support\Response;
 
 class MemberService
 {
@@ -37,6 +39,7 @@ class MemberService
         $isAuth = $request->get('is_auth', '');
         $addtime = $request->get('member_addtimes', []);
         $type = $request->get('type', '');
+        $status = $request->get('member_status', '');
 
         $rows = Member::with([
             'account' => function ($query) {
@@ -85,8 +88,10 @@ class MemberService
                 $query->where(function ($query2) use ($nickname) {
                     $query2->where('member_info.member_info_nickname', 'like', '%' . $nickname . '%')->orWhere('member.member_mobile', 'like', '%' . $nickname . '%');
                 });
+            })->when(!empty($status), function ($query) use ($status) {
+                $query->where('member_status', $status);
             })
-            ->select('member_id', 'member_is_vip', 'member_is_owner', 'member_classify', 'member_status', 'member_mobile', 'member_from', 'member_addtimes', 'member_extend_json',
+            ->select('member_id', 'member_is_vip', 'member_is_owner','member_is_partner','member_is_referrer', 'member_classify', 'member_status', 'member_mobile', 'member_from', 'member_addtimes', 'member_extend_json',
                 'member_info.member_info_nickname', 'member_info.member_info_headimg', 'member_info.member_info_referee', 'member_info.member_info_business', 'member_info.member_info_service', 'member_info.member_info_city', 'member_info.member_info_address', 'member_info.member_info_gender', 'member_info.member_info_birthday',
                 'member_role.member_role_id', 'member_role.member_role_name',
                 'member_cert.member_cert_birth', 'member_cert.member_cert_gender', 'member_cert.member_cert_name', 'member_cert.member_cert_nbr', 'member_cert.member_cert_province', 'member_cert.member_cert_addr', 'member_cert.member_cert_face', 'member_cert.member_cert_photo', 'member_cert.member_cert_nation'
@@ -210,6 +215,16 @@ class MemberService
                     }
                 }
             }
+            // 粉丝
+            $fans1 = Member::where('join_invite_member_id', $row['member_id'])
+                ->select('member_id')
+                ->get()
+                ->toArray();
+            $fans1Ids = array_column($fans1, 'member_id');
+            $fans2Count = Member::whereIn('join_invite_member_id', $fans1Ids)
+                ->count();
+            $row['fans_total'] = count($fans1) + $fans2Count;
+
         }
 
         return json_success('', compact('rows', 'page', 'pageSize', 'total'));
@@ -659,14 +674,129 @@ class MemberService
         return json_success('', compact('rows', 'page', 'pageSize', 'total'));
     }
 
+    /**
+     * @Desc 我的粉丝列表
+     * @Author Gorden
+     * @Date 2024/9/20 10:22
+     *
+     * @param Request $request
+     */
+    public static function fansList(Request $request)
+    {
+        $memberId = $request->get('member_id');
+        $name = $request->get('name', '');
+        $mobile = $request->get('mobile', '');
+        $memberIds = [];
+        $memberInviteIds = [];
+        if (!empty($name)) {
+            $memberIds = MemberCert::where('member_cert_name', 'like', '%' . $name . '%')->pluck('join_cert_member_id')->toArray();
+            $memberInviteIds = Member::whereIn('member_id', $memberIds)->pluck('join_invite_member_id')->toArray();
+        }
+        if (!empty($mobile)) {
+            $members = Member::where('member_mobile', 'like', '%' . $mobile . '%')
+                ->select('member_id', 'join_invite_member_id')
+                ->get()
+                ->toArray();
+            $memberIds2 = array_column($members, 'member_id');
+            $memberInviteIds2 = array_column($members, 'join_invite_member_id');
+            $memberIds = array_merge($memberIds, $memberIds2);
+            $memberInviteIds = array_merge($memberInviteIds, $memberInviteIds2);
+        }
+
+        $fans1 = Member::with([
+            'info' => function ($query) {
+                $query->select('join_info_member_id', 'member_info_nickname', 'member_info_headimg');
+            },
+            'cert' => function ($query) {
+                $query->select('join_cert_member_id', 'member_cert_name');
+            },
+            'role' => function ($query) {
+                $query->select('member_role_id', 'member_role_name');
+            }
+        ])->where('join_invite_member_id', $memberId)
+            ->when(!empty($memberIds), function ($query) use ($memberIds, $memberInviteIds) {
+                $allSub = array_merge($memberIds, $memberInviteIds);
+                $query->whereIn('member_id', $allSub);
+            })
+            ->select('member_id', 'join_member_role_id', 'member_id as id', 'join_invite_member_id as pid', 'member_partner_json', 'member_mobile', 'member_addtimes', 'member_is_owner', 'member_is_vip', 'member_is_partner', 'member_is_referrer')
+            ->get()
+            ->toArray();
+        $fans1Ids = array_column($fans1, 'id');
+        $fans2 = Member::with([
+            'info' => function ($query) {
+                $query->select('join_info_member_id', 'member_info_nickname', 'member_info_headimg');
+            },
+            'cert' => function ($query) {
+                $query->select('join_cert_member_id', 'member_cert_name');
+            },
+            'role' => function ($query) {
+                $query->select('member_role_id', 'member_role_name');
+            }
+        ])->whereIn('join_invite_member_id', $fans1Ids)
+            ->when(!empty($memberIds), function ($query) use ($memberIds) {
+                $query->whereIn('member_id', $memberIds);
+            })
+            ->select('member_id', 'join_member_role_id', 'member_id as id', 'join_invite_member_id as pid', 'member_partner_json', 'member_mobile', 'member_addtimes', 'member_is_owner', 'member_is_vip', 'member_is_partner', 'member_is_referrer')
+            ->get()
+            ->toArray();
+
+        $fans = array_merge($fans1, $fans2);
+        foreach ($fans as &$fan) {
+            $memberMobile = $fan['member_mobile'] ?? '';
+//            $memberNickname = $fan['info'] && $fan['info']['member_info_nickname'] ? $fan['info']['member_info_nickname'] : '';
+            $memberCertName = $fan['cert'] && $fan['cert']['member_cert_name'] ? $fan['cert']['member_cert_name'] : '';
+            $fan['member_name'] = '';
+            if (!empty($memberCertName) && !empty($memberMobile)) {
+                $fan['member_name'] = $memberCertName . '-' . $memberMobile;
+            } elseif (!empty($memberCertName)) {
+                $fan['member_name'] = $memberCertName;
+            } elseif (!empty($memberMobile)) {
+                $fan['member_name'] = $memberMobile;
+            }
+            if (!empty($fan['info']) && substr($fan['info']['member_info_headimg'], 0, 4) == 'http') {
+                $fan['member_info_headimg'] = $fan['info']['member_info_headimg'];
+            } else {
+                $fan['member_info_headimg'] = 'https://img.wanyuewellness.com.cn/images/avatar_default.png';
+            }
+            // 等级名称
+            $fan['role_name'] = $fan['role'] && $fan['role']['member_role_name'] ? $fan['role']['member_role_name'] : '';
+
+            unset($fan['info'], $fan['cert'], $fan['role']);
+        }
+
+        $tree = new Tree($fans);
+        return json_success('success', $tree->getTree());
+    }
+
+
+    /**
+     * 格式化树
+     * @param $items
+     * @return Response
+     */
+    protected static function formatTree($items): Response
+    {
+        $format_items = [];
+        foreach ($items as $item) {
+            $format_items[] = [
+                'name' => $item->title ?? $item->name ?? $item->id,
+                'value' => (string)$item->id,
+                'id' => $item->id,
+                'pid' => $item->pid,
+            ];
+        }
+        $tree = new Tree($format_items);
+        return json_success('success', $tree->getTree());
+    }
+
     public static function clearWelfare(Request $request)
     {
         $memberId = $request->post('member_id');
         $payTime = $request->post('pay_paytimes', date('Y-m-d H:i:s'));
-        $payTime = date('Y-m-d H:i:s',strtotime($payTime));
+        $payTime = date('Y-m-d H:i:s', strtotime($payTime));
         $payRemark = $request->post('pay_remark', '');
         $clearPwd = $request->post('clear_password');
-        if (!$clearPwd || $clearPwd != '123456'){
+        if (!$clearPwd || $clearPwd != '123456') {
             return json_fail('清零密码错误');
         }
 
@@ -679,7 +809,7 @@ class MemberService
             if (!$account) {
                 throw new BusinessException("账户异常");
             }
-            if ($account->member_account_surplus <= 0){
+            if ($account->member_account_surplus <= 0) {
                 throw new BusinessException("账户余额为0,无需清零");
             }
             // 创建清除记录
@@ -702,7 +832,7 @@ class MemberService
             Db::commit();
 
             return json_success('success');
-        }catch (BusinessException $e){
+        } catch (BusinessException $e) {
             Db::rollBack();
             return json_fail($e->getMessage());
         } catch (\Exception $e) {
@@ -765,12 +895,12 @@ class MemberService
             if (mb_substr($item['goods_category'], 0, 7) == '自定义金额充值') {
                 $item['goods_category'] = '自定义金额充值';
             }
-            if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE','PARTNER'])) {
+            if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'PARTNER'])) {
                 $item['balance_type'] = 'add';
             } else {
                 $item['balance_type'] = 'cut';
             }
-            if ($key == 0 && in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE','PARTNER'])) {
+            if ($key == 0 && in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'PARTNER'])) {
                 if (!empty($item['pay_extend_json'])) {
                     $extendJson = json_decode($item['pay_extend_json'], true);
                     if (!isset($extendJson['added_amount'])) {
@@ -802,7 +932,7 @@ class MemberService
                 continue;
             }
 
-            if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE','PARTNER'])) {
+            if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE', 'PARTNER'])) {
                 if (!empty($item['pay_extend_json'])) {
                     $extendJson = json_decode($item['pay_extend_json'], true);
                     if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {

+ 1 - 0
route/admin.php

@@ -697,6 +697,7 @@ Route::group('/admin', function () {
             Route::post('/add', [\app\admin\controller\member\MemberController::class, 'add']);
             Route::post('/update', [\app\admin\controller\member\MemberController::class, 'update']);
             Route::get('/exportMember', [\app\admin\controller\member\MemberController::class, 'exportMember']);
+            Route::get('/fansList', [\app\admin\controller\member\MemberController::class, 'fansList']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);