123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- namespace app\expand\controller;
- use app\common\service\HelperService;
- /**
- * 打印扫码贴
- * Class Baidu
- * @package app\expand\controller
- */
- class PrintSMT extends BaseAuth
- {
- private $_smtAccount = [];
-
- public function __construct(){
- parent::__construct();
- $this->_smtAccount = $this->getKey($this->_apiCode);
- //验证是否具有访问这个接口的权限
- if( !isset($this->_smtAccount['printSMT']) ){
- HelperService::returnJson(['code'=>400,'msg'=>'smt interface unauthorized access','data'=>[]]);
- }
- }
- /**
- * 打印关西店
- */
- public function mu(){
-
- $muPath = "static/image/mu";
-
- $fileList = scandir($muPath);
- foreach($fileList as $fileItem){
- if(strpos($fileItem,'.')!==0){
- $nameArr = explode("_", $fileItem);
- $enName = end($nameArr);
-
- $this->printMu("$muPath/$fileItem", "$muPath.png", "环贸广场店".current(explode(".", $enName)));
-
- //exit;
- }
- }
- }
-
- /**
- * 打印关西店
- */
- public function bear(){
-
- $muPath = "static/image/xiong";
-
- $fileList = scandir($muPath);
- foreach($fileList as $fileItem){
- if(strpos($fileItem,'.')!==0){
- $nameArr = explode("_", $fileItem);
- $enName = end($nameArr);
-
- $this->printBear("$muPath/$fileItem", "$muPath.png", "189店".current(explode(".", $enName)));
-
- //exit;
- }
- }
- }
- /**
- * 打印扫码贴关西
- * @param $fileName
- * @param $bgName
- * @param $storeName
- */
- private function printMu($fileName,$bgName,$storeName){
- //裁剪
- $qrImage = stripos($fileName,'jpg')?imagecreatefromjpeg($fileName): imagecreatefrompng($fileName);
- $bgImage = stripos($bgName,'jpg')?imagecreatefromjpeg($bgName):imagecreatefrompng($bgName);
- $width = imagesx($bgImage);
- $newFileName = str_replace('mu/', 'mu2/', $fileName);
- //320
- imagecopymerge($bgImage, $qrImage, 190, 300, 0, 0, imagesx($qrImage), imagesy($qrImage), 100);
- stripos($fileName,'jpg')?imagejpeg($bgImage,$newFileName):imagepng($bgImage,$newFileName);
- $new_bgImage = stripos($newFileName,'jpg')?imagecreatefromjpeg($newFileName):imagecreatefrompng($newFileName);
- //$white = imagecolorallocate($new_bgImage, 255, 255, 255);
- $black = imagecolorallocate($new_bgImage, 0, 0, 0);
- $fontBox = imagettfbbox(18, 0, './font/NotoSansHans-DemiLight.ttf', $storeName);//水平居中实质
- imagettftext($new_bgImage,18,0,ceil(($width - $fontBox[2]) / 2)+34,536,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName);
- imagettftext($new_bgImage,18,0,ceil(($width - $fontBox[2]) / 2)+35,536,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName);
- //imagettftext($new_bgImage,24,0,30,30,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName);
- //imagettftext($new_bgImage,50,0,430,420,$white,'./NotoSansHans-DemiLight.ttf',$tableName);
-
- stripos($newFileName,'jpg')?imagejpeg($new_bgImage, $newFileName):imagepng($new_bgImage, $newFileName);
- //system("rm -rf $tableName.png");
- //$this->downloadFile($newFileName);
- }
-
- /**
- * 打印扫码贴关西
- * @param $fileName
- * @param $bgName
- * @param $storeName
- */
- private function printBear($fileName,$bgName,$storeName){
- //裁剪
- $qrImage = stripos($fileName,'jpg')?imagecreatefromjpeg($fileName): imagecreatefrompng($fileName);
- $bgImage = stripos($bgName,'jpg')?imagecreatefromjpeg($bgName):imagecreatefrompng($bgName);
- $width = imagesx($bgImage);
- $newFileName = str_replace('xiong/', 'xiong2/', $fileName);
- //320
- imagecopymerge($bgImage, $qrImage, 152, 286, 0, 0, imagesx($qrImage), imagesy($qrImage), 100);
- stripos($fileName,'jpg')?imagejpeg($bgImage,$newFileName):imagepng($bgImage,$newFileName);
- $new_bgImage = stripos($newFileName,'jpg')?imagecreatefromjpeg($newFileName):imagecreatefrompng($newFileName);
- //$white = imagecolorallocate($new_bgImage, 255, 255, 255);
- $black = imagecolorallocate($new_bgImage, 0, 0, 0);
- $fontBox = imagettfbbox(20, 0, './font/NotoSansHans-DemiLight.ttf', $storeName);//水平居中实质
- imagettftext($new_bgImage,20,0,ceil(($width - $fontBox[2]) / 2),520,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName);
- imagettftext($new_bgImage,20,0,ceil(($width - $fontBox[2]) / 2)+1,520,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName);
- //imagettftext($new_bgImage,24,0,30,30,$black,'./font/NotoSansHans-DemiLight.ttf',$storeName);
- //imagettftext($new_bgImage,50,0,430,420,$white,'./NotoSansHans-DemiLight.ttf',$tableName);
-
- stripos($newFileName,'jpg')?imagejpeg($new_bgImage, $newFileName):imagepng($new_bgImage, $newFileName);
- //system("rm -rf $tableName.png");
- //$this->downloadFile($newFileName);
- }
-
- private function downloadFile($file){
- $file_name = $file;
- $mime = 'application/force-download';
- header('Pragma: public'); // required
- header('Expires: 0'); // no cache
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Cache-Control: private',false);
- header('Content-Type: '.$mime);
- header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
- header('Content-Transfer-Encoding: binary');
- header('Connection: close');
- readfile($file_name); // push it out
- exit();
- }
- }
|