admin/plugins/new-poster/src/services/CreateActivityPosters.php

107 lines
2.9 KiB
PHP

<?php
namespace Yunshop\NewPoster\services;
use app\common\helpers\ImageHelper;
use app\common\services\Utils;
use Illuminate\Support\Str;
class CreateActivityPosters extends MergePoster
{
public function __construct($posterModel, $memberModel, $type, $host = '')
{
$this->posterModel = $posterModel;
$this->memberModel = $memberModel;
$this->type = $type;
$this->host = $host;
$this->shopSet = \Setting::get('shop.shop');
$this->yzMember();
}
public function getUrl()
{
return $this->createMemberPoster();
}
protected function createMemberPoster()
{
set_time_limit(0);
@ini_set('memory_limit', '256M');
$cv_width = 640;
$cv_height = 1008;
$target = imagecreatetruecolor($cv_width, $cv_height);
$target = $this->mergeBg($target, $cv_width, $cv_height);
$params = json_decode($this->posterModel->style_data, true);
$continue = true;
foreach ($params as $item) {
$item = $this->getRealParams($item);
$function_name = Str::camel($item['type']);
if (!method_exists(self::class, $function_name)) {
continue;
}
$target = self::$function_name($target, $item);
if ($target === false) {
$continue = false;
break;
}
}
if (!$continue) {
return [
'error_code' => 500,
'error_message' => '海报生成错误',
'file_path' => '',
];
}
$time = time();
imagepng($target, $this->getPosterFileFullPath() . $time);
imagedestroy($target);
return [
'error_code' => 0,
'error_message' => '',
'file_path' => $this->getPosterFileFullPath() . $time,
'relative_path'=>$this->getPosterRelativePath()
];
}
//logo
protected function logo($target, $item)
{
if ($item['logo_type'] != 1) {
$item['src'] = yz_tomedia($this->shopSet['logo']);
}
return $this->mergeOtherImage($target, $item);
}
//昵称
protected function nickname($target, $item)
{
return $this->mergeText($target, $item, $this->memberModel->nickname);
}
//头像
protected function head($target, $item)
{
return $this->mergeHeadImage($target, $item);
}
//邀请码
protected function invite($target, $item)
{
return $this->mergeInvite($target, $item, $this->yzMemberModel->invite_code);
}
//会员id
protected function mid($target, $item)
{
return $this->mergeInvite($target, $item, $this->memberModel->uid);
}
/**
* 活动二维码
* @param $target
* @param $item
* @return mixed
*/
protected function activeQrCode($target, $item)
{
return $this->mergeQrImageByType($target, $item, $this->type);
}
}