Forráskód Böngészése

Merge branch 'develop' of http://git.caihongxingqiu.net/rainbow/config-service into develop

xielin 5 éve
szülő
commit
6e07eaecd8

+ 11 - 1
app/Http/Controllers/ConfigController.php

@@ -7,8 +7,11 @@
  */
 namespace App\Http\Controllers;
 
+use App\Traits\CommunityTrait;
+
 class ConfigController extends Controller
 {
+    use CommunityTrait;
     /**
      * Create a new controller instance.
      *
@@ -22,7 +25,14 @@ class ConfigController extends Controller
     {
         $data = [
             //商品类型
-            'order_expired_time' => config('customer.order_expired_time')
+            'order_expired_time' => config('customer.order_expired_time'),
+            'virus_url' => config('customer.VIRUS_URL'),
+            'virus_app_id' => config('customer.VIRUS_APP_ID'),
+            'virus_app_secret' => config('customer.VIRUS_APP_SECRET'),
+            'virus' => $this->getAllBehavior(),
+            'find_friend_img' => config('customer.find_friend_img'),
+            'suggest_img' => config('customer.suggest_img'),
+            'share_post_bean' => (int) config('customer.share_post_bean'),
         ];
         return $this->jsonSuccess($data, '成功');
     }

+ 26 - 0
app/Http/Controllers/MessageRuleController.php

@@ -0,0 +1,26 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/25
+ * Time: 17:12
+ */
+namespace App\Http\Controllers;
+
+use App\Models\MessageRule;
+
+class MessageRuleController extends Controller
+{
+    public function __construct()
+    {
+    }
+
+    /**
+     * 已隐藏规则消息
+     */
+    public function hide()
+    {
+        $ids = MessageRule::where('message_status', 3)->pluck('id');
+        return jsonSuccess($ids);
+    }
+}

+ 29 - 2
app/Http/Controllers/PosterController.php

@@ -9,6 +9,7 @@ namespace App\Http\Controllers;
 
 use App\Repositories\PosterRepository;
 use App\Traits\UserTrait;
+use Illuminate\Support\Facades\Redis;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Http\Request;
 use Intervention\Image\ImageManagerStatic;
@@ -20,6 +21,9 @@ class PosterController extends Controller
     {
     }
 
+    /**
+     * 分享内容海报
+     */
     public function post(Request $request)
     {
         $validator = Validator::make($request->all(), [
@@ -33,12 +37,35 @@ class PosterController extends Controller
         if(!$userInfo){
             return jsonError('获取用户信息失败');
         }
+        $key = 'share_post_id_'.$request['id'].'_uid'.$userInfo['uid'];
+        $url = Redis::get($key);
+        if($url) return jsonSuccess($url);
 
         // 合成基本图
         $main = public_path('/image/post/main.png');
         $imageRepository = new PosterRepository($main);
 
-        $url = $imageRepository->post($main,$userInfo, $request['id']);
-        return $url;
+        return $imageRepository->post($main,$userInfo,$request['id'],$key);
+    }
+
+    /**
+     * 邀请海报
+     */
+    public function invite()
+    {
+        $userInfo = $this->getUserInfo();
+        if(!$userInfo){
+            return jsonError('获取用户信息失败');
+        }
+        $bean = config('customer.share_invite_bean');
+        $key = 'share_invite_uid'.$userInfo['uid'].'bean_'.$bean;
+        $url = Redis::get($key);
+        if($url) return jsonSuccess($url);
+
+        // 合成基本图
+        $main = public_path('/image/invite/main.png');
+        $imageRepository = new PosterRepository($main);
+
+        return $imageRepository->invite($main,$userInfo,$key,$bean);
     }
 }

+ 4 - 2
app/Http/Controllers/UploadController.php

@@ -20,7 +20,8 @@ class UploadController extends Controller
 //            $type=$request->file('image')->getClientMimeType();
 //            //获取文件的绝对路径,但是获取到的在本地不能打开
             $filePath = $request->file('image')->getRealPath();
-            if (in_array($kuoname, ['jpg', 'jpeg', 'png'])) {
+            Log::debug('文件类型'.$kuoname);
+            if (in_array($kuoname, ['jpg', 'jpeg', 'gif', 'png'])) {
                 $width = Image::make($filePath)->width();
                 $height = Image::make($filePath)->height();
                 //要保存的文件名 时间+扩展名
@@ -49,8 +50,9 @@ class UploadController extends Controller
         for ($i = 0; $i < $fileCount; $i++) {
             $kuoname = $files[$i]->getClientOriginalExtension();
             $filePath = $files[$i]->getRealPath();
+            Log::debug('文件类型'.$kuoname);
             //要保存的文件名 时间+扩展名
-            if (in_array($kuoname, ['jpg', 'jpeg', 'png'])) {
+            if (in_array($kuoname, ['jpg', 'jpeg', 'gif', 'png'])) {
                 $width = Image::make($filePath)->width();
                 $height = Image::make($filePath)->height();
                 //要保存的文件名 时间+扩展名

+ 1 - 1
app/Http/Controllers/V2/ActivitiesController.php

@@ -26,7 +26,7 @@ class ActivitiesController extends Controller {
         if ($validator->fails()) {
             return $this->jsonError($validator->errors()->first());
         }
-        $info = $this->activities->where('id',$data['id'])->first();
+        $info = $this->activities->where('id',$data['id'])->select('id','name','content')->first();
         if($info){
            return jsonSuccess($info);
         }

+ 3 - 9
app/Http/Controllers/V2/PlatformContentController.php

@@ -2,11 +2,9 @@
 namespace App\Http\Controllers\V2;
 use App\Http\Controllers\BaseController;
 use App\Repositories\PlatformContentRepository;
-use App\Transformers\PlatformContentTransformer;
 use Illuminate\Http\Request;
-use League\Fractal\Resource\Collection;
-use League\Fractal\Manager;
-use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use Illuminate\Support\Facades\Validator;
+
 /**
  * Created by PhpStorm.
  * User: durong
@@ -25,11 +23,7 @@ class PlatformContentController extends BaseController
     public function index(Request $request)
     {
         $platformContent = $this->platformContentRepository->index($request->all());
+        return $this->jsonSuccess($platformContent);
 
-        $fractal = new Manager();
-        $resource = new Collection($platformContent , new PlatformContentTransformer());
-        $resource->setPaginator(new IlluminatePaginatorAdapter($platformContent));
-        $data = $fractal->createData($resource)->toArray();
-        return $this->jsonSuccess($data);
     }
 }

+ 1 - 6
app/Http/Controllers/V2/StarNewsController.php

@@ -27,11 +27,6 @@ class StarNewsController extends BaseController
     public function index(Request $request)
     {
         $starNews = $this->starNewsRepository->index($request->all());
-
-        $fractal = new Manager();
-        $resource = new Collection($starNews , new StarNewsTransformer());
-        $resource->setPaginator(new IlluminatePaginatorAdapter($starNews));
-        $data = $fractal->createData($resource)->toArray();
-        return $this->jsonSuccess($data);
+        return $this->jsonSuccess($starNews);
     }
 }

+ 14 - 0
app/Models/MessageRule.php

@@ -0,0 +1,14 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/25
+ * Time: 17:09
+ */
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+class MessageRule extends Model
+{
+    protected $table = 'message_rule';
+    protected $guarded = [];
+}

+ 8 - 4
app/Repositories/PlatformContentRepository.php

@@ -19,11 +19,15 @@ class PlatformContentRepository
 
     public function index($request)
     {
-        $perPage = isset($request['per_page']) ? $request['per_page'] : env('PER_PAGE');
-        $this->platformContent = $this->platformContent
-            ->orderBy('id', 'desc');
+        if (isset($request['id'])){
+            return $this->platformContent
+                ->where('id',$request['id'])->orderBy('id', 'desc')->first();
+        }
 
-        return $this->platformContent->paginate($perPage);
+            $this->platformContent = $this->platformContent
+                ->orderBy('id', 'desc')->get();
+
+            return $this->platformContent;
     }
 
 }

+ 121 - 34
app/Repositories/PosterRepository.php

@@ -8,6 +8,7 @@
 namespace App\Repositories;
 
 use App\Traits\CommunityTrait;
+use Illuminate\Support\Facades\Redis;
 use Intervention\Image\Facades\Image;
 use Intervention\Image\ImageManagerStatic;
 use Illuminate\Support\Facades\Storage;
@@ -23,14 +24,12 @@ class PosterRepository
         if (extension_loaded('imagick')) {
             ImageManagerStatic::configure(['driver'=>'imagick']);
         }
-//        $this->main = ImageManagerStatic::make($mainImg);
-//        return $this->main->encoded;
     }
 
     /**
-     * 分享帖子生成海报
+     * 分享内容海报
      */
-    public function post($mainImg,$userInfo, $id)
+    public function post($mainImg,$userInfo,$id,$key)
     {
         $main = ImageManagerStatic::make($mainImg);
         $postDetail = $this->getPostDetail($id);
@@ -38,14 +37,17 @@ class PosterRepository
             return jsonError('获取内容信息失败');
         }
 
-        // 设置头像
-        if(!$userInfo['avatar']){
-            $userInfo['avatar'] = 'https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83ep3asJn8emiat1MnPdviaPNroWY3f65y5ezkTAk2qtibv7ea9Ht9R2ahxr9bicY1DIj5vN5FibpDOwXegg/132';
-        }
+        // 彩虹豆数
+        $bean = config('customer.share_post_bean');
+        $beanWidth = 540;
+        if(strlen($bean) == 4) $beanWidth = 532;
+        $main->text($bean, $beanWidth, 1214, function ($font) {
+            $font->file(public_path('font/PingFang Bold.ttf'));
+            $font->size(28);
+            $font->color('#FFFFFF');
+            $font->align('left');
+        });
 
-        if(!$userInfo['username']){
-            $userInfo['username'] = '我是谁啦啦啦里哦';
-        }
         //内容图片
         $postImg = ImageManagerStatic::make($postDetail['img'].'!poster_app')->fit(750, 962);
         $main->insert($postImg, 'left-top', 0, 0);
@@ -100,45 +102,130 @@ class PosterRepository
         });
 
         // 用户名称
-        $main->text($userInfo['username'], 155, 470, function ($font) {
-            $font->file(public_path('font/PingFang Regular.ttf'));
-            $font->size(24);
-            $font->color('#FFFFFF');
-            $font->align('left');
-        });
+        if($userInfo['username']){
+            $main->text($userInfo['username'], 155, 470, function ($font) {
+                $font->file(public_path('font/PingFang Regular.ttf'));
+                $font->size(24);
+                $font->color('#FFFFFF');
+                $font->align('left');
+            });
+        }
 
-        //用户头像
-        $avatar = Image::make($userInfo['avatar'])->resize(42,42);
-        $new= Image::canvas(750, 1334);
-        $r=$avatar->width() /2;
-        for($x=0;$x<$avatar->width();$x++) {
+        // 用户头像
+        if($userInfo['avatar']){
+            $avatar = Image::make($userInfo['avatar'])->resize(42,42);
+            $new= Image::canvas(750, 1334);
+            $r=$avatar->width() /2;
+            for($x=0;$x<$avatar->width();$x++) {
 
-            for($y=0;$y<$avatar->height();$y++) {
+                for($y=0;$y<$avatar->height();$y++) {
 
-                $c=$avatar->pickColor($x,$y,'array');
+                    $c=$avatar->pickColor($x,$y,'array');
 
-                if(((($x-$r) * ($x-$r) + ($y-$r) * ($y-$r)) < ($r*$r))) {
-                    $new->pixel($c,$x,$y);
-                }
+                    if(((($x-$r) * ($x-$r) + ($y-$r) * ($y-$r)) < ($r*$r))) {
+                        $new->pixel($c,$x,$y);
+                    }
 
+                }
             }
-        }
 
-        $main->insert($new, 'top-left', 105, 436);
+            $main->insert($new, 'top-left', 105, 436);
+        }
 
-        $qrcode = Image::make(QrCode::format('png')->generate('https://www.jianshu.com/p/1c78294f26f8'));
+        $qrcode = Image::make(QrCode::format('png')->generate(config('customer.share_post_h5url')."?post_id={$id}&invite_code={$userInfo['invite_code']}"));
 
         $qrcode->resize(164,164);
 
         $main->insert($qrcode,'top-left', 63, 1087);
 
-//        $main->save(public_path('test/post_id'.$id.'.png'));
-//        return $response = $main->response();
+        // 存储图片
+        $filename = date('Ym').'/'.time() . '_' . uniqid() . '.jpg';
+        Storage::put($filename, (string)$main->encode('jpg'));
+        $url = 'http://oss.caihongxingqiu.net/'.$filename;
+        Redis::set($key, $url);
+        Redis::expire($key, 3600 * 24 * 3);
+
+        return jsonSuccess($url);
+    }
+
+    /**
+     * 邀请海报
+     */
+    public function invite($mainImg,$userInfo,$key, $bean)
+    {
+        $main = ImageManagerStatic::make($mainImg);
+
+        // 彩虹豆数
+        $beanWidth = 194;
+        if(strlen($bean) == 4) $beanWidth = 182;
+        $main->text($bean, $beanWidth, 1060, function ($font) {
+            $font->file(public_path('font/PingFang Bold.ttf'));
+            $font->size(36);
+            $font->color('#C74A48');
+            $font->align('left');
+        });
+
+        // 邀请码
+        if($userInfo['invite_code']){
+            $str = $userInfo['invite_code'];
+            $strLower = strtolower($str);
+            $upperNumber = 0;
+            for($i=0;$i<6;$i++){
+                if($str[$i] != $strLower[$i]) $upperNumber++;
+            }
+            $codeWidth = 212 - $upperNumber * 3;
+            $main->text($str, $codeWidth, 912, function ($font) {
+                $font->file(public_path('font/PingFang Regular.ttf'));
+                $font->size(28);
+                $font->color('#3C5852');
+                $font->align('left');
+            });
+        }
+
+        // 用户名称
+        if($userInfo['username']){
+            $main->text($userInfo['username'], 30, 860, function ($font) {
+                $font->file(public_path('font/PingFang Regular.ttf'));
+                $font->size(28);
+                $font->color('#3C5852');
+                $font->align('left');
+            });
+        }
+
+        // 用户头像
+        if($userInfo['avatar']){
+            $avatar = Image::make($userInfo['avatar'])->resize(88,88);
+            $new= Image::canvas(750, 1346);
+            $r=$avatar->width() /2;
+            for($x=0;$x<$avatar->width();$x++) {
+
+                for($y=0;$y<$avatar->height();$y++) {
+
+                    $c=$avatar->pickColor($x,$y,'array');
+
+                    if(((($x-$r) * ($x-$r) + ($y-$r) * ($y-$r)) < ($r*$r))) {
+                        $new->pixel($c,$x,$y);
+                    }
+
+                }
+            }
+
+            $main->insert($new, 'top-left', 30, 717);
+        }
+
+        $qrcode = Image::make(QrCode::format('png')->generate(config('customer.share_invite_h5url')."?invite_code={$userInfo['invite_code']}"));
+
+        $qrcode->resize(170,170);
+
+        $main->insert($qrcode,'top-left', 547, 944);
 
         // 存储图片
         $filename = date('Ym').'/'.time() . '_' . uniqid() . '.jpg';
-        $url = Storage::put($filename, (string)$main->encode('jpg'));
+        Storage::put($filename, (string)$main->encode('jpg'));
+        $url = 'http://oss.caihongxingqiu.net/'.$filename;
+        Redis::set($key, $url);
+        Redis::expire($key, 3600 * 24 * 3);
 
-        return $filename;
+        return jsonSuccess($url);
     }
 }

+ 6 - 3
app/Repositories/StarNewsRepository.php

@@ -19,10 +19,13 @@ class StarNewsRepository
 
     public function index($request)
     {
-        $perPage = isset($request['per_page']) ? $request['per_page'] : env('PER_PAGE');
+        if (isset($request['id'])){
+            return $this->starNews
+                ->where('id',$request['id'])->orderBy('id', 'desc')->first();
+        }
         $this->starNews = $this->starNews
-            ->orderBy('id', 'desc');
+            ->orderBy('id', 'desc')->get();
 
-        return $this->starNews->paginate($perPage);
+        return $this->starNews;
     }
 }

+ 14 - 0
app/Traits/CommunityTrait.php

@@ -24,4 +24,18 @@ trait CommunityTrait
         }
 
     }
