瀏覽代碼

人员导入

linwu 2 年之前
父節點
當前提交
0760d8f00c

+ 20 - 67
app/admin/controller/User.php

@@ -18,6 +18,7 @@ use app\common\model\ComjobsCate as ComjobsCateModel;
 use app\common\model\Agent as AgentModel;
 use app\common\model\Broker as BrokerModel;
 
+use app\common\service\UserService;
 use app\common\validate\User as UserValidate;
 use think\exception\ValidateException;
 
@@ -759,18 +760,6 @@ class User extends BaseController
 
         $address      = input('address/s', "");
         $jobintention = input('jobintention/s', "");
-        if (!$address) {
-            exit(json_encode([
-                'code' => 1,
-                'msg'  => "请填写居住地址。",
-            ]));
-        }
-        if (!$jobintention) {
-            exit(json_encode([
-                'code' => 1,
-                'msg'  => "请填写意向岗位。",
-            ]));
-        }
         $agentbrokerarr = explode(",", input('agentbroker/s'));
         $brokerid       = isset($agentbrokerarr[1]) ? $agentbrokerarr[1] : 0;
         $data           = [
@@ -1015,66 +1004,30 @@ class User extends BaseController
         ]));
     }
 
-    public function import()
+    public function importView()
     {
-        $data = ['nickname', 'gender', 'mobile', 'education', 'birthday', 'workexperience', 'jobintention',
-                 'com_cate', 'emp_time', 'address', 'eduexperience'];
-        $list = importExecl('2.xls', $data, 1);
-
-        $data           = [];
-        $gender         = ['男' => 1, '女' => 2];
-        $education      = ['初中' => 1, '高中' => 2, '中技' => 3, '中专' => 4, '大专' => 5, '本科' => 6, '硕士' => 7, '博士' => 8];
-        $workexperience = ['无经验' => 1, '一年以下' => 2, '1-3年' => 3, '3-5年' => 4, '5-10年' => 5, '10年以上' => 6];
-        $jobintention   = ['长期工' => 1, '临时工' => 3];
-
-        $rensheCode = RensheCode::where('type', 'emp_time')->column('code', 'name');
-        $cateList   = ComjobsCateModel::column('id', 'title');
-
-        foreach ($list as $v) {
-            $item              = [];
-            $item['nickname']  = $item['realname'] = $v['nickname'];
-            $item['gender']    = $gender[$v['gender']];
-            $item['mobile']    = $v['mobile'];
-            $item['education'] = $education[$v['education']];
-            $item['birthday']  = date('Y-m-d', strtotime($v['birthday']));
-            if (empty($workexperience[$v['workexperience']])) {
-                halt($v['workexperience']);
-            }
-            $item['workexperience'] = $workexperience[$v['workexperience']];
-            $item['jobintention']   = $jobintention[$v['jobintention']];
-            $item['com_cate']       = [];
-            if (!empty($v['com_cate'])) {
-                $com_cate = explode(',', str_replace(',', ',', $v['com_cate']));
-                foreach ($com_cate as $cate) {
-                    if (!empty($cateList[$cate])) {
-                        $item['com_cate'][] = $cate;
-                    }
-                }
-            }
-            $item['emp_time'] = [];
-            if (!empty($v['emp_time'])) {
-                $emp_time = explode(',', str_replace(',', ',', $v['emp_time']));
-                foreach ($emp_time as $time) {
-                    if (!empty($rensheCode[$time])) {
-                        $item['emp_time'][] = $time;
-                    }
-                }
-            }
-
-            $item['address']       = $v['address'] ?: '';
-            $item['eduexperience'] = $v['eduexperience'] ?: '';
+        return view('user/importview');
+    }
 
-            $item['groupsid']   = 2;
-            $item['status']     = 2;
-            $item['authstatus'] = 3;
-            $item['createtime'] = time();
-            $data[]             = $item;
+    public function import()
+    {
+        $file_url = input('file_url/s', "");
+        if (!file_exists($file_url)) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "文件不存在",
+            ]));
         }
 
-        foreach ($data as $v) {
-            UserModel::create($v);
+        $service = new UserService();
+        $res = $service->importComjobs($file_url);
+        if (empty($res['code'])) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => $res['msg'],
+            ]));
         }
 
-        return '成功';
+        exit(json_encode(['code'  => 0]));
     }
 }

+ 68 - 0
app/admin/view/user/importview.html

