You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
<?php
|
|
|
|
namespace app\enterprise\model;
|
|
|
|
use app\BaseModel;
|
|
use app\common\controller\Upload;
|
|
|
|
class Posts extends BaseModel
|
|
{
|
|
|
|
// 创建朋友圈头像
|
|
public static function createAvatar($posts_id)
|
|
{
|
|
$PostsFile = PostsFile::where(['posts_id' => $posts_id])->field('file_id')->select();
|
|
if (count($PostsFile) > 1) {
|
|
$imgFileIdArr = array_column($PostsFile, 'file_id');
|
|
$imgFileArr = [];
|
|
foreach ($imgFileIdArr as $file_id) {
|
|
$src = File::where('file_id', '=', $file_id)->value('src');
|
|
if ($src) {
|
|
$imgFileArr[] = $src;
|
|
}
|
|
}
|
|
if (count($imgFileArr) > 1) {
|
|
self::createPostsAvatar($posts_id,$imgFileArr);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 生成朋友圈头像
|
|
public static function createPostsAvatar($posts_id, $imageFileArr)
|
|
{
|
|
$dirPath=app()->getRootPath().'public/temp';
|
|
$fileName = $posts_id . time();
|
|
$path=$dirPath.'/'.$fileName.'.jpg';
|
|
foreach ($imageFileArr as $key => $imageSrc) {
|
|
$imageFileArr[$key] = getDiskUrl() .'/'. ltrim($imageSrc,'/');
|
|
}
|
|
$avatar = getGroupAvatar($imageFileArr,1, $path);
|
|
$url='';
|
|
if($avatar){
|
|
$upload=new Upload();
|
|
$newPath=$upload->uploadLocalAvatar($path,[],$posts_id);
|
|
if($newPath){
|
|
self::where('id',$posts_id)->update(['avatar'=>$newPath]);
|
|
$url=avatarUrl($newPath);
|
|
}
|
|
}
|
|
return $url;
|
|
}
|
|
}
|