dyjh hace 6 años
padre
commit
43d1d13407
Se han modificado 1 ficheros con 98 adiciones y 0 borrados
  1. 98 0
      app/Http/Controllers/Api/V1/AlbumPosterController.php

+ 98 - 0
app/Http/Controllers/Api/V1/AlbumPosterController.php

xqd xqd
@@ -95,6 +95,7 @@ class AlbumPosterController extends Controller
         $datas['avatar'] = $userAuth->avatar;
         $datas['share'] = $WeChatApp->share_image;
         $datas['title'] = $WeChatApp->share_title;
+        $datas['personalQrcode'] = $this->createPosterPersonal($WeChatApp, $store_id);
         $datas['qrcode'] = $this->createPoster($userAuth, $store_id);
         return $this->api(compact('datas'));
     }
@@ -163,6 +164,103 @@ class AlbumPosterController extends Controller
         return $this->api([]);
     }
 
+    Private function createPosterPersonal($WeChatApp, $store_id)
+    {
+
+        $userAuth = Auth('api')->user();
+        if (file_exists(public_path() . '/download/' . $userAuth->id . '_personal.png')) {
+            unlink(public_path() . '/download/' . $userAuth->id . '_personal.png');
+        }
+        if ($userAuth->is_dealer == 1) {
+            $user_agent = AlbumAgentModel::where([['user_id',$userAuth->id],['status',1]])->first();
+            $agent_id = $user_agent['id'];
+        } else {
+            $agent_id = $userAuth->up_agent_id == 0 ? 0 : $userAuth->up_agent_id;
+        }
+        if ($userAuth->up_agent_id != 0) {
+            $add_record['agent_id'] = $userAuth->up_agent_id;
+            $add_record['open_id'] = $userAuth->open_id;
+            $add_record['action'] = 9;
+            $add_record['store_id'] = $store_id;
+            $add_record['detail'] = '保存了图片';
+            $user_agent = AlbumAgentModel::where('id', $userAuth->up_agent_id)->first();
+            $user_agent->share_times++;
+            $user_agent->save();
+            AlbumWatchRecord::create($add_record);
+        }
+        $editor = Grafika::createEditor();
+        $editor->open($image_poster, public_path() . '/base/poster/img/poster_canvas.png');
+        $editor->open($image_poduct, str_replace(env('CDN_URL'), public_path(), $WeChatApp->circleOfFriends));
+        $editor->resizeExactWidth($image_poduct, 440);
+        $editor->resizeExactHeight($image_poduct, 440);
+        $editor->blend($image_poster, $image_poduct, 'normal', 1, 'top-left', 10, 10);
+        $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($WeChatApp->introduce);
+            if ($len <= 17) {
+                $editor->text($image_poster, $WeChatApp->introduce, 19, 10, 460, new Color("#000000"), $font_bold, 0);
+                break;
+            }
+            if ($i == 0) {
+                $text = mb_substr($WeChatApp->introduce, $i * 17, 17);
+            } else {
+                $text = mb_substr($WeChatApp->introduce, $i * 17, ($len - 17) > 10 ? 10 : ($len - 17));
+            }
+            $editor->text($image_poster, $text, 19, 10, 460 + 50 * $i, new Color("#000000"), $font_bold, 0);
+        }
+        $editor->open($image_icon, public_path() . '/base/poster/img/phone.png');
+        $editor->resizeExactWidth($image_icon, 40);
+        $editor->resizeExactHeight($image_icon, 40);
+        $editor->blend($image_poster, $image_icon, 'normal', 1, 'top-left', 10, 570);
+
+        if ($userAuth->is_dealer != 1) {
+            if ($userAuth->up_agent_id == 0) {
+                $name = $WeChatApp->name;
+                $phone = $WeChatApp->phone;
+            } else {
+                $agent_check = AlbumAgentModel::where([
+                    ['store_id',$store_id],
+                    ['id',$userAuth->up_agent_id]
+                ])->first();
+                $name = $agent_check->realname;
+                $phone = $agent_check->phone;
+            }
+        } else {
+            $agent_check = AlbumAgentModel::where([
+                ['store_id',$store_id],
+                ['user_id',$userAuth->id]
+            ])->first();
+            $name = $agent_check->realname;
+            $phone = $agent_check->phone;
+        }
+        $editor->text($image_poster, $phone, 20, 55, 577, new Color("#eb7a48"), $font, 0);
+        $editor->text($image_poster, '长按识别二维码 展示家具画册', 16, 10, 650, new Color("#666666"), $font, 0);
+        if ($agent_id == 0) {
+            $editor->open($image_qrcode, str_replace(env('CDN_URL'), public_path(), $info['qrcode']));
+            $editor->resizeExactWidth($image_qrcode, 140);
+            $editor->resizeExactHeight($image_qrcode, 140);
+        } else {
+            $file = $this->getQrCodeEasy($WeChatApp->xyx_id, $WeChatApp->xyx_secret, $agent_id, $store_id, $userAuth->id);
+            if (!$file) {
+                return $this->error(0, '参数错误,请检查配置', []);
+            }
+            $editor->open($image_qrcode, $file);
+            $editor->resizeExactWidth($image_qrcode, 140);
+            $editor->resizeExactHeight($image_qrcode, 140);
+        }
+
+        $editor->blend($image_poster, $image_qrcode, 'normal', 1, 'top-left', 310, 500);
+        $editor->open($image_avatar, public_path() . '/base/poster/avatar/' . $store_id . "/$userAuth->id.jpg");
+        $editor->resizeExactWidth($image_avatar, 64);
+        $editor->resizeExactHeight($image_avatar, 64);
+        $editor->blend($image_poster, $image_avatar, 'normal', 1, 'top-left', 348, 538);
+        $editor->text($image_poster, $name, 16, 380 - (22 * (mb_strlen($name) / 2)), 650, new Color("#666666"), $font, 0);
+        $editor->save($image_poster, public_path() . '/download/' . $userAuth->id . '_personal.png');
+        $real_url = env('CDN_URL') . '/download/' . $userAuth->id . '_personal.png';
+        return $real_url;
+    }
+
 
     private function getQrCode($appId, $appSecret, $store_id)
     {