@@ -0,0 +1,68 @@
+<div class="layui-fluid">
+	<div class="layui-row layui-col-space15">
+		<div class="layui-col-md12">
+			<div class="layui-card">
+				<div class="layui-card-header">导入</div>
+				<div class="layui-card-body" pad15>
+					<div class="layui-form layui-form-pane" lay-filter="LAY-user-userform-upload">
+						<div class="layui-form-item">
+							<label class="layui-form-label">文件名</label>
+							<div class="layui-input-block">
+								<input type="text" id="file_name" autocomplete="off" readonly placeholder="请点击上传文件按钮" class="layui-input">
+							</div>
+						</div>
+						<input type="hidden" name="file_url" value="" id="file_url">
+						<div class="layui-form-item">
+							<div class="layui-input-block">
+								<a href="/static/exl/user_import.xlsx" target="_blank">
+									<button type="button" class="layui-btn layui-btn-normal" id="test3">下载模板</button>
+								</a>
+								<button type="button" class="layui-btn layui-btn-normal" id="upload"><i class="layui-icon"></i>上传文件</button>
+								<input type="button" lay-submit lay-filter="LAY-user-userform-upload-submit" value="确认提交" class="layui-btn">
+							</div>
+						</div>
+					</div>
+
+				</div>
+			</div>
+		</div>
+	</div>
+</div>
+
+
+<script>
+	layui.config({
+		base: '/static/echoui/' //静态资源所在路径
+	}).extend({
+		index: 'lib/index' //主入口模块
+	}).use(['index', 'form', 'upload'], function() {
+		var $ = layui.$,setter = layui.setter, admin = layui.admin, upload = layui.upload,form = layui.form;
+		form.render();
+
+		form.on('submit(LAY-user-userform-upload-submit)', function(obj) {
+			var index = parent.layer.getFrameIndex(window.name);
+			admin.req({
+				url: setter.baseAdminUrl + 'user/import',
+				data: obj.field,
+				type: 'post',
+				done: function(res) {
+					layer.msg("导入成功", {
+						icon: 1
+					});
+					parent.layui.table.reload('LAY-user-userlist-table'); //重载表格
+					parent.layer.close(index);
+				}
+			});
+		});
+
+		upload.render({
+			elem: '#upload'
+			,url: setter.baseAdminUrl + 'attachment/tplFieldFile' //此处配置你自己的上传接口即可
+			,accept: 'file' //普通文件
+			,done: function(res){
+				$('#file_url').val(res.data.path);
+				$('#file_name').val(res.data.title);
+			}
+		});
+	});
+</script>

+ 11 - 1
app/admin/view/user/userlist.html

@@ -82,6 +82,7 @@
 					<div class="layui-inline">
 						<button class="layui-btn layuiadmin-btn" data-type="add">添加新用户</button>
 					</div>
+					<button class="layui-btn layuiadmin-btn" data-type="import">批量导入</button>
 					<div class="layui-inline">
 						<div class="layui-input-block" style="margin-left: 20px;" id="setagentbroker">
 						</div>
@@ -290,7 +291,16 @@
 					area: ['550px', '550px']
 				});
 				layer.full(index);
