作者 Richer

功能优化

@@ -170,6 +170,6 @@ trait UserGrid @@ -170,6 +170,6 @@ trait UserGrid
170 $this->gridTextField('login_times')->sortable(); 170 $this->gridTextField('login_times')->sortable();
171 // $this->gridDateField('last_login_time'); 171 // $this->gridDateField('last_login_time');
172 $this->gridDateField('created_at', __('registered_at')); 172 $this->gridDateField('created_at', __('registered_at'));
173 -// $this->gridSingleImageField('invite_qr_code', '小程序码'); 173 + $this->gridSingleImageField('invite_qr_code', '推广二维码');
174 } 174 }
175 } 175 }
@@ -77,7 +77,7 @@ class ToolCommand extends Command @@ -77,7 +77,7 @@ class ToolCommand extends Command
77 })->chunkById(100, function ($users) { 77 })->chunkById(100, function ($users) {
78 $users->each(function ($user) { 78 $users->each(function ($user) {
79 // 生成用户小程序码 79 // 生成用户小程序码
80 - $this->generateUserMiniProgramCode($user); 80 + $this->generateUserQrCode($user);
81 }); 81 });
82 }); 82 });
83 } 83 }
@@ -62,7 +62,7 @@ class UserCreatedJob extends BaseJob @@ -62,7 +62,7 @@ class UserCreatedJob extends BaseJob
62 $this->log('尝试次数过多'); 62 $this->log('尝试次数过多');
63 } else { 63 } else {
64 // 生成用户小程序码 64 // 生成用户小程序码
65 - $this->generateUserMiniProgramCode($this->model); 65 + $this->generateUserQrCode($this->model);
66 // 创建用户的邀请记录 66 // 创建用户的邀请记录
67 $this->recordInviteRecord($this->model); 67 $this->recordInviteRecord($this->model);
68 // 创建用户钱包 68 // 创建用户钱包
@@ -17,31 +17,15 @@ @@ -17,31 +17,15 @@
17 namespace App\Models\Traits; 17 namespace App\Models\Traits;
18 18
19 use App\Factories\WechatFactory; 19 use App\Factories\WechatFactory;
20 -use App\Jobs\User\TimesRecordCreatedJob;  
21 -use App\Jobs\User\UserTimesUpdateJob;  
22 -use App\Models\Category\CategoryLabelItem;  
23 use App\Models\Category\CategoryLabelItemRemote; 20 use App\Models\Category\CategoryLabelItemRemote;
24 use App\Models\Category\CategoryLabelRemote; 21 use App\Models\Category\CategoryLabelRemote;
25 use App\Models\Category\CategoryRemote; 22 use App\Models\Category\CategoryRemote;
26 -use App\Models\Chat\ChatRecordItem;  
27 use App\Models\Chat\ChatRecordItemRemote; 23 use App\Models\Chat\ChatRecordItemRemote;
28 use App\Models\Chat\ChatRecordRemote; 24 use App\Models\Chat\ChatRecordRemote;
29 -use App\Models\System\SystemSetting;  
30 -use App\Models\User\TimesRecord;  
31 use App\Models\User\TimesRecordRemote; 25 use App\Models\User\TimesRecordRemote;
32 -use App\Models\User\User;  
33 use App\Models\User\UserRemote; 26 use App\Models\User\UserRemote;
34 -use App\Util\OpenAI\src\OpenAi;  
35 -use GuzzleHttp\Client;  
36 -use GuzzleHttp\Exception\GuzzleException;  
37 -use Illuminate\Http\Response;  
38 -use Illuminate\Support\Arr;  
39 -use Illuminate\Support\Facades\Cache;  
40 -use Illuminate\Support\Facades\Log;  
41 -use Illuminate\Support\Str;  
42 -use Tectalic\OpenAi\Authentication;  
43 -use Tectalic\OpenAi\ClientException;  
44 -use Tectalic\OpenAi\Manager; 27 +use Illuminate\Support\Facades\Storage;
  28 +use SimpleSoftwareIO\QrCode\Facades\QrCode;
45 29
46 /** 30 /**
47 * Trait SyncTrait 31 * Trait SyncTrait
@@ -61,11 +45,15 @@ trait SyncTrait @@ -61,11 +45,15 @@ trait SyncTrait
61 'user_id' => $model->user_id, 45 'user_id' => $model->user_id,
62 'category_id' => $model->category_id, 46 'category_id' => $model->category_id,
63 'label_id' => $model->label_id, 47 'label_id' => $model->label_id,
  48 + 'type' => $model->type,
  49 + 'consume_times' => $model->consume_times,
  50 + 'context' => $model->context,
64 'labels' => my_json_encode($model->labels), 51 'labels' => my_json_encode($model->labels),
65 'start_statement' => $model->start_statement, 52 'start_statement' => $model->start_statement,
66 'question' => $model->question, 53 'question' => $model->question,
67 'ai_model' => $model->ai_model, 54 'ai_model' => $model->ai_model,
68 'status' => $model->status, 55 'status' => $model->status,
  56 + 'synchronized' => 1,
69 'created_at' => $model->created_at, 57 'created_at' => $model->created_at,
70 'updated_at' => $model->updated_at, 58 'updated_at' => $model->updated_at,
71 ]); 59 ]);
@@ -140,6 +128,8 @@ trait SyncTrait @@ -140,6 +128,8 @@ trait SyncTrait
140 if (!UserRemote::find($model->id)) { 128 if (!UserRemote::find($model->id)) {
141 UserRemote::create([ 129 UserRemote::create([
142 'id' => $model->id, 130 'id' => $model->id,
  131 + 'pid' => $model->pid,
  132 + 'gid' => $model->gid,
143 'name' => $model->name, 133 'name' => $model->name,
144 'password' => $model->password, 134 'password' => $model->password,
145 'mobile' => $model->mobile, 135 'mobile' => $model->mobile,
@@ -165,6 +155,8 @@ trait SyncTrait @@ -165,6 +155,8 @@ trait SyncTrait
165 if(!UserRemote::find($model->id)) { 155 if(!UserRemote::find($model->id)) {
166 UserRemote::create([ 156 UserRemote::create([
167 'id' => $model->id, 157 'id' => $model->id,
  158 + 'pid' => $model->pid,
  159 + 'gid' => $model->gid,
168 'name' => $model->name, 160 'name' => $model->name,
169 'username' => $model->username, 161 'username' => $model->username,
170 'password' => $model->password, 162 'password' => $model->password,
@@ -180,8 +172,8 @@ trait SyncTrait @@ -180,8 +172,8 @@ trait SyncTrait
180 'login_times' => $model->login_times, 172 'login_times' => $model->login_times,
181 'created_at' => $model->created_at, 173 'created_at' => $model->created_at,
182 ]); 174 ]);
183 - $model->synchronized = 1;  
184 - $model->save(); 175 +// $model->synchronized = 1;
  176 +// $model->save();
185 } 177 }
186 break; 178 break;
187 } 179 }
@@ -356,18 +348,84 @@ trait SyncTrait @@ -356,18 +348,84 @@ trait SyncTrait
356 } 348 }
357 349
358 /** 350 /**
359 - * 创建用户的邀请二维码 351 + * 本地生成文件
360 * 352 *
361 - * @param $user 353 + * @param $model
  354 + * @return string
362 */ 355 */
363 - public function generateUserMiniProgramCode($user) 356 + public function generateUserQrCode($user)
364 { 357 {
365 - $factory = app(WechatFactory::class);  
366 - $result = $factory->generateMiniProgramCode($user->id);  
367 - if ($result) {  
368 - $user->invite_qr_code = $result; 358 + // 设置上传路径和文件名
  359 + $dir = config('filesystems.disks.qr_code.root');
  360 + $id = $user->id;
  361 +// $logo = splice_file_path(optional($model->enterprise)->logo);
  362 +// if (!$logo) {
  363 +// $logo = config('app.url') .'/assets/admin/img/logo.png';
  364 +// }
  365 + // add by Richer 于2022年6月10日14:02:26使用系统的logo
  366 + dump($dir);
  367 + // 生成二维码
  368 + if (!is_dir($dir)) {
  369 + mkdir(iconv("UTF-8", "GBK", $dir), 0777, true);
  370 + }
  371 + $filename = $id .'.png';
  372 + $filepath = $dir . '/' . $filename;
  373 +
  374 + dump($filepath);
  375 + $url = config('app.url') . '?inviter_id='.$user->id;
  376 +
  377 +// if (!file_exists($filepath)) {
  378 + // 生成二维码
  379 + QrCode::format('png')
  380 + ->backgroundColor(255, 255, 255) // 设置背景色
  381 + ->size(200) // 设置尺寸
  382 + ->margin(1) // 边距设置
  383 +// ->eyeColor(0, 0, 0, 0, 255, 215, 0)
  384 +// ->eyeColor(1, 0, 0, 0, 255, 215, 0)
  385 +// ->eyeColor(2, 0, 0, 0, 255, 215, 0)
  386 +// ->eyeColor(1, 0, 0, 0, 205, 127, 50)
  387 +// ->eyeColor(1, 0, 0, 0, 166, 124, 64)
  388 + ->errorCorrection('H') // 容错级别设置:
  389 + ->generate($url, $filepath);
  390 +// }
  391 + // 返回二维码图片路径
  392 + $img_src = config('filesystems.disks.qr_code.url') . '/'. $filename;
  393 + dump($img_src);
  394 +
  395 + // 创建一张空的画布,像素3628x1757,背景白色
  396 +// $img = Image::canvas(300, 300, '#fff');
  397 +// // 获取本地图片,可以获取input上传文件
  398 +// $leftImage = Image::make('https://www.baidu.com/img/flexible/logo/pc/result.png')->resize(30, 30);
  399 +// $rightImage = Image::make($img_src)->resize(220, 220);
  400 +// // 插入到画布,left-top是距离左侧和顶部,值对应的是后面 100 100 处
  401 +// $img->insert($leftImage, 'left-top', 0, 0);
  402 +// $img->insert($rightImage, 'center');
  403 +// //可以直接返回图像,也可通过$img->save()进行保存图片
  404 + $user->invite_qr_code = ltrim($img_src);
369 $user->save(); 405 $user->save();
  406 +
  407 + return $img_src;
370 } 408 }
  409 +
  410 + /**
  411 + * 创建用户的邀请二维码
  412 + *
  413 + * @param $user
  414 + */
  415 + public function generateUserQrCode1($user)
  416 + {
  417 + $url = config('app.url') . '?inviter_id='.$user->id;
  418 +
  419 + QrCode::generate($url, '../public/q/qrcode.svg');
  420 +
  421 + $user_id = $user->id;
  422 +
  423 +
  424 +
  425 + $filename = $user_id . '.png'; // 文件名
  426 + Storage::disk('qr_code')->put($filename, $url); // 存储到本地
  427 +
  428 + return $url = Storage::disk('qr_code')->url($filename); // 获取 URL;
371 } 429 }
372 430
373 /** 431 /**
@@ -102,10 +102,10 @@ return [ @@ -102,10 +102,10 @@ return [
102 'root' => storage_path('app/public/chunk_file'), 102 'root' => storage_path('app/public/chunk_file'),
103 ], 103 ],
104 // 用户小程序码 104 // 用户小程序码
105 - 'mini_program_code' => [ 105 + 'qr_code' => [
106 'driver' => 'local', 106 'driver' => 'local',
107 - 'root' => storage_path('app/public/mini_program_code'),  
108 - 'url' => env('APP_URL') . '/storage/mini_program_code', 107 + 'root' => storage_path('app/public/qr_code'),
  108 + 'url' => env('APP_URL') . '/storage/qr_code',
109 'visibility' => 'public', 109 'visibility' => 'public',
110 ], 110 ],
111 ], 111 ],
1 <!DOCTYPE html><html lang=zh-CN><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><title>chatApp</title><script>var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)')) 1 <!DOCTYPE html><html lang=zh-CN><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><title>chatApp</title><script>var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
2 - document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')</script><link rel=stylesheet href=./static/index.b0707a6a.css></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id=app></div><script src=./static/js/chunk-vendors.fc0b6f42.js></script><script src=./static/js/index.293a48ba.js></script></body></html> 2 + document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')</script><link rel=stylesheet href=./static/index.63b34199.css></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id=app></div><script src=./static/js/chunk-vendors.87f773bf.js></script><script src=./static/js/index.c244513e.js></script></body></html>