审查视图

app/index/controller/MeGuaranteeController.php 12.7 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 MeGuaranteeController 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
        //微信授权
        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));//托管中状态的本年保险支出(附加险)
王晓刚 authored
52
        $insurer = $collocationModel->insurerData(array('user_id'=>$user_id),"insurer");//获取全部保险人
王晓刚 authored
53
        $collocation = $orderInfoModel->selectData(array('c.user_id'=>$user_id));//获取到在托管中状态的保单
王晓刚 authored
54
        //获取第一个被保人的默认信息
王晓刚 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
        $pageHtmlModel = new PageHtmlModel();
        $page_html = $pageHtmlModel->findData(array('id'=>4));
王晓刚 authored
58 59 60 61 62 63 64 65 66 67
        $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,
王晓刚 authored
68
                'collocation_data' => $collocation_data,
王晓刚 authored
69
                'page_html'=>$page_html,
王晓刚 authored
70 71 72 73 74
            )
        );
        return $this->fetch();
    }
    public function guarantee_info(){
王晓刚 authored
75 76 77 78 79 80 81
        $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;
王晓刚 authored
82
        $jssdk = $js->config(['chooseImage', 'uploadImage', 'previewImage'], $debug = false, $beta = false, $json = true);
王晓刚 authored
83 84 85
        $id = $this->request->param('id');
        $user_id = cmf_get_current_user_id();
        $orderInfoModel = new OrderInfoModel();
王晓刚 authored
86
        $data = $orderInfoModel->findData(array('o.id'=>$id,'o.user_id'=>$user_id))->toArray();
王晓刚 authored
87
        $subjoinInsuranceModel = new SubjoinInsuranceModel();
王晓刚 authored
88
        $subjoin = $subjoinInsuranceModel->selectData2(array('collocation_id'=>$data['id']));
王晓刚 authored
89 90
        $this->assign(
            array(
王晓刚 authored
91
                'jssdk'=>$jssdk,
王晓刚 authored
92 93
                'data'=>$data,
                'subjoin'=>$subjoin,
王晓刚 authored
94 95
            )
        );
王晓刚 authored
96 97 98 99
        return $this->fetch();
    }
    public function select_status(){
        $param = $this->request->param();
王晓刚 authored
100 101 102 103 104 105
        if(!empty($param['application'])){
            $where['c.application'] = ['eq',$param['application']];
        }
        if(!empty($param['agent_phone'])){
            $where['c.agent_phone'] = ['eq',$param['agent_phone']];
        }
王晓刚 authored
106
        $user_id = cmf_get_current_user_id();
王晓刚 authored
107 108
        $insurer = $param['insurer'];
        $time = time();
王晓刚 authored
109 110
//        $where['c.insurer'] = ['eq',$insurer];
        $where = [];
王晓刚 authored
111 112 113 114 115
        $whereor = '';
        if(!empty($param['status'])){//0为全部1为托管中2为即将到期3为未托管
            if($param['status'] == 1){
                $where['o.status'] = ['eq',1];
                $where['c.insurer'] = ['eq',$param['insurer']];
王晓刚 authored
116 117
//                $where['o.order_about_time'] = ['>',$time];
//                $where['o.order_expire_time2'] = ['>',$time];
王晓刚 authored
118
                if(!empty($param['application']) && !empty($param['agent_phone'])){
王晓刚 authored
119
                    $whereor = "o.status = 3 and o.order_expire_time2 > ".$time." and c.application = "."'"."$param[application]"."'"." and c.agent_phone = $param[agent_phone] and c.insurer ="."'"."$insurer"."'";
王晓刚 authored
120
                }else if(!empty($param['application'])){
王晓刚 authored
121
                    $whereor = "o.status = 3 and o.order_expire_time2 > ".$time." and c.application = "."'"."$param[application]"."'"." and c.insurer ="."'"."$insurer"."'";
王晓刚 authored
122
                }else if(!empty($param['agent_phone'])){
王晓刚 authored
123
                    $whereor = "o.status = 3 and o.order_expire_time2 > ".$time." and c.agent_phone = $param[agent_phone] and c.insurer ="."'"."$insurer"."'";
王晓刚 authored
124
                }else{
王晓刚 authored
125
                    $where['o.user_id'] = ['eq',$user_id];
王晓刚 authored
126
                    $whereor = "o.user_id = $user_id and o.status = 3 and o.order_expire_time2 > ".$time." and c.insurer ="."'"."$insurer"."'";
王晓刚 authored
127
                }
王晓刚 authored
128 129 130
            }else if($param['status'] == 2){
                $where['o.status'] = ['eq',3];
                $where['c.insurer'] = ['eq',$param['insurer']];
王晓刚 authored
131
                $where['o.order_expire_time2'] = ['>',$time];
王晓刚 authored
132
                $where['o.order_about_time'] = array(array('<',$time),array('>',$time-30*24*60*60));//array(array('gt',1),array('lt',10))
王晓刚 authored
133 134 135 136 137 138 139 140 141 142
                if(!empty($param['application']) && !empty($param['agent_phone'])){
                    $whereor = "o.status = 1 and c.insurer = "."'".$insurer."'"." and o.order_about_time < $time and o.order_about_time > ".($time-30*24*60*60)." and o.order_expire_time2 > $time and c.application = "."'"."$param[application]"."'"." and c.agent_phone = $param[agent_phone]";
                }else if(!empty($param['application'])){
                    $whereor = "o.status = 1 and c.insurer = "."'".$insurer."'"." and o.order_about_time < $time and o.order_about_time > ".($time-30*24*60*60)." and o.order_expire_time2 > $time and c.application = "."'"."$param[application]"."'"."";
                }else if(!empty($param['agent_phone'])){
                    $whereor = "o.status = 1 and c.insurer = "."'".$insurer."'"." and o.order_about_time < $time and o.order_about_time > ".($time-30*24*60*60)." and o.order_expire_time2 > $time and c.agent_phone = $param[agent_phone]";
                }else{
                    $where['o.user_id'] = ['eq',$user_id];
                    $whereor = "o.user_id = $user_id and o.status = 1 and c.insurer = "."'".$insurer."'"." and o.order_about_time < $time and o.order_about_time > ".($time-30*24*60*60)." and o.order_expire_time2 > $time";
                }
王晓刚 authored
143
            }else if($param['status'] == 3){
王晓刚 authored
144
//                $where['o.status'] = ['eq',2];
王晓刚 authored
145
//                $where['c.insurer'] = ['eq',$param['insurer']];
王晓刚 authored
146
//                $where['o.order_expire_time2'] = ['<',$time];
王晓刚 authored
147
                if(!empty($param['application']) && !empty($param['agent_phone'])){
王晓刚 authored
148
                    $whereor = "(o.status = 3 and o.order_expire_time2 < $time and c.insurer ="."'"."$insurer"."'"." and c.application = "."'"."$param[application]"."'"." and c.agent_phone = $param[agent_phone]) or (o.status = 1 and c.insurer ="."'"."$insurer"."'"." and c.application = "."'"."$param[application]"."'"." and c.agent_phone = $param[agent_phone])";
王晓刚 authored
149
                    //$whereor = "(o.user_id = $user_id and o.status = 2 and o.delete_time = 0 and o.order_expire_time2 < $time) or (o.user_id = $user_id and o.status = 1 and c.insurer ="."'"."$insurer"."'"." and o.order_about_time < ".($time-24*30*60*60)." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and c.application = "."'"."$param[application]"."'"." and c.agent_phone = $param[agent_phone] and c.insurer ="."'"."$insurer"."'"."and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and o.order_about_time < ".($time-24*30*60*60)." and c.insurer ="."'"."$insurer"."'and o.delete_time = 0)";
王晓刚 authored
150
                }else if(!empty($param['application'])){
王晓刚 authored
151
                    $whereor = "(o.status = 3 and o.order_expire_time2 < $time and c.insurer ="."'"."$insurer"."'"." and c.application = "."'"."$param[application]"."'".") or (o.status = 1 and c.insurer ="."'"."$insurer"."'"." and c.application = "."'"."$param[application]"."'".")";
王晓刚 authored
152
//                    $whereor = "(o.user_id = $user_id and o.status = 2 and o.delete_time = 0 and o.order_expire_time2 < $time) or (o.user_id = $user_id and o.status = 1 and c.insurer ="."'"."$insurer"."'"." and o.order_about_time < ".($time-24*30*60*60)." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and c.application = "."'"."$param[application]"."'"." and c.insurer ="."'"."$insurer"."'"." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and o.order_about_time < ".($time-24*30*60*60)." and c.insurer ="."'"."$insurer"."' and o.delete_time = 0)";
王晓刚 authored
153
                }else if(!empty($param['agent_phone'])){
王晓刚 authored
154
                    $whereor = "(o.status = 3 and o.order_expire_time2 < $time and c.insurer ="."'"."$insurer"."'"." and c.agent_phone = $param[agent_phone]) or (o.status = 1 and c.insurer ="."'"."$insurer"."'"." and c.agent_phone = $param[agent_phone])";
王晓刚 authored
155
//                    $whereor = "(o.user_id = $user_id and o.status = 2 and o.delete_time = 0 and o.order_expire_time2 < $time) or (o.user_id = $user_id and o.status = 1 and c.insurer ="."'"."$insurer"."'"." and o.order_about_time < ".($time-24*30*60*60)." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and c.agent_phone = $param[agent_phone] and c.insurer ="."'"."$insurer"."'"." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and o.order_about_time < ".($time-24*30*60*60)." and c.insurer ="."'"."$insurer"."'and o.delete_time = 0)";
王晓刚 authored
156
                }else{
王晓刚 authored
157
                    $whereor = "(o.user_id = $user_id and o.status = 3 and o.order_expire_time2 < $time and c.insurer ="."'"."$insurer"."'".")";
王晓刚 authored
158
//                    $whereor = "(o.user_id = $user_id and o.status = 2 and o.delete_time = 0 and o.order_expire_time2 < $time) or (o.user_id = $user_id and o.status = 1 and c.insurer ="."'"."$insurer"."'"." and o.order_about_time < ".($time-24*30*60*60)." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and o.order_about_time < ".($time-24*30*60*60)." and c.insurer ="."'"."$insurer"."')";
王晓刚 authored
159
                    //$whereor = "(o.status = 2 and o.delete_time = 0) or (o.order_expire_time < $time ) or (o.status = 1 and o.order_about_time < ".($time-24*30*60*60)." and o.delete_time = 0) or (o.status = 3 and o.order_about_time < ".($time-24*30*60*60)." and o.delete_time = 0)";
王晓刚 authored
160
                }
王晓刚 authored
161
            }
王晓刚 authored
162
        }else{
王晓刚 authored
163 164 165
            if(empty($param['application']) || empty($param['agent_phone'])){
                $where['o.user_id'] = ['eq',$user_id];
            }
王晓刚 authored
166
            $where['c.insurer'] = ['eq',$insurer];
王晓刚 authored
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
        }
        $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]['take_time'] = date('Y-m-d',$vo['take_time']);
王晓刚 authored
185
            $data[$key]['insurer_time'] = date('Y-m-d',$vo['insurer_time']);
王晓刚 authored
186 187
        }
        return $data;
王晓刚 authored
188 189
    }
}