Ver código fonte

客户转会员关联门店

gorden 4 meses atrás
pai
commit
49c547efaf

+ 22 - 0
app/admin/controller/sys_manage/UserController.php

@@ -182,4 +182,26 @@ class UserController
 
         return json_success('', $user);
     }
+
+    public function selectSalesmanList(Request $request)
+    {
+        $keywords = $request->get('keywords','');
+        if(!$keywords){
+            return json_fail('参数异常');
+        }
+
+        $users = SysUser::leftJoin('sys_dept','sys_dept.dept_id','=','sys_user.join_user_dept_id')
+            ->where(function($query) use ($keywords){
+                $query->where('sys_user.user_name','like','%'.$keywords.'%')
+                ->orWhere('sys_user.user_mobile','like','%'.$keywords.'%')
+                ->orWhere('sys_dept.dept_name','like','%'.$keywords.'%');
+            })->where('sys_dept.dept_name','<>','')
+            ->where('sys_dept.dept_category','营业场所')
+            
+            ->select('sys_user.user_id','sys_user.user_name','sys_user.user_mobile','sys_dept.dept_name')
+            ->get()
+            ->toArray();
+
+        return json_success('',$users);
+    }
 }

+ 49 - 11
app/admin/service/member/MemberService.php

@@ -16,8 +16,11 @@ use app\model\Order;
 use app\model\OrderSheet;
 use app\model\PayDetail;
 use app\model\SysCategory;
+use app\model\SysDept;
 use app\model\SysSerial;
+use app\model\SysUser;
 use support\Db;
+use support\exception\BusinessException;
 use support\Request;
 
 class MemberService
@@ -127,11 +130,21 @@ class MemberService
             }
 
             $row['source'] = "APP";
+            $row['belong'] = [];
             if (!empty($row['member_extend_json'])) {
                 $extendJson = json_decode($row['member_extend_json'], true);
                 if (isset($extendJson['come_from'])) {
                     $row['source'] = $extendJson['come_from'] ?? '';
                 }
+                if (isset($extendJson['belong'])){
+                    $user = SysUser::where('user_id',$extendJson['belong']['user_id'])->select('user_name','user_mobile')->first();
+                    if($user){
+                        $row['belong']['user_id'] = $extendJson['belong']['user_id'];
+                        $row['belong']['username'] = $user->user_name;
+                        $row['belong']['user_mobile'] = $user->user_mobile;
+                    }
+                    $row['belong']['deptName'] = SysDept::where('dept_id',$extendJson['belong']['premises'])->value('dept_name');
+                }
             }
         }
 
@@ -441,14 +454,25 @@ class MemberService
             // 先写主表,要ID
             $memberData = [
                 'member_id' => $memberId,
-                'member_is_owner' => $params['is_owner'],
-                'member_classify' => $params['classify'],
-                'member_status' => $params['status'],
-                'member_mobile' => $params['mobile'],
+                'member_is_owner' => $params['is_owner'] ?? 'N',
+                'member_classify' => $params['classify'] ?? '',
+                'member_status' => $params['status'] ?? 'ISABLED',
+                'member_mobile' => $params['mobile'] ?? '',
 //                'member_from' => $params['source'],
-                'member_extend_json' => json_encode(['come_from' => $params['source']]),
+                // 'member_extend_json' => json_encode(['come_from' => $params['source']]),
                 'member_addtimes' => time(),
             ];
+            
+            $extendJson['come_from'] = $params['source'];
+            if(!empty($params['user_id'])){
+                $deptId = SysUser::where('user_id',$params['user_id'])->value('join_user_dept_id');
+                if(!$deptId){
+                    throw new BusinessException('请先关联业务员和门店');
+                }
+                $extendJson['belong'] = ['user_id'=>$params['user_id'],'premises'=>$deptId];
+            }
+            $memberData['member_extend_json'] = json_encode($extendJson);
+
             Member::insert($memberData);
 
             // 账户表
@@ -475,9 +499,9 @@ class MemberService
                 'member_cert_nation' => $params['member_cert_nation'] ?? '',
                 'member_cert_name' => $params['cert_name'] ?? '',
                 'member_cert_nbr' => $params['cert_nbr'] ?? '',
-                'member_cert_birth' => $params['birth'] ? date('Y-m-d', strtotime($params['birth'])) : '',
+                'member_cert_birth' => !empty($params['birth']) ? date('Y-m-d', strtotime($params['birth'])) : '',
                 'member_cert_gender' => $params['gender'] ?? '',
-                'member_cert_province' => $params['province'] ? json_encode($params['province'], JSON_UNESCAPED_UNICODE) : '[]',
+                'member_cert_province' => !empty($params['province']) ? json_encode($params['province'], JSON_UNESCAPED_UNICODE) : '[]',
                 'member_cert_city' => $params['city'] ?? '',
                 'member_cert_addr' => $params['addr'] ?? '',
 //                'member_cert_face' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_face']),
