<?php /** * Created by PhpStorm. * User: Administrator * Date: 2019/1/4 * Time: 11:01 */ namespace app\index\controller; use app\index\model\CollocationModel; use app\index\model\OrderInfoModel; use app\index\model\SubjoinInsuranceModel; use app\index\model\UserModel; use cmf\controller\WeChatBaseController; use EasyWeChat\Foundation\Application; class AgentController extends WeChatBaseController { //授权 function _initialize() { //判断用户是否微信浏览器打开 $this->isWechat(); //判断是否手机端 $this->isMobile(); //微信授权 parent::_initialize(); $this->checkWeChatUserLogin(); //阻止拉黑用户 $this->ban(); } public function index(){ $user = $this->isAgent(); $collocationModel = new CollocationModel(); //共有多少保单 $no_collocation_count = $collocationModel->collocationCount(array('agent_phone'=>$user['mobile2'])); //查询所有保险人 $data = $collocationModel->insurerData(array('agent_phone'=>$user['mobile2']),'application'); $this->assign( array( 'user'=>$user, 'no_collocation_count'=>$no_collocation_count, 'data'=>$data, ) ); return $this->fetch(); } //搜索 public function search(){ $keyword = $this->request->param('keyword',0); $user = $this->isAgent(); $collocationModel = new CollocationModel(); $where['agent_phone'] = ['eq',$user['mobile2']]; $where['insurance_num|application|insurer'] = ['like',"%$keyword%"]; $data = $collocationModel->insurerData($where,'application'); $arr['code'] = 20000; $arr['msg'] = '获取成功!'; $arr['data'] = $data; return json_encode($arr); } public function more(){ $application = $this->request->param('application',0); $user = $this->isAgent(); $collocationModel = new CollocationModel(); $no_collocation_count = $collocationModel->collocationCount(array('application'=>$application,'agent_phone'=>$user['mobile2']));//保单总数 $no_people_count = $collocationModel->peopleCount(array('application'=>$application,'agent_phone'=>$user['mobile2']));//被保人数 $no_main_total_sum = $collocationModel->totalSum(array('application'=>$application,'agent_phone'=>$user['mobile2']));//本年保险支出(主险) $subjoinInsuranceModel = new SubjoinInsuranceModel(); $no_vice_total_sum = $subjoinInsuranceModel->subjoinSum(array('c.application'=>$application,'c.agent_phone'=>$user['mobile2']));//本年保险支出(附加险) $insurer = $collocationModel->insurerData(array('application'=>$application,'agent_phone'=>$user['mobile2']),'insurer'); $orderInfoModel = new OrderInfoModel(); $collocation_data = $orderInfoModel->selectData1(array('c.application'=>$application,'c.insurer'=>$insurer[0]['insurer'],'c.agent_phone'=>$user['mobile2'])); $this->assign( array( 'no_collocation_count' => $no_collocation_count, 'no_people_count' => $no_people_count, 'no_total_sum' => $no_main_total_sum+$no_vice_total_sum, 'application'=>$application, 'insurer'=>$insurer, 'collocation_data' => $collocation_data, 'agent_phone'=>$user['mobile2'], ) ); return $this->fetch(); } //进入保单信息页面 public function application_information(){ $param = $this->request->param(); $user_id = cmf_get_current_user_id(); $this->isAgent(); $collocationModel = new CollocationModel(); //获取全部的被保人 $insurer = $collocationModel->insurerData(array('application'=>$param['application']),"insurer"); //获取保单总数 $collocation_count = $collocationModel->collocationCount(array('application'=>$param['application'])); //获取本年保险支出 $no_main_total_sum = $collocationModel->totalSum(array('application'=>$param['application']));//本年保险支出(主险) $subjoinInsuranceModel = new SubjoinInsuranceModel(); $no_vice_total_sum = $subjoinInsuranceModel->subjoinSum(array('application'=>$param['application']));//本年保险支出(附加险) $total_sum = $no_main_total_sum+$no_vice_total_sum; //获取默认显示保单信息 $orderInfoModel = new OrderInfoModel(); $collocation = $orderInfoModel->selectData(array('c.application'=>$param['application'])); dump($insurer); dump($collocation_count); dump($total_sum); dump($collocation); } 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'); $orderInfoModel = new OrderInfoModel(); $data = $orderInfoModel->findData(array('o.id'=>$id)); $subjoinInsuranceModel = new SubjoinInsuranceModel(); $subjoin = $subjoinInsuranceModel->findData(array('collocation_id'=>$data['id'])); $this->assign( array( 'data'=>$data, 'subjoin'=>$subjoin, 'jssdk'=>$jssdk, ) ); return $this->fetch(); } //获取当前代理人的手机号 public function get_agent_mobile(){ $user_id = cmf_get_current_user_id(); $userModel = new UserModel(); $user = $userModel->findUserData(array('id'=>$user_id)); return $user['mobile2']; } }