UniversityEvent.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\UniversityEventModel;
  5. use app\utils\Service\Tencent\TencentIm;
  6. use think\Db;
  7. /**
  8. * 老年大学 活动板块
  9. */
  10. class UniversityEvent extends Api
  11. {
  12. protected $noNeedLogin = [''];
  13. protected $noNeedRight = ['*'];
  14. // 活动列表
  15. public function list()
  16. {
  17. $user_id = $this->auth->id;
  18. $list = UniversityEventModel::with([
  19. 'apply' => function ($query) use ($user_id) {
  20. $query->field('id,event_id,user_id')->where('user_id', $user_id)->where('status', 1);
  21. }
  22. ])
  23. ->field('id,name,price,image,start_apply_time,end_apply_time,start_time,address')
  24. ->where('status', 1)
  25. ->order('id desc')
  26. ->autopage()
  27. ->select();
  28. foreach ($list as $k => $v) {
  29. $list[$k]['start_apply_time'] = date('Y-m-d H:i', $v['start_apply_time']);
  30. $list[$k]['end_apply_time'] = date('Y-m-d H:i', $v['end_apply_time']);
  31. $list[$k]['start_time'] = date('Y-m-d H:i', $v['start_time']);
  32. $list[$k]['apply'] = !empty($v['apply']) ? 1 : 0;
  33. }
  34. return $this->success('success',$list);
  35. }
  36. // 活动详情
  37. public function info()
  38. {
  39. $params = $this->request->param();
  40. if (empty($params['event_id'])){
  41. return $this->error('参数缺失');
  42. }
  43. $user_id = $this->auth->id;
  44. $info = UniversityEventModel::with([
  45. 'apply' => function ($query) use ($user_id) {
  46. $query->field('id,event_id,user_id')->where('user_id', $user_id)->where('status', 1);
  47. }
  48. ])
  49. ->field('id,name,price,image,images,start_apply_time,end_apply_time,start_time,address,content')
  50. ->where('id', $params['event_id'])
  51. ->where('status', 1)
  52. ->order('id desc')
  53. ->find();
  54. $info['start_apply_time'] = date('Y-m-d H:i', $info['start_apply_time']);
  55. $info['end_apply_time'] = date('Y-m-d H:i', $info['end_apply_time']);
  56. $info['start_time'] = date('Y-m-d H:i', $info['start_time']);
  57. $info['apply'] = !empty($info['apply']) ? 1 : 0;
  58. return $this->success('success',$info);
  59. }
  60. }