生成邀请小程序码
parent
cccf1d5fff
commit
cf99ebc801
|
|
@ -3,3 +3,11 @@
|
||||||
## Require
|
## Require
|
||||||
|
|
||||||
- php >= 8.0
|
- php >= 8.0
|
||||||
|
|
||||||
|
|
||||||
|
## Step
|
||||||
|
|
||||||
|
- `composer install`
|
||||||
|
- `cp .env.example .env`, 并修改配置文件
|
||||||
|
- `php artisan migrate --seed`
|
||||||
|
- `php artisan storage:link`
|
||||||
|
|
@ -3,9 +3,12 @@
|
||||||
namespace App\Endpoint\Api\Http\Controllers;
|
namespace App\Endpoint\Api\Http\Controllers;
|
||||||
|
|
||||||
use App\Endpoint\Api\Http\Resources\ShareBgResource;
|
use App\Endpoint\Api\Http\Resources\ShareBgResource;
|
||||||
use App\Models\ShareBg;
|
use App\Models\{ShareBg, User};
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use App\Exceptions\BizException;
|
||||||
|
use EasyWeChat\Kernel\Http\StreamResponse;
|
||||||
|
|
||||||
class ShareBgController extends Controller
|
class ShareBgController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -22,9 +25,45 @@ class ShareBgController extends Controller
|
||||||
|
|
||||||
public function userQrCode(Request $request)
|
public function userQrCode(Request $request)
|
||||||
{
|
{
|
||||||
$inviteUri = app_settings('app.invite_uri').'/register?code=';
|
$user = $request->user();
|
||||||
|
$qr_code = $user->userInfo->invite_qrcode;
|
||||||
|
|
||||||
|
if (!$qr_code || $request->input('force')) {
|
||||||
|
$disk = Storage::disk('public');
|
||||||
|
$app = $this->getWechatApp();
|
||||||
|
$scene = http_build_query([
|
||||||
|
'invite_code' => $user->userInfo->code,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $app->app_code->get($scene, [
|
||||||
|
'page' => 'pages/welcome/index',
|
||||||
|
'check_path' => false,
|
||||||
|
// develop: 开发版, trial: 体验版
|
||||||
|
'env_version' => app()->isProduction() ? 'release' : $request->input('env_version', 'trial'),
|
||||||
|
'width' => $request->input('width', 200),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($response instanceof StreamResponse) {
|
||||||
|
$filepath = 'invite-qrocde';
|
||||||
|
$filename = $user->id . '.png';
|
||||||
|
$response->saveAs($disk->path($filepath), $filename);
|
||||||
|
|
||||||
|
$qr_code = $disk->url($filepath . '/' . $filename);
|
||||||
|
$user->userInfo->update([
|
||||||
|
'invite_qrcode' => $qr_code
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
throw new BizException('生成失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'qr_code' => base64_encode(QrCode::format('png')->size(100)->margin(0)->generate($inviteUri.$request->user()->userInfo?->code)),
|
'qr_code' => $qr_code,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getWechatApp($getway = 'default')
|
||||||
|
{
|
||||||
|
return \EasyWeChat\Factory::miniProgram(config('wechat.mini_program.' . $getway));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ class UserInfo extends Model
|
||||||
'path',
|
'path',
|
||||||
'growth_value',
|
'growth_value',
|
||||||
'real_inviter_id',
|
'real_inviter_id',
|
||||||
'is_company'
|
'is_company',
|
||||||
|
'invite_qrcode',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ class AddRoleToUserInfos extends Migration
|
||||||
Schema::table('user_infos', function (Blueprint $table) {
|
Schema::table('user_infos', function (Blueprint $table) {
|
||||||
$table->decimal('profit', 12, 2)->default(0)->comment('累计收益');
|
$table->decimal('profit', 12, 2)->default(0)->comment('累计收益');
|
||||||
$table->tinyInteger('is_company')->default(0)->comment('是否员工');
|
$table->tinyInteger('is_company')->default(0)->comment('是否员工');
|
||||||
|
$table->string('invite_qrcode')->nullable()->comment('小程序邀请码');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue