<?php
namespace app\common\service\qrcode;
use app\common\enum\OrderType as OrderTypeEnum;
class Extract extends Base
{
private $wxappId;
private $user;
private $orderId;
private $orderType;
public function __construct($wxappId, $user, $orderId, $orderType = OrderTypeEnum::MASTER)
{
parent::__construct();
$this->wxappId = $wxappId;
$this->user = $user;
$this->orderId = $orderId;
$this->orderType = $orderType;
}
public function getImage()
{
if (file_exists($this->getPosterPath())) {
return $this->getPosterUrl();
}
$qrcode = $this->saveQrcode(
$this->wxappId,
"oid:{$this->orderId},oty:{$this->orderType}",
'pages/store/check/order'
);
return $this->savePoster($qrcode);
}
private function savePoster($qrcode)
{
copy($qrcode, $this->getPosterPath());
return $this->getPosterUrl();
}
private function getPosterPath()
{
$tempPath = WEB_PATH . "temp/{$this->wxappId}/";
!is_dir($tempPath) && mkdir($tempPath, 0755, true);
return $tempPath . $this->getPosterName();
}
private function getPosterName()
{
return 'extract_' . md5("{$this->orderId}_{$this->user['open_id']}}") . '.png';
}
private function getPosterUrl()
{
return \base_url() . 'temp/' . $this->wxappId . '/' . $this->getPosterName() . '?t=' . time();
}
}