User.php 11.9 KB
Newer Older
G
gongfuxiang 已提交
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
<?php
namespace app\index\controller;

use app\service\OrderService;
use app\service\GoodsService;
use app\service\UserService;
use app\service\BuyService;

/**
 * 用户
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2017-03-02T22:48:35+0800
 */
class User extends Common
{
    /**
     * 构造方法
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-11-30
     * @desc    description
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * [GetrefererUrl 获取上一个页面地址]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-09T15:46:16+0800
     */
    private function GetrefererUrl()
    {
        // 上一个页面, 空则用户中心
D
devil_gong 已提交
41
        $referer_url = empty($_SERVER['HTTP_REFERER']) ? MyUrl('index/user/index') : $_SERVER['HTTP_REFERER'];
G
gongfuxiang 已提交
42 43 44 45 46 47 48
        if(!empty($_SERVER['HTTP_REFERER']))
        {
            $all = ['logininfo', 'reginfo', 'smsreginfo', 'emailreginfo', 'forgetpwdinfo'];
            foreach($all as $v)
            {
                if(strpos($_SERVER['HTTP_REFERER'], $v) !== false)
                {
D
devil_gong 已提交
49
                    $referer_url = MyUrl('index/user/index');
G
gongfuxiang 已提交
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
                    break;
                }
            }
        }
        return $referer_url;
    }

    /**
     * [Index 用户中心]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-02T22:48:35+0800
     */
    public function Index()
    {
        // 登录校验
        $this->Is_Login();
        
        // 订单总数
        $where = ['user_id'=>$this->user['id'], 'is_delete_time'=>0, 'user_is_delete_time'=>0];
        $this->assign('user_order_count', OrderService::OrderTotal($where));

        // 商品收藏总数
        $where = ['user_id'=>$this->user['id']];
        $this->assign('user_goods_favor_count', GoodsService::GoodsFavorTotal($where));

        // 商品浏览总数
        $where = ['user_id'=>$this->user['id']];
        $this->assign('user_goods_browse_count', GoodsService::GoodsBrowseTotal($where));

        // 用户订单状态
        $user_order_status = OrderService::OrderStatusStepTotal(['user_type'=>'user', 'user'=>$this->user, 'is_comments'=>1]);
        $this->assign('user_order_status', $user_order_status['data']);

        // 获取进行中的订单列表
        $params = array_merge($_POST, $_GET);
        $params['user'] = $this->user;
        $params['is_more'] = 1;
        $params['status'] = [1,2,3,4];
        $params['is_comments'] = 0;
G
gongfuxiang 已提交
91 92
        $params['user_type'] = 'user';
        $where = OrderService::OrderListWhere($params);
G
gongfuxiang 已提交
93
        $order_params = array(
G
admin  
gongfuxiang 已提交
94 95 96
            'm'         => 0,
            'n'         => 3,
            'where'     => $where,
G
gongfuxiang 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109
        );
        $order = OrderService::OrderList($order_params);
        $this->assign('order_list', $order['data']);

        // 获取购物车
        $cart_list = BuyService::CartList(['user'=>$this->user]);
        $this->assign('cart_list', $cart_list['data']);

        // 收藏商品
        $params = array_merge($_POST, $_GET);
        $params['user'] = $this->user;
        $where = GoodsService::UserGoodsFavorListWhere($params);
        $favor_params = array(
G
admin  
gongfuxiang 已提交
110 111 112
            'm'         => 0,
            'n'         => 8,
            'where'     => $where,
G
gongfuxiang 已提交
113 114 115 116 117 118 119 120 121
        );
        $favor = GoodsService::GoodsFavorList($favor_params);
        $this->assign('goods_favor_list', $favor['data']);

        // 我的足迹
        $params = array_merge($_POST, $_GET);
        $params['user'] = $this->user;
        $where = GoodsService::UserGoodsBrowseListWhere($params);
        $browse_params = array(
G
admin  
gongfuxiang 已提交
122 123 124
            'm'         => 0,
            'n'         => 6,
            'where'     => $where,
G
gongfuxiang 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
        );
        $data = GoodsService::GoodsBrowseList($browse_params);
        $this->assign('goods_browse_list', $data['data']);

        // 用户中心公告
        $this->assign('common_user_center_notice', MyC('common_user_center_notice'));

        return $this->fetch();
    }

    /**
     * [ForgetPwdInfo 密码找回]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-10T17:06:47+0800
     */
    public function ForgetPwdInfo()
    {
        if(empty($this->user))
        {
            return $this->fetch();
        } else {
D
语言  
devil_gong 已提交
148
            $this->assign('msg', '已经登录了,如要重置密码,请先退出当前账户');
G
gongfuxiang 已提交
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
            return $this->fetch('public/tips_error');
        }
    }

    /**
     * [RegInfo 用户注册页面]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-02T22:48:35+0800
     */
    public function RegInfo()
    {
        $reg_all = MyC('home_user_reg_state');
        if(!empty($reg_all))
        {
            if(empty($this->user))
            {
                return $this->fetch();
            } else {
D
语言  
devil_gong 已提交
169
                $this->assign('msg', '已经登录了,如要注册新账户,请先退出当前账户');
G
gongfuxiang 已提交
170 171 172
                return $this->fetch('public/tips_error');
            }
        } else {
D
语言  
devil_gong 已提交
173
            $this->assign('msg', '暂时关闭用户注册');
G
gongfuxiang 已提交
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
            return $this->fetch('public/tips_error');
        }
    }

    /**
     * [EmailRegInfo 用户注册页面-邮箱]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-10T12:18:17+0800
     */
    public function EmailRegInfo()
    {
        if(in_array('email', MyC('home_user_reg_state')))
        {
            if(empty($this->user))
            {
                $this->assign('referer_url', $this->GetrefererUrl());
                return $this->fetch();
            } else {
D
语言  
devil_gong 已提交
194
                $this->assign('msg', '已经登录了,如要注册新账户,请先退出当前账户');
G
gongfuxiang 已提交
195 196 197
                return $this->fetch('public/tips_error');
            }
        } else {
D
语言  
devil_gong 已提交
198
            $this->assign('msg', '暂时关闭邮箱注册');
G
gongfuxiang 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
            return $this->fetch('public/tips_error');
        }
    }

    /**
     * [SmsRegInfo 用户注册页面-短信]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-02T22:48:35+0800
     */
    public function SmsRegInfo()
    {
        if(in_array('sms', MyC('home_user_reg_state')))
        {
            if(empty($this->user))
            {
                $this->assign('referer_url', $this->GetrefererUrl());
                return $this->fetch();
            } else {
D
语言  
devil_gong 已提交
219
                $this->assign('msg', '已经登录了,如要注册新账户,请先退出当前账户');
G
gongfuxiang 已提交
220 221 222
                return $this->fetch('public/tips_error');
            }
        } else {
D
语言  
devil_gong 已提交
223
            $this->assign('msg', '暂时关闭短信注册');
G
gongfuxiang 已提交
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
            return $this->fetch('public/tips_error');
        }
    }

    /**
     * [LoginInfo 用户登录页面]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-02T22:48:35+0800
     */
    public function LoginInfo()
    {
        if(MyC('home_user_login_state') == 1)
        {
            if(empty($this->user))
            {
                $this->assign('referer_url', $this->GetrefererUrl());
                return $this->fetch();
            } else {
D
语言  
devil_gong 已提交
244
                $this->assign('msg', '已经登录了,请勿重复登录');
G
gongfuxiang 已提交
245 246 247
                return $this->fetch('public/tips_error');
            }
        } else {
D
语言  
devil_gong 已提交
248
            $this->assign('msg', '暂时关闭用户登录');
G
gongfuxiang 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
            return $this->fetch('public/tips_error');
        }
    }

