Policy.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\policy\Type;
  4. use app\common\controller\Api;
  5. use app\common\model\Activity;
  6. use app\common\model\City;
  7. use app\common\model\Message;
  8. use app\common\model\Park;
  9. use app\common\model\PolicyModel;
  10. use app\common\model\Protable;
  11. use think\Db;
  12. /**
  13. * 政策集锦
  14. */
  15. class Policy extends Api
  16. {
  17. protected $noNeedLogin = ['lists', 'banner', 'listInfo', 'gg', 'parkMessage', 'type', 'protable', 'protableInfo', 'NoticeInfo', 'GgInfo'];
  18. protected $noNeedRight = ['*'];
  19. /**
  20. * 政策集轮播图
  21. */
  22. public function banner()
  23. {
  24. $data = Db::name('policy_banner')
  25. ->where('switch', 1)
  26. ->order('sort desc')
  27. ->select();
  28. foreach ($data as &$v) {
  29. $v['image'] = config('site.httpurl') . $v['image'];
  30. }
  31. return $this->success('', $data);
  32. }
  33. /**
  34. * 政策分类
  35. */
  36. public function type()
  37. {
  38. $data = Db::name('policy_type')->where('switch',1)->order('sort desc')->select();
  39. return $this->success('',$data);
  40. }
  41. /**
  42. * 政策集锦列表
  43. * @param string $page 页数
  44. * @param string $limit 条数
  45. * @param string $type 分类id
  46. */
  47. public function lists()
  48. {
  49. $page = $this->request->get('page');
  50. $limit = $this->request->get('limit');
  51. $type = $this->request->get('type');
  52. if (!isset($type) || empty($type)) return $this->error('请选择分类');
  53. if (!$page) {
  54. $pages = '0,10';
  55. } else {
  56. $page = $page - 1;
  57. if ($page < 0) $page = 0;
  58. $pages = $page . ',' . $limit;
  59. }
  60. $policyMdoel = new PolicyModel();
  61. $data = $policyMdoel->where('switch', 1)
  62. ->where('t_id',$type)
  63. ->order('sort desc')
  64. ->limit($pages)
  65. ->select();
  66. return $this->success('', $data);
  67. }
  68. /**
  69. * 政策集锦详情
  70. * @param string $id id
  71. *
  72. */
  73. public function listInfo()
  74. {
  75. $id = $this->request->get('id');
  76. if (!isset($id) || empty($id)) return $this->error('缺少参数');
  77. $policyMdoel = new PolicyModel();
  78. $data = $policyMdoel
  79. ->where('id', $id)
  80. ->where('switch', 1)
  81. ->order('sort desc')
  82. ->find();
  83. return $this->success('', $data);
  84. }
  85. /**
  86. * 政策入住申请
  87. * @ApiMethod (POST)
  88. * @param string $lid id
  89. * @param string $name id
  90. * @param string $mobile id
  91. * @param string $notice id
  92. *
  93. */
  94. public function ruzhu()
  95. {
  96. $data = $this->request->post();
  97. if (!isset($data['lid']) || empty($data['lid'])) return $this->error('参数错误');
  98. if (!isset($data['name']) || empty($data['name'])) return $this->error('请输入姓名');
  99. if (!isset($data['mobile']) || empty($data['mobile'])) return $this->error('请输入手机号');
  100. if (!isset($data['notice']) || empty($data['notice'])) return $this->error('请输入具体需求');
  101. $user = $this->auth->getUser();
  102. if (!$user) return $this->error(__('Please login first'), null, 401);
  103. $data['uid'] = $user['id'];
  104. $data['create_time'] = date('Y-m-d H:i:s',time());
  105. $isert = Db::name('policy_ruzhu')->where('uid',$user['id'])->where('lid',$data['lid'])->find();
  106. if ($isert) return $this->error('您已经申请过了');
  107. $add = Db::name('policy_ruzhu')->insert($data);
  108. if ($add ) {
  109. $id = Db::name('policy_ruzhu')->getLastInsID();
  110. $data['id'] = $id;
  111. return $this->success('提交成功',$data);
  112. } else {
  113. return $this->error('提交失败');
  114. }
  115. }
  116. /**
  117. * 入住返回数据
  118. * @param string $id 注册返回的id
  119. */
  120. public function ruzhuInfo()
  121. {
  122. $data = $this->request->param();
  123. if (!isset($data['id']) || empty($data['id'])) return $this->error('参数错误');
  124. $res = Db::name('policy_ruzhu')->where('id',$data['id'])->find();
  125. return $this->success('',$res);
  126. }
  127. }