422 lines
19 KiB
PHP
422 lines
19 KiB
PHP
<?php
|
||
// +---------------------------------------------------------------------+
|
||
// | NiuCloud | [ WE CAN DO IT JUST NiuCloud ] |
|
||
// +---------------------------------------------------------------------+
|
||
// | Copy right 2019-2029 www.niucloud.com |
|
||
// +---------------------------------------------------------------------+
|
||
// | Author | NiuCloud <niucloud@outlook.com> |
|
||
// +---------------------------------------------------------------------+
|
||
// | Repository | https://github.com/niucloud/framework.git |
|
||
// +---------------------------------------------------------------------+
|
||
|
||
namespace addon\fenxiao\shop\controller;
|
||
|
||
use addon\fenxiao\model\Poster as PosterModel;
|
||
use app\model\system\Site;
|
||
use app\model\upload\Upload;
|
||
use app\shop\controller\BaseShop;
|
||
use extend\Poster as PosterExtend;
|
||
use think\facade\Cache;
|
||
|
||
/**
|
||
* 海报模板 控制器
|
||
*/
|
||
class Poster extends BaseShop
|
||
{
|
||
|
||
public function __construct()
|
||
{
|
||
//执行父类构造函数
|
||
parent::__construct();
|
||
}
|
||
|
||
/**
|
||
* 海报模板列表
|
||
* @return mixed
|
||
*/
|
||
public function list()
|
||
{
|
||
if (request()->isAjax()) {
|
||
$page_index = input('page', 1);
|
||
$page_size = input('page_size', PAGE_LIST_ROWS);
|
||
$search_text = input('search_text', '');
|
||
$condition = [['site_id', '=', $this->site_id]];
|
||
if(!empty($search_text)){
|
||
$condition[] = ['poster_name','like', '%' . $search_text . '%'];
|
||
}
|
||
$condition[] = ['template_type', '=', 'fenxiao'];
|
||
$poster_template_model = new PosterModel();
|
||
$res = $poster_template_model->getPosterTemplatePageList($condition, $page_index, $page_size);
|
||
return $res;
|
||
} else {
|
||
return $this->fetch('poster/lists');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 添加海报模板
|
||
* @return mixed
|
||
*/
|
||
public function add()
|
||
{
|
||
$template_id = input('template_id', '');
|
||
$poster_template_model = new PosterModel();
|
||
if (request()->isAjax()) {
|
||
$input = input('param.poster_detail');
|
||
if(empty(input('template_id'))){
|
||
//数据
|
||
$data = [
|
||
'poster_name' => input('poster_detail.poster_name', ''),
|
||
'background' => input('poster_detail.background', ''),
|
||
'qrcode_width' => input('poster_detail.qrcode_width', ''),
|
||
'qrcode_height' => input('poster_detail.qrcode_height', ''),
|
||
'qrcode_top' => input('poster_detail.qrcode_top', ''),
|
||
'qrcode_left' => input('poster_detail.qrcode_left', ''),
|
||
'template_type' => input('poster_detail.template_type',''),
|
||
'create_time' => time(),
|
||
'site_id' => $this->site_id
|
||
];
|
||
$goods_template = [
|
||
'headimg_is_show' => 1,
|
||
'headimg_shape' => input('poster_detail.headimg_shape', ''),
|
||
'nickname_is_show' => 1,
|
||
'nickname_font_size' => input('poster_detail.nickname_font_size', ''),
|
||
'nickname_color' => input('poster_detail.nickname_color', ''),
|
||
'headimg_width' => input('poster_detail.headimg_width', ''),
|
||
'headimg_height' => input('poster_detail.headimg_height', ''),
|
||
'headimg_top' => input('poster_detail.headimg_top', ''),
|
||
'headimg_left' => input('poster_detail.headimg_left', ''),
|
||
'nickname_width' => input('poster_detail.nickname_width', ''),
|
||
'nickname_height' => input('poster_detail.nickname_height', ''),
|
||
'nickname_top' => input('poster_detail.nickname_top', ''),
|
||
'nickname_left' => input('poster_detail.nickname_left', ''),
|
||
'poster_text' => input('poster_detail.poster_text', ''),
|
||
'text_content_size' => input('poster_detail.text_content_size', ''),
|
||
'text_content_color' => input('poster_detail.text_content_color', ''),
|
||
'text_content_top' => input('poster_detail.text_content_top', ''),
|
||
'text_content_left' => input('poster_detail.text_content_left', ''),
|
||
];
|
||
|
||
$data['template_json'] = json_encode($goods_template,true);
|
||
$poster_data = $poster_template_model->addPosterTemplate($data);
|
||
}else{
|
||
//数据
|
||
$data = [
|
||
'poster_name' => input('poster_detail.poster_name', ''),
|
||
'background' => input('poster_detail.background', ''),
|
||
'qrcode_width' => input('poster_detail.qrcode_width', ''),
|
||
'qrcode_height' => input('poster_detail.qrcode_height', ''),
|
||
'qrcode_top' => input('poster_detail.qrcode_top', ''),
|
||
'qrcode_left' => input('poster_detail.qrcode_left', ''),
|
||
'template_type' => input('poster_detail.template_type',''),
|
||
'site_id' => $this->site_id
|
||
];
|
||
$goods_template = [
|
||
'headimg_is_show' => 1,
|
||
'headimg_shape' => input('poster_detail.headimg_shape', ''),
|
||
'nickname_is_show' => 1,
|
||
'nickname_font_size' => input('poster_detail.nickname_font_size', ''),
|
||
'nickname_color' => input('poster_detail.nickname_color', ''),
|
||
'headimg_width' => input('poster_detail.headimg_width', ''),
|
||
'headimg_height' => input('poster_detail.headimg_height', ''),
|
||
'headimg_top' => input('poster_detail.headimg_top', ''),
|
||
'headimg_left' => input('poster_detail.headimg_left', ''),
|
||
'nickname_width' => input('poster_detail.nickname_width', ''),
|
||
'nickname_height' => input('poster_detail.nickname_height', ''),
|
||
'nickname_top' => input('poster_detail.nickname_top', ''),
|
||
'nickname_left' => input('poster_detail.nickname_left', ''),
|
||
'poster_text' => input('poster_detail.poster_text', ''),
|
||
'text_content_size' => input('poster_detail.text_content_size', ''),
|
||
'text_content_color' => input('poster_detail.text_content_color', ''),
|
||
'text_content_top' => input('poster_detail.text_content_top', ''),
|
||
'text_content_left' => input('poster_detail.text_content_left', ''),
|
||
];
|
||
$data['template_json'] = json_encode($goods_template,true);
|
||
$poster_data = $poster_template_model->editdPosterTemplate($data,[['template_id','=',input('template_id')],['site_id','=',$this->site_id]]);
|
||
}
|
||
return $poster_data;
|
||
} else {
|
||
|
||
if (!empty($template_id)){
|
||
$condition = [
|
||
['template_id', '=', 1],
|
||
['site_id', '=', $this->site_id]
|
||
];
|
||
$res = $poster_template_model->getPosterTemplateInfo($condition);
|
||
$res['data']['json_array'] = json_decode($res['data']['template_json'],true);
|
||
$res['data']['json_array']['qrcode_type'] = $res['data']['qrcode_type'] ?? '';
|
||
$res['data']['json_array']['qrcode_width'] = $res['data']['qrcode_width'] ?? 80;
|
||
$res['data']['json_array']['qrcode_height'] = $res['data']['qrcode_height'] ?? 80;
|
||
$res['data']['json_array']['qrcode_top'] = $res['data']['qrcode_top'] ?? 540;
|
||
$res['data']['json_array']['qrcode_left'] = $res['data']['qrcode_left'] ?? 260;
|
||
$res['data']['json_array']['template_type'] = $res['data']['template_type'] ?? 'goods';
|
||
|
||
$this->assign('template_data', $res['data']);
|
||
|
||
}
|
||
$site_model = new Site();
|
||
$where = array (
|
||
[ "site_id", "=", $this->site_id ]
|
||
);
|
||
$site_info = $site_model->getSiteInfo($where,'site_name,logo');
|
||
$this->assign('site_data',$site_info['data']);
|
||
return $this->fetch('poster/add');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 添加海报模板
|
||
* @return mixed
|
||
*/
|
||
public function edit()
|
||
{
|
||
$template_id = input('template_id', '');
|
||
$poster_template_model = new PosterModel();
|
||
if (request()->isAjax()) {
|
||
$input = input('param.poster_detail');
|
||
//数据
|
||
$data = [
|
||
'poster_name' => input('poster_detail.poster_name', ''),
|
||
'background' => input('poster_detail.background', ''),
|
||
'qrcode_width' => input('poster_detail.qrcode_width', ''),
|
||
'qrcode_height' => input('poster_detail.qrcode_height', ''),
|
||
'qrcode_top' => input('poster_detail.qrcode_top', ''),
|
||
'qrcode_left' => input('poster_detail.qrcode_left', ''),
|
||
'template_type' => input('poster_detail.template_type',''),
|
||
'site_id' => $this->site_id
|
||
];
|
||
$goods_template = [
|
||
'headimg_is_show' => 1,
|
||
'headimg_shape' => input('poster_detail.headimg_shape', ''),
|
||
'nickname_is_show' => 1,
|
||
'nickname_font_size' => input('poster_detail.nickname_font_size', ''),
|
||
'nickname_color' => input('poster_detail.nickname_color', ''),
|
||
'headimg_width' => input('poster_detail.headimg_width', ''),
|
||
'headimg_height' => input('poster_detail.headimg_height', ''),
|
||
'headimg_top' => input('poster_detail.headimg_top', ''),
|
||
'headimg_left' => input('poster_detail.headimg_left', ''),
|
||
'nickname_width' => input('poster_detail.nickname_width', ''),
|
||
'nickname_height' => input('poster_detail.nickname_height', ''),
|
||
'nickname_top' => input('poster_detail.nickname_top', ''),
|
||
'nickname_left' => input('poster_detail.nickname_left', ''),
|
||
'poster_text' => input('poster_detail.poster_text', ''),
|
||
'text_content_size' => input('poster_detail.text_content_size', ''),
|
||
'text_content_color' => input('poster_detail.text_content_color', ''),
|
||
'text_content_top' => input('poster_detail.text_content_top', ''),
|
||
'text_content_left' => input('poster_detail.text_content_left', ''),
|
||
];
|
||
$data['template_json'] = json_encode($goods_template,true);
|
||
$poster_data = $poster_template_model->editdPosterTemplate($data,[['template_id','=',input('template_id')],['site_id','=',$this->site_id]]);
|
||
return $poster_data;
|
||
} else {
|
||
if (!empty($template_id)){
|
||
$condition = [
|
||
['template_id', '=', $template_id],
|
||
['site_id', '=', $this->site_id]
|
||
];
|
||
$res = $poster_template_model->getPosterTemplateInfo($condition);
|
||
$res['data']['json_array'] = json_decode($res['data']['template_json'],true);
|
||
$res['data']['json_array']['qrcode_type'] = $res['data']['qrcode_type'] ?? '';
|
||
$res['data']['json_array']['qrcode_width'] = $res['data']['qrcode_width'] ?? 80;
|
||
$res['data']['json_array']['qrcode_height'] = $res['data']['qrcode_height'] ?? 80;
|
||
$res['data']['json_array']['qrcode_top'] = $res['data']['qrcode_top'] ?? 540;
|
||
$res['data']['json_array']['qrcode_left'] = $res['data']['qrcode_left'] ?? 260;
|
||
$res['data']['json_array']['template_type'] = $res['data']['template_type'] ?? 'goods';
|
||
$this->assign('template_data', $res['data']);
|
||
|
||
}
|
||
$site_model = new Site();
|
||
$where = array (
|
||
[ "site_id", "=", $this->site_id ]
|
||
);
|
||
$site_info = $site_model->getSiteInfo($where,'site_name,logo');
|
||
$this->assign('site_data',$site_info['data']);
|
||
return $this->fetch('poster/edit');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取海报模板预览
|
||
* @return mixed
|
||
*/
|
||
public function posterTemplateDetail()
|
||
{
|
||
$template_id = input('template_id', '');
|
||
$condition = [
|
||
['template_id', '=', $template_id],
|
||
['site_id', '=', $this->site_id]
|
||
];
|
||
$poster_template_model = new PosterModel();
|
||
$poster_data = $poster_template_model->getPosterTemplateInfo($condition);
|
||
if(!empty($poster_data['data'])){
|
||
$poster_data['data']['template_json'] = json_decode($poster_data['data']['template_json'],true);
|
||
$site_model = new Site();
|
||
$where = array (
|
||
[ "site_id", "=", $this->site_id ]
|
||
);
|
||
$site_info = $site_model->getSiteInfo($where);
|
||
$poster_width = 720;
|
||
$poster_height = 1280;
|
||
$poster = new PosterExtend($poster_width, $poster_height);
|
||
$ground = [
|
||
[
|
||
'action' => 'setBackground', // 设背景色
|
||
'data' => [255, 255, 255]
|
||
],
|
||
];
|
||
|
||
$fontRate = 0.725; // 20px 等于 14.5磅,换算比率 1px = 0.725磅
|
||
$option = [
|
||
[
|
||
'action' => 'imageCopy', // 写入二维码
|
||
'data' => [
|
||
getUrl().'/public/static/img/caner_erweima.png',
|
||
$poster_data['data']['qrcode_left']*2,
|
||
$poster_data['data']['qrcode_top']*2,
|
||
$poster_data['data']['qrcode_width']*2,
|
||
$poster_data['data']['qrcode_height']*2,
|
||
'square',
|
||
0,
|
||
1
|
||
]
|
||
],
|
||
[
|
||
'action' => 'imageText', // 写入分享语
|
||
'data' => [
|
||
$poster_data['data']['template_json']['poster_text'],
|
||
18,
|
||
[141, 141, 141],
|
||
$poster_data['data']['template_json']['text_content_left']*2,
|
||
($poster_data['data']['template_json']['text_content_top'])*2,
|
||
440,
|
||
1
|
||
]
|
||
]
|
||
];
|
||
$nickname_color = is_array($poster_data['data']['template_json']['nickname_color']) ? $poster_data['data']['template_json']['nickname_color'] : hex2rgb($poster_data['data']['template_json']['nickname_color']);
|
||
$member_option = [
|
||
[
|
||
'action' => 'imageCopy', // 写入用户头像
|
||
'data' => [
|
||
getUrl().'/app/shop/view/public/img/default_headimg.png',
|
||
$poster_data['data']['template_json']['headimg_left']*2,
|
||
$poster_data['data']['template_json']['headimg_top']*2,
|
||
$poster_data['data']['template_json']['headimg_width']*2,
|
||
$poster_data['data']['template_json']['headimg_height']*2,
|
||
!empty($poster_data['data']['template_json']['headimg_shape'])?$poster_data['data']['template_json']['headimg_shape']:'square',
|
||
0,
|
||
$poster_data['data']['template_json']['headimg_is_show']
|
||
]
|
||
],
|
||
[
|
||
'action' => 'imageText', // 写入分享人昵称
|
||
'data' => [
|
||
'用户昵称',
|
||
$poster_data['data']['template_json']['nickname_font_size'] * $fontRate*2,
|
||
$nickname_color,
|
||
$poster_data['data']['template_json']['nickname_left']*2,
|
||
($poster_data['data']['template_json']['nickname_top'])*2,
|
||
$poster_data['data']['template_json']['nickname_width']*2,
|
||
$poster_data['data']['template_json']['nickname_height']*2,
|
||
0,
|
||
$poster_data['data']['template_json']['nickname_is_show']
|
||
]
|
||
],
|
||
];
|
||
list($width,$height,$type,$attr)=getimagesize(img($poster_data['data']['background']));
|
||
$height = 720*$height/$width;
|
||
$back_ground = [
|
||
[
|
||
'action' => 'imageCopy', // 写入背景图
|
||
'data' => [
|
||
img($poster_data['data']['background']),
|
||
0,
|
||
0,
|
||
720,
|
||
$height,
|
||
'square',
|
||
0,
|
||
1
|
||
]
|
||
],
|
||
];
|
||
$option = array_merge($ground,$back_ground,$option, $member_option);
|
||
$option_res = $poster->create($option);
|
||
|
||
if (is_array($option_res)) return $option_res;
|
||
$pic_name = rand(10000, 99999);
|
||
$res = $option_res->jpeg('upload/poster/goods', 'fenxiao'.$pic_name);
|
||
if ($res['code'] == 0) {
|
||
$upload = new Upload($this->site_id);
|
||
$cloud_res = $upload->fileCloud($res['data']['path']);
|
||
if ($cloud_res['code'] >= 0) {
|
||
return $cloud_res[ 'data' ];
|
||
} else {
|
||
return $this->error();
|
||
}
|
||
}
|
||
}else{
|
||
return '参数不能为空';
|
||
}
|
||
|
||
}
|
||
|
||
public function getMubanInfo(){
|
||
$muban_id = input('muban_id',0);
|
||
$muban_model = new PosterModel();
|
||
$muban_info = $muban_model->getMubanInfo([['muban_id','=',$muban_id]]);
|
||
$site_model = new Site();
|
||
$where = array (
|
||
[ "site_id", "=", $this->site_id ]
|
||
);
|
||
$site_info = $site_model->getSiteInfo($where,'site_name,logo');
|
||
$muban_info['data']['site_data'] = $site_info['data'];
|
||
return $muban_info;
|
||
}
|
||
/**
|
||
* 删除海报模板
|
||
* @return mixed
|
||
*/
|
||
public function delPosterTemplate()
|
||
{
|
||
if (request()->isAjax()) {
|
||
$template_ids = input('template_ids', '');
|
||
$condition = [
|
||
['template_id', 'in', $template_ids],
|
||
['site_id', '=', $this->site_id]
|
||
];
|
||
$poster_template_model = new PosterModel();
|
||
$res = $poster_template_model->deletePosterTemplate($condition);
|
||
return $res;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 编辑模板状态啊
|
||
* @return array
|
||
*/
|
||
public function editstatus()
|
||
{
|
||
if (request()->isAjax()) {
|
||
$template_id = input('template_id', 0);
|
||
$template_status = input('template_status', 0);
|
||
$condition = [
|
||
['template_id', 'in', $template_id],
|
||
['site_id', '=', $this->site_id]
|
||
];
|
||
$data = ['template_status' => $template_status];
|
||
$poster_template_model = new PosterModel();
|
||
$res = $poster_template_model->editdPosterTemplate($data, $condition);
|
||
return $res;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取海报模板
|
||
* @return mixed
|
||
*/
|
||
public function getMubanList(){
|
||
return 1;
|
||
}
|
||
|
||
} |