dyjh 6 years ago
parent
commit
0525996a7e

+ 1 - 1
.gitignore

xqd
@@ -12,4 +12,4 @@ _ide_helper*
 *.lock
 /storage/logs
 /public/upload
-/public/download
+/public/download

+ 1 - 0
app/Http/Controllers/Admin/Album/PosterController.php

xqd
@@ -54,6 +54,7 @@ class PosterController extends Controller
             $data['posters'] = json_encode($data['posters']['url']);
         }
         $data['share'] = $this->formatImgUrl($data['share']);
+        $data['qrcode'] = $this->formatImgUrl($data['qrcode']);
         if (!empty($data['words'])) {
             $data['words'] = json_encode($data['words']);
         }

+ 130 - 9
app/Http/Controllers/Api/V1/AlbumPosterController.php

xqd xqd xqd xqd xqd xqd
@@ -8,9 +8,11 @@
 
 namespace App\Http\Controllers\Api\V1;
 
+use App\Models\AlbumAgentModel;
 use App\Models\AlbumManufacturerModel;
 use App\Models\AlbumPosterModel;
 use App\Services\Base\ErrorCode;
+use Grafika\Color;
 use Grafika\Grafika;
 use Validator, Response,Auth;
 use Illuminate\Http\Request;
@@ -38,6 +40,8 @@ class AlbumPosterController extends Controller
      *           'share':'xxx'        //分享图片
      *           'phone':'xxx'        //电话
      *           'username':'xxx'     //姓名
+     *           'title':'xxx'        //分享标题
+     *           'qrcode':'xxx'     //二维码
      *      ]
      * }
      * @apiErrorExample {json} Error-Response:
@@ -67,13 +71,8 @@ class AlbumPosterController extends Controller
         }
         $store_id = $request->input('store_id');
         $info = AlbumPosterModel::where('store_id', $store_id)->first()->toArray();
-        $wechat_app = AlbumManufacturerModel::where('store_id', $store_id)->first();
-        if (!file_exists(public_path() . '/upload/QrCodee/' . $store_id . '.gif')) {
-            $this->getQrCode($wechat_app->xyx_id, $wechat_app->xyx_secret, $store_id);
-        }
         $info['phone'] = $userAuth->phone;
         $info['username'] = $userAuth->username;
-        $info['QrCode'] = env('APP_URL') . '/upload/QrCode/' . $store_id . '.gif';
         return $this->api(compact('info'));
     }
 
@@ -106,6 +105,35 @@ class AlbumPosterController extends Controller
         }
     }
 
+    /**
+     * @api {post} /api/album_post/create 生成海报(create)
+     * @apiDescription 生成海报(create)
+     * @apiGroup Album_Post
+     * @apiPermission 需要登录
+     * @apiVersion 0.1.0
+     * @apiParam {int}    [store_id]  商户id
+     * @apiParam {string}    [image]  图片
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "status": true,
+     *     "status_code": 0,
+     *     "message": "",
+     *     "data": [
+     *           'real_url':'asdawd',  //海报
+     *      ]
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     */
     public function createPoster(Request $request)
     {
         $userAuth = Auth('api')->user();
@@ -114,17 +142,110 @@ class AlbumPosterController extends Controller
         }
         $validator = Validator::make($request->all(), [
             'store_id' => 'required',
-            'store_id' => 'required',
+            'image' => 'required',
         ], [
             'store_id.required' => '店铺信息未知',
+            'image' => '缺少图片链接'
         ]);
         if ($validator->fails()) {
             return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
         }
-        $data = $request->input('store_id');
+        $data = $request->input();
+        $info = AlbumPosterModel::where('store_id', $data['store_id'])->first()->toArray();
         $editor = Grafika::createEditor();
         $editor->open($image_poster, public_path() . '/base/poster/img/poster_canvas.png');
