...
|
...
|
@@ -17,31 +17,15 @@ |
|
|
namespace App\Models\Traits;
|
|
|
|
|
|
use App\Factories\WechatFactory;
|
|
|
use App\Jobs\User\TimesRecordCreatedJob;
|
|
|
use App\Jobs\User\UserTimesUpdateJob;
|
|
|
use App\Models\Category\CategoryLabelItem;
|
|
|
use App\Models\Category\CategoryLabelItemRemote;
|
|
|
use App\Models\Category\CategoryLabelRemote;
|
|
|
use App\Models\Category\CategoryRemote;
|
|
|
use App\Models\Chat\ChatRecordItem;
|
|
|
use App\Models\Chat\ChatRecordItemRemote;
|
|
|
use App\Models\Chat\ChatRecordRemote;
|
|
|
use App\Models\System\SystemSetting;
|
|
|
use App\Models\User\TimesRecord;
|
|
|
use App\Models\User\TimesRecordRemote;
|
|
|
use App\Models\User\User;
|
|
|
use App\Models\User\UserRemote;
|
|
|
use App\Util\OpenAI\src\OpenAi;
|
|
|
use GuzzleHttp\Client;
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
use Illuminate\Http\Response;
|
|
|
use Illuminate\Support\Arr;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Str;
|
|
|
use Tectalic\OpenAi\Authentication;
|
|
|
use Tectalic\OpenAi\ClientException;
|
|
|
use Tectalic\OpenAi\Manager;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
|
|
|
|
|
/**
|
|
|
* Trait SyncTrait
|
...
|
...
|
@@ -61,11 +45,15 @@ trait SyncTrait |
|
|
'user_id' => $model->user_id,
|
|
|
'category_id' => $model->category_id,
|
|
|
'label_id' => $model->label_id,
|
|
|
'type' => $model->type,
|
|
|
'consume_times' => $model->consume_times,
|
|
|
'context' => $model->context,
|
|
|
'labels' => my_json_encode($model->labels),
|
|
|
'start_statement' => $model->start_statement,
|
|
|
'question' => $model->question,
|
|
|
'ai_model' => $model->ai_model,
|
|
|
'status' => $model->status,
|
|
|
'synchronized' => 1,
|
|
|
'created_at' => $model->created_at,
|
|
|
'updated_at' => $model->updated_at,
|
|
|
]);
|
...
|
...
|
@@ -140,6 +128,8 @@ trait SyncTrait |
|
|
if (!UserRemote::find($model->id)) {
|
|
|
UserRemote::create([
|
|
|
'id' => $model->id,
|
|
|
'pid' => $model->pid,
|
|
|
'gid' => $model->gid,
|
|
|
'name' => $model->name,
|
|
|
'password' => $model->password,
|
|
|
'mobile' => $model->mobile,
|
...
|
...
|
@@ -165,6 +155,8 @@ trait SyncTrait |
|
|
if(!UserRemote::find($model->id)) {
|
|
|
UserRemote::create([
|
|
|
'id' => $model->id,
|
|
|
'pid' => $model->pid,
|
|
|
'gid' => $model->gid,
|
|
|
'name' => $model->name,
|
|
|
'username' => $model->username,
|
|
|
'password' => $model->password,
|
...
|
...
|
@@ -180,8 +172,8 @@ trait SyncTrait |
|
|
'login_times' => $model->login_times,
|
|
|
'created_at' => $model->created_at,
|
|
|
]);
|
|
|
$model->synchronized = 1;
|
|
|
$model->save();
|
|
|
// $model->synchronized = 1;
|
|
|
// $model->save();
|
|
|
}
|
|
|
break;
|
|
|
}
|
...
|
...
|
@@ -356,18 +348,84 @@ trait SyncTrait |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 本地生成文件
|
|
|
*
|
|
|
* @param $model
|
|
|
* @return string
|
|
|
*/
|
|
|
public function generateUserQrCode($user)
|
|
|
{
|
|
|
// 设置上传路径和文件名
|
|
|
$dir = config('filesystems.disks.qr_code.root');
|
|
|
$id = $user->id;
|
|
|
// $logo = splice_file_path(optional($model->enterprise)->logo);
|
|
|
// if (!$logo) {
|
|
|
// $logo = config('app.url') .'/assets/admin/img/logo.png';
|
|
|
// }
|
|
|
// add by Richer 于2022年6月10日14:02:26使用系统的logo
|
|
|
dump($dir);
|
|
|
// 生成二维码
|
|
|
if (!is_dir($dir)) {
|
|
|
mkdir(iconv("UTF-8", "GBK", $dir), 0777, true);
|
|
|
}
|
|
|
$filename = $id .'.png';
|
|
|
$filepath = $dir . '/' . $filename;
|
|
|
|
|
|
dump($filepath);
|
|
|
$url = config('app.url') . '?inviter_id='.$user->id;
|
|
|
|
|
|
// if (!file_exists($filepath)) {
|
|
|
// 生成二维码
|
|
|
QrCode::format('png')
|
|
|
->backgroundColor(255, 255, 255) // 设置背景色
|
|
|
->size(200) // 设置尺寸
|
|
|
->margin(1) // 边距设置
|
|
|
// ->eyeColor(0, 0, 0, 0, 255, 215, 0)
|
|
|
// ->eyeColor(1, 0, 0, 0, 255, 215, 0)
|
|
|
// ->eyeColor(2, 0, 0, 0, 255, 215, 0)
|
|
|
// ->eyeColor(1, 0, 0, 0, 205, 127, 50)
|
|
|
// ->eyeColor(1, 0, 0, 0, 166, 124, 64)
|
|
|
->errorCorrection('H') // 容错级别设置:
|
|
|
->generate($url, $filepath);
|
|
|
// }
|
|
|
// 返回二维码图片路径
|
|
|
$img_src = config('filesystems.disks.qr_code.url') . '/'. $filename;
|
|
|
dump($img_src);
|
|
|
|
|
|
// 创建一张空的画布,像素3628x1757,背景白色
|
|
|
// $img = Image::canvas(300, 300, '#fff');
|
|
|
// // 获取本地图片,可以获取input上传文件
|
|
|
// $leftImage = Image::make('https://www.baidu.com/img/flexible/logo/pc/result.png')->resize(30, 30);
|
|
|
// $rightImage = Image::make($img_src)->resize(220, 220);
|
|
|
// // 插入到画布,left-top是距离左侧和顶部,值对应的是后面 100 100 处
|
|
|
// $img->insert($leftImage, 'left-top', 0, 0);
|
|
|
// $img->insert($rightImage, 'center');
|
|
|
// //可以直接返回图像,也可通过$img->save()进行保存图片
|
|
|
$user->invite_qr_code = ltrim($img_src);
|
|
|
$user->save();
|
|
|
|
|
|
return $img_src;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建用户的邀请二维码
|
|
|
*
|
|
|
* @param $user
|
|
|
*/
|
|
|
public function generateUserMiniProgramCode($user)
|
|
|
public function generateUserQrCode1($user)
|
|
|
{
|
|
|
$factory = app(WechatFactory::class);
|
|
|
$result = $factory->generateMiniProgramCode($user->id);
|
|
|
if ($result) {
|
|
|
$user->invite_qr_code = $result;
|
|
|
$user->save();
|
|
|
}
|
|
|
$url = config('app.url') . '?inviter_id='.$user->id;
|
|
|
|
|
|
QrCode::generate($url, '../public/q/qrcode.svg');
|
|
|
|
|
|
$user_id = $user->id;
|
|
|
|
|
|
|
|
|
|
|
|
$filename = $user_id . '.png'; // 文件名
|
|
|
Storage::disk('qr_code')->put($filename, $url); // 存储到本地
|
|
|
|
|
|
return $url = Storage::disk('qr_code')->url($filename); // 获取 URL;
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
|