123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- // 应用公共文件
- 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,
- ];
- $html = view('/public/jump', $result);
- throw new \think\exception\HttpResponseException($html);
- }
- function ajax_success($data)
- {
- $res = ['code' => 0, 'msg' => '成功', 'data' => $data];
- $response = \think\Response::create($res, 'json');
- throw new \think\exception\HttpResponseException($response);
- }
- function get_user()
- {
- $sessionUserId = session('mobile.user.id');
- if (empty($sessionUserId)) {
- if (request()->isAjax()) {
- $res = ['code' => 401, 'msg' => '请登录'];
- $response = \think\Response::create($res, 'json');
- throw new \think\exception\HttpResponseException($response);
- } else {
- session('back_url', request()->url());
- $response = redirect('/mobile/login/login');
- throw new \think\exception\HttpResponseException($response);
- }
- }
- $user = \app\common\model\UserModel::where('id', $sessionUserId)->hidden(['password', 'salt'])->find();
- if (empty($user)) {
- jump('该用户已删除');
- }
- if ($user['status'] != \app\common\model\UserModel::STATUS_PASS) {
- jump('该账号暂时无法使用');
- }
- return $user;
- }
- function get_user_id()
- {
- $sessionUserId = session('mobile.user.id');
- if (empty($sessionUserId)) {
- return 0;
- }
- return $sessionUserId;
- }
- function array_to_vue($arr, $key = "", $value = "")
- {
- $res = [];
- foreach ($arr as $k => $v) {
- if (!empty($key)) {
- $res[] = ['text' => $v[$key], 'value' => $v[$value]];
- } else {
- $res[] = ['text' => $v, 'value' => $k];
- }
- }
- return json_encode($res);
- }
|