zhaojs
2023-05-16 ea24ddd0b978cbd3b0a900711b49b8a9c2db4186
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
 
namespace app\index\controller;
 
use addons\wechat\model\WechatCaptcha;
use app\common\controller\Frontend;
use app\common\library\Ems;
use app\common\library\Sms;
use app\common\model\Attachment;
use think\Config;
use think\Cookie;
use think\Hook;
use think\Session;
use think\Validate;
use app\common\model\User as  ModelUser;
 
/**
 * 会员中心
 */
class User extends Frontend
{
    protected $layout = '';
    protected $noNeedLogin = ['login', 'register', 'getInvitationInfo','phoneIsRegister'];
    protected $noNeedRight = ['*'];
 
    public function _initialize()
    {
        parent::_initialize();
    }
    /**
     * 注册会员
     */
    public function register()
    {
       
        $this->assign('appName',config('site.name'));
        return $this->view->fetch();
    }
 
    public function getInvitationInfo()
    {
        $invite_code = request()->param('code','','trim');
        $ModelUser = new ModelUser();
        $user = $ModelUser->field('id,nickname,avatar,invitation_code,status')->where(['invitation_code' => $invite_code])->find();
        $info = [
            'appName' => config('site.name'),
            'user' => empty($user) ? [] : $user,
            'userAgreement' => request()->domain()."/index/index/user_agreement",
            'privacyAgreement' =>request()->domain()."/index/index/privacy_agreement",
            "logo"=> cdnurl(config('site.logo')),
            'beian' => config('site.beian'),
            'appAndroidDownUrl' => config('site.appAndroidDownUrl'),
            'appIosDownUrl' => config('site.appIosDownUrl'),
        ];
        if($user['status'] != 'normal')json(['code' => 1, 'msg' => '用户已被禁用或注销','info' => $info]); 
        return json(['code' => 0, 'msg' => '获取成功','info' => $info]);
    }
 
    public function phoneIsRegister(){
        $mobile = request()->param('phone','','trim');
        if(empty($mobile)) return json(['code' => 1, 'msg' => '手机号不能为空','info' =>[]]);
        $ModelUser = new ModelUser();
        $user = $ModelUser->where(['mobile'=>$mobile])->find();
        return json(['code' => 0, 'msg' =>'获取成功','is_registered' => empty($user) ? 0 : 1]);
    }
 
 
    public function attachment()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            $mimetypeQuery = [];
            $where = [];
            $filter = $this->request->request('filter');
            $filterArr = (array)json_decode($filter, true);
            if (isset($filterArr['mimetype']) && preg_match("/(\/|\,|\*)/", $filterArr['mimetype'])) {
                $this->request->get(['filter' => json_encode(array_diff_key($filterArr, ['mimetype' => '']))]);
                $mimetypeQuery = function ($query) use ($filterArr) {
                    $mimetypeArr = array_filter(explode(',', $filterArr['mimetype']));
                    foreach ($mimetypeArr as $index => $item) {
                        $query->whereOr('mimetype', 'like', '%' . str_replace("/*", "/", $item) . '%');
                    }
                };
            } elseif (isset($filterArr['mimetype'])) {
                $where['mimetype'] = ['like', '%' . $filterArr['mimetype'] . '%'];
            }
 
            if (isset($filterArr['filename'])) {
                $where['filename'] = ['like', '%' . $filterArr['filename'] . '%'];
            }
 
            if (isset($filterArr['createtime'])) {
                $timeArr = explode(' - ', $filterArr['createtime']);
                $where['createtime'] = ['between', [strtotime($timeArr[0]), strtotime($timeArr[1])]];
            }
            $search = $this->request->get('search');
            if ($search) {
                $where['filename'] = ['like', '%' . $search . '%'];
            }
 
            $model = new Attachment();
            $offset = $this->request->get("offset", 0);
            $limit = $this->request->get("limit", 0);
            $total = $model
                ->where($where)
                ->where($mimetypeQuery)
                ->where('user_id', $this->auth->id)
                ->order("id", "DESC")
                ->count();
 
            $list = $model
                ->where($where)
                ->where($mimetypeQuery)
                ->where('user_id', $this->auth->id)
                ->order("id", "DESC")
                ->limit($offset, $limit)
                ->select();
            $cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root());
            foreach ($list as $k => &$v) {
                $v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url'];
            }
            unset($v);
            $result = array("total" => $total, "rows" => $list);
 
            return json($result);
        }
        $mimetype = $this->request->get('mimetype', '');
        $mimetype = substr($mimetype, -1) === '/' ? $mimetype . '*' : $mimetype;
        $this->view->assign('mimetype', $mimetype);
        $this->view->assign("mimetypeList", \app\common\model\Attachment::getMimetypeList());
        return $this->view->fetch();
    }
}