123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <?php
- /**
- * 保险
- */
- namespace app\api\controller;
- use app\admin\controller\InsurancePersonal;
- use app\admin\model\Category;
- use app\admin\model\Company;
- use app\admin\model\InsuranceEnterprise;
- use app\admin\model\InsuranceInfo;
- use app\admin\model\InsuranceMedical;
- use app\admin\model\InsuranceMedicalList;
- use app\admin\model\InsuranceProperty;
- use app\admin\model\Product;
- use app\admin\model\ProductRanking;
- use app\common\controller\Api;
- use think\Config;
- class Insurance extends Api{
- protected $noNeedLogin = '*';
- protected $noNeedRight = '*';
- /**
- * 首页获取排行榜
- */
- public function getRanking(){
- $type = $this->request->post("type");
- //产品排行
- if($type == 1){
- $list = Product::field('id,name,sort')->order('sort asc')->select();
- // if($list){
- // foreach ($list as $key=>$value){
- // $list[$key]['name'] = $value['product_name'];
- // unset($list[$key]['product_name']);
- // }
- // }
- $this->success(__('成功'),$list);
- }
- //个人保险
- if($type == 2){
- //$list = \app\admin\model\InsurancePersonal::field('id,name,label,sort')->order('sort asc')->select();
- $list = Category::where(array('pid'=>1))->select();
- $new_list = [];
- if($list){
- foreach ($list as $key=>$value){
- $new_list[$key]['id'] = $value['id'];
- $new_list[$key]['name'] = $value['name'];
- $new_list[$key]['label'] = $value['nickname'];
- $new_list[$key]['sort'] = 0;
- }
- }
- $this->success(__('成功'),$new_list);
- }
- //企业保险
- if($type == 3){
- //$list = InsuranceEnterprise::field('id,name,label,sort')->order('sort asc')->select();
- $list = Category::where(array('pid'=>3))->select();
- $new_list = [];
- if($list){
- foreach ($list as $key=>$value){
- $new_list[$key]['id'] = $value['id'];
- $new_list[$key]['name'] = $value['name'];
- $new_list[$key]['label'] = $value['nickname'];
- $new_list[$key]['sort'] = 0;
- }
- }
- $this->success(__('成功'),$new_list);
- }
- //财产保险
- if($type == 4){
- //$list = InsuranceProperty::field('id,name,label,sort')->order('sort asc')->select();
- $list = Category::where(array('pid'=>2))->select();
- $new_list = [];
- if($list){
- foreach ($list as $key=>$value){
- $new_list[$key]['id'] = $value['id'];
- $new_list[$key]['name'] = $value['name'];
- $new_list[$key]['label'] = $value['nickname'];
- $new_list[$key]['sort'] = 0;
- }
- }
- $this->success(__('成功'),$new_list);
- }
- $this->error(__('参数错误'));
- }
- /**
- * 查询首页二级分类
- */
- public function getIndexSecondaryClassification(){
- $first_ids = Category::where(array('pid'=>0))->order('sort desc')->field('id')->select();
- $ids = array_column($first_ids, 'id');
- // foreach ($first_ids as $key=>$value){
- // $ids[$key]
- // }
- $secondaryList = Category::where('pid','in',$ids)->field('id,name,sort')->order('sort asc')->select();
- if($secondaryList){
- foreach ($secondaryList as $key=>$value){
- $subordinate = Category::where(array('pid'=>$value['id']))->field('id,name,sort')->page(1,4)->select();
- if($subordinate){
- $last_names = array_column($subordinate,'sort');
- array_multisort($last_names,SORT_ASC,$subordinate);
- }
- $secondaryList[$key]['subordinate'] = $subordinate;
- }
- }
- $this->success(__('成功'),$secondaryList);
- }
- /**
- * 查看三级分类更多列表接口
- */
- public function lookSecondaryList(){
- $id = $this->request->post("id",0); //二级分类的id
- $p = input("p",0);
- $list = Category::where(array('pid'=>$id))->field('id,name')->order('sort asc')->page($p,20)->select();
- $this->success(__('成功'),$list);
- }
-
- public function lookthird(){
- $p = input("p",0);
- $first_ids = Category::where(array('pid'=>0))->order('sort desc')->field('id')->select();
- $ids = array_column($first_ids, 'id');
- // foreach ($first_ids as $key=>$value){
- // $ids[$key]
- // }
- $secondaryList = Category::where('pid','in',$ids)->field('id')->order('sort asc')->select();
- $sids = array_column($secondaryList, 'id');
-
- $thirdlist = Category::where('pid','in',$sids)->field('id,name,sort')->order('sort asc')->select();
-
-
- $this->success(__('成功'),$thirdlist);
- }
- /**
- * 查询产品列表接口
- */
- public function getProductList(){
- $id = $this->request->post("id",0); //分类的id
- $p = $this->request->post("p",0);
- $list = Product::where(array('category_id'=>$id,'status'=>0))->order('sort desc')->page($p,20)->select();
- if($list){
- foreach ($list as $key=>$value){
- $list[$key]['p_image'] = 'http://'.$_SERVER['HTTP_HOST'].'/'.$value['p_image'];
- $list[$key]['content'] = json_decode($value['content'],true);
- }
- }
- $this->success(__('成功'),$list);
- }
- /**
- * 获取 个人保险 企业保险 财产保险 产品 接口
- */
- public function getIndexUpperList(){
- $type = $this->request->post("type",0);
- //分类的id
- $id = $this->request->post("id",0);
- $p = $this->request->post("p",0);
- //个人保险
- // if($type == 1){
- // $model = new \app\admin\model\InsurancePersonal();
- // }
- // //企业保险
- // else if($type == 2){
- // $model = new InsuranceEnterprise();
- // }
- // //财产保险
- // else if($type == 3){
- // $model = new InsuranceProperty();
- // }
- //
- // else{
- // $this->error(__('参数错误'));
- // }
- $list = Product::where(array('category_id'=>$id))
- ->order('sort asc')->page($p,20)->select();
- $this->success(__('成功'),$list);
- }
- /**
- * 获取医疗险排行榜
- */
- public function getMedicalList(){
- $type = $this->request->post("type",0); //1 疾病意外医疗推荐排行榜 2意外伤害险推荐排行榜
- $p = $this->request->post("p",1);
- $more = $this->request->post("more",0); //是否查看更多
- if($more == 1){
- //查看更多
- $rows = 20;
- }else{
- $rows = 3;
- }
- // if($type == 1){
- // $where['optionlist'] = '疾病意外医疗险推荐排行榜';
- // }else{
- // $where['optionlist'] = '意外伤害险推荐排行榜';
- // }
- if($type == 1){
- $where['id'] = 9;
- }else{
- $where['id'] = 22;
- }
- $list = Category::where($where)->page($p,$rows)->select();
- $this->success(__('成功'),$list);
- }
- /**
- * 获取疾病和伤害险 产品
- */
- public function getIndexBelowList(){
- $p = $this->request->post("p",1);
- $id = $this->request->post("id",1);
- $list = Product::where(array('category_id'=>$id))->order('sort asc')
- ->page($p,20)->select();
- $this->success(__('成功'),$list);
- }
- /**
- * 获取推荐查询 一级分类
- */
- public function getEcommendList(){
- $p = $this->request->post("p",0);
- $where['pid'] = 0;
- $list = Category::where($where)->field('id,name')->order('sort asc')->page($p,20)->select();
- $this->success(__('成功'),$list);
- }
- /**
- * 获取推荐查询 二级分类
- */
- public function getEcommendList2(){
- $id = $this->request->post("id",0);
- if(empty($id)){
- $this->error('缺少id');
- }
- $p = $this->request->post("p",0);
- $where['pid'] = $id;
- $list = Category::where($where)->field('id,name')->order('sort asc')->page($p,20)->select();
- $this->success(__('成功'),$list);
- }
- /**
- * 获取推荐查询 三级分类
- */
- public function getEcommendList3(){
- $id = $this->request->post("id",0);
- if(empty($id)){
- $this->error('缺少id');
- }
- $p = $this->request->post("p",0);
- $where['pid'] = $id;
- $list = Category::where($where)->field('id,name')->order('sort asc')->page($p,20)->select();
- $this->success(__('成功'),$list);
- }
- /**
- * 获取险种分类
- */
- public function getInsuranceClassification(){
- $id = $this->request->post("id",0);
- $p = $this->request->post("p",0);
- $list = Category::where(array('pid'=>$id))->field('id,name')->order('sort desc')->page($p,50)->select();
- $this->success(__('成功'),$list);
- }
- /**
- * 推荐查询 保险列表
- */
- public function getInsuranceClassList(){
- $category_id = $this->request->post("id",0);
- $p = $this->request->post("p",0);
- $where['category_id'] =$category_id;
- $where['status'] =0;
- $list = Product::where($where)->order('sort asc')->page($p,50)->select();
- $companyModel = new Company();
- if($list){
- foreach ($list as $key=>$value){
- $list[$key]['p_image'] = 'http://'.$_SERVER['HTTP_HOST'].'/'.$value['p_image'];
- $list[$key]['content'] = json_decode($value['content'],true);
- $list[$key]['company_name'] = $companyModel->where(array('id'=>$value['company_id']))->value('name');
- if($value['attribute'] == '新上架产品'){
- $list[$key]['attribute_status'] = 1;
- }
- if($value['attribute'] == '在售产品'){
- $list[$key]['attribute_status'] = 2;
- }
- if($value['attribute'] == '停售产品'){
- $list[$key]['attribute_status'] = 3;
- }
- }
- }
- $this->success(__('成功'),$list);
- }
- /**
- * 获取关于我们接口信息
- */
- public function getAboutInfo(){
- $info['mobile'] = Config::get('about_mobile');
- $info['email'] = Config::get('about_email');
- $this->success(__('成功'),$info);
- }
- }
|