72 lines
2.4 KiB
PHP
72 lines
2.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs;
|
||
|
|
|
||
|
|
use App\Http\Controllers\UploadController;
|
||
|
|
use App\Models\Server\Survey;
|
||
|
|
use App\Models\Server\SurveyService;
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||
|
|
use Illuminate\Support\Facades\Log;
|
||
|
|
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||
|
|
|
||
|
|
class MakeSurveyQrcode implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
|
||
|
|
protected $m_id, $type, $type_id, $survey_id;
|
||
|
|
/**
|
||
|
|
* Create a new job instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct($m_id, $type, $type_id, $survey_id)
|
||
|
|
{
|
||
|
|
$this->m_id = $m_id;
|
||
|
|
$this->type = $type;
|
||
|
|
$this->type_id = $type_id;
|
||
|
|
$this->survey_id = $survey_id;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the job.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
$base_url = env('APP_URL')."/pu/#/questionnaireV3/".$this->survey_id."?merchant_id=".$this->m_id."&type=".$this->type."&type_id=".$this->type_id;
|
||
|
|
$base_url = urlencode($base_url);
|
||
|
|
$url = env('APP_URL')."/survey/auth?url=".$base_url;
|
||
|
|
$pic_path = storage_path('qrcode/'.$this->m_id.'_survey_'.$this->survey_id."_".$this->type.'_'.$this->type_id.'_sharer_qrcode.png');
|
||
|
|
//二维码图片
|
||
|
|
QrCode::format('png')->margin(1)->size(300)->generate($url, $pic_path);
|
||
|
|
if(file_exists($pic_path)){
|
||
|
|
$qrcode = $this->uploadFile($pic_path);
|
||
|
|
if ($this->type && $this->type_id) {
|
||
|
|
SurveyService::where('survey_id', $this->survey_id)->where('type', $this->type)->where('type_id', $this->type_id)->update(['qrcode'=>$qrcode, 'share_url'=>$url]);
|
||
|
|
}else {
|
||
|
|
Survey::where('id', $this->survey_id)->update(['qrcode'=>$qrcode, 'share_url'=>$url]);
|
||
|
|
}
|
||
|
|
unlink($pic_path);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public function uploadFile($file)
|
||
|
|
{
|
||
|
|
$ossClient = UploadController::getOssClient();
|
||
|
|
//生成file
|
||
|
|
$object = date('Y').date('m')."/".date('d')."/".basename($file);
|
||
|
|
$url = 'https://'.config('alioss.picture_domain').'/'.$object;
|
||
|
|
try {
|
||
|
|
$ossClient->uploadFile(config('alioss.buckets.picture'), $object, $file);
|
||
|
|
} catch(\OSS\Core\OssException $e) {
|
||
|
|
Log::info($e->getMessage());
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return $url;
|
||
|
|
}
|
||
|
|
}
|