PersonalcenterController.php 8.0 KB
<?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;
use extend\lib\sendAPI;

class PersonalcenterController extends WeChatBaseController{

    /**
     * 显示个人中心页
     */
    public function personal_center(){

        $uid = cmf_get_current_user_id();
        $my_user_status = Db::name('my_user') -> where('uid',$uid) -> find();
        $weixin = Db::name('user') -> where('id',$uid) -> find();
        $this -> assign('weixin',$weixin);
        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){
            if($my_user_status['status'] == 0){
                $this -> assign('status',0);
            }
            if($my_user_status['status'] == 1 || $my_user_status['status'] == 5 || $my_user_status['status'] == 6){
                $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();
        }
        //业务员个人中心页
        if($my_user_status['status'] == 2){
            $this -> assign('weixin',$weixin);
            return $this -> fetch('personalcenter/salesman_center');
        }

    }

    /**
     * 完善个人信息页
     */
    public function perfect_information(){

        $uid = cmf_get_current_user_id();
        $my_user_status = Db::name('my_user') -> where('uid',$uid) -> find();
        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();
        }

    }


    /**
     * 我的收藏页
     */
    public function personal_collect(){

        $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();
            }
            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];
            }
        }else{
            $data_goods = '';
        }
        $this -> assign('data_count',$data_count);
        $this -> assign('data_goods',$data_goods);
        return $this -> fetch();

    }

    /**
     * 填写个人信息页
     */
    public function add_information(){

        return $this -> fetch();

    }

    /**
     * 浏览记录
     */
    public function browsing_history(){

        $uid = cmf_get_current_user_id();
        $data = Db::name('browsing_history') -> where("uid =".$uid) -> select();
        foreach($data as $key => $val){
            $data_goods[] = Db::name('goods') -> where('id',$val['goods_id']) -> find();
        }
        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];
            }
        }else{
            $data_goods = '';
        }
        $this -> assign('data_goods',$data_goods);
        return $this -> fetch();

    }

    /**
     * 收货地址页
     */
    public function shop_address(){

        $data = Db::name('address') -> where("delete_time = 0") ->  select() -> toArray();
        if(!empty($data)){
            foreach($data as $key => $val){
                $detailed = explode(',',$val['detailed']);
                $data[$key]['detailed'] = $detailed[0].$detailed[1];
            }
        }
        $this -> assign('data',$data);
        return $this -> fetch();

    }

    /**
     * 新增地址页
     */
    public function add_shop_address(){

        if($this -> request -> isPost()){
            $uid = cmf_get_current_user_id();
            $_POST['uid'] = $uid;
            $add = Db::name('address') -> insert($_POST);
            if($add){
               return true;
            }else{
                return false;
            }
        }else{
            return $this -> fetch();
        }

    }

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

        $uid = cmf_get_current_user_id();
        Db::name('address') -> where('uid',$uid) -> update(['default_address'=>0]);
        $data = Db::name('address') -> where('id',$_POST['id']) -> update(['default_address'=>1]);
        if($data){
            return true;
        }else{
            return false;
        }

    }

    /**
     * 删除地址
     */
    public function address_del(){

        $delete_time = time();
        $data = Db::name('address') -> where('id',$_POST['id']) ->  update(['delete_time'=>$delete_time]);
        if($data){
            return true;
        }else{
            return false;
        }

    }

    /**
     * 编辑地址
     */
    public function address_edit(){

        if($this -> request -> isPost()){
            $data_update = Db::name('address') -> update($_POST);
            if($data_update){
               return true;
            }else{
                return false;
            }
        }else{
            $id = $this -> request -> param();
            $data = Db::name('address') -> where('id',$id['id']) -> find();
            $detailed = explode(',',$data['detailed']);
            $data['detailed0'] = $detailed[0];
            $data['detailed1'] = $detailed[1];
            $this -> assign('data',$data);
            return $this -> fetch();
        }

    }

    /**
     * 发送短信
     */
    public function send_message(){

        $url 		= "http://www.ztsms.cn/sendNSms.do";//提交地址
        $username 	= 'xuekaowuyou';//用户名
        $password 	= 'Cxz307312';//原密码
        $sendAPI = new sendAPI($url, $username, $password);
        $key = '';
        $pattern='1234567890';
        for( $i=0; $i<6; $i++ ) {
            $key .= $pattern[mt_rand(0, 9)];
        }
        $rand_name = "验证码:".$key."【学考无忧】";
        $phone = $_POST['phone'];
        $data = array(
            'content' 	=> $rand_name,//短信内容
            'mobile' 	=> $phone,//手机号码
            'productid' => '676767',//产品id
            'xh'		=> ''//小号
        );
        $sendAPI->data = $data;//初始化数据包
        $return = $sendAPI->sendSMS('POST');//GET or POST
        if($return){
           return true;
        }else{
            return false;
        }

    }










}