AllGuaranteeController.php 6.4 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/4
 * Time: 9:11
 */

namespace app\index\controller;


use app\index\model\CollocationModel;
use app\index\model\OrderInfoModel;
use app\index\model\PageHtmlModel;
use app\index\model\SubjoinInsuranceModel;
use app\index\model\UserModel;
use cmf\controller\WeChatBaseController;
use EasyWeChat\Foundation\Application;

//全部保单
class AllGuaranteeController extends WeChatBaseController
{
    //授权
    function _initialize()
    {
        //判断用户是否微信浏览器打开
        $this->isWechat();
        //判断是否手机端
        $this->isMobile();
        //微信授权
        parent::_initialize();
        $this->checkWeChatUserLogin();
        //阻止拉黑用户
        $this->ban();
    }
    public function 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->selectData(array('c.user_id'=>$user_id));//获取到在托管中状态的保单
        //获取第一个被保人的默认信息
        $collocation_data = $orderInfoModel->selectData1(array('c.user_id'=>$user_id,'c.insurer'=>!empty($insurer[0]['insurer']) ? $insurer[0]['insurer'] : null));

        $pageHtmlModel = new PageHtmlModel();
        $page_html = $pageHtmlModel->findData(array('id'=>4));
        $this->assign(
            array(
                '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,
                'collocation_data' => $collocation_data,
                'page_html' => $page_html
            )
        );
        return $this->fetch();
    }
    public function guarantee_info(){
        $options = [
            'app_id' => config('wechat_config.app_id'),
            'secret' => config('wechat_config.secret'),
            'payment' => config('wechat_config.payment'),
        ];
        $app = new Application($options);
        $js = $app->js;
        $jssdk = $js->config(['chooseImage', 'uploadImage', 'previewImage'], $debug = false, $beta = false, $json = true);
        $id = $this->request->param('id');
        $user_id = cmf_get_current_user_id();
        $orderInfoModel = new OrderInfoModel();
        $data = $orderInfoModel->findData(array('o.id'=>$id,'o.user_id'=>$user_id))->toArray();
        $subjoinInsuranceModel = new SubjoinInsuranceModel();
        $subjoin = $subjoinInsuranceModel->selectData2(array('collocation_id'=>$data['id']));
        $this->assign(
            array(
                'jssdk'=>$jssdk,
                'data'=>$data,
                'subjoin'=>$subjoin,
            )
        );
        return $this->fetch();
    }
    public function select_status(){
        $param = $this->request->param();
        $insurer = $param['insurer'];
        $time = time();
        $where['c.insurer'] = ['eq',$insurer];
        $whereor = '';
        if(!empty($param['status'])){//0为全部1为托管中2为即将到期3为未托管
            if($param['status'] == 1){
                $where['o.status'] = ['eq',1];
                $where['c.insurer'] = ['eq',$param['insurer']];
                $where['o.order_about_time'] = ['>',$time];
                $whereor = "o.status = 3 and o.order_about_time > $time and c.insurer ="."'"."$insurer"."'";
            }else if($param['status'] == 2){
                $where['o.status'] = ['eq',3];
                $where['c.insurer'] = ['eq',$param['insurer']];
                $where['o.order_about_time'] = ['<',$time];
                $where['o.order_expire_time'] = ['>',$time];
//                $whereor = "o.status = 3 and o.order_about_time < $time and c.insurer ="."'"."$insurer"."'";
            }else if($param['status'] == 3){
                $where['o.status'] = ['eq',2];
                $where['c.insurer'] = ['eq',$param['insurer']];
                $whereor = "o.status = 3 and o.order_expire_time < $time and c.insurer ="."'"."$insurer"."'";
            }
        }
        $orderInfoModel = new OrderInfoModel();
        $data = $orderInfoModel->selectData1($where,$whereor);
        $data = $this->dispose($data);
        $arr['code'] = 20000;
        $arr['msg'] = 'SUCCESS';
        $arr['data'] = $data;
        return json_encode($arr);
    }
    public function dispose($data){
        foreach($data as $key => $vo){
            $data[$key]['thumbnail'] = cmf_get_image_url($vo['thumbnail']);
            if($vo['remit'] == 1){
                $data[$key]['remit'] = '是';
            }else if($vo['remit'] == 2){
                $data[$key]['remit'] = '否';
            }
            $data[$key]['insurer_time'] = date('Y-m-d',$vo['insurer_time']);
            $data[$key]['take_time'] = date('Y-m-d',$vo['take_time']);
            $data[$key]['o_id'] = cmf_url('me_guarantee/guarantee_info',array('id'=>$vo['o_id']));
        }
        return $data;
    }
}