【!注意!】技术指导专用文章,实在不会搭建再点击此处
【!注意!】
✨ 新推出:兑换码!
进入小程序,获得大额兑换码!最高减100% |
![]() 扫码进入小程序 |
权益商城系统源码,支持多种支付方式,后台商品管理,订单管理,串货管理,分站管理,会员列表,分销日志,应用配置。
上传到服务器,修改数据库信息,导入数据库,即可账号密码:123456L
namespace leadmall\app;
use basics\app\BasicsController as BasicsModules;
use leadmall\Map;
use Yii;
class PosterController extends BasicsModules implements Map
{
public $user_info = [];
/**
* 重写父类
* @return [type] [description]
*/
public function actions()
{
$actions = parent::actions();
unset($actions['create']);
unset($actions['update']);
return $actions;
}
/**
* 处理海报生成
* @param string $value [description]
* @return [type] [description]
*/
public function actionIndex()
{
$type = Yii::$app->request->get('type', 1);
$goods_id = Yii::$app->request->get('goods_id', false);
$is_task = Yii::$app->request->get('is_task', false);
$scene = '';
if (!empty(Yii::$app->user->identity)) {
$model = M('users', 'User')::findOne(Yii::$app->user->identity->id);
$this->user_info = $model;
if ($model) {
$promoter = $model->promoter;
if ($promoter && $promoter->status == 2) {
$scene = 'spu=' . $model->id; //spu为share_promoter_uid缩写
}
}
}
if ($is_task == "false") {
$is_task = false;
}
if ($goods_id && $is_task == false) {
return $this->goods($type, $goods_id, $scene);
}
if ($goods_id && ($is_task || $is_task == 'true')) {
return $this->goodstask($type, $goods_id, $scene);
}
$coupon_id = Yii::$app->request->get('coupon_id', false);
if ($coupon_id) {
return $this->coupon($type, $coupon_id, $scene);
}
$store = Yii::$app->request->get('store', false);
if ($store == 1) {
return $this->store($type, $scene);
}
$invitation = Yii::$app->request->get('invitation', false);
if ($invitation == 1) {
return $this->invitation($type, $scene);
}
$zoom = Yii::$app->request->get('zoom', false);
if ($zoom == 1) {
return $this->zoom($type, $scene);
}
}
public function zoom($type, $scene)
{
$UID = Yii::$app->request->get('UID', false);
$UID = $UID ? $UID : $this->user_info->id;
$scene = $scene && $scene != 'index' ? '&' . $scene : '';
$dynamic = StoreSetting('promoter_page_setting', 'dynamic');
if ($dynamic && $dynamic['bg_url']) {
$dynamic_url = $dynamic['bg_url'];
} else {
$dynamic_url = realpath('../system/static/promoter_zoom_banner.png');
}
$box = imagettfbbox(32, 0, realpath('../system/static/PingFang.ttf'), $this->user_info->nickname);
$text_length = $box[2] - $box[0];
//图片转换
$config = array(
'text' => array(
array(
'text' => $this->user_info->nickname,
'left' => 375 - ($text_length / 2),
'top' => 540,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 32, //字号
'fontColor' => '34,34,34', //字体颜色
'angle' => 0,
'lineation' => 0,
),
array(
'text' => $type == 1 ? '长按识别二维码' : '长按识别小程序码',
'left' => $type == 1 ? 298 : 288,
'top' => 920,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 16, //字号
'fontColor' => '153,153,153', //字体颜色
'angle' => 0,
'lineation' => 0,
),
),
'image' => array(
array(
'url' => $dynamic_url,
'left' => 70,
'top' => 72,
'right' => 0,
'stream' => 0,
'bottom' => 0,
'width' => 608,
'height' => 304,
'opacity' => 100,
'radius' => 16,
'color' => '255, 255, 255',
),
array(
'url' => $this->user_info->avatar,
'left' => 295,
'top' => 324,
'right' => 0,
'stream' => 0,
'bottom' => 0,
'width' => 160,
'height' => 160,
'opacity' => 100,
'radius' => 80,
'color' => '255, 255, 255',
),
//二维码
array(
'url' => $type == 1 ? $this->getWechatQrCode("promoter/pages/dynamic", "UID=" . $UID . $scene) : $this->getWeappQrCode("promoter/pages/dynamic", "UID=" . $UID . $scene),
'left' => 285,
'top' => 712,
'right' => 0,
'stream' => 1,
'bottom' => 0,
'width' => 180,
'height' => 180,
'opacity' => 100,
'radius' => 0,
'color' => '255, 255, 255',
),
),
'background' => realpath('../system/static/promoter_zoom_bg.png'),
);
//createPoster($config);
ob_start();
echo createPoster($config);
$imagedata = ob_get_contents();
ob_end_clean();
return 'data:image/png;base64,' . base64_encode($imagedata);
}
public function invitation($type, $scene)
{
$scene = $scene && $scene != 'index' ? '&' . $scene : '';
$box = imagettfbbox(32, 0, realpath('../system/static/PingFang.ttf'), $this->user_info->nickname);
$text_length = $box[2] - $box[0];
//图片转换
$config = array(
'text' => array(
array(
'text' => $this->user_info->nickname,
'left' => 375 - ($text_length / 2),
'top' => 545,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 32, //字号
'fontColor' => '34,34,34', //字体颜色
'angle' => 0,
'lineation' => 0,
),
array(
'text' => $type == 1 ? '长按识别二维码' : '长按识别小程序码',
'left' => $type == 1 ? 298 : 288,
'top' => 920,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 16, //字号
'fontColor' => '153,153,153', //字体颜色
'angle' => 0,
'lineation' => 0,
),
),
'image' => array(
array(
'url' => $this->user_info->avatar,
'left' => 295,
'top' => 324,
'right' => 0,
'stream' => 0,
'bottom' => 0,
'width' => 160,
'height' => 160,
'opacity' => 100,
'radius' => 80,
'color' => '255, 255, 255',
),
//二维码
array(
'url' => $type == 1 ? $this->getWechatQrCode("promoter/pages/recruit", "invite_id=" . $this->user_info->id . $scene) : $this->getWeappQrCode("promoter/pages/recruit", "invite_id=" . $this->user_info->id . $scene),
'left' => 285,
'top' => 712,
'right' => 0,
'stream' => 1,
'bottom' => 0,
'width' => 180,
'height' => 180,
'opacity' => 100,
'radius' => 0,
'color' => '255, 255, 255',
),
),
'background' => realpath('../system/static/invitation_bg.png'),
);
//createPoster($config);
ob_start();
echo createPoster($config);
$imagedata = ob_get_contents();
ob_end_clean();
return 'data:image/png;base64,' . base64_encode($imagedata);
}
public function store($type, $scene)
{
$store_setting = StoreSetting('setting_collection', 'store_setting');
$box = imagettfbbox(32, 0, realpath('../system/static/PingFang.ttf'), $store_setting['name']);
$text_length = $box[2] - $box[0];
//图片转换
$config = array(
'text' => array(
array(
'text' => $store_setting['name'],
'left' => 375 - ($text_length / 2),
'top' => 275,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 32, //字号
'fontColor' => '34,34,34', //字体颜色
'angle' => 0,
'lineation' => 0,
),
array(
'text' => $type == 1 ? '长按识别二维码' : '长按识别小程序码',
'left' => $type == 1 ? 298 : 288,
'top' => 625,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 16, //字号
'fontColor' => '153,153,153', //字体颜色
'angle' => 0,
'lineation' => 0,
),
),
'image' => array(
array(
'url' => $store_setting['logo'],
'left' => 295,
'top' => 32,
'right' => 0,
'stream' => 0,
'bottom' => 0,
'width' => 160,
'height' => 160,
'opacity' => 100,
'radius' => 80,
'color' => '255, 255, 255',
),
//二维码
array(
'url' => $type == 1 ? $this->getWechatQrCode("pages/index/index", $scene) : $this->getWeappQrCode("pages/index/index", $scene),
'left' => 285,
'top' => 418,
'right' => 0,
'stream' => 1,
'bottom' => 0,
'width' => 180,
'height' => 180,
'opacity' => 100,
'radius' => 0,
'color' => '255, 255, 255',
),
),
'background' => realpath('../system/static/store_bg.png'),
);
//createPoster($config);
ob_start();
echo createPoster($config);
$imagedata = ob_get_contents();
ob_end_clean();
return 'data:image/png;base64,' . base64_encode($imagedata);
}
public function coupon($type, $coupon_id, $scene)
{
$model = M('coupon', 'Coupon')::findOne($coupon_id);
$setting_data = M('setting', 'Setting')::find()->where(['keyword' => 'setting_collection', 'merchant_id' => 1, 'AppID' => Yii::$app->params['AppID']])->select('content')->asArray()->one();
$setting_data = to_array($setting_data['content']);
$setting_data = str2url($setting_data);
if ($model) {
$model = $model->toArray();
if ($model['expire_type'] == 1) {
$time = '可用时间:领取当日起' . $model['expire_day'] . '天内';
} else {
$time = '可用时间:' . date("Y.m.d", $model['begin_time']) . ' - ' . date("Y.m.d", $model['end_time']);
}
$scene = $scene && $scene != 'index' ? '&' . $scene : '';
//图片转换
$config = array(
'text' => array(
array(
'text' => $setting_data['store_setting']['name'],
'left' => 189,
'top' => 120,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 20, //字号
'fontColor' => '34,34,34', //字体颜色
'angle' => 0,
'lineation' => 0,
),
array(
'text' => '送你一张优惠券',
'left' => 190,
'top' => 150,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 16, //字号
'fontColor' => '153,153,153', //字体颜色
'angle' => 0,
'lineation' => 0,
),
array(
'text' => '¥',
'left' => 150,
'top' => 270,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 22, //字号
'fontColor' => '255,255,255', //字体颜色
'angle' => 0,
'lineation' => 0,
),
array(
'text' => $model['min_price'] * 1 > 0 ? '满' . $model['min_price'] . '可用' : '无门槛',
'left' => 168 + (mb_strlen($model['sub_price']) * 28),
'top' => 265,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 22, //字号
'fontColor' => '255,255,255', //字体颜色
'angle' => 0,
'lineation' => 0,
),
array(
'text' => $model['sub_price'],
'left' => 168,
'top' => 265,
'fontPath' => realpath('../system/static/DINPro.ttf'), //字体文件
'fontSize' => 40, //字号
'fontColor' => '255,255,255', //字体颜色
'angle' => 0,
'lineation' => 0,
),
array(
'text' => $model['name'],
'left' => 149,
'top' => 315,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 24, //字号
'fontColor' => '255,255,255', //字体颜色
'angle' => 0,
'lineation' => 0,
),
array(
'text' => $time,
'left' => 149,
'top' => 355,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 15, //字号
'fontColor' => '255,255,255', //字体颜色
'angle' => 0,
'lineation' => 0,
),
array(
'text' => $type == 1 ? '长按识别二维码' : '长按识别小程序码',
'left' => $type == 1 ? 305 : 295,
'top' => 735,
'fontPath' => realpath('../system/static/PingFang.ttf'), //字体文件
'fontSize' => 16, //字号
'fontColor' => '153,153,153', //字体颜色
'angle' => 0,
'lineation' => 0,
),
),
'image' => array(
array(
'url' => $setting_data['store_setting']['logo'],
'left' => 101,
'top' => 96,
'right' => 0,
'stream' => 0,
'bottom' => 0,
'width' => 64,
'height' => 64,
'opacity' => 100,
'radius' => 32,
'color' => '255, 255, 255',
),
//二维码
array(
'url' => $type == 1 ? $this->getWechatQrCode("pages/coupon/detail", "couponShare=1&id=" . $model['id'] . $scene) : $this->getWeappQrCode("pages/coupon/detail", "couponShare=1&id=" . $model['id'] . $scene),
'left' => 285,
'top' => 508,
'right' => 0,
'stream' => 1,
'bottom' => 0,
'width' => 190,
'height' => 190,
'opacity' => 100,
'radius' => 0,
'color' => '255, 255, 255',
),
),
'background' => 'http://qmxq.oss-cn-hangzhou.aliyuncs.com/guide/coupon_bg.png',
);
//createPoster($config);
ob_start();
echo createPoster($config);
$imagedata = ob_get_contents();
ob_end_clean();
return 'data:image/png;base64,' . base64_encode($imagedata);
} else {
Error('优惠券不存在');
}
}
public function goodstask($type, $goods_id, $scene)
{
$model = M('goods', 'Goods')::find()
->joinWith('task')
->where(['goods_id' => $goods_id])
->asArray()
->one();
$setting_data = M('setting', 'Setting')::find()->where(['keyword' => 'setting_collection', 'merchant_id' => 1, 'AppID' => Yii::$app->params['AppID']])->select('content')->asArray()->one();
$setting_data = to_array($setting_data['content']);
$setting_data = str2url($setting_data);
$UID = 0;
if (@Yii::$app->user->identity->id) {
$UID = Yii::$app->user->identity->id;
}
<?php
ini_set("display_errors", "On");
error_reporting(E_ALL);
//开启Session
session_start();
//当前文件名称
define('LE_SCRIPT_NAME', basename(__FILE__));
//站点根目录路径
define('LE_PACKAGE_BASE', dirname(__DIR__));
//设置当前运行模式
define('LE_OPERATION_MODE', 'develop');
© 版权声明
THE END
暂无评论内容