Login.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?php
  2. namespace app\mobile\controller;
  3. use app\common\model\User;
  4. use app\common\model\UserAuths as UserAuthsModel;
  5. use app\common\model\Sinpage as SinpageModel;
  6. use app\common\model\User as UserModel;
  7. use app\common\model\RensheCode as RensheCodeModel;
  8. use app\common\model\ComjobsCate as ComjobsCateModel;
  9. use app\common\model\UserWill as UserWillModel;
  10. use app\common\model\Worker as WorkerModel;
  11. use app\common\service\SmsService;
  12. use think\facade\Session;
  13. class Login
  14. {
  15. /**
  16. * 登录
  17. */
  18. public function index()
  19. {
  20. my_redirect('https://www.jucai.gov.cn/api/auth/wechat_auth?url=' . urlencode(url('/login/wechatBack', [], true, true)));
  21. }
  22. public function login1()
  23. {
  24. session('user.id', 6);
  25. return '登录成功!';
  26. }
  27. /**
  28. * 微信回调
  29. */
  30. public function wechatBack()
  31. {
  32. $param = input('param.');
  33. $open_id = $param['openid'];
  34. //登录
  35. $auth = UserAuthsModel::where(['identitytype' => 'weixin', 'identifier' => $open_id])->find();
  36. if (empty($auth)) {
  37. session('user.open_id', $open_id);
  38. session('user.nickname', $param['nickname']);
  39. session('user.headimgurl', $param['headimgurl']);
  40. my_redirect('/login/mobile');
  41. } else {
  42. $auth->logintime = time();
  43. $auth->loginip = request()->ip();
  44. $auth->save();
  45. }
  46. session('user.id', $auth['userid']);
  47. my_redirect('/');
  48. }
  49. public function type()
  50. {
  51. $user_id = get_user_id();
  52. if (empty($user_id)) {
  53. my_redirect('/login/index');
  54. }
  55. return view('login/type');
  56. }
  57. public function setType()
  58. {
  59. $type = input('type') == 2 ? 2 : 1;
  60. session('user.type', $type);
  61. if ($type == 1) {
  62. my_redirect('/');
  63. } else {
  64. my_redirect('/emp/index');
  65. }
  66. }
  67. public function sinPage()
  68. {
  69. $field = input('field/s');
  70. $sinpage = SinpageModel::where(1)->find();
  71. $data = [];
  72. if ($field == "woman_aboutus") {
  73. $data = [
  74. 'pagetil' => '关于我们',
  75. 'pagecon' => $sinpage->woman_aboutus,
  76. ];
  77. } elseif ($field == "woman_privacy") {
  78. $data = [
  79. 'pagetil' => '隐私政策',
  80. 'pagecon' => $sinpage->woman_privacy,
  81. ];
  82. } elseif ($field == "woman_service") {
  83. $data = [
  84. 'pagetil' => '用户协议',
  85. 'pagecon' => $sinpage->woman_service,
  86. ];
  87. } elseif ($field == "woman_contact") {
  88. $data = [
  89. 'pagetil' => '联系客服',
  90. 'pagecon' => $sinpage->woman_contact,
  91. ];
  92. } else {
  93. $data = [
  94. 'pagetil' => '关于我们',
  95. 'pagecon' => $sinpage->woman_aboutus,
  96. ];
  97. }
  98. $pagecon = explode("\n", $data['pagecon']);
  99. $str = '';
  100. foreach ($pagecon as $con) {
  101. $str .= "<p>{$con}</p>";
  102. }
  103. $data['pagecon'] = $str;
  104. return view('/login/page', $data);
  105. }
  106. public function perfect()
  107. {
  108. $user_id = get_user_id();
  109. $info = UserModel::where('id', $user_id)->find();
  110. $catelist = ComjobsCateModel::order(['priority' => 'desc', 'id' => 'desc'])->select();
  111. $userwill = UserWillModel::field('title as text,id')->select();
  112. $emptime = RensheCodeModel::getList('emp_time');
  113. $community = RensheCodeModel::getList('community')->toArray();
  114. $community[] = ['name' => '不限'];
  115. return view('my/info', [
  116. 'info' => $info,
  117. 'catelist' => $catelist,
  118. 'userwill' => $userwill,
  119. 'emptime' => $emptime,
  120. 'community' => json_encode($community),
  121. 'workexperience' => getWorkExperience(),
  122. 'education' => getEducation(),
  123. 'type' => 1,
  124. 'url' => url('/login/infoPost'),
  125. ]);
  126. }
  127. public function infoPost()
  128. {
  129. $user_id = get_user_id();
  130. $info = UserModel::where('id', $user_id)->find();
  131. $form = input('param.');
  132. foreach ($form as $k => $v) {
  133. $info->$k = $v;
  134. }
  135. $info->is_perfect = 1;
  136. $info->save();
  137. page_result(0, '操作成功');
  138. }
  139. /**
  140. * 手机登录
  141. */
  142. public function mobile()
  143. {
  144. return view('login/mobile');
  145. }
  146. public function mobilePost()
  147. {
  148. $mobile = input('mobile/s', '');
  149. $verify = input('verify/s', '');
  150. $session_verify = session('verify');
  151. if ($verify != $session_verify) {
  152. page_result(1, '验证码错误!');
  153. }
  154. $auth = UserAuthsModel::where(['identitytype' => 'mobile', 'identifier' => $mobile])->find();
  155. if (empty($auth)) {
  156. $open_id = session('user.open_id');
  157. $nickname = session('user.nickname');
  158. $headimgurl = session('user.headimgurl');
  159. $user_data = [
  160. 'groupsid' => 7,
  161. 'brokerid' => 0,
  162. 'nickname' => $nickname,
  163. 'avatar' => $headimgurl ?? '',
  164. 'realname' => "",
  165. 'mobile' => $mobile,
  166. 'integral' => 0,
  167. 'inttotal' => 0,
  168. 'status' => 2,
  169. 'isvip' => 1,
  170. 'authstatus' => 1,
  171. 'authremark' => "",
  172. 'idcardzpic' => "",
  173. 'idcardfpic' => "",
  174. 'idcard' => "",
  175. 'gender' => 1,
  176. 'birthday' => "",
  177. 'address' => "",
  178. 'education' => "",
  179. 'createtime' => time(),
  180. 'jobintention' => "",
  181. 'workexperience' => "",
  182. 'eduexperience' => "",
  183. 'followstatus' => 1,
  184. 'wxampcode' => "",
  185. 'bankcard' => ['openbank' => "", 'account' => "", 'number' => ""],
  186. 'emp_time' => [],
  187. 'com_cate' => [],
  188. 'work_place' => [],
  189. 'user_tags' => [],
  190. ];
  191. $user = User::create($user_data);
  192. $auth = UserAuthsModel::create([
  193. 'userid' => $user['id'],
  194. 'identitytype' => 'weixin',
  195. 'identifier' => $open_id,
  196. 'logintime' => time(),
  197. 'loginip' => request()->ip(),
  198. ]);
  199. UserAuthsModel::create([
  200. 'userid' => $user['id'],
  201. 'identitytype' => 'mobile',
  202. 'identifier' => $mobile,
  203. 'logintime' => time(),
  204. 'loginip' => request()->ip(),
  205. ]);
  206. } else {
  207. $auth->logintime = time();
  208. $auth->loginip = request()->ip();
  209. $auth->save();
  210. }
  211. session('user.id', $auth['userid']);
  212. page_result();
  213. }
  214. public function sendSms()
  215. {
  216. Session::delete('verify');
  217. $rand = rand(100000, 999999);
  218. $mobile = trim(input('post.mobile'));
  219. $preg_phone = '/^1[34578]\d{9}$/ims';
  220. $rtn = [];
  221. if (!$mobile) {
  222. page_result(1, '手机号为空');
  223. } else {
  224. if (preg_match($preg_phone, $mobile)) {
  225. $sms = new SmsService();
  226. $res = $sms->send($mobile, 'verification', [$rand]);
  227. if ($res['code'] == 0) {
  228. $rtn['code'] = 0;
  229. Session::set('verify', $rand);
  230. } else {
  231. page_result(1, '网络故障,请重试');
  232. }
  233. } else {
  234. page_result(1, '手机号格式不正确');
  235. }
  236. }
  237. page_result();
  238. }
  239. /**
  240. * 雇主注册
  241. */
  242. public function empRegister()
  243. {
  244. $user_id = get_user_id();
  245. $worker = WorkerModel::field(['id', 'realname', 'mobile', 'address', 'title', 'details', 'picone', 'remark', 'status'])->where('userid', $user_id)->find();
  246. if (empty($worker)) {
  247. $worker = json_encode(['id' => 0, 'wtype' => '', 'realname' => '', 'mobile' => '', 'address' => '', 'title' => '', 'details' => '', 'picone' => '', 'remark' => '']);
  248. } else {
  249. if ($worker->status == 1) {
  250. return $this->_jump('等待管理员审核', url('/login/setType') . '?type=1');
  251. } elseif ($worker->status == 3 || $worker->status == 4) {
  252. return $this->_jump('账号异常,请联系管理员', url('/login/setType') . '?type=1');
  253. } elseif ($worker->status == 5) {
  254. my_redirect(url('/emp/index'));
  255. }
  256. }
  257. return view('login/emp_register', ['worker' => $worker]);
  258. }
  259. public function empRegisterPost()
  260. {
  261. $data = input('post.');
  262. $data['status'] = 1;
  263. if ($data['id']) {
  264. WorkerModel::update($data);
  265. } else {
  266. $user_id = get_user_id();
  267. $data['userid'] = $user_id;
  268. $data['ftitle'] = $data['title'];
  269. $data['province'] = '福建省';
  270. $item['city'] = '福州市';
  271. $item['district'] = '马尾区';
  272. $data['createitme'] = time();
  273. if ($data['wtype'] == 1) {
  274. $data['title'] = $data['ftitle'] = $data['realname'];
  275. }
  276. WorkerModel::create($data);
  277. }
  278. page_result();
  279. }
  280. /**
  281. * 错误提示
  282. */
  283. private function _jump($msg = '', $url = null, $wait = 3)
  284. {
  285. if (is_null($url)) {
  286. $url = 'javascript:history.back(-1);';
  287. } else {
  288. $url = "location.href = '" . url($url) . "'";
  289. }
  290. $result = [
  291. 'msg' => $msg,
  292. 'url' => $url,
  293. 'wait' => $wait,
  294. ];
  295. return view('/public/jump', $result);
  296. }
  297. }