-			}
+			},
+			import: function() {
+				layer.open({
+					type: 2,
+					title: '批量导入',
+					content: 'importView.html',
+					maxmin: true,
+					area: ['750px', '300px']
+				});
+			},
 		};
 
 		table.on('tool(LAY-user-userlist-table)', function(obj) {

+ 324 - 321
app/agent/controller/User.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace app\agent\controller;
 
 use app\common\model\ComjobsCate;
@@ -20,336 +21,338 @@ use PHPExcel;
 
 class User extends BaseController
 {
-	
-	// 用户跟进记录
-	public function follow()
-	{
-		$userid = input('userid/d');
-		$user = UserModel::findOrEmpty($userid);
-		$followlist = UserFollowModel::where('userid',$userid)->order('id','desc')->limit(100)->select();
-		return view('user/follow',[
-			'user'			=> $user,
-			'followlist'	=> $followlist
-		]);
-	}
-	
-	public function editFollow()
-	{
-		$userid = input('userid/d', 0);
-		$user = UserModel::findOrEmpty($userid);
-		if ($user->isEmpty()){
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> "用户信息不存在。"
-			)));
-		}
-		$agent = $this->access_agent;
-		$broker = BrokerModel::where('agentid','=',$agent['id'])->findOrEmpty($user->brokerid);
-		if ($broker->isEmpty()){
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> "你无权限上报该用户跟进记录。"
-			)));
-		}
-		UserFollowModel::create([
-			'userid'		=> $userid,
-			'ftype'			=> input('ftype/s', ""),
-			'remark'		=> input('remark/s', ""),
-			'createtime'	=> time()
-		]);
-		$followstatus = input('followstatus/d', 1);
-		$user->save([
-			'followstatus' => $followstatus
-		]);
-		exit(json_encode(array(
-			'code' 	=> 0
-		)));
-	}
-	
-		
-	// 用户授权
-	public function authsList()
-	{
-		$userid = input('userid/d');
-		return view('user/authslist',[
-			'userid'	=> $userid
-		]);
-	}
-	
-	public function listAuths()
-	{
-		$userid = input('userid/d');
-		$list = UserAuthsModel::where('userid',$userid)->order('id','asc')->append(['identitytype_text'])->select();
-		$count = UserAuthsModel::where('userid',$userid)->count();
-		if ($count==0){
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> "未查询到数据"
-			)));
-		}
-		exit(json_encode(array(
-			'code' 	=> 0,
-			'msg'	=> "",
-			'count' => $count,
-			'data'  => $list
-		)));
-	}
-	
-	public function delAuths()
-	{
-		$id = input('id/d');
-		$auths = UserAuthsModel::find($id);
-		if ($auths->identitytype == 'mobile'){
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> "手机号授权方式不允许删除"
-			)));
-		}
-		$result = $auths->delete();
-		if ($result){
-			exit(json_encode(array(
-				'code' 	=> 0
-			)));
-		}
-		exit(json_encode(array(
-			'code' 	=> 1,
-			'msg'	=> "删除失败,请稍后重试"
-		)));
-	}
-	
-	// 用户
-	public function userList()
-	{
-		$agentid = $this->access_agent['id'];
-		$groupslist = UserGroupsModel::order(['isdefault'=>'desc','id'=>'asc'])->select();
-		$brokerlist = BrokerModel::where('agentid', '=', $agentid)->order(['id'=>'desc'])->select();
-		return view('user/userlist',[
-			'groupslist'	=> $groupslist,
-			'brokerlist'	=> $brokerlist
-		]);
-	}
-	
-	public function userForm()
-	{
-		$agentid = $this->access_agent['id'];
-		$brokeridarr = BrokerModel::where('agentid','=',$agentid)->column('id');
-		$id = input('id/d', 0);
-		$user = UserModel::whereIn('brokerid',$brokeridarr)->where('brokerid','<>', 0)->findOrEmpty($id);
-		$agent = $this->access_agent;
-		$groupslist = UserGroupsModel::order(['isdefault'=>'desc','id'=>'asc'])->select();
-		$brokerlist = BrokerModel::where('agentid', '=', $agentid)->order(['id'=>'desc'])->select();
+
+    // 用户跟进记录
+    public function follow()
+    {
+        $userid     = input('userid/d');
+        $user       = UserModel::findOrEmpty($userid);
+        $followlist = UserFollowModel::where('userid', $userid)->order('id', 'desc')->limit(100)->select();
+        return view('user/follow', [
+            'user'       => $user,
+            'followlist' => $followlist,
+        ]);
+    }
+
+    public function editFollow()
+    {
+        $userid = input('userid/d', 0);
+        $user   = UserModel::findOrEmpty($userid);
+        if ($user->isEmpty()) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "用户信息不存在。",
+            ]));
+        }
+        $agent  = $this->access_agent;
+        $broker = BrokerModel::where('agentid', '=', $agent['id'])->findOrEmpty($user->brokerid);
+        if ($broker->isEmpty()) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "你无权限上报该用户跟进记录。",
+            ]));
+        }
+        UserFollowModel::create([
+            'userid'     => $userid,
+            'ftype'      => input('ftype/s', ""),
+            'remark'     => input('remark/s', ""),
+            'createtime' => time(),
+        ]);
+        $followstatus = input('followstatus/d', 1);
+        $user->save([
+            'followstatus' => $followstatus,
+        ]);
+        exit(json_encode([
+            'code' => 0,
+        ]));
+    }
+
+
+    // 用户授权
+    public function authsList()
+    {
+        $userid = input('userid/d');
+        return view('user/authslist', [
+            'userid' => $userid,
+        ]);
+    }
+
+    public function listAuths()
+    {
+        $userid = input('userid/d');
+        $list   = UserAuthsModel::where('userid', $userid)->order('id', 'asc')->append(['identitytype_text'])->select();
+        $count  = UserAuthsModel::where('userid', $userid)->count();
+        if ($count == 0) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "未查询到数据",
+            ]));
+        }
+        exit(json_encode([
+            'code'  => 0,
+            'msg'   => "",
+            'count' => $count,
+            'data'  => $list,
+        ]));
+    }
+
+    public function delAuths()
+    {
+        $id    = input('id/d');
+        $auths = UserAuthsModel::find($id);
+        if ($auths->identitytype == 'mobile') {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "手机号授权方式不允许删除",
+            ]));
+        }
+        $result = $auths->delete();
+        if ($result) {
+            exit(json_encode([
+                'code' => 0,
+            ]));
+        }
+        exit(json_encode([
+            'code' => 1,
+            'msg'  => "删除失败,请稍后重试",
+        ]));
+    }
+
+    // 用户
+    public function userList()
+    {
+        $agentid    = $this->access_agent['id'];
+        $groupslist = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
+        $brokerlist = BrokerModel::where('agentid', '=', $agentid)->order(['id' => 'desc'])->select();
+        return view('user/userlist', [
+            'groupslist' => $groupslist,
+            'brokerlist' => $brokerlist,
+        ]);
+    }
+
+    public function userForm()
+    {
+        $agentid       = $this->access_agent['id'];
+        $brokeridarr   = BrokerModel::where('agentid', '=', $agentid)->column('id');
+        $id            = input('id/d', 0);
+        $user          = UserModel::whereIn('brokerid', $brokeridarr)->where('brokerid', '<>', 0)->findOrEmpty($id);
+        $agent         = $this->access_agent;
+        $groupslist    = UserGroupsModel::order(['isdefault' => 'desc', 'id' => 'asc'])->select();
+        $brokerlist    = BrokerModel::where('agentid', '=', $agentid)->order(['id' => 'desc'])->select();
         $willlist      = UserWill::select();
         $emptimelist   = RensheCode::getList('emp_time');
         $communitylist = RensheCode::getList('community')->toArray();
         array_push($communitylist, ['code' => 0, 'id' => 0, 'name' => "不限"]);
         $comlist = ComjobsCate::select();
-		return view('user/userform',[
-			'brokerlist'	=> $brokerlist,
-			'groupslist'	=> $groupslist,
-			'agent'			=> $agent,
-			'user'			=> $user,
+        return view('user/userform', [
+            'brokerlist'    => $brokerlist,
+            'groupslist'    => $groupslist,
+            'agent'         => $agent,
+            'user'          => $user,
             'willlist'      => $willlist,
             'emptimelist'   => $emptimelist,
             'communitylist' => $communitylist,
             'comlist'       => $comlist,
-		]);
-	}
-	
-	public function fieldUser()
-	{
-		$agentid = $this->access_agent['id'];
-		$brokeridarr = BrokerModel::where('agentid','=',$agentid)->column('id');
-		$id = input('id/d',0); 
-		$user = UserModel::whereIn('brokerid',$brokeridarr)->where('brokerid','<>', 0)->findOrEmpty($id);
-		if ($user->isEmpty()){
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> "信息不存在"
-			)));
-		}else{
-			$user->save([
-				input('field/s')  => input('value/s')
-			]);
-		}
-		exit(json_encode(array(
-			'code' 	=> 0
-		)));
-	}
-	
-	public function listUser()
-	{
-		$agentid = $this->access_agent['id'];
-		$limit = input('limit', 20);
-		$page = input('page', 1);
-		$map = array();
-		$brokeridarr = BrokerModel::where('agentid','=',$agentid)->column('id');
-		$map[] = ['brokerid', 'in', $brokeridarr];
-		$map[] = ['brokerid', '<>', 0];
-		$keywords = input('keywords/s');
-		if (!empty($keywords)){
-			$map[] =['nickname|realname|mobile', 'like', '%'.$keywords.'%', 'or'];
-		}
-		$groupsid = input('groupsid/d');
-		if (!empty($groupsid)){
-			$map[] = ['groupsid', '=', $groupsid];
-		}
-		$brokerid = input('brokerid/d');
-		if (!empty($brokerid)){
-			$map[] = ['brokerid', '=', $brokerid];
-		}
-		$status = input('status/d');
-		if (!empty($status)){
-			$map[] = ['status', '=', $status];
-		}
-		$authstatus = input('authstatus/d');
-		if (!empty($authstatus)){
-			$map[] = ['authstatus', '=', $authstatus];
-		}
-		$followstatus = input('followstatus/d');
-		if (!empty($followstatus)){
-			$map[] = ['followstatus', '=', $followstatus];
-		}
-		$list = UserModel::with(['userGroups','broker'])->where($map)->order('id','desc')->limit($limit)->page($page)->append(['status_text','isvip_text','authstatus_text','followstatus_text'])->select();
-		$count = UserModel::where($map)->count();
-		if ($count==0){
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> "未查询到数据"
-			)));
-		}
-		exit(json_encode(array(
-			'code' 	=> 0,
-			'msg'	=> "",
-			'count' => $count,
-			'data'  => $list
-		)));
-	}
-	
-	public function exportUser()
-	{
-		$agentid = $this->access_agent['id'];
-		$map = array();
-		$brokeridarr = BrokerModel::where('agentid','=',$agentid)->column('id');
-		$map[] = ['brokerid', 'in', $brokeridarr];
-		$map[] = ['brokerid', '<>', 0];
-		$keywords = input('keywords/s');
-		if (!empty($keywords)){
-			$map[] =['nickname|realname|mobile', 'like', '%'.$keywords.'%', 'or'];
-		}
-		$groupsid = input('groupsid/d');
-		if (!empty($groupsid)){
-			$map[] = ['groupsid', '=', $groupsid];
-		}
-		$brokerid = input('brokerid/d');
-		if (!empty($brokerid)){
-			$map[] = ['brokerid', '=', $brokerid];
-		}
-		$status = input('status/d');
-		if (!empty($status)){
-			$map[] = ['status', '=', $status];
-		}
-		$authstatus = input('authstatus/d');
-		if (!empty($authstatus)){
-			$map[] = ['authstatus', '=', $authstatus];
-		}
-		$followstatus = input('followstatus/d');
-		if (!empty($followstatus)){
-			$map[] = ['followstatus', '=', $followstatus];
-		}
-		$xlsData = UserModel::with(['userGroups','broker'])->where($map)->order('id','desc')->append(['status_text','isvip_text','authstatus_text','followstatus_text'])->select()->toArray();
-		$xlsCell = array(
-			array('id','表ID'),
-			array('nickname','昵称'),
-			array('realname','姓名'),
-			array('mobile','手机号'),
-			array('status_text','状态'),
-			array('isvip_text','是否VIP'),
-			array('authstatus_text','是否实名认证'),
-			array('idcard','身份证号'),
-			array('gender','性别',array(1=>'男',2=>'女')),
-			array('birthday','出生日期'),
-			array('address','现居住地'),
-			array('education','学历'),
-			array('bankcard.openbank','开户行'),
-			array('bankcard.account','账户名'),
-			array('bankcard.number','账户号'),
-			array('followstatus_text','跟进状态'),
-			array('userGroups.title','用户组'),
-			array('broker.title','职业顾问'),
-			array('createtime','注册时间'),
-		);
-		export_excel("系统用户",$xlsCell,$xlsData);
-	}
-		
-	public function editUser()
-	{
-		$id = input('id/d');
-		$mobile = input('mobile/s');
-		$vdata = array(
-			'id'		=> $id,
-			'mobile'    => $mobile
-		);
-		try {
-			validate(UserValidate::class)->check($vdata);
-		} catch (ValidateException $e) {
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> $e->getError()
-			)));
-		}
-		$data = array(
-			'groupsid'			=> input('groupsid/d', 0),
-			'brokerid'			=> input('brokerid/d', 0),
-			'nickname'			=> input('nickname/s', ""),
-			'avatar'			=> input('avatar/s', ""),
-			'realname'			=> input('realname/s', ""),
-			'mobile'			=> $mobile,
-			'status'			=> input('status/d', 1),
-			'isvip'				=> input('isvip/d', 1),
-			'authstatus'		=> input('authstatus/d', 1),
-			'authremark'		=> input('authremark/s', ""),
-			'idcardzpic'		=> input('idcardzpic/s', ""),
-			'idcardfpic'		=> input('idcardfpic/s', ""),
-			'idcard'			=> input('idcard/s', ""),
-			'gender'			=> input('gender/d', 1),
-			'birthday'			=> input('birthday/s', ""),
-			'address'			=> input('address/s', ""),
-			'education'			=> input('education/s', ""),
-			'jobintention'		=> input('jobintention/s', ""),
-			'workexperience'	=> input('workexperience/s', ""),
-			'eduexperience'		=> input('eduexperience/s', ""),
-			'followstatus'		=> input('followstatus/d', 1),
-			'bankcard'			=> input('bankcard/a', array()),
-		);
-		$password = input('password/s');
-		if (empty($id)){
-			$data['integral'] = 0;
-			$data['inttotal'] = 0;
-			$data['createtime'] = time();
-			$user = UserModel::create($data);
-			$auths = UserAuthsModel::create([
-				'userid'		=> $user->id,
-				'identitytype'	=> "mobile",
-				'identifier'	=> $mobile,
-				'password'		=> empty($password) ? md5("123456789") : md5($password),
-				'logintime'		=> time(),
-				'loginip'		=> $_SERVER['SERVER_ADDR'],
-				'wxampcode'		=> ""
-			]);
-		}else{
-			$data['id'] = $id;
-			$user = UserModel::update($data);
-			$adata = ['identifier'=>$mobile];
-			if (!empty($password)){
-				$adata['password'] =  md5($password);
-			}
-			UserAuthsModel::update($adata, ['userid'=>$id,'identitytype'=>'mobile']);
-		}
-		exit(json_encode(array(
-			'code' 	=> 0
-		)));
-	}
-	
+        ]);
+    }
+
+    public function fieldUser()
+    {
+        $agentid     = $this->access_agent['id'];
+        $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
+        $id          = input('id/d', 0);
+        $user        = UserModel::whereIn('brokerid', $brokeridarr)->where('brokerid', '<>', 0)->findOrEmpty($id);
+        if ($user->isEmpty()) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "信息不存在",
+            ]));
+        } else {
+            $user->save([
+                input('field/s') => input('value/s'),
+            ]);
+        }
+        exit(json_encode([
+            'code' => 0,
+        ]));
+    }
+
+    public function listUser()
+    {
+        $agentid     = $this->access_agent['id'];
+        $limit       = input('limit', 20);
+        $page        = input('page', 1);
+        $map         = [];
+        $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
+        if (!empty($brokeridarr)) {
+            $map[] = ['brokerid', 'in', $brokeridarr];
+        } else {
+            $map[] = ['brokerid', '=', -1];
+        }
+        $keywords = input('keywords/s');
+        if (!empty($keywords)) {
+            $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
+        }
+        $groupsid = input('groupsid/d');
+        if (!empty($groupsid)) {
+            $map[] = ['groupsid', '=', $groupsid];
+        }
+        $brokerid = input('brokerid/d');
+        if (!empty($brokerid)) {
+            $map[] = ['brokerid', '=', $brokerid];
+        }
+        $status = input('status/d');
+        if (!empty($status)) {
+            $map[] = ['status', '=', $status];
+        }
+        $authstatus = input('authstatus/d');
+        if (!empty($authstatus)) {
+            $map[] = ['authstatus', '=', $authstatus];
+        }
+        $followstatus = input('followstatus/d');
+        if (!empty($followstatus)) {
+            $map[] = ['followstatus', '=', $followstatus];
+        }
+        $list  = UserModel::with(['userGroups', 'broker'])->where($map)->order('id', 'desc')->limit($limit)->page($page)->append(['status_text', 'isvip_text', 'authstatus_text', 'followstatus_text'])->select();
+        $count = UserModel::where($map)->count();
+        if ($count == 0) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "未查询到数据",
+            ]));
+        }
+        exit(json_encode([
+            'code'  => 0,
+            'msg'   => "",
+            'count' => $count,
+            'data'  => $list,
+        ]));
+    }
+
+    public function exportUser()
+    {
+        $agentid     = $this->access_agent['id'];
+        $map         = [];
+        $brokeridarr = BrokerModel::where('agentid', '=', $agentid)->column('id');
+        $map[]       = ['brokerid', 'in', $brokeridarr];
+        $map[]       = ['brokerid', '<>', 0];
+        $keywords    = input('keywords/s');
+        if (!empty($keywords)) {
+            $map[] = ['nickname|realname|mobile', 'like', '%' . $keywords . '%', 'or'];
+        }
+        $groupsid = input('groupsid/d');
+        if (!empty($groupsid)) {
+            $map[] = ['groupsid', '=', $groupsid];
+        }
+        $brokerid = input('brokerid/d');
+        if (!empty($brokerid)) {
+            $map[] = ['brokerid', '=', $brokerid];
+        }
+        $status = input('status/d');
+        if (!empty($status)) {
+            $map[] = ['status', '=', $status];
+        }
+        $authstatus = input('authstatus/d');
+        if (!empty($authstatus)) {
+            $map[] = ['authstatus', '=', $authstatus];
+        }
+        $followstatus = input('followstatus/d');
+        if (!empty($followstatus)) {
+            $map[] = ['followstatus', '=', $followstatus];
+        }
+        $xlsData = UserModel::with(['userGroups', 'broker'])->where($map)->order('id', 'desc')->append(['status_text', 'isvip_text', 'authstatus_text', 'followstatus_text'])->select()->toArray();
+        $xlsCell = [
+            ['id', '表ID'],
+            ['nickname', '昵称'],
+            ['realname', '姓名'],
+            ['mobile', '手机号'],
+            ['status_text', '状态'],
+            ['isvip_text', '是否VIP'],
+            ['authstatus_text', '是否实名认证'],
+            ['idcard', '身份证号'],
+            ['gender', '性别', [1 => '男', 2 => '女']],
+            ['birthday', '出生日期'],
+            ['address', '现居住地'],
+            ['education', '学历'],
+            ['bankcard.openbank', '开户行'],
+            ['bankcard.account', '账户名'],
+            ['bankcard.number', '账户号'],
+            ['followstatus_text', '跟进状态'],
+            ['userGroups.title', '用户组'],
+            ['broker.title', '职业顾问'],
+            ['createtime', '注册时间'],
+        ];
+        export_excel("系统用户", $xlsCell, $xlsData);
+    }
+
+    public function editUser()
+    {
+        $id     = input('id/d');
+        $mobile = input('mobile/s');
+        $vdata  = [
+            'id'     => $id,
+            'mobile' => $mobile,
+        ];
+        try {
+            validate(UserValidate::class)->check($vdata);
+        } catch (ValidateException $e) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => $e->getError(),
+            ]));
+        }
+        $data     = [
+            'groupsid'       => input('groupsid/d', 0),
+            'brokerid'       => input('brokerid/d', 0),
+            'nickname'       => input('nickname/s', ""),
+            'avatar'         => input('avatar/s', ""),
+            'realname'       => input('realname/s', ""),
+            'mobile'         => $mobile,
+            'status'         => input('status/d', 1),
+            'isvip'          => input('isvip/d', 1),
+            'authstatus'     => input('authstatus/d', 1),
+            'authremark'     => input('authremark/s', ""),
+            'idcardzpic'     => input('idcardzpic/s', ""),
+            'idcardfpic'     => input('idcardfpic/s', ""),
+            'idcard'         => input('idcard/s', ""),
+            'gender'         => input('gender/d', 1),
+            'birthday'       => input('birthday/s', ""),
+            'address'        => input('address/s', ""),
+            'education'      => input('education/s', ""),
+            'jobintention'   => input('jobintention/s', ""),
+            'workexperience' => input('workexperience/s', ""),
+            'eduexperience'  => input('eduexperience/s', ""),
+            'followstatus'   => input('followstatus/d', 1),
+            'bankcard'       => input('bankcard/a', []),
+        ];
+        $password = input('password/s');
+        if (empty($id)) {
+            $data['integral']   = 0;
+            $data['inttotal']   = 0;
+            $data['createtime'] = time();
+            $user               = UserModel::create($data);
+            $auths              = UserAuthsModel::create([
+                'userid'       => $user->id,
+                'identitytype' => "mobile",
+                'identifier'   => $mobile,
+                'password'     => empty($password) ? md5("123456789") : md5($password),
+                'logintime'    => time(),
+                'loginip'      => $_SERVER['SERVER_ADDR'],
+                'wxampcode'    => "",
+            ]);
+        } else {
+            $data['id'] = $id;
+            $user       = UserModel::update($data);
+            $adata      = ['identifier' => $mobile];
+            if (!empty($password)) {
+                $adata['password'] = md5($password);
+            }
+            UserAuthsModel::update($adata, ['userid' => $id, 'identitytype' => 'mobile']);
+        }
+        exit(json_encode([
+            'code' => 0,
+        ]));
+    }
 
 
 }

