123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- /**
- * Created by PhpStorm.
- * User: guanxl
- * Date: 2018/9/28
- * Time: 11:41
- */
-
- namespace App\Http\Controllers;
-
- use App\Models\Corp;
- use App\Services\BrainstormingService;
- use App\Services\UserService;
- use Illuminate\Support\Facades\Cookie;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Http\Request;
- use App\Models\User;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
-
- class CorpController extends BaseController
- {
- /**
- * 企业活动列表
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function activityList(Request $request)
- {
-
- try{
- $ddCorpId = $request->get("dd_corp_id");
- $corpId = 0;
- if(!empty($ddCorpId)){
- $corp = Corp::where("dd_corp_id",$ddCorpId)->first();
- if($corp){
- $corpId = $corp->corp_id;
- }
- }else{
- $corpId = $request->get("corp_id");
- }
-
- if(empty($corpId)){
- $corpId = empty(Cookie::get("oauth_corp_id"))? 0:Cookie::get("oauth_corp_id");
- }
- $status = $request->get("status","running");
- $redisKey = "bs_corp:".$status.":".$corpId;
- //$redisValue = Redis::get($redisKey);
- $redisValue = "";
- if(empty($redisValue)){
- $curTime = time();
- $where = " and A.corp_id={$corpId} and A.status=1 and is_complete_set=1";
- switch ($status) {
- case "upcoming":
- $where .= " and A.start_time>".$curTime;
- break;
- case "finish":
- $where .= " and A.end_time<".$curTime;
- break;
- default:
- $where .= " and (A.start_time<$curTime and A.end_time>$curTime)";
- break;
- }
- $data = [];
- $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");
- foreach ($activitys as $activity){
- $userCount = User::where("activity_id",$activity->activity_id)->where("status",1)->count();
- $data[] = [
- "activity_id" => $activity->activity_id,
- "title" => $activity->title,
- "desc" => $activity->share_home_desc,
- "start_time" => $activity->start_time*1000,
- "end_time" => $activity->end_time*1000,
- "top_banner" => $activity->top_banner,
- "url" => env("WEB_URL")."?activity_id=".$activity->activity_id,
- "user_count" => $userCount
- ];
- }
-
- Redis::setex($redisKey,300,json_encode($data));
-
- }else{
- $data = json_decode($redisValue,true);
- }
- return response()->json([
- "error" => 0,
- "message" => "OK",
- "data" => $data
- ]);
- }catch (\Exception $exception){
- Log::info($exception->getTraceAsString());
- return response()->json([
- "error" => 0,
- "message" => "OK",
- "data" => []
- ]);
- }
- }
-
- /**
- * 我加入的活动
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function joinActivity(Request $request){
- try{
- $openId = $request->get("openid");
- $ddCorpId = $request->get("dd_corp_id");
- $corpId = 0;
- if(!empty($ddCorpId)){
- $corp = Corp::where("dd_corp_id",$ddCorpId)->first();
- if($corp){
- $corpId = $corp->corp_id;
- }
- }else{
- $corpId = $request->get("corp_id");
- }
- $data = [];
- if($openId){
- $redisKey = "bs_corp:activitys:".$openId;
- //$redisValue = Redis::get($redisKey);
- $redisValue = "";
- if(empty($redisValue)){
- $where = " and B.open_id='$openId' and A.corp_id='$corpId' and A.status=1";
- $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");
- foreach ($activitys as $activity){
- $activityRedis = BrainstormingService::getInstance()->get($activity->activity_id);
- $userCount = User::where("activity_id",$activity->activity_id)->where("status",1)->count();
- $data[] = [
- "activity_id" => $activity->activity_id,
- "title" => $activity->title,
- "desc" => $activity->share_home_desc,
- "start_time" => $activity->start_time*1000,
- "end_time" => $activity->end_time*1000,
- "top_banner" => $activityRedis["top_banner"],
- "url" => env("WEB_URL")."?activity_id=".$activity->activity_id,
- "user_count" => $userCount
- ];
- }
-
- Redis::setex($redisKey,300,json_encode($data));
- }else{
- $data = json_decode($redisValue,true);
- }
- }
- return response()->json([
- "error" => 0,
- "message" => "OK",
- "data" => $data
- ]);
- }catch (\Exception $exception){
- Log::info($exception->getTraceAsString());
- return response()->json([
- "error" => 0,
- "message" => "OK",
- "data" => []
- ]);
- }
- }
- }
|