MyActivity.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\AcitivityOrder;
  5. use app\common\model\MeetingOrder;
  6. use app\common\model\OfficeOrderModel;
  7. use app\common\model\SheActivityModel;
  8. use think\Db;
  9. /**
  10. * 我的活动
  11. */
  12. class MyActivity extends Api
  13. {
  14. protected $noNeedLogin = ['acvitityLists', 'Info', 'listInfo', 'qustion', 'qustionInfo', 'buildInfo', 'protable', 'trueTime', 'chooseTime', 'GgInfo'];
  15. protected $noNeedRight = ['*'];
  16. /**
  17. * 我的活动(个人)
  18. */
  19. public function gerenFabu()
  20. {
  21. $page = $this->request->get('page');
  22. $limit = $this->request->get('limit');
  23. if (!$page) {
  24. $pages = '0,10';
  25. } else {
  26. $page = $page - 1;
  27. if ($page < 0) $page = 0;
  28. $pages = $page . ',' . $limit;
  29. }
  30. $sheActivityModel = new SheActivityModel();
  31. $user = $this->auth->getUser();
  32. $where = [];
  33. if ($user) $where['a.uid'] = $user['id'];
  34. $data = $sheActivityModel->alias('a')
  35. ->join('user u','a.uid=u.id',"left")
  36. ->where($where)
  37. ->limit($pages)
  38. ->order('a.create_time desc')
  39. ->field('a.*')
  40. ->select()->toArray();
  41. $time = date('Y-m-d H:i:s', time());
  42. foreach ($data as $k => $v) {
  43. if ($time < $v['start_time']) {
  44. $data[$k]['status'] = '0';
  45. $data[$k]['status_str'] = '未开始';
  46. }
  47. if ($time > $v['start_time'] && $time < $v['end_time']) {
  48. $data[$k]['status'] = '1';
  49. $data[$k]['status_str'] = '报名中';
  50. }
  51. if ($time > $v['end_time']) {
  52. $data[$k]['status'] = '3';
  53. $data[$k]['status_str'] = '报名结束';
  54. }
  55. $order = AcitivityOrder::where('a_id', $v['id'])->column('uid');
  56. $str = implode(',', $order);
  57. $data[$k]['users'] = Db::name('user')->where('id', 'in', $str)->field('id,avatar')->select();
  58. unset($order);
  59. }
  60. return json(['code' => 1, 'data' => $data]);
  61. }
  62. /**
  63. * 我参与的
  64. */
  65. public function join()
  66. {
  67. $user = $this->auth->getUser();
  68. // 后台发布的活动
  69. $data = Db::name('park_order o')
  70. ->join('park_activity p','o.a_id=p.id')
  71. ->where('o.uid',$user['id'])
  72. ->select();
  73. $time = date('Y-m-d H:i:s', time());
  74. if (!empty($data)) {
  75. foreach ($data as $m=>$n) {
  76. $data[$m]['type'] = 1;
  77. $data[$m]['mianfei'] = '';
  78. $data[$m]['price'] = '';
  79. $data[$m]['image'] = config('site.httpurl'). $data[$m]['image'];
  80. $data[$m]['images'] =[];
  81. $data[$m]['notice'] =$data[$m]['content'];
  82. if ($time < $data[$m]['start_time']) {
  83. $data[$m]['status'] = '0';
  84. $data[$m]['status_str'] = '未开始';
  85. }
  86. if ($time > $data[$m]['start_time'] && $time < $data[$m]['end_time']) {
  87. $data[$m]['status'] = '1';
  88. $data[$m]['status_str'] = '报名中';
  89. }
  90. if ($time > $data[$m]['end_time']) {
  91. $data[$m]['status'] = '3';
  92. $data[$m]['status_str'] = '报名结束';
  93. }
  94. $data[$m]['num_count'] = Db::name('park_order')->where('a_id',$n['id'])->count();
  95. $arr = Db::name('park_order')->where('a_id',$n['id'])->column('uid');
  96. $arrStr = implode(',',$arr);
  97. unset($arr);
  98. $data[$m]['user'] = Db::name('user')->where('id','in',$arrStr)->field('id,avatar')->select();
  99. }
  100. }
  101. // 用户发布的活动
  102. $activcityOrder = new AcitivityOrder();
  103. $data1 = $activcityOrder->alias('o')
  104. ->join('avcitity a','o.a_id = a.id','left')
  105. ->where('o.uid',$user['id'])
  106. ->select();
  107. if (!empty($data1)) {
  108. foreach ($data1 as $k=>$v) {
  109. $data1[$k]['type'] = 2;
  110. if ($time < $data1[$k]['start_time']) {
  111. $data1[$k]['status'] = '0';
  112. $data1[$k]['status_str'] = '未开始';
  113. }
  114. if ($time > $data1[$k]['start_time'] && $time < $data1[$k]['end_time']) {
  115. $data1[$k]['status'] = '1';
  116. $data1[$k]['status_str'] = '报名中';
  117. }
  118. if ($time > $data1[$k]['end_time']) {
  119. $data1[$k]['status'] = '3';
  120. $data1[$k]['status_str'] = '报名结束';
  121. }
  122. $arr = $activcityOrder->where('a_id',$v['a_id'])->group('uid')->column('uid');
  123. $arrStr = implode(',',$arr);
  124. unset($arr);
  125. $data1[$k]['user'] = Db::name('user')->where('id','in',$arrStr)->field('id,avatar')->select();
  126. }
  127. }
  128. $data2 = array_merge($data1,$data);
  129. return json(['code' =>1,'data'=>$data2]);
  130. }
  131. /**
  132. * 我分享的
  133. */
  134. public function fenxiang()
  135. {
  136. $user = $this->auth->getUser();
  137. // 后台发布的活动
  138. $data = Db::name('activity_fenxiang o')
  139. ->join('park_activity p','o.a_id=p.id')
  140. ->where('o.uid',$user['id'])
  141. ->where('type',1)
  142. ->select();
  143. $time = date('Y-m-d H:i:s', time());
  144. if (!empty($data)) {
  145. foreach ($data as $m=>$n) {
  146. $data[$m]['type'] = 1;
  147. $data[$m]['mianfei'] = '';
  148. $data[$m]['price'] = '';
  149. $data[$m]['image'] = config('site.httpurl'). $data[$m]['image'];
  150. $data[$m]['images'] =[];
  151. $data[$m]['notice'] =$data[$m]['content'];
  152. if ($time < $data[$m]['start_time']) {
  153. $data[$m]['status'] = '0';
  154. $data[$m]['status_str'] = '未开始';
  155. }
  156. if ($time > $data[$m]['start_time'] && $time < $data[$m]['end_time']) {
  157. $data[$m]['status'] = '1';
  158. $data[$m]['status_str'] = '报名中';
  159. }
  160. if ($time > $data[$m]['end_time']) {
  161. $data[$m]['status'] = '3';
  162. $data[$m]['status_str'] = '报名结束';
  163. }
  164. $data[$m]['num_count'] = Db::name('activity_fenxiang')->where('type',1)->where('a_id',$n['id'])->count();
  165. $arr = Db::name('activity_fenxiang')->where('type',1)->where('a_id',$n['id'])->column('uid');
  166. $arrStr = implode(',',$arr);
  167. unset($arr);
  168. $data[$m]['user'] = Db::name('user')->where('id','in',$arrStr)->field('id,avatar')->select();
  169. }
  170. }
  171. // 用户发布的活动
  172. $activcityOrder = new AcitivityOrder();
  173. $data1 = Db::name('activity_fenxiang o')
  174. ->join('avcitity a','o.a_id = a.id','left')
  175. ->where('o.uid',$user['id'])
  176. ->where('type',2)
  177. ->select();
  178. if (!empty($data1)) {
  179. foreach ($data1 as $k=>$v) {
  180. $data1[$k]['type'] = 2;
  181. if ($time < $data1[$k]['start_time']) {
  182. $data1[$k]['status'] = '0';
  183. $data1[$k]['status_str'] = '未开始';
  184. }
  185. if ($time > $data1[$k]['start_time'] && $time < $data1[$k]['end_time']) {
  186. $data1[$k]['status'] = '1';
  187. $data1[$k]['status_str'] = '报名中';
  188. }
  189. if ($time > $data1[$k]['end_time']) {
  190. $data1[$k]['status'] = '3';
  191. $data1[$k]['status_str'] = '报名结束';
  192. }
  193. $arr = Db::name('activity_fenxiang')->where('type',2)->where('a_id',$v['a_id'])->group('uid')->column('uid');
  194. $arrStr = implode(',',$arr);
  195. unset($arr);
  196. $data1[$k]['user'] = Db::name('user')->where('id','in',$arrStr)->field('id,avatar')->select();
  197. }
  198. }
  199. $data2 = array_merge($data1,$data);
  200. return json(['code' =>1,'data'=>$data2]);
  201. }
  202. /**
  203. * 我收藏的
  204. */
  205. public function collection()
  206. {
  207. $user = $this->auth->getUser();
  208. // 后台发布的活动
  209. $data = Db::name('activity_collection o')
  210. ->join('park_activity p','o.a_id=p.id')
  211. ->where('o.uid',$user['id'])
  212. ->select();
  213. $time = date('Y-m-d H:i:s', time());
  214. if (!empty($data)) {
  215. foreach ($data as $m=>$n) {
  216. $data[$m]['type'] = 1;
  217. $data[$m]['mianfei'] = '';
  218. $data[$m]['price'] = '';
  219. $data[$m]['image'] = config('site.httpurl'). $data[$m]['image'];
  220. $data[$m]['images'] =[];
  221. $data[$m]['notice'] =$data[$m]['content'];
  222. if ($time < $data[$m]['start_time']) {
  223. $data[$m]['status'] = '0';
  224. $data[$m]['status_str'] = '未开始';
  225. }
  226. if ($time > $data[$m]['start_time'] && $time < $data[$m]['end_time']) {
  227. $data[$m]['status'] = '1';
  228. $data[$m]['status_str'] = '报名中';
  229. }
  230. if ($time > $data[$m]['end_time']) {
  231. $data[$m]['status'] = '3';
  232. $data[$m]['status_str'] = '报名结束';
  233. }
  234. $data[$m]['num_count'] = Db::name('activity_collection')->where('a_id',$n['id'])->count();
  235. $arr = Db::name('activity_collection')->where('a_id',$n['id'])->column('uid');
  236. $arrStr = implode(',',$arr);
  237. unset($arr);
  238. $data[$m]['user'] = Db::name('user')->where('id','in',$arrStr)->field('id,avatar')->select();
  239. }
  240. }
  241. // 用户发布的活动
  242. $activcityOrder = new AcitivityOrder();
  243. $data1 = Db::name('user_collection o')
  244. ->join('avcitity a','o.a_id = a.id','left')
  245. ->where('o.uid',$user['id'])
  246. ->select();
  247. if (!empty($data1)) {
  248. foreach ($data1 as $k=>$v) {
  249. $data1[$k]['type'] = 2;
  250. if ($time < $data1[$k]['start_time']) {
  251. $data1[$k]['status'] = '0';
  252. $data1[$k]['status_str'] = '未开始';
  253. }
  254. if ($time > $data1[$k]['start_time'] && $time < $data1[$k]['end_time']) {
  255. $data1[$k]['status'] = '1';
  256. $data1[$k]['status_str'] = '报名中';
  257. }
  258. if ($time > $data1[$k]['end_time']) {
  259. $data1[$k]['status'] = '3';
  260. $data1[$k]['status_str'] = '报名结束';
  261. }
  262. $arr = Db::name('user_collection')->where('a_id',$v['a_id'])->group('uid')->column('uid');
  263. $arrStr = implode(',',$arr);
  264. unset($arr);
  265. $data1[$k]['user'] = Db::name('user')->where('id','in',$arrStr)->field('id,avatar')->select();
  266. }
  267. }
  268. $data2 = array_merge($data1,$data);
  269. return json(['code' =>1,'data'=>$data2]);
  270. }
  271. /**
  272. * 我的活动(商家/企业)
  273. * @param string $type 0全部1待审核2已结束3已取消
  274. */
  275. public function qiye()
  276. {
  277. $type = $this->request->get('type');
  278. $page = $this->request->get('page');
  279. $limit = $this->request->get('limit');
  280. if (!$page) {
  281. $pages = '0,10';
  282. } else {
  283. $page = $page - 1;
  284. if ($page < 0) $page = 0;
  285. $pages = $page . ',' . $limit;
  286. }
  287. if ($type==0) {
  288. $sheActivityModel = new SheActivityModel();
  289. $user = $this->auth->getUser();
  290. $where = [];
  291. if ($user) $where['a.uid'] = $user['id'];
  292. $data = $sheActivityModel->alias('a')
  293. ->join('user u','a.uid=u.id',"left")
  294. ->where($where)
  295. ->limit($pages)
  296. ->order('create_time desc')
  297. ->field('a.*')
  298. ->select()->toArray();
  299. if (empty($data)) return json(['code'=>1,'data'=>$data]);
  300. $time = date('Y-m-d H:i:s', time());
  301. foreach ($data as $k => $v) {
  302. $startTime = strtotime($v['start_time']);
  303. $endTime = strtotime($v['end_time']);
  304. if ($v['is_quxiao'] == 1) {
  305. $data[$k]['status'] = '3';
  306. $data[$k]['status_str'] = '已取消';
  307. } else if($v['is_quxiao']==0&&$v['switch']==0) {
  308. $data[$k]['status'] = '1';
  309. $data[$k]['status_str'] = '待审核';
  310. } else if ($v['is_quxiao']==0&&$v['switch']==1) {
  311. if ($startTime <= $time && $endTime >= $time) {
  312. $data[$k]['status'] = 4;
  313. $data[$k]['status_name'] = '进行中';
  314. Db::name('park_activity')->where('id',$v['id'])->update(['status' => 1]);
  315. } elseif ( $startTime > $time && $endTime > $time) {
  316. $data[$k]['status'] = 0;
  317. $data[$k]['status_name'] = '未开始';
  318. Db::name('park_activity')->where('id',$v['id'])->update(['status' => 0]);
  319. } elseif ($startTime <= $time && $endTime <= $time) {
  320. $data[$k]['status'] = 2;
  321. $data[$k]['status_name'] = '已结束';
  322. Db::name('park_activity')->where('id',$v['id'])->update(['status' => 2]);
  323. }
  324. }
  325. $order = AcitivityOrder::where('a_id',$v['id'])->column('uid');
  326. $str = implode(',',$order);
  327. $data[$k]['users'] = Db::name('user')->where('id','in',$str)->field('id,avatar')->select();
  328. unset($order);
  329. }
  330. return json(['code'=>1,'data'=>$data]);
  331. } else if($type==1) {
  332. $sheActivityModel = new SheActivityModel();
  333. $user = $this->auth->getUser();
  334. $where = [];
  335. if ($user) $where['a.uid'] = $user['id'];
  336. $data = $sheActivityModel->alias('a')
  337. ->join('user u','a.uid=u.id',"left")
  338. ->where($where)
  339. ->limit($pages)
  340. ->where('switch',0)
  341. ->where('is_quxiao',0)
  342. ->order('create_time desc')
  343. ->field('a.*')
  344. ->select()->toArray();
  345. if (empty($data)) return json(['code'=>1,'data'=>$data]);
  346. $time = date('Y-m-d H:i:s', time());
  347. foreach ($data as $k => $v) {
  348. // if ($v['is_quxiao'] == 1) {
  349. // $data[$k]['status'] = '3';
  350. // $data[$k]['status_str'] = '已取消';
  351. // } else if($v['is_quxiao']==0&&$v['switch']==0) {
  352. $data[$k]['status'] = '1';
  353. $data[$k]['status_str'] = '待审核';
  354. // }
  355. //
  356. // if ($time > $v['end_time']) {
  357. // $data[$k]['status'] = '2';
  358. // $data[$k]['status_str'] = '已结束';
  359. // }
  360. $order = AcitivityOrder::where('a_id',$v['id'])->column('uid');
  361. $str = implode(',',$order);
  362. $data[$k]['users'] = Db::name('user')->where('id','in',$str)->field('id,avatar')->select();
  363. unset($order);
  364. }
  365. return json(['code'=>1,'data'=>$data]);
  366. } else if($type==2) {
  367. $sheActivityModel = new SheActivityModel();
  368. $user = $this->auth->getUser();
  369. $where = [];
  370. if ($user) $where['a.uid'] = $user['id'];
  371. $data = $sheActivityModel->alias('a')
  372. ->join('user u','a.uid=u.id',"left")
  373. ->where($where)
  374. ->limit($pages)
  375. ->order('create_time desc')
  376. ->field('a.*')
  377. ->select()->toArray();
  378. if (empty($data)) return json(['code'=>1,'data'=>$data]);
  379. $time = date('Y-m-d H:i:s', time());
  380. $res = [];
  381. foreach ($data as $k => $v) {
  382. if ($time > $v['end_time']) {
  383. $res[$k] = $v;
  384. $res[$k]['status'] = '2';
  385. $res[$k]['status_str'] = '已结束';
  386. $order = AcitivityOrder::where('a_id',$v['id'])->column('uid');
  387. $str = implode(',',$order);
  388. unset($order);
  389. $res[$k]['users'] = Db::name('user')->where('id','in',$str)->field('id,avatar')->select();
  390. }
  391. }
  392. return json(['code'=>1,'data'=>$res]);
  393. } else if($type==3) {
  394. $sheActivityModel = new SheActivityModel();
  395. $user = $this->auth->getUser();
  396. $where = [];
  397. if ($user) $where['a.uid'] = $user['id'];
  398. $data = $sheActivityModel->alias('a')
  399. ->join('user u','a.uid=u.id',"left")
  400. ->where($where)
  401. ->limit($pages)
  402. // ->where('switch',0)
  403. ->where('is_quxiao',1)
  404. ->order('create_time desc')
  405. ->field('a.*')
  406. ->select()->toArray();
  407. if (empty($data)) return json(['code'=>1,'data'=>$data]);
  408. $time = date('Y-m-d H:i:s', time());
  409. foreach ($data as $k => $v) {
  410. $data[$k]['status'] = '3';
  411. $data[$k]['status_str'] = '已取消';
  412. $order = AcitivityOrder::where('a_id',$v['id'])->column('uid');
  413. $str = implode(',',$order);
  414. $data[$k]['users'] = Db::name('user')->where('id','in',$str)->field('id,avatar')->select();
  415. unset($order);
  416. }
  417. return json(['code'=>1,'data'=>$data]);
  418. }
  419. }
  420. /**
  421. * 报名人员
  422. *
  423. * @param string $id 活动id
  424. */
  425. public function baoming()
  426. {
  427. $id = $this->request->get('id');
  428. $orderModel = new AcitivityOrder();
  429. $page = $this->request->get('page');
  430. $limit = $this->request->get('limit');
  431. if (!$page) {
  432. $pages = '0,10';
  433. } else {
  434. $page = $page - 1;
  435. if ($page < 0) $page = 0;
  436. $pages = $page . ',' . $limit;
  437. }
  438. $data = $orderModel->alias('a')
  439. ->where('a_id',$id)
  440. ->group('uid')
  441. ->limit($pages)
  442. ->column('uid');
  443. if (empty($data)) return $this->success('',[]);
  444. $dataArr = implode(',',$data);
  445. $users = Db::name('user')
  446. ->where('id','in',$dataArr)
  447. ->where('status',1)
  448. ->field('id,username,position,company')
  449. ->select();
  450. foreach ($users as $k=>$v) {
  451. if (!empty($v['company'])) {
  452. $isqiye = Db::name('user')->where('group_id',2)->where('shenhe_status',0)->find();
  453. if ($isqiye) {
  454. $users[$k]['company_str'] =$isqiye['notice'];
  455. } else {
  456. $users[$k]['company_str'] = '';
  457. }
  458. } else {
  459. $users[$k]['company_str'] = '';
  460. }
  461. }
  462. return $this->success('',$users);
  463. }
  464. /**
  465. * 我的办公室订单
  466. */
  467. public function officeOrder()
  468. {
  469. $page = $this->request->get('page');
  470. $limit = $this->request->get('limit');
  471. if (!$page) {
  472. $pages = '0,10';
  473. } else {
  474. $page = $page - 1;
  475. if ($page < 0) $page = 0;
  476. $pages = $page . ',' . $limit;
  477. }
  478. $user = $this->auth->getUser();
  479. $orderModel = new OfficeOrderModel();
  480. $data = $orderModel
  481. ->with(['office'])
  482. ->where('uid',$user['id'])
  483. ->limit($pages)
  484. ->order('create_time desc')
  485. ->select();
  486. return $this->success('',$data);
  487. }
  488. /**
  489. * 我的会议室订单
  490. */
  491. public function meetingOrder()
  492. {
  493. $page = $this->request->get('page');
  494. $limit = $this->request->get('limit');
  495. if (!$page) {
  496. $pages = '0,10';
  497. } else {
  498. $page = $page - 1;
  499. if ($page < 0) $page = 0;
  500. $pages = $page . ',' . $limit;
  501. }
  502. $user = $this->auth->getUser();
  503. $orderModel = new MeetingOrder();
  504. $data = $orderModel
  505. ->with(['meeting'])
  506. ->where('u_id',$user['id'])
  507. ->limit($pages)
  508. ->order('create_time desc')
  509. ->select();
  510. return $this->success('',$data);
  511. }
  512. /**
  513. *
  514. * 邀请记录
  515. * @param string $a_id $活动id
  516. */
  517. public function yaoqing()
  518. {
  519. $page = $this->request->get('page');
  520. $limit = $this->request->get('limit');
  521. if (!$page) {
  522. $pages = '0,10';
  523. } else {
  524. $page = $page - 1;
  525. if ($page < 0) $page = 0;
  526. $pages = $page . ',' . $limit;
  527. }
  528. $a_id = $this->request->get('a_id');
  529. $user = $this->auth->getUser();
  530. $beUid = Db::name('fenxiang')
  531. ->where('a_id',$a_id)
  532. ->where('u_id',$user['id'])
  533. ->limit($pages)
  534. ->column('be_uid');
  535. $str = implode(',',$beUid);
  536. $users = Db::name('user')
  537. ->where('id','in',$str)
  538. ->where('status',1)
  539. ->field('id,username,avatar,mobile')
  540. ->select();
  541. return json(['code' => 1, 'data'=>$users]);
  542. }
  543. }