BrainstormingService.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: gevnc
  5. * Date: 2018/5/14
  6. * Time: 17:59
  7. */
  8. namespace App\Services;
  9. use App\Traits\Singleton;
  10. use Illuminate\Support\Facades\DB;
  11. use Illuminate\Support\Facades\Redis;
  12. use Yansongda\Pay\Log;
  13. class BrainstormingService
  14. {
  15. use Singleton;
  16. const BRAINSTORMING = "bs_brainstorming";
  17. public function cache($activityId){
  18. $activity = DB::table("agh_activitys")->where("activity_id",$activityId)->first();
  19. $corp = DB::table("agh_corps")->where("corp_id",$activity->corp_id)->first();
  20. $config = DB::table("bs_configs")->where("activity_id",$activityId)->first();
  21. $brainstorming = collect($config)->toArray();
  22. $extendConfigs =[];
  23. if(!empty($brainstorming["extend_configs"])){
  24. $extendConfigs = json_decode($brainstorming["extend_configs"],true);
  25. }
  26. unset($brainstorming["extend_configs"]);
  27. $brainstorming = array_merge(collect($activity)->toArray(),$brainstorming);
  28. $brainstorming = array_merge($brainstorming,$extendConfigs);
  29. $brainstorming["title"] = $activity->title;
  30. $brainstorming["logo"] = $activity->logo;
  31. $brainstorming["regulation"] = $activity->regulation;
  32. $brainstorming["corp_name"] = $corp->corp_name;
  33. $brainstorming["corp_short_name"] = $corp->corp_short_name;
  34. $brainstorming["qy_corp_id"] = $corp->qy_corp_id;
  35. $brainstorming["gcorp_id"] = $corp->source_id;
  36. unset($brainstorming["update_time"]);
  37. unset($brainstorming["create_time"]);
  38. \Illuminate\Support\Facades\Log::info(json_encode($brainstorming,256));
  39. Redis::hMset(self::BRAINSTORMING.":".$activityId,$brainstorming);
  40. Redis::expire(self::BRAINSTORMING.":".$activityId,600);
  41. //缓存题目
  42. if(!Redis::exists("question_cache:".$activityId)){
  43. QuestionService::getInstance()->cache($activityId);
  44. Redis::setex("question_cache:".$activityId,86400,$activityId);
  45. }
  46. return $brainstorming;
  47. }
  48. public function get($activityId){
  49. $data = Redis::hGetall(self::BRAINSTORMING.":".$activityId);
  50. if($data){
  51. return $data;
  52. }else{
  53. return $this->cache($activityId);
  54. }
  55. }
  56. }