+ 118 - 0
app/common/service/UserService.php

@@ -0,0 +1,118 @@
+<?php
+
+namespace app\common\service;
+
+
+use app\common\model\RensheCode;
+use app\common\model\User as UserModel;
+use app\common\model\ComjobsCate as ComjobsCateModel;
+
+class UserService extends BaseService
+{
+
+    public function importComjobs($file_url)
+    {
+        $data           = ['nickname', 'mobile', 'idcard', 'gender', 'birthday', 'address', 'education', 'jobintention', 'workexperience', 'eduexperience', 'emp_time', 'com_cate', 'com_cate_other', 'work_place'];
+        $list           = importExecl($file_url, $data, 1);
+        $data           = [];
+        $gender         = ['男' => 1, '女' => 2];
+        $education      = ['初中' => 1, '高中' => 2, '中技' => 3, '中专' => 4, '大专' => 5, '本科' => 6, '硕士' => 7, '博士' => 8];
+        $workexperience = ['无经验' => 1, '一年以下' => 2, '1-3年' => 3, '3-5年' => 4, '5-10年' => 5, '10年以上' => 6];
+        $jobintention   = ['长期工' => 1, '临时工' => 3];
+
+        $rensheCode = RensheCode::select();
+        $renshe     = [];
+        foreach ($rensheCode as $v) {
+            $renshe[$v['type']][$v['name']] = $v['code'];
+        }
+        $cateList = ComjobsCateModel::column('id', 'title');
+
+        foreach ($list as $k => $v) {
+            $empty_check = [
+                'nickname'       => '姓名',
+                'mobile'         => '电话',
+                'gender'         => '性别',
+                'education'      => '学历',
+                'jobintention'   => '求职意向',
+                'workexperience' => '工作经验',
+            ];
+            foreach ($empty_check as $key => $value) {
+                if (empty($v[$key])) {
+                    return $this->error('第' . ($k + 2) . '行的' . $value . '不能为空');
+                }
+            }
+            $mobile_check = UserModel::where('mobile',$v['mobile'])->find();
+            if (!empty($mobile_check)) {
+                return $this->error('第' . ($k + 2) . '行的电话已存在');
+            }
+
+            $item             = [];
+            $item['nickname'] = $item['realname'] = $v['nickname'];
+            $item['mobile']   = $v['mobile'];
+            $item['idcard']   = $v['idcard'];
+            if (empty($gender[$v['gender']])) {
+                return $this->error('第' . ($k + 2) . '行的性别选择有误');
+            }
+            $item['gender']   = $gender[$v['gender']];
+            $item['birthday'] = $v['birthday'];
+            $item['address']  = $v['address'];
+            if (empty($education[$v['education']])) {
+                return $this->error('第' . ($k + 2) . '行的学历选择有误');
+            }
+            $item['education'] = $education[$v['education']];
+            if (empty($jobintention[$v['jobintention']])) {
+                return $this->error('第' . ($k + 2) . '行的求职意向选择有误');
+            }
+            $item['jobintention'] = $jobintention[$v['jobintention']];
+            if (empty($workexperience[$v['workexperience']])) {
+                return $this->error('第' . ($k + 2) . '行的工作经验选择有误');
+            }
+            $item['workexperience'] = $workexperience[$v['workexperience']];
+            $item['eduexperience']  = $v['eduexperience'];
+            $item['emp_time']       = [];
+            if (!empty($v['emp_time'])) {
+                $emp_time = explode(',', str_replace(',', ',', $v['emp_time']));
+                foreach ($emp_time as $time) {
+                    if (!empty($renshe['emp_time'][$time])) {
+                        $item['emp_time'][] = $time;
+                    }
+                }
+            }
+            $item['com_cate_type'] = 1;
+            $item['com_cate']      = [];
+            if (!empty($v['com_cate'])) {
+                $com_cate = explode(',', str_replace(',', ',', $v['com_cate']));
+                foreach ($com_cate as $cate) {
+                    if (!empty($cateList[$cate])) {
+                        $item['com_cate'][] = $cate;
+                    }
+                }
+            }
+            if (empty($item['com_cate']) && !empty($v['com_cate_other'])) {
+                $item['com_cate_type']  = 2;
+                $item['com_cate_other'] = $v['com_cate_other'];
+            }
+            $item['work_place'] = [];
+            if (!empty($v['work_place'])) {
+                $work_place = explode(',', str_replace(',', ',', $v['work_place']));
+                foreach ($work_place as $place) {
+                    if (!empty($renshe['community'][$place])) {
+                        $item['work_place'][] = $place;
+                    }
+                }
+            }
+
+            $item['groupsid']   = 7;
+            $item['status']     = 2;
+            $item['authstatus'] = 3;
+            $item['createtime'] = time();
+            $data[]             = $item;
+        }
+
+        foreach ($data as $v) {
+            UserModel::create($v);
+        }
+
+        return $this->success('导入成功');
+    }
+}

+ 2 - 3
app/worker/view/comjobs/comjobslist.html

@@ -105,7 +105,6 @@
 			url: setter.baseWorkerUrl + 'comjobs/listcomjobs',
 			height: 'full-20',
 			cols: [
-
 				[
 						{ type: 'checkbox', fixed: 'left' },
 						// { field: 'id', width: 100, title: '排序ID', sort: true, edit: 'text' },
@@ -220,9 +219,9 @@
 				});
 			},
 			import: function() {
-				var index = layer.open({
+				layer.open({
 					type: 2,
-					title: '添加悬赏聘',
+					title: '批量导入',
 					content: 'importView.html',
 					maxmin: true,
 					area: ['750px', '300px']

二進制
public/static/exl/user_import.xlsx