1
0

GroupCommentService.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Services\Groups;
  3. use App\Models\GroupComment;
  4. use Cache;
  5. use Illuminate\Support\Facades\Redis;
  6. use League\Fractal;
  7. use League\Fractal\Serializer\ArraySerializer;
  8. use League\Fractal\Pagination\IlluminatePaginatorAdapter;
  9. use App\Transformer\Api\GroupPostTransformer;
  10. class GroupCommentService
  11. {
  12. const CACHE_KEY = 'pf:services:groups:comment:';
  13. public static function key($gid, $pid)
  14. {
  15. return self::CACHE_KEY . $gid . ':' . $pid;
  16. }
  17. public static function get($gid, $pid)
  18. {
  19. return Cache::remember(self::key($gid, $pid), 604800, function() use($gid, $pid) {
  20. $gp = GroupComment::whereGroupId($gid)->find($pid);
  21. if(!$gp) {
  22. return null;
  23. }
  24. $fractal = new Fractal\Manager();
  25. $fractal->setSerializer(new ArraySerializer());
  26. $resource = new Fractal\Resource\Item($gp, new GroupPostTransformer());
  27. $res = $fractal->createData($resource)->toArray();
  28. $res['pf_type'] = 'group:post:comment';
  29. $res['url'] = $gp->url();
  30. // if($gp['type'] == 'poll') {
  31. // $status['poll'] = PollService::get($status['id']);
  32. // }
  33. //$status['account']['url'] = url("/groups/{$gp['group_id']}/user/{$status['account']['id']}");
  34. return $res;
  35. });
  36. }
  37. public static function del($gid, $pid)
  38. {
  39. return Cache::forget(self::key($gid, $pid));
  40. }
  41. }