-        $editor->open($image_poduct, public_path() . '');
+        $editor->open($image_poduct, str_replace(env('CDN_URL'), public_path(), $data['image']));
+        $editor->blend($image_poster, $image_poduct, 'normal', 1, 'top-left', 5, 5);
+        $font_bold = public_path() . '/base/poster/font/msyhbd.ttc';
+        $font = public_path() . '/base/poster/font/msyh.ttc';
+        for ($i = 0; $i <= 1; $i++) {
+            $len = mb_strlen($info['introduce']);
+            if ($len <= 17) {
+                $editor->text($image_poster, $info['introduce'], 10, 5, 215, new Color("#000000"), $font_bold, 0);
+                break;
+            }
+            if ($i == 0) {
+                $text = mb_substr($info['introduce'], $i * 17, 17);
+            } else {
+                $text = mb_substr($info['introduce'], $i * 17, ($len - 17) > 10 ? 10 : ($len - 17));
+            }
+            $editor->text($image_poster, $text, 10, 5, 215 + 23 * $i, new Color("#000000"), $font_bold, 0);
+        }
+        $editor->open($image_icon, public_path() . '/base/poster/img/phone.png');
+        $editor->blend($image_poster, $image_icon, 'normal', 1, 'top-left', 5, 270);
+        $WeChatApp = AlbumManufacturerModel::where('store_id', $data['store_id'])->first();
+        if ($userAuth->is_dealer != 1) {
+            if ($userAuth->up_agent_id == 0) {
+                $name = $WeChatApp->name;
+                $phone = $WeChatApp->phone;
+            } else {
+                $agent_check = AlbumAgentModel::where([
+                    ['store_id',$data['store_id']],
+                    ['user_id',$userAuth->up_agent_id]
+                ])->first();
+                $name = $agent_check->realname;
+                $phone = $agent_check->phone;
+            }
+        } else {
+            $agent_check = AlbumAgentModel::where([
+                ['store_id',$data['store_id']],
+                ['user_id',$userAuth->id]
+            ])->first();
+            $name = $agent_check->realname;
+            $phone = $agent_check->phone;
+        }
+        $editor->text($image_poster, $phone, 12, 29, 264, new Color("#eb7a48"), $font, 0);
+        $editor->text($image_poster, '长按识别二维码 展示家具画册', 8, 5, 309, new Color("#666666"), $font, 0);
+        $editor->open($image_qrcode, str_replace(env('CDN_URL'), public_path(), $info['qrcode']));
+        $editor->resizeExactWidth($image_qrcode, 70);
+        $editor->resizeExactHeight($image_qrcode, 70);
+        $editor->blend($image_poster, $image_qrcode, 'normal', 1, 'top-left', 150, 235);
+        $editor->text($image_poster, $name, 8, 155, 316, new Color("#666666"), $font, 0);
+        $editor->save($image_poster, public_path() . '/base/poster/download/' . $userAuth->id . '.png');
+        $real_url = env('CDN_URL') . '/base/poster/download/' . $userAuth->id . '.png';
+        return $this->api(compact('real_url'));
+    }
+
+    /**
+     * @api {post} /api/album_post/del 删除海报(del)
+     * @apiDescription 删除海报(del)
+     * @apiGroup Album_Post
+     * @apiPermission 需要登录
+     * @apiVersion 0.1.0
+     * @apiParam {string}    [url]  图片
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "status": true,
+     *     "status_code": 0,
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     */
+    public function posterDel(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'url' => 'required',
+        ], [
+            'url' => '缺少图片链接'
+        ]);
+        if ($validator->fails()) {
+            return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
+        }
+        $url = $request->input('url');
+        $real_url = str_replace(env('CDN_URL'), public_path(), $url);
+        if (file_exists($real_url)) {
+            unlink($real_url);
+        }
+        return $this->api([], 0);
     }
 
     private function curlGet($url)
@@ -147,7 +268,7 @@ class AlbumPosterController extends Controller
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
         $output = curl_exec($ch);
-        file_put_contents(public_path() . '/upload/QrCode/' . $store_id . '.gif', $output . PHP_EOL, FILE_APPEND);
+        file_put_contents(public_path() . '/upload/QrCode/' . $store_id . '.png', $output . PHP_EOL, FILE_APPEND);
         curl_close($ch);
         //$out = json_decode($output);
         return true;

+ 1 - 1
app/Http/Controllers/Api/V1/Controller.php

xqd
@@ -22,7 +22,7 @@ class Controller extends BaseController
         $this->middleware('auth:api', [
             'except' => [
                 'upload', 'getCode', 'reset', 'login', 'get', 'register', 'alipayNotify', 'wechatpayNotify', 'get', 'area', 'get_province', 'get_city', 'get_county', 'albumStyle', 'test', 'index', 'companyInfo', 'shop2', 'cardIndex', 'cardUserInfo', 'cardUserProgress', 'cardUserHonor', 'cardUserProject', 'CardUserTrend', 'projectDetail', 'trendDetail', 'albumSetting', 'albumXyxLogin', 'albumCat', 'albumchecklogin', 'albumGoods', 'albumGoodsDetail', 'albumSetPrice', 'albumXcxLogin', 'albumContentList', 'albumSearchGoods','albumContentDetail','albumFavoriteList','albumAddFavorite','albumFavoriteDel','getAttr','getOrder','getProgress','getReviewCount', 'furnitureNewsDetail','furnitureSetting','furnitureXcxLogin','furnitureGoodsList','serviceLogin','getFurnitureAds','getPhoneNumber','getQrcode','orderCount','searchList','printOrder','saveFormId','furnitureNewsList','getMoreComments','addToLike','albumSavePhone',
-                'albumGetWatchRecord','albumSetWatch','albumGetCartOfWatch','albumSaveFormId','albumAddAgent','albumGetBanner','albumGetDataGoods','newgoods_list','newgoods_index','albumGetAgentAdress','albumSetCustomer','albumGetCustomer','albumGetDataCat','albumCustomerGoods','albumCustomerGoodsDetail','albumGetDataCatSingle','albumGetCountOfFavorite','albumGetUserInfo','albumStatistical','posterInfo','createPoster'
+                'albumGetWatchRecord','albumSetWatch','albumGetCartOfWatch','albumSaveFormId','albumAddAgent','albumGetBanner','albumGetDataGoods','newgoods_list','newgoods_index','albumGetAgentAdress','albumSetCustomer','albumGetCustomer','albumGetDataCat','albumCustomerGoods','albumCustomerGoodsDetail','albumGetDataCatSingle','albumGetCountOfFavorite','albumGetUserInfo','albumStatistical','posterInfo','createPoster','posterDel'
             ]
         ]);
 

