Index.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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\Protable;
  10. use think\Db;
  11. /**
  12. * 首页接口
  13. */
  14. class Index extends Api
  15. {
  16. protected $noNeedLogin = ['index','banner','notice','gg','parkMessage','activity','protable','protableInfo','NoticeInfo','GgInfo'];
  17. protected $noNeedRight = ['*'];
  18. /**
  19. * 首页未登录园区活动和资讯
  20. *
  21. */
  22. public function index()
  23. {
  24. $data['message'] = Message::where('index_show',1)->where('switch',1)->order('sort desc')->find();
  25. $data['activity'] = Activity::where('index_show',1)->where('switch',1)->order('sort desc')->find();
  26. $this->success('请求成功',$data);
  27. }
  28. /**
  29. * 轮播图
  30. *
  31. */
  32. public function banner()
  33. {
  34. $data['banner'] = Db::name('banner')->select();
  35. foreach ( $data['banner'] as &$v) {
  36. $v['image'] = config('site.httpurl').$v['image'];
  37. }
  38. $user = $this->auth->getUser();
  39. if ($user) {
  40. $park = Park::where('id',$user['p_id'])->find();
  41. if ($park) {
  42. $data['park_name'] = $park['name'];
  43. } else {
  44. $data['park_name'] = '';
  45. }
  46. } else {
  47. $data['park_name'] = '';
  48. }
  49. return $this->success('',$data);
  50. }
  51. /**
  52. * 公告
  53. * @param string $page 页数
  54. * @param string $limit 条数
  55. */
  56. public function notice()
  57. {
  58. $page = $this->request->get('page');
  59. $limit = $this->request->get('limit');
  60. if (!$page) {
  61. $fen = '0,10';
  62. } else {
  63. $page = $page - 1;
  64. if ($page<0) $page = 0;
  65. $fen = $page.','.$limit;
  66. }
  67. $data = Db::name('notice')
  68. ->where('switch',1)
  69. ->limit($fen)
  70. ->order('sort desc')
  71. ->select();
  72. foreach ( $data as &$v) {
  73. $v['create_time'] = date('Y-m-d',$v['create_time']);
  74. $v['content'] = str_replace('src="','src="'.config('site.httpurl'),$v['content']);
  75. }
  76. return $this->success('',$data);
  77. }
  78. /**
  79. * 公告详情
  80. *
  81. * @param string $id 广告id
  82. */
  83. public function NoticeInfo()
  84. {
  85. $id = $this->request->get('id');
  86. $data = Db::name('notice')
  87. ->where('id',$id)
  88. ->find();
  89. $data['create_time'] = date('Y-m-d',$data['create_time']);
  90. $data['content'] = str_replace('src="','src="'.config('site.httpurl'),$data['content']);
  91. return $this->success('',$data);
  92. }
  93. /**
  94. * 广告位
  95. * @param string $page 页数
  96. * @param string $limit 条数
  97. */
  98. public function gg()
  99. {
  100. $page = $this->request->get('page');
  101. $limit = $this->request->get('limit');
  102. if (!$page) {
  103. $fen = '0,10';
  104. } else {
  105. $page = $page - 1;
  106. if ($page<0) $page = 0;
  107. $fen = $page.','.$limit;
  108. }
  109. $data = Db::name('gg')
  110. ->where('switch',1)
  111. ->order('sort desc')
  112. ->limit($fen)
  113. ->select();
  114. foreach ($data as &$v) {
  115. $v['image'] = config('site.httpurl').$v['image'];
  116. $v['images'] = config('site.httpurl').$v['images'];
  117. $v['content'] = str_replace('src="','src="'.config('site.httpurl'),$v['content']);
  118. }
  119. return $this->success('',$data);
  120. }
  121. /**
  122. * 广告详情
  123. *
  124. * @param string $id 广告id
  125. */
  126. public function GgInfo()
  127. {
  128. $id = $this->request->get('id');
  129. $data = Db::name('gg')
  130. ->where('id',$id)
  131. ->find();
  132. $data['image'] = config('site.httpurl').$data['image'];
  133. $data['images'] = explode(',',$data['images']);
  134. foreach ($data['images'] as &$v) {
  135. $v = config('site.httpurl').$v;
  136. }
  137. $data['content'] = str_replace('src="','src="'.config('site.httpurl'),$data['content']);
  138. return $this->success('',$data);
  139. }
  140. /**
  141. * 广告位申请
  142. * @ApiMethod (POST)
  143. * @param string $name id
  144. * @param string $mobile id
  145. * @param string $notice id
  146. *
  147. */
  148. public function shenqing()
  149. {
  150. $data = $this->request->post();
  151. if (!isset($data['name']) || empty($data['name'])) return $this->error('请输入姓名');
  152. if (!isset($data['mobile']) || empty($data['mobile'])) return $this->error('请输入手机号');
  153. if (!isset($data['notice']) || empty($data['notice'])) return $this->error('请输入具体需求');
  154. $user = $this->auth->getUser();
  155. if (!$user) return $this->error(__('Please login first'), null, 401);
  156. $data['uid'] = $user['id'];
  157. $data['create_time'] = date('Y-m-d H:i:s',time());
  158. // $isert = Db::name('gg_shenqing')->where('uid',$user['id'])->find();
  159. //
  160. // if ($isert) return $this->error('您已经申请过了');
  161. $add = Db::name('gg_shenqing')->insert($data);
  162. return $this->error('提交失败');
  163. }
  164. /**
  165. * 便携号码
  166. * @param string $page 页数
  167. * @param string $limit 条数
  168. */
  169. public function protable()
  170. {
  171. $page = $this->request->get('page');
  172. $limit = $this->request->get('limit');
  173. if (!$page) {
  174. $fen = '0,10';
  175. } else {
  176. $page = $page - 1;
  177. if ($page<0) $page = 0;
  178. $fen = $page.','.$limit;
  179. }
  180. $tableModel = new Protable();
  181. $data = $tableModel->where('switch',1)
  182. ->limit($fen)
  183. ->order('sort desc')
  184. ->field('id,name,name_eng,image')
  185. ->select();
  186. return $this->success('暂无数据',$data);
  187. }
  188. /**
  189. * 便携号码详情
  190. *
  191. * @param string $id 号码id
  192. */
  193. public function protableInfo()
  194. {
  195. $id = $this->request->get('id');
  196. if (!isset($id) || empty($id)) return $this->error('参数错误');
  197. $protableModel = new Protable();
  198. $data = $protableModel->where('id',$id)
  199. ->field('id,title1,mobile1,title2,mobile2')
  200. ->find();
  201. $data['info'] = Db::name('protable_info')
  202. ->where('p_id',$data['id'])
  203. ->where('switch',1)
  204. ->order('sort desc')
  205. ->select();
  206. return $this->success('暂无数据',$data);
  207. }
  208. }