@@ -487,12 +511,16 @@ class MemberService
             // member info
             $infoData = [
                 'join_info_member_id' => $memberId,
-                'member_info_nickname' => $params['account_name'],
-                'member_info_headimg' => getenv('SYSTEM_AVATAR_DOMAIN') . str_replace(getenv('STORAGE_DOMAIN'), '', $params['avatar'])
+                'member_info_nickname' => $params['account_name'] ?? '',
+                'member_info_headimg' => !empty($params['avatar']) ? getenv('SYSTEM_AVATAR_DOMAIN') . str_replace(getenv('STORAGE_DOMAIN'), '', $params['avatar']) : ''
             ];
             MemberInfo::insert($infoData);
 
             Db::commit();
+        }catch(BusinessException $e){
+            Db::rollBack();
+
+            return json_fail($e->getMessage());
         } catch (\Exception $e) {
             Db::rollBack();
             dump($e->getMessage() . ';line:' . $e->getLine());
@@ -524,6 +552,14 @@ class MemberService
                 $extendJson = json_decode($member->member_extend_json, true);
             }
             $extendJson['come_from'] = $params['source'];
+            // 门店、业务员
+            if(!empty($params['user_id'])){
+                $deptId = SysUser::where('user_id',$params['user_id'])->value('join_user_dept_id');
+                if(!$deptId){
+                    throw new BusinessException('请先关联业务员和门店');
+                }
+                $extendJson['belong'] = ['user_id'=>$params['user_id'],'premises'=>$deptId];
+            }
             // 先写主表,要ID
             $memberData = [
                 'member_id' => $memberId,
@@ -534,6 +570,7 @@ class MemberService
 //                'member_from' => $params['source'],
                 'member_extend_json' => json_encode($extendJson)
             ];
+
             Member::where('member_id', $params['member_id'])->update($memberData);
             // member cert
             $certData = [
@@ -555,9 +592,10 @@ class MemberService
                 MemberCert::where('join_cert_member_id', $params['member_id'])->update($certData);
             }
             // member info
-            if (strpos($params['avatar'], getenv('APP_IMAGE_DOMAIN')) !== false || strpos($params['avatar'], getenv('SYSTEM_AVATAR_DOMAIN')) !== false) {
+            $avatar = '';
+            if ($params['avatar'] && (strpos($params['avatar'], getenv('APP_IMAGE_DOMAIN')) !== false || strpos($params['avatar'], getenv('SYSTEM_AVATAR_DOMAIN')) !== false)) {
                 $avatar = $params['avatar'];
-            } else {
+            } else if($params['avatar']) {
                 $avatar = getenv('SYSTEM_AVATAR_DOMAIN') . str_replace(getenv('STORAGE_DOMAIN'), '', $params['avatar']);
             }
 

+ 11 - 11
app/admin/validate/member/MemberValidate.php

@@ -8,18 +8,18 @@ class MemberValidate extends Validate
 {
     protected $rule = [
         'member_id' => 'require|alphaDash',
-        'account_name|账号名称' => 'require',
-        'avatar|头像' => 'require',
+        // 'account_name|账号名称' => 'require',
+        // 'avatar|头像' => 'require',
         'source|来源' => 'require', // 来源
-        'is_owner' => 'require|in:Y,N',
-        'classify|归类' => 'require', // 归类 会员/游客
-        'birth|生日' => 'require',
-        'gender|性别' => 'require',
-        'status|状态' => 'require|in:ACTIVED,DISABLED',
-        'mobile|手机号' => 'require|mobile',
-        'addr|具体地址' => 'require',
-        'cert_name证件姓名' => 'require',
-        'cert_nbr|身份证号' => 'require|idCard',
+        // 'is_owner' => 'require|in:Y,N',
+        // 'classify|归类' => 'require', // 归类 会员/游客
+        // 'birth|生日' => 'require',
+        // 'gender|性别' => 'require',
+        // 'status|状态' => 'require|in:ACTIVED,DISABLED',
+        'mobile|手机号' => 'mobile',
+        // 'addr|具体地址' => 'require',
+        // 'cert_name证件姓名' => 'require',
+        'cert_nbr|身份证号' => 'idCard',
         'member_cert_face|身份证人像面照片' => 'url', // 身份证人像面照片 base64
         'member_cert_photo|身份证国徽面照片' => 'url' // 身份证国徽面照片 base64
     ];

+ 1 - 0
route/admin.php

@@ -162,6 +162,7 @@ Route::group('/admin', function () {
             Route::delete('/delete', [\app\admin\controller\sys_manage\UserController::class, 'delUser']);
             Route::post('/correlationMember',[\app\admin\controller\sys_manage\UserController::class,'correlationMember']);
             Route::get('/selectDoctorList',[\app\admin\controller\sys_manage\UserController::class,'selectDoctorList']);
+            Route::get('/selectSalesmanList',[\app\admin\controller\sys_manage\UserController::class,'selectSalesmanList']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);