会员购买小程序码
parent
7e62970561
commit
dddef607d3
|
|
@ -9,14 +9,45 @@ use Dcat\Admin\Form;
|
|||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Show;
|
||||
use EasyWeChat\Factory;
|
||||
use EasyWeChat\Kernel\Http\StreamResponse;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class VipController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
* 维信小程序码
|
||||
*/
|
||||
public function mpQrcode()
|
||||
{
|
||||
$disk = Storage::disk('public');
|
||||
|
||||
$directory = '';
|
||||
$filename = 'buy_vip_qrcode.png';
|
||||
$filepath = ($directory ? "{$directory}/" : '').$filename;
|
||||
|
||||
if (! $disk->exists($filepath)) {
|
||||
$scene = http_build_query(['vip' => 1]);
|
||||
|
||||
$app = Factory::miniProgram(config('wechat.mini_program.default'));
|
||||
|
||||
$response = $app->app_code->getUnlimit($scene, [
|
||||
'page' => 'pages/welcome/index',
|
||||
'check_path' => false,
|
||||
'env_version' => app()->isProduction() ? 'release' : 'trial',
|
||||
'width' => 200,
|
||||
]);
|
||||
|
||||
if (! $response instanceof StreamResponse) {
|
||||
throw new BizException('小程序码获取失败');
|
||||
}
|
||||
|
||||
$response->saveAs($disk->path($directory), $filename);
|
||||
}
|
||||
|
||||
return $disk->download($filepath);
|
||||
}
|
||||
|
||||
protected function grid()
|
||||
{
|
||||
return Grid::make(new Vip(), function (Grid $grid) {
|
||||
|
|
@ -30,6 +61,13 @@ class VipController extends AdminController
|
|||
$grid->column('sort')->editable();
|
||||
$grid->column('status')->switch();
|
||||
|
||||
$grid->tools(function (Grid\Tools $tools) {
|
||||
// x
|
||||
if (Admin::user()->can('dcat.admin.vip.mp_qrcode')) {
|
||||
$tools->append('<a class="btn btn-primary btn-outline" href="'.route('dcat.admin.vip.mp_qrcode').'" target="_blank"><i class="feather grid-action-icon icon-download"></i> 下载小程序码</a>');
|
||||
}
|
||||
});
|
||||
|
||||
$grid->disableViewButton(false);
|
||||
//新增
|
||||
$grid->showCreateButton(Admin::user()->can('dcat.admin.vip.create'));
|
||||
|
|
|
|||
|
|
@ -206,6 +206,7 @@ Route::group([
|
|||
|
||||
$router->resource('user-vip', 'UserVipController')->only(['index', 'show'])->names('user_vip');
|
||||
$router->resource('vip', 'VipController')->names('vip');
|
||||
$router->get('vip-mp-qrcode', 'VipController@mpQrcode')->name('vip.mp_qrcode');
|
||||
|
||||
// wang-editor update
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue