User.php 14.4 KB
Newer Older
D
v1.2.0  
devil_gong 已提交
1 2 3 4
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
D
devil_gong 已提交
5
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
D
v1.2.0  
devil_gong 已提交
6 7 8 9 10 11 12
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\index\controller;

13
use think\facade\Hook;
14 15 16 17
use app\service\OrderService;
use app\service\GoodsService;
use app\service\UserService;
use app\service\BuyService;
D
devil_gong 已提交
18
use app\service\SeoService;
D
devil_gong 已提交
19
use app\service\MessageService;
D
devil 已提交
20
use app\service\NavigationService;
D
devil 已提交
21
use app\service\GoodsBrowseService;
D
devil 已提交
22
use app\service\GoodsFavorService;
D
v1.2.0  
devil_gong 已提交
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

/**
 * 用户
 * @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()
    {
        // 上一个页面, 空则用户中心
        $referer_url = empty($_SERVER['HTTP_REFERER']) ? MyUrl('index/user/index') : $_SERVER['HTTP_REFERER'];
        if(!empty($_SERVER['HTTP_REFERER']))
        {
D
devil_gong 已提交
59
            $all = ['login', 'regster', 'forget', 'logininfo', 'reginfo', 'smsreginfo', 'emailreginfo', 'forgetpwdinfo'];
D
v1.2.0  
devil_gong 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
            foreach($all as $v)
            {
                if(strpos($_SERVER['HTTP_REFERER'], $v) !== false)
                {
                    $referer_url = MyUrl('index/user/index');
                    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()
    {
        // 登录校验
82
        $this->IsLogin();
D
v1.2.0  
devil_gong 已提交
83

D
devil 已提交
84 85 86
        // 用户中心基础信息 mini 导航
        $mini_navigation = NavigationService::UserCenterMiniNavigation(['user'=>$this->user]);
        $this->assign('mini_navigation', $mini_navigation);
D
v1.2.0  
devil_gong 已提交
87 88

        // 用户订单状态
D
Devil 已提交
89
        $user_order_status = OrderService::OrderStatusStepTotal(['user_type'=>'user', 'user'=>$this->user, 'is_comments'=>1, 'is_aftersale'=>1]);
D
v1.2.0  
devil_gong 已提交
90 91
        $this->assign('user_order_status', $user_order_status['data']);

D
devil_gong 已提交
92 93 94
        // 未读消息总数
        $params = ['user'=>$this->user, 'is_more'=>1, 'is_read'=>0, 'user_type'=>'user'];
        $common_message_total = MessageService::UserMessageTotal($params);
D
devil 已提交
95
        $this->assign('common_message_total', $common_message_total);
D
devil_gong 已提交
96

D
v1.2.0  
devil_gong 已提交
97
        // 获取进行中的订单列表
D
devil 已提交
98
        $params = $this->data_request;
D
v1.2.0  
devil_gong 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
        $params['user'] = $this->user;
        $params['is_more'] = 1;
        $params['status'] = [1,2,3,4];
        $params['is_comments'] = 0;
        $params['user_type'] = 'user';
        $where = OrderService::OrderListWhere($params);
        $order_params = array(
            'm'         => 0,
            'n'         => 3,
            'where'     => $where,
        );
        $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']);

        // 收藏商品
        $favor_params = array(
            'm'         => 0,
D
devil 已提交
120 121 122 123 124
            'n'         => 6,
            'where'     => [
                ['g.is_delete_time', '=', 0],
                ['f.user_id', '=', $this->user['id']],
            ],
D
v1.2.0  
devil_gong 已提交
125
        );
D
devil 已提交
126
        $favor = GoodsFavorService::GoodsFavorList($favor_params);
D
v1.2.0  
devil_gong 已提交
127 128 129 130 131 132
        $this->assign('goods_favor_list', $favor['data']);

        // 我的足迹
        $browse_params = array(
            'm'         => 0,
            'n'         => 6,
D
devil 已提交
133 134 135 136
            'where'     => [
                ['g.is_delete_time', '=', 0],
                ['b.user_id', '=', $this->user['id']],
            ],
D
v1.2.0  
devil_gong 已提交
137
        );
D
devil 已提交
138
        $data = GoodsBrowseService::GoodsBrowseList($browse_params);
D
v1.2.0  
devil_gong 已提交
139 140
        $this->assign('goods_browse_list', $data['data']);

D
devil 已提交
141
        // 订单页面订单状态form key
142 143
        $this->assign('form_search_order_status_form_key', 'status');
        $this->assign('form_search_order_user_is_comments_form_key', 'user_is_comments');
D
devil 已提交
144

D
devil 已提交
145 146
        // 钩子
        $this->PluginsHook();
D
v1.2.0  
devil_gong 已提交
147

D
devil_gong 已提交
148 149 150
        // 浏览器名称
        $this->assign('home_seo_site_title', SeoService::BrowserSeoTitle('用户中心', 1));

D
v1.2.0  
devil_gong 已提交
151 152 153
        return $this->fetch();
    }

D
devil 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    /**
     * 钩子处理
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-04-22
     * @desc    description
     */
    private function PluginsHook()
    {
        // 顶部钩子
        $this->assign('plugins_view_user_center_top_data', Hook::listen('plugins_view_user_center_top', ['hook_name'=>'plugins_view_user_center_top', 'is_backend'=>false, 'user'=>$this->user]));

        // 基础信息底部钩子
        $this->assign('plugins_view_user_base_bottom_data', Hook::listen('plugins_view_user_base_bottom', ['hook_name'=>'plugins_view_user_base_bottom', 'is_backend'=>false, 'user'=>$this->user]));

        // 聚合内容顶部钩子
        $this->assign('plugins_view_user_various_top_data', Hook::listen('plugins_view_user_various_top', ['hook_name'=>'plugins_view_user_various_top', 'is_backend'=>false, 'user'=>$this->user]));

        // 聚合内容底部钩子
        $this->assign('plugins_view_user_various_bottom_data', Hook::listen('plugins_view_user_various_bottom', ['hook_name'=>'plugins_view_user_various_bottom', 'is_backend'=>false, 'user'=>$this->user]));

        // 聚合内容里面顶部钩子
        $this->assign('plugins_view_user_various_inside_top_data', Hook::listen('plugins_view_user_various_inside_top', ['hook_name'=>'plugins_view_user_various_inside_top', 'is_backend'=>false, 'user'=>$this->user]));

        // 聚合内容里面底部钩子
        $this->assign('plugins_view_user_various_bottom_data', Hook::listen('plugins_view_user_various_bottom', ['hook_name'=>'plugins_view_user_various_bottom', 'is_backend'=>false, 'user'=>$this->user]));
    }

