master
wangxinglong 2022-01-21 10:32:52 +08:00
parent d38e6b7555
commit b4c233d8bf
2 changed files with 47 additions and 0 deletions

View File

@ -12,6 +12,11 @@ use app\repository\BusinessRepository;
use app\repository\CouponRepository;
use app\validate\CouponRelease;
use app\validate\CouponUsingRule;
use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelHigh;
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin;
use Endroid\QrCode\Writer\PngWriter;
use Exception;
use think\facade\Config;
use think\facade\Db;
@ -25,6 +30,7 @@ use think\facade\Config as CConfig;
class Coupon extends Base
{
protected $noNeedLogin = ["downloadQrCode"];
protected function initialize()
{
parent::initialize(); // TODO: Change the autogenerated stub
@ -353,6 +359,45 @@ class Coupon extends Base
}
/**
* 下载小程序二维码
* */
public function downloadQrCode()
{
$id = input("id/d");
$couponMain = CouponMain::findById($id);
if(empty($couponMain)){
return $this->json(4001,"优惠券不存在");
}
$qrData = $this->request->domain() . "/coupon_info?id={$id}&business_code={$couponMain['business_code']}" ;
$w = 3000;//尺寸
$logoImg = app()->getRootPath().'public/static/images/icon-logo.jpg';
$result = Builder::create()
->writer(new PngWriter())
->writerOptions([])
->data($qrData)
->encoding(new Encoding('UTF-8'))
->errorCorrectionLevel(new ErrorCorrectionLevelHigh())
->size($w)
->margin(10)
->roundBlockSizeMode(new RoundBlockSizeModeMargin())
->logoPath($logoImg)
->logoResizeToHeight(ceil($w/6))
->logoResizeToWidth(ceil($w/6))
->logoPunchoutBackground(true)
->build();
header(
"Content-type: image/jpg"
);
$path = "/storage/coupon/{$id}.jpg";
$result->saveToFile( public_path() . $path);
return download(public_path() . $path,$couponMain['name']);
}
}

View File

@ -86,12 +86,14 @@
<!-- 操作列 -->
<script type="text/html" id="row-operate">
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/coupon/info.html?id={{d.id}}" data-title="【{{ d.name }}】详情" lay-event="info">详情</a>
{{# if(d.on_shelf == 1){ }}
<a class="layui-btn layui-btn-xs" data-href="/manager/coupon/shelf.html?id={{d.id}}&&on_shelf=0" lay-event="shelf">上架</a>
{{# }else{ }}
<a class="layui-btn layui-btn-xs" data-href="/manager/coupon/shelf.html?id={{d.id}}&&on_shelf=1" lay-event="shelf">下架</a>
{{# } }}
<a class="layui-btn layui-btn-primary layui-btn-xs" target="_blank" href="/manager/coupon/downloadQrCode.html?id={{d.id}}">下载二维码</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" data-href="/manager/coupon/edit.html?id={{d.id}}" data-title="【{{ d.name }}】编辑" lay-event="info">编辑</a>
</script>