PersonDingtalkController.php 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: guanxl
  5. * Date: 2018/9/28
  6. * Time: 11:41
  7. */
  8. namespace App\Http\Controllers;
  9. use App\Models\Corp;
  10. use App\Services\BrainstormingService;
  11. use App\Services\UserService;
  12. use Illuminate\Support\Facades\Cookie;
  13. use Illuminate\Support\Facades\DB;
  14. use Illuminate\Http\Request;
  15. use App\Models\User;
  16. use Illuminate\Support\Facades\Log;
  17. use Illuminate\Support\Facades\Redis;
  18. class PersonDingtalkController extends BaseController
  19. {
  20. /**
  21. * 活动列表
  22. * @param Request $request
  23. * @return \Illuminate\Http\JsonResponse
  24. */
  25. public function activityList(Request $request)
  26. {
  27. try{
  28. $status = $request->get("status","running");
  29. $redisKey = "bs_person_dingtalk:".$status;
  30. //$redisValue = Redis::get($redisKey);
  31. $redisValue = "";
  32. if(empty($redisValue)){
  33. $curTime = time();
  34. $where = " and A.status=1 and is_complete_set=1 and activity_type=3";
  35. switch ($status) {
  36. case "upcoming":
  37. $where .= " and A.start_time>".$curTime;
  38. break;
  39. case "finish":
  40. $where .= " and A.end_time<".$curTime;
  41. break;
  42. default:
  43. $where .= " and (A.start_time<$curTime and A.end_time>$curTime)";
  44. break;
  45. }
  46. $data = [];
  47. $activitys = DB::select("select A.activity_id,A.title,B.share_home_desc,A.start_time,A.end_time,B.top_banner from agh_activitys as A,bs_configs as B where A.activity_id=B.activity_id ".$where." limit 0,100");
  48. foreach ($activitys as $activity){
  49. $userCount = User::where("activity_id",$activity->activity_id)->where("status",1)->count();
  50. $data[] = [
  51. "activity_id" => $activity->activity_id,
  52. "title" => $activity->title,
  53. "desc" => $activity->share_home_desc,
  54. "start_time" => $activity->start_time*1000,
  55. "end_time" => $activity->end_time*1000,
  56. "top_banner" => $activity->top_banner,
  57. "url" => env("WEB_URL")."?activity_id=".$activity->activity_id,
  58. "user_count" => $userCount
  59. ];
  60. }
  61. Redis::setex($redisKey,300,json_encode($data));
  62. }else{
  63. $data = json_decode($redisValue,true);
  64. }
  65. return response()->json([
  66. "error" => 0,
  67. "message" => "OK",
  68. "data" => $data
  69. ]);
  70. }catch (\Exception $exception){
  71. Log::info($exception->getTraceAsString());
  72. return response()->json([
  73. "error" => 0,
  74. "message" => "OK",
  75. "data" => []
  76. ]);
  77. }
  78. }
  79. /**
  80. * 我加入的活动
  81. * @param Request $request
  82. * @return \Illuminate\Http\JsonResponse
  83. */
  84. public function joinActivity(Request $request){
  85. try{
  86. $openId = $request->get("openid");
  87. $data = [];
  88. if($openId){
  89. $redisKey = "bs_person_dingtalk:activitys:".$openId;
  90. //$redisValue = Redis::get($redisKey);
  91. $redisValue = "";
  92. if(empty($redisValue)){
  93. $where = " and B.open_id='$openId' and A.status=1 and activity_type=3";
  94. $activitys = DB::select("select A.activity_id,A.title,C.share_home_desc,A.start_time,A.end_time from agh_activitys as A,bs_users as B,bs_configs as C where A.activity_id=C.activity_id and A.activity_id=B.activity_id ".$where." limit 0,100");
  95. foreach ($activitys as $activity){
  96. $activityRedis = BrainstormingService::getInstance()->get($activity->activity_id);
  97. $userCount = User::where("activity_id",$activity->activity_id)->where("status",1)->count();
  98. $data[] = [
  99. "activity_id" => $activity->activity_id,
  100. "title" => $activity->title,
  101. "desc" => $activity->share_home_desc,
  102. "start_time" => $activity->start_time*1000,
  103. "end_time" => $activity->end_time*1000,
  104. "top_banner" => $activityRedis["top_banner"],
  105. "url" => env("WEB_URL")."?activity_id=".$activity->activity_id,
  106. "user_count" => $userCount
  107. ];
  108. }
  109. Redis::setex($redisKey,300,json_encode($data));
  110. }else{
  111. $data = json_decode($redisValue,true);
  112. }
  113. }
  114. return response()->json([
  115. "error" => 0,
  116. "message" => "OK",
  117. "data" => $data
  118. ]);
  119. }catch (\Exception $exception){
  120. Log::info($exception->getTraceAsString());
  121. return response()->json([
  122. "error" => 0,
  123. "message" => "OK",
  124. "data" => []
  125. ]);
  126. }
  127. }
  128. }