审查视图

app/portal/controller/PersonalcenterController.php 6.1 KB
anyv authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\WeChatBaseController;
use think\Db;

class PersonalcenterController extends WeChatBaseController{

    /**
     * 显示个人中心页
     */
4  
anyv authored
19
    public function personal_center(){
anyv authored
20
5  
anyv authored
21 22
        $uid = cmf_get_current_user_id();
        $my_user_status = Db::name('my_user') -> where('uid',$uid) -> find();
anyv authored
23 24
        $weixin = Db::name('user') -> where('id',$uid) -> find();
        $this -> assign('weixin',$weixin);
5  
anyv authored
25
        if($my_user_status['status'] == 0 || $my_user_status['status'] == 1 || $my_user_status['status'] == 3 || $my_user_status['status'] == 4 || $my_user_status['status'] == 5 || $my_user_status['status'] == 6){
5  
anyv authored
26 27 28
            if($my_user_status['status'] == 0){
                $this -> assign('status',0);
            }
5  
anyv authored
29
            if($my_user_status['status'] == 1 || $my_user_status['status'] == 5 || $my_user_status['status'] == 6){
5  
anyv authored
30 31 32 33 34 35 36 37 38 39
                $this -> assign('status',1);
            }
            if($my_user_status['status'] == 3){
                $this -> assign('status',3);
            }
            if($my_user_status['status'] == 4){
                $this -> assign('status',4);
            }
            return $this -> fetch();
        }
5  
anyv authored
40
        //业务员个人中心页
5  
anyv authored
41
        if($my_user_status['status'] == 2){
1  
anyv authored
42
            $this -> assign('weixin',$weixin);
5  
anyv authored
43
            return $this -> fetch('personalcenter/salesman_center');
5  
anyv authored
44
        }
5  
anyv authored
45
8  
anyv authored
46
    }
5  
anyv authored
47
8  
anyv authored
48 49 50 51
    /**
     * 完善个人信息页
     */
    public function perfect_information(){
5  
anyv authored
52
8  
anyv authored
53
        $uid = cmf_get_current_user_id();
5  
anyv authored
54
        $my_user_status = Db::name('my_user') -> where('uid',$uid) -> find();
5  
anyv authored
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
        if($my_user_status['status'] == 2){
            $this -> redirect('Personalcenter/personal_center');
        }else{
            if($my_user_status['status'] == 1){
                $this -> assign('status',1);
            }
            if($my_user_status['status'] == 5){
                $this -> assign('status',5);
            }
            if($my_user_status['status'] == 6){
                $this -> assign('status',6);
            }
            $weixin = Db::name('user') -> where('id',$uid) -> find();
            $this -> assign('weixin',$weixin);
            return $this -> fetch();
5  
anyv authored
70
        }
5  
anyv authored
71
anyv authored
72 73
    }
8  
anyv authored
74
7  
anyv authored
75 76 77 78 79
    /**
     * 我的收藏页
     */
    public function personal_collect(){
4  
anyv authored
80 81 82 83 84 85 86
        $uid = cmf_get_current_user_id();
        $data = Db::name('collect') -> where("uid =".$uid) -> select();
        $data_count = count($data);
        if(!empty($data)){
            foreach($data as $key => $val){
                $data_goods[] = Db::name('goods') -> where("id =".$val['goods_id']) -> find();
            }
8  
anyv authored
87 88 89 90 91 92 93 94
            foreach ($data_goods as $key => $val){
                $price = explode('.',$val['price']);
                $pricing = explode('.',$val['pricing']);
                $data_goods[$key]['price0'] = $price[0];
                $data_goods[$key]['price1'] = $price[1];
                $data_goods[$key]['pricing0'] = $pricing[0];
                $data_goods[$key]['pricing1'] = $pricing[1];
            }
4  
anyv authored
95 96
        }else{
            $data_goods = '';
4  
anyv authored
97
        }
5  
anyv authored
98
        $this -> assign('data_count',$data_count);
8  
anyv authored
99
        $this -> assign('data_goods',$data_goods);
7  
anyv authored
100 101 102 103
        return $this -> fetch();

    }
5  
anyv authored
104 105 106 107 108 109 110 111
    /**
     * 填写个人信息页
     */
    public function add_information(){

        return $this -> fetch();

    }
7  
anyv authored
112
4  
anyv authored
113 114 115 116 117
    /**
     * 浏览记录
     */
    public function browsing_history(){
5  
anyv authored
118
        $uid = cmf_get_current_user_id();
5  
anyv authored
119
        $data = Db::name('browsing_history') -> where("uid =".$uid) -> select();
5  
anyv authored
120 121 122
        foreach($data as $key => $val){
            $data_goods[] = Db::name('goods') -> where('id',$val['goods_id']) -> find();
        }
5  
anyv authored
123 124 125 126 127 128 129 130
        if(!empty($data_goods)){
            foreach($data_goods as $key => $val){
                $price = explode('.',$val['price']);
                $classification_name = Db::name('classification') -> where('id',$val['classify_id']) -> find();
                $data_goods[$key]['classification_name'] = $classification_name['name'];
                $data_goods[$key]['price0'] = $price[0];
                $data_goods[$key]['price1'] = $price[1];
            }
anyv authored
131 132
        }else{
            $data_goods = '';
4  
anyv authored
133
        }
5  
anyv authored
134
        $this -> assign('data_goods',$data_goods);
4  
anyv authored
135 136 137
        return $this -> fetch();

    }
7  
anyv authored
138
5  
anyv authored
139 140 141 142 143
    /**
     * 收货地址页
     */
    public function shop_address(){
5  
anyv authored
144
        $data = Db::name('address') -> where("delete_time = 0") ->  select();
5  
anyv authored
145
        $this -> assign('data',$data);
5  
anyv authored
146 147 148
        return $this -> fetch();

    }
7  
anyv authored
149
5  
anyv authored
150 151 152 153 154
    /**
     * 新增地址页
     */
    public function add_shop_address(){
5  
anyv authored
155
        if($this -> request -> isPost()){
5  
anyv authored
156 157
            $uid = cmf_get_current_user_id();
            $_POST['uid'] = $uid;
5  
anyv authored
158 159 160 161 162 163
            $add = Db::name('address') -> insert($_POST);
            if($add){
               return true;
            }else{
                return false;
            }
5  
anyv authored
164 165 166 167
        }else{
            return $this -> fetch();
        }
5  
anyv authored
168 169 170 171 172 173 174 175
    }

    /**
     * 设置默认地址
     */
    public function set_default_address(){

        $uid = cmf_get_current_user_id();
anyv authored
176
        Db::name('address') -> where('uid',$uid) -> update(['default_address'=>0]);
5  
anyv authored
177 178 179 180 181 182
        $data = Db::name('address') -> where('id',$_POST['id']) -> update(['default_address'=>1]);
        if($data){
            return true;
        }else{
            return false;
        }
5  
anyv authored
183 184

    }
7  
anyv authored
185
5  
anyv authored
186 187 188 189
    /**
     * 删除默认地址
     */
    public function address_del(){
7  
anyv authored
190
5  
anyv authored
191 192
        $delete_time = time();
        $data = Db::name('address') -> where('id',$_POST['id']) ->  update(['delete_time'=>$delete_time]);
5  
anyv authored
193 194 195 196 197
        if($data){
            return true;
        }else{
            return false;
        }
7  
anyv authored
198
5  
anyv authored
199
    }
7  
anyv authored
200 201 202 203 204 205 206 207 208 209









anyv authored
210 211 212 213



}