+ 2 - 0
app/Models/AlbumPosterModel.php

xqd
@@ -35,6 +35,8 @@ class AlbumPosterModel extends BaseModel
                            'posters',
                            'words',
                            'introduce',
+                           'qrcode',
+                           'title',
                            'share'
                           ];
 

+ 34 - 0
database/migrations/2019_03_05_184614_add_column_to_album_poster.php

xqd
@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddColumnToAlbumPoster extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('album_poster', function (Blueprint $table) {
+            //
+            $table->string('qrcode', 255)->comment('二维码');
+            $table->string('title', 20)->comment('分享标题');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('album_poster', function (Blueprint $table) {
+            //
+        });
+    }
+}

BIN
public/base/poster/download/111.png


BIN
public/base/poster/font/msyh.ttc


BIN
public/base/poster/font/msyhbd.ttc


BIN
public/base/poster/img/phone.png


BIN
public/base/poster/img/poster_canvas.png


+ 19 - 2
resources/views/admin/album/poster/edit.blade.php

xqd xqd
@@ -37,9 +37,9 @@
                                 <input type="hidden" name="id" value="{{ $data['id'] or ''}}"/>
                                 <div class="form-group">
 
-                                    <label class="control-label col-sm-3">海报(1920*1080)</label>
+                                    <label class="control-label col-sm-3">海报(240*200)</label>
                                     <div class="col-sm-9">
-                                        {!!  widget('Tools.ImgUpload')->multi2('/upload/posters','posters',"data[posters]", isset($data['posters'])? $data['posters'] : '',array("sizex"=>240,"sizey"=>200)) !!}
+                                        {!!  widget('Tools.ImgUpload')->multi2('/upload/posters','posters',"data[posters]", isset($data['posters'])? $data['posters'] : '',array("sizex"=>220,"sizey"=>200)) !!}
                                     </div>
                                 </div>
                                 <div class="form-group">
@@ -86,6 +86,23 @@
                                         {!!  widget('Tools.ImgUpload')->single2('/upload/share','share',"share",  isset($data['share'])? $data['share'] : '',array("sizex"=>1920,"sizey"=>1080)) !!}
                                     </div>
                                 </div>
+                                <div class="form-group">
+
+                                    <label class="control-label col-sm-3">分享标题</label>
+
+                                    <div class="col-sm-9">
+                                        <input id="data_introduce" name="data[title]" class="form-control" value="{{ $data['title'] or ''}}" required="" aria-required="true"  placeholder="">
+                                    </div>
+
+                                </div>
+                                <div class="form-group">
+
+                                    <label class="control-label col-sm-3">海报二维码(70*70)</label>
+                                    <div class="col-sm-9">
+                                        {{--{!!  widget('Tools.ImgUpload')->single2('/upload/cover_pic','cover_pic',"cover_pic",  isset($data['cover_pic'])? $data['cover_pic'] : '',array("sizex"=>662,"sizey"=>510)) !!}--}}
+                                        {!!  widget('Tools.ImgUpload')->single2('/upload/qrcode','qrcode',"qrcode",  isset($data['qrcode'])? $data['qrcode'] : '',array("sizex"=>70,"sizey"=>70)) !!}
+                                    </div>
+                                </div>
                                 <div class="form-group">
                                     <label class="control-label col-sm-3">&nbsp;</label>
                                     <div class="col-sm-9">

+ 4 - 0
routes/api.php

xqd
@@ -306,6 +306,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'album_post.create',
         'uses' => 'AlbumPosterController@createPoster',
     ]);
+    $api->post('album_post/del', [
+        'as' => 'album_post.del',
+        'uses' => 'AlbumPosterController@posterDel',
+    ]);
 
     $api->get('album/get-customer', [
         'as' => 'album.get-customer',