Activity.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\mainapp\controller;
  3. use app\mainapp\BaseController;
  4. use app\common\model\Activity as ActivityModel;
  5. use app\common\model\ActivityJoin as ActivityJoinModel;
  6. class Activity extends BaseController
  7. {
  8. public function listActivity()
  9. {
  10. $ppage = input('ppage/d', 1);
  11. $psize = input('psize/d', 20);
  12. $map[] = ['status', '=', 1];
  13. $plist = ActivityModel::where($map)->order(['priority' => 'desc', 'id' => 'desc'])->page($ppage)->limit($psize)->select();
  14. page_result(0, "", [
  15. 'plist' => $plist,
  16. 'pstatus' => $psize > count($plist) ? 'noMore' : 'more',
  17. ]);
  18. }
  19. public function detailActivity()
  20. {
  21. $id = input('id/d', 0);
  22. $list = ActivityModel::findOrEmpty($id);
  23. if ($list->isEmpty()) {
  24. page_result(1, "活动不存在");
  25. }
  26. $userid = input('userid/d', 0);
  27. $join_status = ActivityJoinModel::where([['user_id', '=', $userid], ['activity_id', '=', $id]])->count();
  28. page_result(0, "", [
  29. 'list' => $list,
  30. 'join_status' => $join_status > 0 ? true : false,
  31. ]);
  32. }
  33. public function joinActivity()
  34. {
  35. $id = input('id/d', 0);
  36. $userid = input('userid/d', 0);
  37. if (empty($id) || empty($userid)) {
  38. page_result(1, "数据错误");
  39. }
  40. $info = ActivityModel::findOrEmpty($id);
  41. if ($info->isEmpty()) {
  42. page_result(1, "活动不存在");
  43. }
  44. $info->join_num++;
  45. $info->save();
  46. ActivityJoinModel::create([
  47. 'user_id' => $userid,
  48. 'activity_id' => $id,
  49. 'create_time' => time(),
  50. ]);
  51. page_result(0);
  52. }
  53. public function joinList()
  54. {
  55. $userid = input('userid/d', 0);
  56. if (empty($userid)) {
  57. page_result(1, "请先登录");
  58. }
  59. $ppage = input('ppage/d', 1);
  60. $psize = input('psize/d', 20);
  61. $map[] = ['user_id', '=', $userid];
  62. $plist = ActivityJoinModel::with('activity')->where($map)->order(['id' => 'desc'])->page($ppage)->limit($psize)->append(['status_text'])->select();
  63. page_result(0, "", [
  64. 'plist' => $plist,
  65. 'pstatus' => $psize > count($plist) ? 'noMore' : 'more',
  66. ]);
  67. }
  68. public function cancelJoin()
  69. {
  70. $id = input('id/d', 0);
  71. if (empty($id)) {
  72. page_result(1, "数据错误");
  73. }
  74. $join = ActivityJoinModel::find($id);
  75. if (empty($join)) {
  76. page_result(1, "数据错误");
  77. }
  78. if ($join->status == 2) {
  79. page_result(0, "操作成功");
  80. }
  81. $join->cancel_time = time();
  82. $join->status = 2;
  83. $join->save();
  84. ActivityModel::where('id' , $join['activity_id'])->dec('join_num')->update();
  85. page_result(0, "操作成功");
  86. }
  87. }