Insurance.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <?php
  2. /**
  3. * 保险
  4. */
  5. namespace app\api\controller;
  6. use app\admin\controller\InsurancePersonal;
  7. use app\admin\model\Category;
  8. use app\admin\model\Company;
  9. use app\admin\model\InsuranceEnterprise;
  10. use app\admin\model\InsuranceInfo;
  11. use app\admin\model\InsuranceMedical;
  12. use app\admin\model\InsuranceMedicalList;
  13. use app\admin\model\InsuranceProperty;
  14. use app\admin\model\Product;
  15. use app\admin\model\ProductRanking;
  16. use app\common\controller\Api;
  17. use think\Config;
  18. class Insurance extends Api{
  19. protected $noNeedLogin = '*';
  20. protected $noNeedRight = '*';
  21. /**
  22. * 首页获取排行榜
  23. */
  24. public function getRanking(){
  25. $type = $this->request->post("type");
  26. //产品排行
  27. if($type == 1){
  28. $list = Product::field('id,name,sort')->order('sort asc')->select();
  29. // if($list){
  30. // foreach ($list as $key=>$value){
  31. // $list[$key]['name'] = $value['product_name'];
  32. // unset($list[$key]['product_name']);
  33. // }
  34. // }
  35. $this->success(__('成功'),$list);
  36. }
  37. //个人保险
  38. if($type == 2){
  39. //$list = \app\admin\model\InsurancePersonal::field('id,name,label,sort')->order('sort asc')->select();
  40. $list = Category::where(array('pid'=>1))->select();
  41. $new_list = [];
  42. if($list){
  43. foreach ($list as $key=>$value){
  44. $new_list[$key]['id'] = $value['id'];
  45. $new_list[$key]['name'] = $value['name'];
  46. $new_list[$key]['label'] = $value['nickname'];
  47. $new_list[$key]['sort'] = 0;
  48. }
  49. }
  50. $this->success(__('成功'),$new_list);
  51. }
  52. //企业保险
  53. if($type == 3){
  54. //$list = InsuranceEnterprise::field('id,name,label,sort')->order('sort asc')->select();
  55. $list = Category::where(array('pid'=>3))->select();
  56. $new_list = [];
  57. if($list){
  58. foreach ($list as $key=>$value){
  59. $new_list[$key]['id'] = $value['id'];
  60. $new_list[$key]['name'] = $value['name'];
  61. $new_list[$key]['label'] = $value['nickname'];
  62. $new_list[$key]['sort'] = 0;
  63. }
  64. }
  65. $this->success(__('成功'),$new_list);
  66. }
  67. //财产保险
  68. if($type == 4){
  69. //$list = InsuranceProperty::field('id,name,label,sort')->order('sort asc')->select();
  70. $list = Category::where(array('pid'=>2))->select();
  71. $new_list = [];
  72. if($list){
  73. foreach ($list as $key=>$value){
  74. $new_list[$key]['id'] = $value['id'];
  75. $new_list[$key]['name'] = $value['name'];
  76. $new_list[$key]['label'] = $value['nickname'];
  77. $new_list[$key]['sort'] = 0;
  78. }
  79. }
  80. $this->success(__('成功'),$new_list);
  81. }
  82. $this->error(__('参数错误'));
  83. }
  84. /**
  85. * 查询首页二级分类
  86. */
  87. public function getIndexSecondaryClassification(){
  88. $first_ids = Category::where(array('pid'=>0))->order('sort desc')->field('id')->select();
  89. $ids = array_column($first_ids, 'id');
  90. // foreach ($first_ids as $key=>$value){
  91. // $ids[$key]
  92. // }
  93. $secondaryList = Category::where('pid','in',$ids)->field('id,name,sort')->order('sort asc')->select();
  94. if($secondaryList){
  95. foreach ($secondaryList as $key=>$value){
  96. $subordinate = Category::where(array('pid'=>$value['id']))->field('id,name,sort')->page(1,4)->select();
  97. if($subordinate){
  98. $last_names = array_column($subordinate,'sort');
  99. array_multisort($last_names,SORT_ASC,$subordinate);
  100. }
  101. $secondaryList[$key]['subordinate'] = $subordinate;
  102. }
  103. }
  104. $this->success(__('成功'),$secondaryList);
  105. }
  106. /**
  107. * 查看三级分类更多列表接口
  108. */
  109. public function lookSecondaryList(){
  110. $id = $this->request->post("id",0); //二级分类的id
  111. $p = input("p",0);
  112. $list = Category::where(array('pid'=>$id))->field('id,name')->order('sort asc')->page($p,20)->select();
  113. $this->success(__('成功'),$list);
  114. }
  115. public function lookthird(){
  116. $p = input("p",0);
  117. $first_ids = Category::where(array('pid'=>0))->order('sort desc')->field('id')->select();
  118. $ids = array_column($first_ids, 'id');
  119. // foreach ($first_ids as $key=>$value){
  120. // $ids[$key]
  121. // }
  122. $secondaryList = Category::where('pid','in',$ids)->field('id')->order('sort asc')->select();
  123. $sids = array_column($secondaryList, 'id');
  124. $thirdlist = Category::where('pid','in',$sids)->field('id,name,sort')->order('sort asc')->select();
  125. $this->success(__('成功'),$thirdlist);
  126. }
  127. /**
  128. * 查询产品列表接口
  129. */
  130. public function getProductList(){
  131. $id = $this->request->post("id",0); //分类的id
  132. $p = $this->request->post("p",0);
  133. $list = Product::where(array('category_id'=>$id,'status'=>0))->order('sort desc')->page($p,20)->select();
  134. if($list){
  135. foreach ($list as $key=>$value){
  136. $list[$key]['p_image'] = 'http://'.$_SERVER['HTTP_HOST'].'/'.$value['p_image'];
  137. $list[$key]['content'] = json_decode($value['content'],true);
  138. }
  139. }
  140. $this->success(__('成功'),$list);
  141. }
  142. /**
  143. * 获取 个人保险 企业保险 财产保险 产品 接口
  144. */
  145. public function getIndexUpperList(){
  146. $type = $this->request->post("type",0);
  147. //分类的id
  148. $id = $this->request->post("id",0);
  149. $p = $this->request->post("p",0);
  150. //个人保险
  151. // if($type == 1){
  152. // $model = new \app\admin\model\InsurancePersonal();
  153. // }
  154. // //企业保险
  155. // else if($type == 2){
  156. // $model = new InsuranceEnterprise();
  157. // }
  158. // //财产保险
  159. // else if($type == 3){
  160. // $model = new InsuranceProperty();
  161. // }
  162. //
  163. // else{
  164. // $this->error(__('参数错误'));
  165. // }
  166. $list = Product::where(array('category_id'=>$id))
  167. ->order('sort asc')->page($p,20)->select();
  168. $this->success(__('成功'),$list);
  169. }
  170. /**
  171. * 获取医疗险排行榜
  172. */
  173. public function getMedicalList(){
  174. $type = $this->request->post("type",0); //1 疾病意外医疗推荐排行榜 2意外伤害险推荐排行榜
  175. $p = $this->request->post("p",1);
  176. $more = $this->request->post("more",0); //是否查看更多
  177. if($more == 1){
  178. //查看更多
  179. $rows = 20;
  180. }else{
  181. $rows = 3;
  182. }
  183. // if($type == 1){
  184. // $where['optionlist'] = '疾病意外医疗险推荐排行榜';
  185. // }else{
  186. // $where['optionlist'] = '意外伤害险推荐排行榜';
  187. // }
  188. if($type == 1){
  189. $where['id'] = 9;
  190. }else{
  191. $where['id'] = 22;
  192. }
  193. $list = Category::where($where)->page($p,$rows)->select();
  194. $this->success(__('成功'),$list);
  195. }
  196. /**
  197. * 获取疾病和伤害险 产品
  198. */
  199. public function getIndexBelowList(){
  200. $p = $this->request->post("p",1);
  201. $id = $this->request->post("id",1);
  202. $list = Product::where(array('category_id'=>$id))->order('sort asc')
  203. ->page($p,20)->select();
  204. $this->success(__('成功'),$list);
  205. }
  206. /**
  207. * 获取推荐查询 一级分类
  208. */
  209. public function getEcommendList(){
  210. $p = $this->request->post("p",0);
  211. $where['pid'] = 0;
  212. $list = Category::where($where)->field('id,name')->order('sort asc')->page($p,20)->select();
  213. $this->success(__('成功'),$list);
  214. }
  215. /**
  216. * 获取推荐查询 二级分类
  217. */
  218. public function getEcommendList2(){
  219. $id = $this->request->post("id",0);
  220. if(empty($id)){
  221. $this->error('缺少id');
  222. }
  223. $p = $this->request->post("p",0);
  224. $where['pid'] = $id;
  225. $list = Category::where($where)->field('id,name')->order('sort asc')->page($p,20)->select();
  226. $this->success(__('成功'),$list);
  227. }
  228. /**
  229. * 获取推荐查询 三级分类
  230. */
  231. public function getEcommendList3(){
  232. $id = $this->request->post("id",0);
  233. if(empty($id)){
  234. $this->error('缺少id');
  235. }
  236. $p = $this->request->post("p",0);
  237. $where['pid'] = $id;
  238. $list = Category::where($where)->field('id,name')->order('sort asc')->page($p,20)->select();
  239. $this->success(__('成功'),$list);
  240. }
  241. /**
  242. * 获取险种分类
  243. */
  244. public function getInsuranceClassification(){
  245. $id = $this->request->post("id",0);
  246. $p = $this->request->post("p",0);
  247. $list = Category::where(array('pid'=>$id))->field('id,name')->order('sort desc')->page($p,50)->select();
  248. $this->success(__('成功'),$list);
  249. }
  250. /**
  251. * 推荐查询 保险列表
  252. */
  253. public function getInsuranceClassList(){
  254. $category_id = $this->request->post("id",0);
  255. $p = $this->request->post("p",0);
  256. $where['category_id'] =$category_id;
  257. $where['status'] =0;
  258. $list = Product::where($where)->order('sort asc')->page($p,50)->select();
  259. $companyModel = new Company();
  260. if($list){
  261. foreach ($list as $key=>$value){
  262. $list[$key]['p_image'] = 'http://'.$_SERVER['HTTP_HOST'].'/'.$value['p_image'];
  263. $list[$key]['content'] = json_decode($value['content'],true);
  264. $list[$key]['company_name'] = $companyModel->where(array('id'=>$value['company_id']))->value('name');
  265. if($value['attribute'] == '新上架产品'){
  266. $list[$key]['attribute_status'] = 1;
  267. }
  268. if($value['attribute'] == '在售产品'){
  269. $list[$key]['attribute_status'] = 2;
  270. }
  271. if($value['attribute'] == '停售产品'){
  272. $list[$key]['attribute_status'] = 3;
  273. }
  274. }
  275. }
  276. $this->success(__('成功'),$list);
  277. }
  278. /**
  279. * 获取关于我们接口信息
  280. */
  281. public function getAboutInfo(){
  282. $info['mobile'] = Config::get('about_mobile');
  283. $info['email'] = Config::get('about_email');
  284. $this->success(__('成功'),$info);
  285. }
  286. }