PosterController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/20
  6. * Time: 16:34
  7. */
  8. namespace App\Http\Controllers;
  9. use App\Repositories\PosterRepository;
  10. use App\Traits\UserTrait;
  11. use Illuminate\Support\Facades\Redis;
  12. use Illuminate\Support\Facades\Validator;
  13. use Illuminate\Http\Request;
  14. use Intervention\Image\ImageManagerStatic;
  15. class PosterController extends Controller
  16. {
  17. use UserTrait;
  18. public function __construct()
  19. {
  20. }
  21. /**
  22. * 分享内容海报
  23. */
  24. public function post(Request $request)
  25. {
  26. $validator = Validator::make($request->all(), [
  27. 'id' => 'required|integer',
  28. ]);
  29. if ($validator->fails()) {
  30. return jsonError($validator->errors()->first());
  31. }
  32. $userInfo = $this->getUserInfo();
  33. if(!$userInfo){
  34. return jsonError('获取用户信息失败');
  35. }
  36. $key = 'share_post_id_'.$request['id'].'_uid'.$userInfo['uid'];
  37. $url = Redis::get($key);
  38. if($url) return jsonSuccess($url);
  39. // 合成基本图
  40. $main = public_path('/image/post/main.png');
  41. $imageRepository = new PosterRepository($main);
  42. return $imageRepository->post($main,$userInfo,$request['id'],$key);
  43. }
  44. /**
  45. * 邀请海报
  46. */
  47. public function invite()
  48. {
  49. $userInfo = $this->getUserInfo();
  50. if(!$userInfo){
  51. return jsonError('获取用户信息失败');
  52. }
  53. $bean = 500;
  54. $key = 'share_invite_uid'.$userInfo['uid'].'bean_'.$bean;
  55. $url = Redis::get($key);
  56. if($url) return jsonSuccess($url);
  57. // 合成基本图
  58. $main = public_path('/image/invite/main.png');
  59. $imageRepository = new PosterRepository($main);
  60. return $imageRepository->invite($main,$userInfo,$key,$bean);
  61. }
  62. }