MeTrusteeshipController.php 17.3 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/27
 * Time: 16:21
 */

namespace app\index\controller;


use app\index\model\CodeModel;
use app\index\model\CollocationModel;
use app\index\model\OrderInfoModel;
use app\index\model\OrderModel;
use app\index\model\PageHtmlModel;
use app\index\model\QuestionModel;
use app\index\model\SubjoinInsuranceModel;
use app\index\model\UserModel;
use app\index\server\IndexServer;
use cmf\controller\WeChatBaseController;

class MeTrusteeshipController extends WeChatBaseController
{
    //授权
    function _initialize()
    {
        //判断用户是否微信浏览器打开
        $this->isWechat();
        //判断是否手机端
        $this->isMobile();
        //微信授权
        parent::_initialize();
        $this->checkWeChatUserLogin();
        //阻止拉黑用户
        $this->ban();
    }
    //进入我的托管页面
    public function index(){
        $result1 = $this->isRegister();
        if(empty($result1)){
            //重定向到注册页面
            $this->redirect('user_register_mobile/index');
        }
        $result2 = $this->isQuestion();
        if(empty($result2)){
            //重定向到问卷调查
            $this->redirect('question/index');
        }
        $user_id = cmf_get_current_user_id();
        $userModel = new UserModel();
        $user = $userModel->findUserData(array('id'=>$user_id));
        $collocationModel = new CollocationModel();
        $no_collocation_count = $collocationModel->collocationCount(array('user_id'=>$user_id));//保单总数
        $no_people_count = $collocationModel->peopleCount(array('user_id'=>$user_id));//被保人数
        $no_main_total_sum = $collocationModel->totalSum(array('user_id'=>$user_id));//本年保险支出(主险)
        $subjoinInsuranceModel = new SubjoinInsuranceModel();
        $no_vice_total_sum = $subjoinInsuranceModel->subjoinSum(array('s.user_id'=>$user_id));//本年保险支出(附加险)
        //已托管的保单信息
        $orderInfoModel = new OrderInfoModel();
        $yes_collocation_count = $orderInfoModel->collocationCount(array('c.user_id'=>$user_id));//托管中状态的保单份数
        $yes_people_count = $orderInfoModel->peopleCount(array('c.user_id'=>$user_id));//托管中状态的被保人数
        $yes_main_total_sum = $orderInfoModel->totalSum(array('c.user_id'=>$user_id));//托管中状态的本年保险支出(主险)
        $yes_vice_total_sum = $orderInfoModel->subjoinSum(array('c.user_id'=>$user_id));//托管中状态的本年保险支出(附加险)
        $insurer = $collocationModel->insurerData(array('user_id'=>$user_id),"insurer");//获取全部保险人
        $collocation = $orderInfoModel->selectData1(array('c.user_id'=>$user_id));//获取到在托管中状态的保单
        //获取第一个保险人的默认信息
        $insurer_one = !empty($insurer[0]['insurer']) ? $insurer[0]['insurer'] : '';
        $time = time();
//        $whereor1 = "o.status = 1 and c.expire_time > $time and c.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and c.insurance_type_id = 1";
//        $whereor2 = "o.status = 1 and c.expire_time > $time and c.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and c.insurance_type_id = 2";
//        $whereor3 = "o.status = 1 and c.expire_time > $time and c.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and c.insurance_type_id = 3";
//        $whereor4 = "o.status = 1 and c.expire_time > $time and c.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and c.insurance_type_id = 4";
//        $whereor5 = "o.status = 1 and c.expire_time > $time and c.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and c.insurance_type_id = 5";
//        $whereor6 = "o.status = 1 and c.expire_time > $time and c.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and c.insurance_type_id = 6";
        $one_collocation_data_one = $orderInfoModel->selectData(
            array(
                'c.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                'c.insurance_type_id'=>1
            )
//            $whereor1
        );//获取第一个人的主保单类型信息$where1['o.order_expire_time'] = ['>',time()];
        $one_collocation_data_two = $orderInfoModel->selectData(
            array(
                'c.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                'c.insurance_type_id'=>2
            )
//            $whereor2
        );
        $one_collocation_data_three = $orderInfoModel->selectData(
            array(
                'c.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                'c.insurance_type_id'=>3
            )
//            $whereor3
        );
        $one_collocation_data_four = $orderInfoModel->selectData(
            array(
                'c.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                'c.insurance_type_id'=>4
            )
//            $whereor4
        );
        $one_collocation_data_five = $orderInfoModel->selectData(
            array(
                'c.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                'c.insurance_type_id'=>5
            )
//            $whereor5
        );
        $one_collocation_data_six = $orderInfoModel->selectData(
            array(
                'c.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                'c.insurance_type_id'=>6
            )
//            $whereor6
        );

//        $subjoin_whereor1 = "o.status = 1 and c.expire_time > $time and s_i.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and s_i.insurance_type_id = 1";
//        $subjoin_whereor2 = "o.status = 1 and c.expire_time > $time and s_i.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and s_i.insurance_type_id = 2";
//        $subjoin_whereor3 = "o.status = 1 and c.expire_time > $time and s_i.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and s_i.insurance_type_id = 3";
//        $subjoin_whereor4 = "o.status = 1 and c.expire_time > $time and s_i.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and s_i.insurance_type_id = 4";
//        $subjoin_whereor5 = "o.status = 1 and c.expire_time > $time and s_i.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and s_i.insurance_type_id = 5";
//        $subjoin_whereor6 = "o.status = 1 and c.expire_time > $time and s_i.user_id = $user_id and o.delete_time = 0 and c.insurer = '$insurer_one' and s_i.insurance_type_id = 6";
        $one_subjoin_data_one = $subjoinInsuranceModel->selectData(
            array(
                's_i.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                's_i.insurance_type_id'=>1,
            )
//            $subjoin_whereor1
        );//获取第一个人的附加保单类型信息
        $one_subjoin_data_two = $subjoinInsuranceModel->selectData(
            array(
                's_i.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                's_i.insurance_type_id'=>2
            )
//            $subjoin_whereor2
        );
        $one_subjoin_data_three = $subjoinInsuranceModel->selectData(
            array(
                's_i.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                's_i.insurance_type_id'=>3
            )
//            $subjoin_whereor3
        );
        $one_subjoin_data_four = $subjoinInsuranceModel->selectData(
            array(
                's_i.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                's_i.insurance_type_id'=>4
            )
//            $subjoin_whereor4
        );
        $one_subjoin_data_five = $subjoinInsuranceModel->selectData(
            array(
                's_i.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                's_i.insurance_type_id'=>5
            )
//            $subjoin_whereor5
        );
        $one_subjoin_data_six = $subjoinInsuranceModel->selectData(
            array(
                's_i.user_id'=>$user_id,
                'c.insurer'=>$insurer_one,
                's_i.insurance_type_id'=>6
            )
//            $subjoin_whereor6
        );

        $data_one = array_merge($one_collocation_data_one,$one_subjoin_data_one);
        $data_one = $this->regroup($data_one,1);
        $data_two = array_merge($one_collocation_data_two,$one_subjoin_data_two);
        $data_two = $this->regroup($data_two,2);
        $data_three = array_merge($one_collocation_data_three,$one_subjoin_data_three);
        $data_three = $this->regroup($data_three,3);
        $data_four = array_merge($one_collocation_data_four,$one_subjoin_data_four);
        $data_four = $this->regroup($data_four,4);
        $data_five = array_merge($one_collocation_data_five,$one_subjoin_data_five);
        $data_five = $this->regroup($data_five,5);
        $data_six = array_merge($one_collocation_data_six,$one_subjoin_data_six);
        $data_six = $this->regroup($data_six,6);


        $pageHtmlModel = new PageHtmlModel();
        $page_html = $pageHtmlModel->findData(array('id'=>4));
        $this->assign(
            array(
                'title'=>"我的托管",
                'user' => $user,
                'no_collocation_count' => $no_collocation_count,
                'no_people_count' => $no_people_count,
                'no_total_sum' => $no_main_total_sum+$no_vice_total_sum,
                'yes_collocation_count' => $yes_collocation_count,
                'yes_people_count' => $yes_people_count,
                'yes_total_sum' => $yes_main_total_sum+$yes_vice_total_sum,
                'insurer' => $insurer,
                'data_one' => $data_one,
                'data_two' => $data_two,
                'data_three' => $data_three,
                'data_four' => $data_four,
                'data_five' => $data_five,
                'data_six' => $data_six,
                'one_collocation_data_six' => $one_collocation_data_six,
                'one_subjoin_data_one' => $one_subjoin_data_one,
                'one_subjoin_data_two' => $one_subjoin_data_two,
                'one_subjoin_data_three' => $one_subjoin_data_three,
                'one_subjoin_data_four' => $one_subjoin_data_four,
                'one_subjoin_data_five' => $one_subjoin_data_five,
                'one_subjoin_data_six' => $one_subjoin_data_six,
                'page_html' => $page_html,
            )
        );
        return $this->fetch();
//        dump($no_collocation_count);
//        dump($no_people_count);
//        dump($no_main_total_sum+$no_vice_total_sum);
//        dump($yes_collocation_count);
//        dump($yes_people_count);
//        dump($yes_main_total_sum+$yes_vice_total_sum);
//        dump($insurer);
//        dump($collocation);
//        dump($one_collocation_data);
    }
    //箭头
    public function arrows(){
        $user_id = cmf_get_current_user_id();
        $param = $this->request->param();
        //获取当前用户的问卷调查
        $questionModel = new QuestionModel();
        $question = $questionModel->findData(array('user_id'=>$user_id));
        if(empty($question)){
            $arr['code'] = 40001;
            $arr['msg'] = "问卷调查未填写!";
            return json_encode($arr);
        }
        //获取填写验证码时输入的姓名
        $userModel = new UserModel();
        $user = $userModel->findUserData(array('id'=>$user_id));
        if(empty($user)){
            $arr['code'] = 40002;
            $arr['msg'] = "未注册手机号!";
            return json_encode($arr);
        }
        $subjoinInsuranceModel = new SubjoinInsuranceModel();
        $orderInfoModel = new OrderInfoModel();
        $collocation_data = $orderInfoModel->selectData(
            array(
                'c.user_id'=>$user_id,
                'c.insurer'=>$param['insurer'],
                'c.insurance_type_id'=>$param['insurance_type_id']
            )
        );
        $subjoin_data_one = $subjoinInsuranceModel->selectData(array('s_i.insurance_type_id'=>$param['insurance_type_id'],'s_i.user_id'=>$user_id,'c.insurer'=>$param['insurer']));
        $data = array_merge($collocation_data,$subjoin_data_one);
        $data = $this->regroup($data,$param['insurance_type_id'],$question,$user);
        $arr['code'] = 20000;
        $arr['msg'] = '获取成功!';
        $arr['data'] = $data;
        return json_encode($arr);
    }
    //切换被保人
    public function select_insurer(){
        $user_id = cmf_get_current_user_id();
        $insurer = $this->request->param('insurer');
        //获取当前用户的问卷调查
        $questionModel = new QuestionModel();
        $question = $questionModel->findData(array('user_id'=>$user_id));
        if(empty($question)){
            $arr['code'] = 40001;
            $arr['msg'] = "问卷调查未填写!";
            return json_encode($arr);
        }
        //获取填写验证码时输入的姓名
        $userModel = new UserModel();
        $user = $userModel->findUserData(array('id'=>$user_id));
        if(empty($user)){
            $arr['code'] = 40002;
            $arr['msg'] = "未注册手机号!";
            return json_encode($arr);
        }
//        $orderInfoModel = new OrderInfoModel();
//        $insurance = $orderInfoModel->selectData(array('c.user_id'=>$user_id,'c.insurer'=>$insurer));
//        $subjoinInsuranceModel = new SubjoinInsuranceModel();
//        $subjoin = $subjoinInsuranceModel->selectData(array('s_i.user_id'=>$user_id,'c.insurer'=>$insurer));
//        $indexServer = new IndexServer();
//        $data = $indexServer->main_arrows($insurance,$subjoin,$question,$user);
        $subjoinInsuranceModel = new SubjoinInsuranceModel();
        $orderInfoModel = new OrderInfoModel();
        $collocation_data_one = $orderInfoModel->selectData(array('c.user_id'=>$user_id,'c.insurer'=>$insurer,'c.insurance_type_id'=>1));
        $collocation_data_two = $orderInfoModel->selectData(array('c.user_id'=>$user_id,'c.insurer'=>$insurer,'c.insurance_type_id'=>2));
        $collocation_data_three = $orderInfoModel->selectData(array('c.user_id'=>$user_id,'c.insurer'=>$insurer,'c.insurance_type_id'=>3));
        $collocation_data_four = $orderInfoModel->selectData(array('c.user_id'=>$user_id,'c.insurer'=>$insurer,'c.insurance_type_id'=>4));
        $collocation_data_five = $orderInfoModel->selectData(array('c.user_id'=>$user_id,'c.insurer'=>$insurer,'c.insurance_type_id'=>5));
        $collocation_data_six = $orderInfoModel->selectData(array('c.user_id'=>$user_id,'c.insurer'=>$insurer,'c.insurance_type_id'=>6));

        $subjoin_data_one = $subjoinInsuranceModel->selectData(array('s_i.user_id'=>$user_id,'c.insurer'=>$insurer,'s_i.insurance_type_id'=>1));
        $subjoin_data_two = $subjoinInsuranceModel->selectData(array('s_i.user_id'=>$user_id,'c.insurer'=>$insurer,'s_i.insurance_type_id'=>2));
        $subjoin_data_three = $subjoinInsuranceModel->selectData(array('s_i.user_id'=>$user_id,'c.insurer'=>$insurer,'s_i.insurance_type_id'=>3));
        $subjoin_data_four = $subjoinInsuranceModel->selectData(array('s_i.user_id'=>$user_id,'c.insurer'=>$insurer,'s_i.insurance_type_id'=>4));
        $subjoin_data_five = $subjoinInsuranceModel->selectData(array('s_i.user_id'=>$user_id,'c.insurer'=>$insurer,'s_i.insurance_type_id'=>5));
        $subjoin_data_six = $subjoinInsuranceModel->selectData(array('s_i.user_id'=>$user_id,'c.insurer'=>$insurer,'s_i.insurance_type_id'=>6));
        $data_one = array_merge($collocation_data_one,$subjoin_data_one);
        $data_one = $this->regroup($data_one,1);
        $data_two = array_merge($collocation_data_two,$subjoin_data_two);
        $data_two = $this->regroup($data_two,2);
        $data_three = array_merge($collocation_data_three,$subjoin_data_three);
        $data_three = $this->regroup($data_three,3);
        $data_four = array_merge($collocation_data_four,$subjoin_data_four);
        $data_four = $this->regroup($data_four,4);
        $data_five = array_merge($collocation_data_five,$subjoin_data_five);
        $data_five = $this->regroup($data_five,5);
        $data_six = array_merge($collocation_data_six,$subjoin_data_six);
        $data_six = $this->regroup($data_six,6);
        $data['data_one'] = $data_one;
        $data['data_two'] = $data_two;
        $data['data_three'] = $data_three;
        $data['data_four'] = $data_four;
        $data['data_five'] = $data_five;
        $data['data_six'] = $data_six;
        $arr['code'] = 20000;
        $arr['msg'] = '获取成功!';
        $arr['data'] = $data;
        return json_encode($arr);
    }

    public function regroup2($data){
        $arr = [];
        $result = [];
        foreach($data as $key => $vo){
            $result1 = [];
            $result2 = [];


            foreach($vo as $k=>$v){

                $result1[] = $v['subjoin_price'];
                if($v['order_expire_time'] > time()){
                    $result2[] = $v['subjoin_price'];
                }
            }

            $arr['name'] = $key;
            $arr['sum'] = array_sum($result2);
            if(empty($result1)){//未有保单
                $arr['type'] = 1;
            }else if(empty($result2)){//保障缺失
                $arr['type'] = 2;
            }else{
                $arr['type'] = 3;
            }
            $result[] = $arr;
        }

        return $result;
    }
}