Browse Source

会员加筛选条件

gorden 2 months ago
parent
commit
21ef4fd6d7
1 changed files with 40 additions and 24 deletions
  1. 40 24
      app/admin/service/member/MemberService.php

+ 40 - 24
app/admin/service/member/MemberService.php

@@ -31,6 +31,7 @@ class MemberService
         $page = $request->get('page', 1);
         $pageSize = $request->get('pageSize', 10);
         $name = $request->get('name', '');
+        $nickname = $request->get('nickname', '');
         $mobile = $request->get('mobile', '');
         $level = $request->get('level', '');
         $isAuth = $request->get('is_auth', '');
@@ -80,6 +81,10 @@ class MemberService
                     $addtime[1] = strtotime(date('Y-m-t') . ' 23:59:59');
                 }
                 $query->whereBetween('member.member_addtimes', $addtime);
+            })->when(!empty($nickname), function ($query) use ($nickname) {
+                $query->where(function($query2) use ($nickname){
+                    $query2->where('member_info.member_info_nickname','like','%'.$nickname.'%')->orWhere('member.member_mobile','like','%'.$nickname.'%');
+                });
             })
             ->select('member_id', 'member_is_vip', 'member_is_owner', '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',
@@ -98,17 +103,17 @@ class MemberService
             $row['coupon_count'] = CouponDetail::where('join_coupon_detail_member_id', $row['member_id'])->count();
             $row['member_mobile'] = substr($row['member_mobile'], 0, 3) . '****' . substr($row['member_mobile'], 7);
             $row['info'] = [
-                'member_info_nickname' => !empty($row['member_info_nickname']) ? $row['member_info_nickname'] : substr($row['member_mobile'], -4, 4) . '用户',
+                'member_info_nickname' => !empty($row['member_info_nickname']) ? $row['member_info_nickname'] : substr($row['member_mobile'], -4, 4) . '会员',
                 'member_info_headimg' => !empty($row['member_info_headimg']) ? $row['member_info_headimg'] : '',
                 'member_info_referee' => !empty($row['member_info_referee']) ? $row['member_info_referee'] : '',
                 'member_info_business' => !empty($row['member_info_business']) ? $row['member_info_business'] : '',
                 'member_info_service' => !empty($row['member_info_service']) ? $row['member_info_service'] : '',
-                'member_info_city' => !empty($row['member_info_city']) ? explode('-',$row['member_info_city']) : '',
+                'member_info_city' => !empty($row['member_info_city']) ? explode('-', $row['member_info_city']) : '',
                 'member_info_address' => !empty($row['member_info_address']) ? $row['member_info_address'] : '',
                 'member_info_birthday' => !empty($row['member_info_birthday']) ? $row['member_info_birthday'] : '',
                 'member_info_gender' => !empty($row['member_info_gender']) ? $row['member_info_gender'] : '',
             ];
-            if (substr($row['info']['member_info_headimg'],0,2) == '..'){
+            if (substr($row['info']['member_info_headimg'], 0, 2) == '..') {
                 $row['info']['member_info_headimg'] = '';
             }
             if (!empty($row['info']['member_info_address']) && in_array($row['info']['member_info_address'], ['请选择', '省-市-区'])) {
@@ -343,7 +348,7 @@ class MemberService
             'member_info_referee' => !empty($member['info']) && !empty($member['info']['member_info_referee']) ? $member['info']['member_info_referee'] : '',
             'member_info_business' => !empty($member['info']) && !empty($member['info']['member_info_business']) ? $member['info']['member_info_business'] : '',
             'member_info_service' => !empty($member['info']) && !empty($member['info']['member_info_service']) ? $member['info']['member_info_service'] : '',
-            'member_info_city' => !empty($member['info']) && !empty($member['info']['member_info_city']) ? explode('-',$member['info']['member_info_city']) : '',
+            'member_info_city' => !empty($member['info']) && !empty($member['info']['member_info_city']) ? explode('-', $member['info']['member_info_city']) : '',
             'member_info_address' => !empty($member['info']) && !empty($member['info']['member_info_address']) ? $member['info']['member_info_address'] : '',
             'member_info_gender' => !empty($member['info']) && !empty($member['info']['member_info_gender']) ? $member['info']['member_info_gender'] : '',
             'member_info_birthday' => !empty($member['info']) && !empty($member['info']['member_info_birthday']) ? $member['info']['member_info_birthday'] : '',
@@ -363,10 +368,10 @@ class MemberService
             'member_cert_nation' => $member['cert']['member_cert_nation'] ?? '',
             'member_cert_addtimes' => $member['cert']['member_cert_addtimes'] ?? '',
         ];
-        if (!empty($member['cert']['member_cert_addtimes'])){
-            $member['cert']['member_cert_addtimes'] = date('Y-m-d',$member['cert']['member_cert_addtimes']);
-        }else{
-            $member['cert']['member_cert_addtimes'] = date('Y-m-d',strtotime($member['member_addtimes']));
+        if (!empty($member['cert']['member_cert_addtimes'])) {
+            $member['cert']['member_cert_addtimes'] = date('Y-m-d', $member['cert']['member_cert_addtimes']);
+        } else {
+            $member['cert']['member_cert_addtimes'] = date('Y-m-d', strtotime($member['member_addtimes']));
         }
         if (!empty($member['join_invite_member_id'])) {
             $inviteMember = Member::with([
@@ -434,6 +439,9 @@ class MemberService
         $account = MemberAccount::where('join_account_member_id', $memberId)
             ->where('member_account_classify', 'VIP')
             ->first();
+        if (!$account) {
+            return json_fail('暂无数据');
+        }
         $balance = $account->member_account_surplus + $account->member_account_added;
 
         $info = PayDetail::where(function ($query) use ($memberId) {
@@ -545,6 +553,9 @@ class MemberService
         $account = MemberAccount::where('join_account_member_id', $memberId)
             ->where('member_account_classify', 'WELFARE')
             ->first();
+        if (!$account) {
+            return json_fail('暂无数据');
+        }
         $balance = $account->member_account_surplus + $account->member_account_added;
 
         $info = PayDetail::where(function ($query) use ($memberId) {
@@ -657,6 +668,9 @@ class MemberService
         $account = MemberAccount::where('join_account_member_id', $memberId)
             ->where('member_account_classify', 'CASH')
             ->first();
+        if (!$account) {
+            return json_fail('暂无数据');
+        }
         $balance = $account->member_account_surplus + $account->member_account_added;
 
         $info = PayDetail::where(function ($query) use ($memberId) {
@@ -697,12 +711,12 @@ class MemberService
             if (mb_substr($item['goods_category'], 0, 7) == '自定义金额充值') {
                 $item['goods_category'] = '自定义金额充值';
             }
-            if (in_array($item['pay_category'], ['RECHARGE', 'REFUND','GIVE'])) {
+            if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE'])) {
                 $item['balance_type'] = 'add';
             } else {
                 $item['balance_type'] = 'cut';
             }
-            if ($key == 0 && in_array($item['pay_category'], ['RECHARGE', 'REFUND','GIVE'])) {
+            if ($key == 0 && in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE'])) {
                 if (!empty($item['pay_extend_json'])) {
                     $extendJson = json_decode($item['pay_extend_json'], true);
                     if (!isset($extendJson['added_amount'])) {
@@ -731,7 +745,7 @@ class MemberService
                 continue;
             }
 
-            if (in_array($item['pay_category'], ['RECHARGE', 'REFUND','GIVE'])) {
+            if (in_array($item['pay_category'], ['RECHARGE', 'REFUND', 'GIVE'])) {
                 if (!empty($item['pay_extend_json'])) {
                     $extendJson = json_decode($item['pay_extend_json'], true);
                     if (isset($extendJson['added_amount']) && floatval($extendJson['added_amount']) > 0) {
@@ -768,7 +782,9 @@ class MemberService
         $account = MemberAccount::where('join_account_member_id', $memberId)
             ->where('member_account_classify', 'POINTS')
             ->first();
-
+        if (!$account) {
+            return json_fail('暂无数据');
+        }
         $balance = $account->member_account_surplus + $account->member_account_added;
         $points = ClientPoints::where('join_client_points_member_id', $memberId)->get()->toArray();
         $nowPoint = 0;
@@ -912,7 +928,7 @@ class MemberService
                 'member_info_service' => $params['member_info_service'] ?? '',
                 'member_info_city' => !empty($params['province']) ? implode('-', $params['province']) : '',
                 'member_info_address' => $params['member_info_address'] ?? '',
-                'member_info_birthday'=>$params['birth'] ? date('Y-m-d', strtotime($params['birth'])) : '',
+                'member_info_birthday' => $params['birth'] ? date('Y-m-d', strtotime($params['birth'])) : '',
                 'member_info_gender' => $params['gender'] ?? '',
             ];
             MemberInfo::insert($infoData);
@@ -1009,7 +1025,7 @@ class MemberService
                 'member_info_service' => $params['member_info_service'] ?? '',
                 'member_info_city' => !empty($params['province']) ? implode('-', $params['province']) : '',
                 'member_info_address' => $params['member_info_address'] ?? '',
-                'member_info_birthday'=>$params['birth'] ? date('Y-m-d', strtotime($params['birth'])) : '',
+                'member_info_birthday' => $params['birth'] ? date('Y-m-d', strtotime($params['birth'])) : '',
                 'member_info_gender' => $params['gender'] ?? '',
             ];
             if (!MemberInfo::where('join_info_member_id', $params['member_id'])->exists()) {
@@ -1018,25 +1034,25 @@ class MemberService
                 MemberInfo::where('join_info_member_id', $params['member_id'])->update($infoData);
             }
             // 福利账户
-            if (!empty($params['member_classify']) && $params['member_classify'] == 'EMPLOY' && !MemberAccount::where('member_account_nbr',$memberId.'-WELFARE')->exists()){
+            if (!empty($params['member_classify']) && $params['member_classify'] == 'EMPLOY' && !MemberAccount::where('member_account_nbr', $memberId . '-WELFARE')->exists()) {
                 $welfareData = [
-                    'join_account_member_id'=>$memberId,
-                    'member_account_classify'=>'WELFARE',
-                    'member_account_status'=>'ACTIVED',
-                    'member_account_category'=>'NORMAL',
-                    'member_account_nbr'=>$memberId.'-WELFARE',
-                    'member_account_name'=>'福利账户',
-                    'member_account_addtimes'=>time()
+                    'join_account_member_id' => $memberId,
+                    'member_account_classify' => 'WELFARE',
+                    'member_account_status' => 'ACTIVED',
+                    'member_account_category' => 'NORMAL',
+                    'member_account_nbr' => $memberId . '-WELFARE',
+                    'member_account_name' => '福利账户',
+                    'member_account_addtimes' => time()
                 ];
                 MemberAccount::insert($welfareData);
             }
 
             Db::commit();
-        }catch (BusinessException $e){
+        } catch (BusinessException $e) {
             Db::rollBack();
             dump($e->getMessage() . ';line:' . $e->getLine());
             return json_fail($e->getMessage());
-        }catch (\Exception $e) {
+        } catch (\Exception $e) {
             Db::rollBack();
             dump($e->getMessage() . ';line:' . $e->getLine());
             return json_fail("数据更新失败");