+
+    public function getAllBehavior() {
+        try {
+            $sign = generateSign([], config('customer.app_secret'));
+            $url = config("customer.app_service_url").'/community/getAllBehavior';
+            $array = [
+                'json' => ['sign' => $sign], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+            ];
+            return http($url,$array, 'get');
+        } catch (\Exception $e) {
+            return [];
+        }
+
+    }
 }

+ 0 - 20
app/Transformers/PlatformContentTransformer.php

@@ -1,20 +0,0 @@
-<?php
-
-namespace App\Transformers;
-
-use App\Models\PlatformContent;
-use League\Fractal\TransformerAbstract;
-
-class PlatformContentTransformer extends TransformerAbstract
-{
-
-    public function transform(PlatformContent $platformContent)
-    {
-        return [
-            'id'  => $platformContent['id'],
-            'title'    => $platformContent['title'],
-            'content'    => $platformContent['content'],
-            'updated_at'    => date($platformContent['updated_at']),
-        ];
-    }
-}

+ 0 - 23
app/Transformers/StarNewsTransformer.php

@@ -1,23 +0,0 @@
-<?php
-
-namespace App\Transformers;
-
-use App\Models\StarNews;
-use League\Fractal\TransformerAbstract;
-
-class StarNewsTransformer extends TransformerAbstract
-{
-
-    public function transform(StarNews $starNews)
-    {
-        return [
-            'id'  => $starNews['id'],
-            'title'    => $starNews['title'],
-            'content'    => $starNews['content'],
-            'cover_img'    => $starNews['cover_img'],
-            'status'    => $starNews['status'],
-            'sort'    => $starNews['sort'],
-            'updated_at'    => date($starNews['updated_at']),
-        ];
-    }
-}

