123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <?php
- namespace app\api\controller;
- use app\admin\model\policy\Type;
- use app\common\controller\Api;
- use app\common\model\Activity as ActicityModel;
- use app\common\model\City;
- use app\common\model\Message;
- use app\common\model\Park;
- use app\common\model\Protable;
- use think\Db;
- /**
- * 园区接口
- */
- class Activity extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- /**
- * 选择园区
- *
- * @param string $p_id 园区id
- */
- public function choosePark()
- {
- $p_id = $this->request->request('p_id');
- $user = $this->auth->getUser();
- $ins = [
- 'p_id' => $p_id,
- 'uid' => $user['id'],
- 'create_time' => time(),
- ];
- Db::name('choose_park_history')->insert($ins);
- $userModel = new \app\common\model\User();
- $iset = $userModel->where('id',$user['id'])->where('p_id',$p_id)->find();
- if ($iset) return $this->success('请选择与之前不同的园区');
- $upd = $userModel->where('id',$user['id'])->update(['p_id'=>$p_id]);
- if ($upd) {
- return $this->success('选择成功');
- } else {
- return $this->error('选择失败');
- }
- }
- /**
- * 园区列表
- *
- */
- public function parkLists()
- {
- $user = $this->auth->getUser();
- if ($user['p_id'] != 0 ) {
- $park = Park::where('id',$user['p_id'])->find();
- if ($park) {
- $data['park_name'] = $park['name'];
- } else {
- $data['park_name'] = '';
- }
- } else {
- $data['park_name'] = '';
- }
- $parkHistory = Db::name('choose_park_history')->where('uid',$user['id'])->column('p_id');
- $historyStr = implode(',',$parkHistory);
- $data['history'] = Park::where('id','in',$historyStr)->column('name');
- $cityModel = new City();
- $data['park_lists'] = $cityModel
- ->with(['park' => function($query) {
- $query->where('switch',1);
- $query->order('sort desc');
- }])
- // ->where('park.switch',1)
- ->order('eng asc')
- ->select();
- return $this->success('',$data);
- }
- /**
- * 园区资讯
- * @param string $page 页数
- * @param string $limit 条数
- */
- public function parkMessage()
- {
- $user = $this->auth->getUser();
- $page = $this->request->get('page');
- $limit = $this->request->get('limit');
- if (!$page) {
- $fen = '0,10';
- } else {
- $page = $page - 1;
- if ($page<0) $page = 0;
- $fen = $page.','.$limit;
- }
- if (!$user) return $this->success('',[]);
- $messageModel = new Message();
- $data = $messageModel->where('p_id',$user['p_id'])
- ->where('switch',1)
- ->order('sort desc')
- ->limit($fen)
- ->select();
- return $this->success('',$data);
- }
- /**
- * 园区活动
- * @param string $page 页数
- * @param string $limit 条数
- */
- public function activity()
- {
- $user = $this->auth->getUser();
- $page = $this->request->get('page');
- $limit = $this->request->get('limit');
- if (!$page) {
- $fen = '0,10';
- } else {
- $page = $page - 1;
- if ($page<0) $page = 0;
- $fen = $page.','.$limit;
- }
- if (!$user) return $this->success('',[]);
- $activityModel = new ActicityModel();
- $data = $activityModel->where('p_id',$user['p_id'])
- ->where('switch',1)
- ->order('sort desc')
- ->limit($fen)
- ->select();
- $time =time();
- foreach ($data as &$v) {
- $v['is_collection'] = 0;
- $isCollection = Db::name('activity_collection')
- ->where('uid',$user['id'])
- ->where('a_id',$v['id'])
- ->find();
- if ($isCollection) $v['is_collection'] = 1;
- $startTime = strtotime($v['start_time']);
- $endTime = strtotime($v['end_time']);
- if ($v['people_num'] == 0) $v['people_num'] = '无限制';
- if ($startTime <= $time && $endTime >= $time) {
- $v['status'] = 1;
- $v['status_name'] = '进行中';
- Db::name('park_activity')->where('id',$v['id'])->update(['status' => 1]);
- } elseif ( $startTime > $time && $endTime > $time) {
- $v['status'] = 0;
- $v['status_name'] = '未开始';
- Db::name('park_activity')->where('id',$v['id'])->update(['status' => 0]);
- } elseif ($startTime <= $time && $endTime <= $time) {
- $v['status'] = 2;
- $v['status_name'] = '已结束';
- Db::name('park_activity')->where('id',$v['id'])->update(['status' => 2]);
- }
- }
- return $this->success('',$data);
- }
- /**
- * 园区活动详情
- * @param string $id 活动id
- */
- public function activityInfo()
- {
- $id = $this->request->get('id');
- $user = $this->auth->getUser();
- if (!isset($id) || empty($id)) return $this->error('参数错误');
- $activityModel = new ActicityModel();
- $data = $activityModel->where('id',$id)
- ->find();
- $data['is_collection'] = 0;
- $isCollection = Db::name('activity_collection')
- ->where('uid',$user['id'])
- ->where('a_id',$data['id'])
- ->find();
- if ($isCollection) $data['is_collection'] = 1;
- return $this->error('暂无数据',[]);
- }
- /**
- * 园区资讯详情
- * @param string $id 活动id
- */
- public function messageInfo()
- {
- $id = $this->request->get('id');
- if (!isset($id) || empty($id)) return $this->error('参数错误');
- $messageModel = new Message();
- $data = $messageModel->where('id',$id)
- ->find();
- return $this->error('暂无数据',[]);
- }
- /**
- * 收藏活动
- *
- * @param string $id 活动id
- */
- public function collectionTrue()
- {
- $id = $this->request->get('id');
- if (!isset($id) || empty($id)) return $this->error('参数错误');
- $user = $this->auth->getUser();
- $data = [
- 'uid'=>$user['id'],
- 'a_id' =>$id,
- 'create_time' => date('Y-m-d H:i:s',time())
- ];
- $add = Db::name('activity_collection')->insert($data);
- if ($add) {
- return $this->success('收藏成功');
- } else {
- return $this->error('收藏失败');
- }
- }
- /**
- * 取消收藏
- *
- * @param string $id 活动id
- */
- public function collectionFalse()
- {
- $id = $this->request->get('id');
- if (!isset($id) || empty($id)) return $this->error('参数错误');
- $user = $this->auth->getUser();
- $del = Db::name('activity_collection')->where('uid',$user['id'])->where('a_id',$id)->delete();
- if ($del) {
- return $this->success('收藏成功');
- } else {
- return $this->error('收藏失败');
- }
- }
- }
|