123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- <?php
- namespace app\mobile\controller;
- use app\common\model\User;
- use app\common\model\UserAuths as UserAuthsModel;
- use app\common\model\Sinpage as SinpageModel;
- use app\common\model\User as UserModel;
- use app\common\model\RensheCode as RensheCodeModel;
- use app\common\model\ComjobsCate as ComjobsCateModel;
- use app\common\model\UserWill as UserWillModel;
- use app\common\model\Worker as WorkerModel;
- use app\common\service\SmsService;
- use think\facade\Session;
- class Login
- {
- /**
- * 登录
- */
- public function index()
- {
- my_redirect('https://www.jucai.gov.cn/api/auth/wechat_auth?url=' . urlencode(url('/login/wechatBack', [], true, true)));
- }
- public function login1()
- {
- session('user.id', 6);
- return '登录成功!';
- }
- /**
- * 微信回调
- */
- public function wechatBack()
- {
- $param = input('param.');
- $open_id = $param['openid'];
- //登录
- $auth = UserAuthsModel::where(['identitytype' => 'weixin', 'identifier' => $open_id])->find();
- if (empty($auth)) {
- session('user.open_id', $open_id);
- session('user.nickname', $param['nickname']);
- session('user.headimgurl', $param['headimgurl']);
- my_redirect('/login/mobile');
- } else {
- $auth->logintime = time();
- $auth->loginip = request()->ip();
- $auth->save();
- }
- session('user.id', $auth['userid']);
- my_redirect('/');
- }
- public function type()
- {
- $user_id = get_user_id();
- if (empty($user_id)) {
- my_redirect('/login/index');
- }
- return view('login/type');
- }
- public function setType()
- {
- $type = input('type') == 2 ? 2 : 1;
- session('user.type', $type);
- if ($type == 1) {
- my_redirect('/');
- } else {
- my_redirect('/emp/index');
- }
- }
- public function sinPage()
- {
- $field = input('field/s');
- $sinpage = SinpageModel::where(1)->find();
- $data = [];
- if ($field == "woman_aboutus") {
- $data = [
- 'pagetil' => '关于我们',
- 'pagecon' => $sinpage->woman_aboutus,
- ];
- } elseif ($field == "woman_privacy") {
- $data = [
- 'pagetil' => '隐私政策',
- 'pagecon' => $sinpage->woman_privacy,
- ];
- } elseif ($field == "woman_service") {
- $data = [
- 'pagetil' => '用户协议',
- 'pagecon' => $sinpage->woman_service,
- ];
- } elseif ($field == "woman_contact") {
- $data = [
- 'pagetil' => '联系客服',
- 'pagecon' => $sinpage->woman_contact,
- ];
- } else {
- $data = [
- 'pagetil' => '关于我们',
- 'pagecon' => $sinpage->woman_aboutus,
- ];
- }
- $pagecon = explode("\n", $data['pagecon']);
- $str = '';
- foreach ($pagecon as $con) {
- $str .= "<p>{$con}</p>";
- }
- $data['pagecon'] = $str;
- return view('/login/page', $data);
- }
- public function perfect()
- {
- $user_id = get_user_id();
- $info = UserModel::where('id', $user_id)->find();
- $catelist = ComjobsCateModel::order(['priority' => 'desc', 'id' => 'desc'])->select();
- $userwill = UserWillModel::field('title as text,id')->select();
- $emptime = RensheCodeModel::getList('emp_time');
- $community = RensheCodeModel::getList('community')->toArray();
- $community[] = ['name' => '不限'];
- return view('my/info', [
- 'info' => $info,
- 'catelist' => $catelist,
- 'userwill' => $userwill,
- 'emptime' => $emptime,
- 'community' => json_encode($community),
- 'workexperience' => getWorkExperience(),
- 'education' => getEducation(),
- 'type' => 1,
- 'url' => url('/login/infoPost'),
- ]);
- }
- public function infoPost()
- {
- $user_id = get_user_id();
- $info = UserModel::where('id', $user_id)->find();
- $form = input('param.');
- foreach ($form as $k => $v) {
- $info->$k = $v;
- }
- $info->is_perfect = 1;
- $info->save();
- page_result(0, '操作成功');
- }
- /**
- * 手机登录
- */
- public function mobile()
- {
- return view('login/mobile');
- }
- public function mobilePost()
- {
- $mobile = input('mobile/s', '');
- $verify = input('verify/s', '');
- $session_verify = session('verify');
- if ($verify != $session_verify) {
- page_result(1, '验证码错误!');
- }
- $auth = UserAuthsModel::where(['identitytype' => 'mobile', 'identifier' => $mobile])->find();
- if (empty($auth)) {
- $open_id = session('user.open_id');
- $nickname = session('user.nickname');
- $headimgurl = session('user.headimgurl');
- $user_data = [
- 'groupsid' => 7,
- 'brokerid' => 0,
- 'nickname' => $nickname,
- 'avatar' => $headimgurl ?? '',
- 'realname' => "",
- 'mobile' => $mobile,
- 'integral' => 0,
- 'inttotal' => 0,
- 'status' => 2,
- 'isvip' => 1,
- 'authstatus' => 1,
- 'authremark' => "",
- 'idcardzpic' => "",
- 'idcardfpic' => "",
- 'idcard' => "",
- 'gender' => 1,
- 'birthday' => "",
- 'address' => "",
- 'education' => "",
- 'createtime' => time(),
- 'jobintention' => "",
- 'workexperience' => "",
- 'eduexperience' => "",
- 'followstatus' => 1,
- 'wxampcode' => "",
- 'bankcard' => ['openbank' => "", 'account' => "", 'number' => ""],
- 'emp_time' => [],
- 'com_cate' => [],
- 'work_place' => [],
- 'user_tags' => [],
- ];
- $user = User::create($user_data);
- $auth = UserAuthsModel::create([
- 'userid' => $user['id'],
- 'identitytype' => 'weixin',
- 'identifier' => $open_id,
- 'logintime' => time(),
- 'loginip' => request()->ip(),
- ]);
- UserAuthsModel::create([
- 'userid' => $user['id'],
- 'identitytype' => 'mobile',
- 'identifier' => $mobile,
- 'logintime' => time(),
- 'loginip' => request()->ip(),
- ]);
- } else {
- $auth->logintime = time();
- $auth->loginip = request()->ip();
- $auth->save();
- }
- session('user.id', $auth['userid']);
- page_result();
- }
- public function sendSms()
- {
- Session::delete('verify');
- $rand = rand(100000, 999999);
- $mobile = trim(input('post.mobile'));
- $preg_phone = '/^1[34578]\d{9}$/ims';
- $rtn = [];
- if (!$mobile) {
- page_result(1, '手机号为空');
- } else {
- if (preg_match($preg_phone, $mobile)) {
- $sms = new SmsService();
- $res = $sms->send($mobile, 'verification', [$rand]);
- if ($res['code'] == 0) {
- $rtn['code'] = 0;
- Session::set('verify', $rand);
- } else {
- page_result(1, '网络故障,请重试');
- }
- } else {
- page_result(1, '手机号格式不正确');
- }
- }
- page_result();
- }
- /**
- * 雇主注册
- */
- public function empRegister()
- {
- $user_id = get_user_id();
- $worker = WorkerModel::field(['id', 'realname', 'mobile', 'address', 'title', 'details', 'picone', 'remark', 'status'])->where('userid', $user_id)->find();
- if (empty($worker)) {
- $worker = json_encode(['id' => 0, 'wtype' => '', 'realname' => '', 'mobile' => '', 'address' => '', 'title' => '', 'details' => '', 'picone' => '', 'remark' => '']);
- } else {
- if ($worker->status == 1) {
- return $this->_jump('等待管理员审核', url('/login/setType') . '?type=1');
- } elseif ($worker->status == 3 || $worker->status == 4) {
- return $this->_jump('账号异常,请联系管理员', url('/login/setType') . '?type=1');
- } elseif ($worker->status == 5) {
- my_redirect(url('/emp/index'));
- }
- }
- return view('login/emp_register', ['worker' => $worker]);
- }
- public function empRegisterPost()
- {
- $data = input('post.');
- $data['status'] = 1;
- if ($data['id']) {
- WorkerModel::update($data);
- } else {
- $user_id = get_user_id();
- $data['userid'] = $user_id;
- $data['ftitle'] = $data['title'];
- $data['province'] = '福建省';
- $item['city'] = '福州市';
- $item['district'] = '马尾区';
- $data['createitme'] = time();
- if ($data['wtype'] == 1) {
- $data['title'] = $data['ftitle'] = $data['realname'];
- }
- WorkerModel::create($data);
- }
- page_result();
- }
- /**
- * 错误提示
- */
- private function _jump($msg = '', $url = null, $wait = 3)
- {
- if (is_null($url)) {
- $url = 'javascript:history.back(-1);';
- } else {
- $url = "location.href = '" . url($url) . "'";
- }
- $result = [
- 'msg' => $msg,
- 'url' => $url,
- 'wait' => $wait,
- ];
- return view('/public/jump', $result);
- }
- }
|