D
v1.2.0  
devil_gong 已提交
183 184 185 186 187 188 189 190 191 192 193
    /**
     * [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))
        {
D
devil_gong 已提交
194 195 196
            // 浏览器名称
            $this->assign('home_seo_site_title', SeoService::BrowserSeoTitle('密码找回', 1));

D
devil_gong 已提交
197 198 199 200
            // 左侧图片,随机其中一个
            $left_data = UserService::UserEntranceLeftData(['left_key'=>'forgetpwd', 'cache_key'=>config('shopxo.cache_user_forgetpwd_left_key')]);
            $this->assign('user_forgetpwd_left_data', empty($left_data['data']) ? [] : $left_data['data'][array_rand($left_data['data'], 1)]);

D
v1.2.0  
devil_gong 已提交
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
            return $this->fetch();
        } else {
            $this->assign('msg', '已经登录了,如要重置密码,请先退出当前账户');
            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))
            {
D
devil_gong 已提交
222 223 224
                // 浏览器名称
                $this->assign('home_seo_site_title', SeoService::BrowserSeoTitle('用户注册', 1));

G
gongfuxiang 已提交
225
                // 返回地址
G
gongfuxiang 已提交
226
                $this->assign('referer_url', $this->GetrefererUrl());
G
gongfuxiang 已提交
227 228 229 230

                // 注册背景图片
                $this->assign('user_register_bg_images', MyC('home_site_user_register_bg_images'));

D
v1.2.0  
devil_gong 已提交
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
                return $this->fetch();
            } else {
                $this->assign('msg', '已经登录了,如要注册新账户,请先退出当前账户');
                return $this->fetch('public/tips_error');
            }
        } else {
            $this->assign('msg', '暂时关闭用户注册');
            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))
            {
D
devil_gong 已提交
255 256 257
                // 浏览器名称
                $this->assign('home_seo_site_title', SeoService::BrowserSeoTitle('用户登录', 1));

D
devil_gong 已提交
258
                // 返回地址
D
v1.2.0  
devil_gong 已提交
259
                $this->assign('referer_url', $this->GetrefererUrl());
D
devil_gong 已提交
260 261 262 263 264

                // 左侧图片,随机其中一个
                $left_data = UserService::UserEntranceLeftData(['left_key'=>'login', 'cache_key'=>config('shopxo.cache_user_login_left_key')]);
                $this->assign('user_login_left_data', empty($left_data['data']) ? [] : $left_data['data'][array_rand($left_data['data'], 1)]);

D
v1.2.0  
devil_gong 已提交
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
                return $this->fetch();
            } else {
                $this->assign('msg', '已经登录了,请勿重复登录');
                return $this->fetch('public/tips_error');
            }
        } else {
            $this->assign('msg', '暂时关闭用户登录');
            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))
            {
D
devil_gong 已提交
293 294 295
                // 浏览器名称
                $this->assign('home_seo_site_title', SeoService::BrowserSeoTitle('用户登录', 1));
                
D
v1.2.0  
devil_gong 已提交
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 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 352 353 354 355 356
                $this->assign('referer_url', $this->GetrefererUrl());
                return $this->fetch();
            } else {
                $this->assign('msg', '已经登录了,请勿重复登录');
                return $this->fetch('public/tips_error');
            }
        } else {
            $this->assign('msg', '暂时关闭用户登录');
            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)
        {
            return $this->error('非法访问');
        }

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

    /**
     * [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)
        {
            return $this->error('非法访问');
        }

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

    /**
     * [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,
D
devil_gong 已提交
357
                'height' => 26,
D
v1.2.0  
devil_gong 已提交
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 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 426 427 428 429
                '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)
        {
            return $this->error('非法访问');
        }

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

    /**
     * [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)
        {
            return $this->error('非法访问');
        }

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

    /**
     * [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)
        {
            return $this->error('非法访问');
        }

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

    /**
     * [Logout 退出]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2016-12-05T14:31:23+0800
     */
    public function Logout()
    {
D
devil_gong 已提交
430 431 432 433 434 435 436 437 438
        // 调用服务层
        $ret = UserService::Logout();

        // 登录返回
        $body_html = (!empty($ret['data']['body_html']) && is_array($ret['data']['body_html'])) ? implode(' ', $ret['data']['body_html']) : $ret['data']['body_html'];
        $this->assign('body_html', $body_html);
        $this->assign('msg', $ret['msg']);

        return $this->fetch();
D
v1.2.0  
devil_gong 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
    }

    /**
     * 用户头像上传
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-03
     * @desc    description
     */
    public function UserAvatarUpload()
    {
        // 是否ajax请求
        if(!IS_AJAX)
        {
            return $this->error('非法访问');
        }

        // 登录校验
458
        $this->IsLogin();
D
v1.2.0  
devil_gong 已提交
459 460 461 462 463 464 465 466

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