diff --git a/app/controller/manager/Coupon.php b/app/controller/manager/Coupon.php index 3231e24..e1987ba 100644 --- a/app/controller/manager/Coupon.php +++ b/app/controller/manager/Coupon.php @@ -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']); + } } \ No newline at end of file diff --git a/view/manager/coupon/index.html b/view/manager/coupon/index.html index b32361c..3ddd0b1 100644 --- a/view/manager/coupon/index.html +++ b/view/manager/coupon/index.html @@ -86,12 +86,14 @@