Index.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\GonggaoModel;
  4. use app\api\model\ImagesModel;
  5. use app\api\model\MemberHouseModel;
  6. use app\common\controller\Api;
  7. use app\api\model\ArticleModel;
  8. /**
  9. * 首页接口
  10. * @ApiWeigh (101)
  11. */
  12. class Index extends Api
  13. {
  14. protected $noNeedLogin = ['phpi'];//,'my_keys','my_detail'
  15. protected $noNeedRight = ['*'];
  16. /**
  17. * 首页接口-轮播图,头条,资讯
  18. *
  19. * @ApiTitle (首页接口-轮播图,头条,资讯)
  20. * @ApiSummary (首页接口-轮播图,头条,资讯)
  21. * @ApiMethod (POST)
  22. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  23. * @ApiRoute (/api/index/index)
  24. *
  25. * @ApiParams (name="user_id", type="int", required=true, description="用户id")
  26. * @ApiParams (name="token", type="int", required=true, description="请求的Token")
  27. * @ApiReturn ()
  28. */
  29. public function index(){
  30. $userId = $this->request->post('user_id');
  31. if (empty($userId)){
  32. $this->result('登录信息丢失');
  33. }
  34. $get_image=ImagesModel::where(['status'=>'1'])->order('weigh desc')->field('id,image')->select();
  35. $get_gonggao=GonggaoModel::where(['status'=>'1','is_delete'=>'0'])->order('id desc')->field('id,title')->find();
  36. $get_list=ArticleModel::where(['status'=>'1','is_delete'=>'0'])->order('id desc')->field('id,title,createtime,images')->limit('5')->select();
  37. $get_house=MemberHouseModel::where('mid',$userId)
  38. ->where('is_delete','0')
  39. ->with(['village'])
  40. ->field('village_id,id')
  41. ->select();
  42. foreach ($get_house as $k=>$v){
  43. $get_house[$k]['name']=$v['village']['name'];
  44. unset($get_house[$k]['village']);
  45. }
  46. $this->result('success', ['images'=>$get_image,'gonggao'=>$get_gonggao,'article'=>$get_list,'house'=>$get_house], 1);
  47. }
  48. }