审查视图

app/index/controller/AllGuaranteeController.php 6.4 KB
王晓刚 authored
1 2 3 4 5 6 7 8 9 10 11 12 13
<?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;
王晓刚 authored
14
use app\index\model\PageHtmlModel;
王晓刚 authored
15 16 17
use app\index\model\SubjoinInsuranceModel;
use app\index\model\UserModel;
use cmf\controller\WeChatBaseController;
王晓刚 authored
18
use EasyWeChat\Foundation\Application;
王晓刚 authored
19 20 21 22 23 24 25 26

//全部保单
class AllGuaranteeController extends WeChatBaseController
{
    //授权
    function _initialize()
    {
        //判断用户是否微信浏览器打开
王晓刚 authored
27
        $this->isWechat();
王晓刚 authored
28
        //判断是否手机端
王晓刚 authored
29
        $this->isMobile();
王晓刚 authored
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
        //微信授权
        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));//获取到在托管中状态的保单
        //获取第一个被保人的默认信息
王晓刚 authored
55
        $collocation_data = $orderInfoModel->selectData1(array('c.user_id'=>$user_id,'c.insurer'=>!empty($insurer[0]['insurer']) ? $insurer[0]['insurer'] : null));
王晓刚 authored
56 57 58

        $pageHtmlModel = new PageHtmlModel();
        $page_html = $pageHtmlModel->findData(array('id'=>4));
王晓刚 authored
59 60 61 62 63 64 65 66 67 68 69
        $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,
王晓刚 authored
70
                'page_html' => $page_html
王晓刚 authored
71 72 73 74 75
            )
        );
        return $this->fetch();
    }
    public function guarantee_info(){
王晓刚 authored
76 77 78 79 80 81 82 83
        $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);
王晓刚 authored
84 85 86
        $id = $this->request->param('id');
        $user_id = cmf_get_current_user_id();
        $orderInfoModel = new OrderInfoModel();
王晓刚 authored
87
        $data = $orderInfoModel->findData(array('o.id'=>$id,'o.user_id'=>$user_id))->toArray();
王晓刚 authored
88
        $subjoinInsuranceModel = new SubjoinInsuranceModel();
王晓刚 authored
89
        $subjoin = $subjoinInsuranceModel->selectData2(array('collocation_id'=>$data['id']));
王晓刚 authored
90 91
        $this->assign(
            array(
王晓刚 authored
92
                'jssdk'=>$jssdk,
王晓刚 authored
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
                '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];
王晓刚 authored
110
                $whereor = "o.status = 3 and o.order_about_time > $time and c.insurer ="."'"."$insurer"."'";
王晓刚 authored
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
            }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;
    }
}