+ 9 - 0
config/customer.tpl

@@ -6,4 +6,13 @@ return [
     'app_service_url' => '{app_service_url}',
     'chxq_oss_url' => '{chxq_oss_url}',
     'order_expired_time' => '{order_expired_time}',
+    'VIRUS_URL' => '{VIRUS_URL}',
+    'VIRUS_APP_ID' => '{VIRUS_APP_ID}',
+    'VIRUS_APP_SECRET' => '{VIRUS_APP_SECRET}',
+    'share_invite_h5url' => '{share_invite_h5url}',
+    'share_invite_bean' => '{share_invite_bean}',
+    'share_post_h5url' => '{share_post_h5url}',
+    'share_post_bean' => '{share_post_bean}',
+    'find_friend_img' => '{find_friend_img}',
+    'suggest_img' => '{suggest_img}',
 ];

BIN
public/image/invite/main.png


BIN
public/image/post/main.png


+ 9 - 6
routes/api.php

@@ -22,15 +22,21 @@ $api->version('v1', [
         $api->post('upload', 'UploadController@uploadImage');
         $api->post('multi_upload', 'UploadController@uploadImages');
 
+        //分享内容海报
         $api->get('poster/post', 'PosterController@post');
+        //邀请海报
+        $api->get('poster/invite', 'PosterController@invite');
+
+        //已隐藏规则消息
+        $api->get('message/hide', 'MessageRuleController@hide');
     });
     //登录+验签
     $api->group(['middleware' => ['chxq_jwt_auth','chxq_sign']], function ($api) {
     });
+    //公共配置
+    $api->get('/config','ConfigController@index');
     //仅验签
     $api->group(['middleware' => 'chxq_sign'], function ($api) {
-        //公共配置
-        $api->get('/config','ConfigController@index');
         //自提点列表
         $api->get('/pickupNode/index','ConfigPickupNodeController@index');
 
@@ -57,14 +63,11 @@ $api->version('v1', [
     ], function ($api) {
         //根据多个ID获取banner
         $api->get('/bannerSet/lists', 'BannerController@lists');
-        $api->group(['middleware' => 'chxq_sign'], function ($api) {
+        $api->group(['middleware' => ['chxq_jwt_auth']], function ($api) {
             //平台内容列表
             $api->get('/platformContent/lists', 'PlatformContentController@index');
             //星球新闻列表
             $api->get('/starNews/lists', 'StarNewsController@index');
-
-        });
-        $api->group(['middleware' => ['chxq_jwt_auth']], function ($api) {
             //活动内容详情
             $api->get('activities', 'ActivitiesController@view');
         });