|
@@ -14,6 +14,7 @@ use crmeb\services\GroupDataService;
|
|
|
use crmeb\services\SystemConfigService;
|
|
use crmeb\services\SystemConfigService;
|
|
|
use crmeb\services\UtilService;
|
|
use crmeb\services\UtilService;
|
|
|
use crmeb\services\upload\Upload;
|
|
use crmeb\services\upload\Upload;
|
|
|
|
|
+use think\facade\Log;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 账单类
|
|
* 账单类
|
|
@@ -154,21 +155,52 @@ class UserBillController
|
|
|
], $request, true);
|
|
], $request, true);
|
|
|
$user = $request->user();
|
|
$user = $request->user();
|
|
|
$rootPath = app()->getRootPath();
|
|
$rootPath = app()->getRootPath();
|
|
|
|
|
+ $qiniu_path = 'user_share_qrcode';
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
$resRoutine = true;//小程序
|
|
$resRoutine = true;//小程序
|
|
|
$resWap = true;//公众号
|
|
$resWap = true;//公众号
|
|
|
$siteUrl = sys_config('site_url');
|
|
$siteUrl = sys_config('site_url');
|
|
|
$routineSpreadBanner = sys_data('routine_spread_banner');
|
|
$routineSpreadBanner = sys_data('routine_spread_banner');
|
|
|
- if (!count($routineSpreadBanner)) return app('json')->fail('暂无海报');
|
|
|
|
|
|
|
+ if (!count($routineSpreadBanner)) {
|
|
|
|
|
+ return app('json')->fail('暂无海报');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if ($type == 1) {
|
|
if ($type == 1) {
|
|
|
- //小程序
|
|
|
|
|
|
|
+ // 直接获取用户海报
|
|
|
|
|
+ foreach ($routineSpreadBanner as &$item) {
|
|
|
|
|
+ $item['namep'] = $user['uid'] . '_' . $user['is_promoter'] . '_' . $item['id'] . '_user_routine_poster.jpg';
|
|
|
|
|
+ }
|
|
|
|
|
+ $posters = SystemAttachment::whereIn('name', array_column($routineSpreadBanner, 'namep'))->field('name, att_dir')->select()->toArray();
|
|
|
|
|
+ if (count($posters)) {
|
|
|
|
|
+ foreach ($routineSpreadBanner as $key => &$item) {
|
|
|
|
|
+ foreach ($posters as $poster) {
|
|
|
|
|
+ if ($item['namep'] == $poster['name']) {
|
|
|
|
|
+ $item['poster'] = $poster['att_dir'];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ unset($item['namep']);
|
|
|
|
|
+ if (!isset($item['poster'])) {
|
|
|
|
|
+ unset($routineSpreadBanner[$key]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $routineSpreadBanner = array_values($routineSpreadBanner);
|
|
|
|
|
+ if (count($routineSpreadBanner) > 0) {
|
|
|
|
|
+ return app('json')->successful($routineSpreadBanner);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //小程序个人分享二维码文件名
|
|
|
$name = $user['uid'] . '_' . $user['is_promoter'] . '_user_routine.jpg';
|
|
$name = $user['uid'] . '_' . $user['is_promoter'] . '_user_routine.jpg';
|
|
|
$imageInfo = SystemAttachment::getInfo($name, 'name');
|
|
$imageInfo = SystemAttachment::getInfo($name, 'name');
|
|
|
//检测远程文件是否存在
|
|
//检测远程文件是否存在
|
|
|
- if (isset($imageInfo['att_dir']) && strstr($imageInfo['att_dir'], 'http') !== false && curl_file_exist($imageInfo['att_dir']) === false) {
|
|
|
|
|
- $imageInfo = null;
|
|
|
|
|
- SystemAttachment::where(['name' => $name])->delete();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 20210722 注释掉,太卡
|
|
|
|
|
+ // if (isset($imageInfo['att_dir']) &&
|
|
|
|
|
+ // strstr($imageInfo['att_dir'], 'http') !== false &&
|
|
|
|
|
+ // curl_file_exist($imageInfo['att_dir']) === false) {
|
|
|
|
|
+ // $imageInfo = null;
|
|
|
|
|
+ // SystemAttachment::where(['name' => $name])->delete();
|
|
|
|
|
+ // }
|
|
|
if (!$imageInfo) {
|
|
if (!$imageInfo) {
|
|
|
$res = RoutineCode::getShareCode($user['uid'], 'spread', '', '');
|
|
$res = RoutineCode::getShareCode($user['uid'], 'spread', '', '');
|
|
|
if (!$res) return app('json')->fail('二维码生成失败');
|
|
if (!$res) return app('json')->fail('二维码生成失败');
|
|
@@ -180,27 +212,37 @@ class UserBillController
|
|
|
'storageName' => sys_config('storage_name'),
|
|
'storageName' => sys_config('storage_name'),
|
|
|
'storageRegion' => sys_config('storage_region'),
|
|
'storageRegion' => sys_config('storage_region'),
|
|
|
]);
|
|
]);
|
|
|
- $uploadRes = $upload->to('routine/spread/code')->validate()->stream($res['res'], $name);
|
|
|
|
|
|
|
+ // 上传分享二维码 [ qiniu 添加一个子路径]
|
|
|
|
|
+ $remoteName = $uploadType == 2 ? $qiniu_path. '/' . $name : $name;
|
|
|
|
|
+ $uploadRes = $upload->to('routine/spread/code')->validate()->stream($res['res'], $remoteName);
|
|
|
if ($uploadRes === false) {
|
|
if ($uploadRes === false) {
|
|
|
return app('json')->fail($upload->getError());
|
|
return app('json')->fail($upload->getError());
|
|
|
}
|
|
}
|
|
|
$upload->delete($name);
|
|
$upload->delete($name);
|
|
|
$imageInfo = $upload->getUploadInfo();
|
|
$imageInfo = $upload->getUploadInfo();
|
|
|
$imageInfo['image_type'] = $uploadType;
|
|
$imageInfo['image_type'] = $uploadType;
|
|
|
- SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
|
|
|
|
|
|
|
+ SystemAttachment::attachmentAdd(basename($imageInfo['name']), $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
|
|
|
RoutineQrcode::setRoutineQrcodeFind($res['id'], ['status' => 1, 'url_time' => time(), 'qrcode_url' => $imageInfo['dir']]);
|
|
RoutineQrcode::setRoutineQrcodeFind($res['id'], ['status' => 1, 'url_time' => time(), 'qrcode_url' => $imageInfo['dir']]);
|
|
|
$urlCode = $imageInfo['dir'];
|
|
$urlCode = $imageInfo['dir'];
|
|
|
- } else $urlCode = $imageInfo['att_dir'];
|
|
|
|
|
- if ($imageInfo['image_type'] == 1) $urlCode = $siteUrl . $urlCode;
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $urlCode = $imageInfo['att_dir'];
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($imageInfo['image_type'] == 1) {
|
|
|
|
|
+ $urlCode = $siteUrl . $urlCode;
|
|
|
|
|
+ }
|
|
|
$siteUrlHttps = set_http_type($siteUrl, $request->isSsl() ? 0 : 1);
|
|
$siteUrlHttps = set_http_type($siteUrl, $request->isSsl() ? 0 : 1);
|
|
|
$filelink = [
|
|
$filelink = [
|
|
|
'Bold' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf',
|
|
'Bold' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf',
|
|
|
'Normal' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf',
|
|
'Normal' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf',
|
|
|
];
|
|
];
|
|
|
- if (!file_exists($filelink['Bold'])) return app('json')->fail('缺少字体文件Bold');
|
|
|
|
|
- if (!file_exists($filelink['Normal'])) return app('json')->fail('缺少字体文件Normal');
|
|
|
|
|
|
|
+ if (!file_exists($filelink['Bold'])) {
|
|
|
|
|
+ return app('json')->fail('缺少字体文件Bold');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!file_exists($filelink['Normal'])) {
|
|
|
|
|
+ return app('json')->fail('缺少字体文件Normal');
|
|
|
|
|
+ }
|
|
|
foreach ($routineSpreadBanner as $key => &$item) {
|
|
foreach ($routineSpreadBanner as $key => &$item) {
|
|
|
- $posterInfo = '海报生成失败:(';
|
|
|
|
|
|
|
+ $posterInfo = '海报生成失败';
|
|
|
$config = array(
|
|
$config = array(
|
|
|
'image' => array(
|
|
'image' => array(
|
|
|
array(
|
|
array(
|
|
@@ -235,11 +277,14 @@ class UserBillController
|
|
|
'angle' => 0,
|
|
'angle' => 0,
|
|
|
)
|
|
)
|
|
|
),
|
|
),
|
|
|
- 'background' => $item['pic']
|
|
|
|
|
|
|
+ 'background' => $item['pic'],
|
|
|
|
|
+ 'name' => $qiniu_path. '/' . $user['uid'] . '_' . $user['is_promoter'] . '_' . $item['id'] . '_user_routine_poster.jpg',
|
|
|
);
|
|
);
|
|
|
$resRoutine = $resRoutine && $posterInfo = UtilService::setSharePoster($config, 'routine/spread/poster');
|
|
$resRoutine = $resRoutine && $posterInfo = UtilService::setSharePoster($config, 'routine/spread/poster');
|
|
|
- if (!is_array($posterInfo)) return app('json')->fail($posterInfo);
|
|
|
|
|
- SystemAttachment::attachmentAdd($posterInfo['name'], $posterInfo['size'], $posterInfo['type'], $posterInfo['dir'], $posterInfo['thumb_path'], 1, $posterInfo['image_type'], $posterInfo['time'], 2);
|
|
|
|
|
|
|
+ if (!is_array($posterInfo)) {
|
|
|
|
|
+ return app('json')->fail($posterInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ SystemAttachment::attachmentAdd(basename($posterInfo['name']), $posterInfo['size'], $posterInfo['type'], $posterInfo['dir'], $posterInfo['thumb_path'], 1, $posterInfo['image_type'], $posterInfo['time'], 2);
|
|
|
if ($resRoutine) {
|
|
if ($resRoutine) {
|
|
|
if ($posterInfo['image_type'] == 1)
|
|
if ($posterInfo['image_type'] == 1)
|
|
|
$item['poster'] = $siteUrlHttps . $posterInfo['dir'];
|
|
$item['poster'] = $siteUrlHttps . $posterInfo['dir'];
|
|
@@ -324,6 +369,7 @@ class UserBillController
|
|
|
if ($resRoutine && $resWap) return app('json')->successful($routineSpreadBanner);
|
|
if ($resRoutine && $resWap) return app('json')->successful($routineSpreadBanner);
|
|
|
else return app('json')->fail('生成图片失败');
|
|
else return app('json')->fail('生成图片失败');
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
|
|
+ Log::error('生成图片时,系统错误:' . $e->getMessage());
|
|
|
return app('json')->fail('生成图片时,系统错误', ['line' => $e->getLine(), 'message' => $e->getMessage(), 'file' => $e->getFile()]);
|
|
return app('json')->fail('生成图片时,系统错误', ['line' => $e->getLine(), 'message' => $e->getMessage(), 'file' => $e->getFile()]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|