    /**
     * modal弹窗登录
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-09-13
     * @desc    description
     */
    public function ModalLoginInfo()
    {
        $this->assign('is_header', 0);
        $this->assign('is_footer', 0);

        if(MyC('home_user_login_state') == 1)
        {
            if(empty($this->user))
            {
                $this->assign('referer_url', $this->GetrefererUrl());
                return $this->fetch();
            } else {
D
语言  
devil_gong 已提交
273
                $this->assign('msg', '已经登录了,请勿重复登录');
G
gongfuxiang 已提交
274 275 276
                return $this->fetch('public/tips_error');
            }
        } else {
D
语言  
devil_gong 已提交
277
            $this->assign('msg', '暂时关闭用户登录');
G
gongfuxiang 已提交
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
            return $this->fetch('public/tips_error');
        }
    }

    /**
     * [Reg 用户注册-数据添加]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-07T00:08:36+0800
     */
    public function Reg()
    {
        // 是否ajax请求
        if(!IS_AJAX)
        {
D
语言  
devil_gong 已提交
294
            return $this->error('非法访问');
G
gongfuxiang 已提交
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
        }

        // 调用服务层
        $ret = UserService::Reg(input('post.'));
        return json($ret);
    }

    /**
     * [Login 用户登录]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-09T10:57:31+0800
     */
    public function Login()
    {
        // 是否ajax请求
        if(!IS_AJAX)
        {
D
语言  
devil_gong 已提交
314
            return $this->error('非法访问');
G
gongfuxiang 已提交
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
        }

        // 调用服务层
        $ret = UserService::Login(input('post.'));
        return json($ret);
    }

    /**
     * [UserVerifyEntry 用户-验证码显示]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-05T15:10:21+0800
     */
    public function UserVerifyEntry()
    {
        $params = array(
                'width' => 100,
                'height' => 32,
                'key_prefix' => input('type', 'reg'),
            );
        $verify = new \base\Verify($params);
        $verify->Entry();
    }

    /**
     * [RegVerifySend 用户注册-验证码发送]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-05T19:17:10+0800
     */
    public function RegVerifySend()
    {
        // 是否ajax请求
        if(!IS_AJAX)
        {
D
语言  
devil_gong 已提交
352
            return $this->error('非法访问');
G
gongfuxiang 已提交
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
        }

        // 调用服务层
        $ret = UserService::RegVerifySend(input('post.'));
        return json($ret);
    }

    /**
     * [ForgetPwdVerifySend 密码找回验证码发送]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-10T17:35:03+0800
     */
    public function ForgetPwdVerifySend()
    {
        // 是否ajax请求
        if(!IS_AJAX)
        {
D
语言  
devil_gong 已提交
372
            return $this->error('非法访问');
G
gongfuxiang 已提交
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
        }

        // 调用服务层
        $ret = UserService::ForgetPwdVerifySend(input('post.'));
        return json($ret);
    }

    /**
     * [ForgetPwd 密码找回]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-03-10T17:55:42+0800
     */
    public function ForgetPwd()
    {
        // 是否ajax请求
        if(!IS_AJAX)
        {
D
语言  
devil_gong 已提交
392
            return $this->error('非法访问');
G
gongfuxiang 已提交
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
        }

        // 调用服务层
        $ret = UserService::ForgetPwd(input('post.'));
        return json($ret);
    }

    /**
     * [Logout 退出]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2016-12-05T14:31:23+0800
     */
    public function Logout()
    {
        session('user', null);
        return redirect(__MY_URL__);
    }

    /**
     * 用户头像上传
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-03
     * @desc    description
     */
    public function UserAvatarUpload()
    {
        // 是否ajax请求
        if(!IS_AJAX)
        {
D
语言  
devil_gong 已提交
426
            return $this->error('非法访问');
G
gongfuxiang 已提交
427 428 429 430 431 432 433 434 435 436 437 438 439
        }

        // 登录校验
        $this->Is_Login();

        $params = $_POST;
        $params['user'] = $this->user;
        $params['img_field'] = 'file';
        $ret = UserService::UserAvatarUpload($params);
        return json($ret);
    }
}
?>