wang hou sheng 10 months ago
parent 0f192f937c
commit 10d4323674
  1. 4
      app/api/controller/User.php
  2. 12
      app/common/service/qrcode/InviteUser.php

@ -318,8 +318,8 @@ class User extends Controller
$userInfo = UserService::getCurrentLoginUser(true);
$type = intval($this->request->post('type'), 1);
// 生成二维码
$Qrcode = new InviteUser($userInfo, 'MP-WEIXIN');
return $this->renderSuccess(['imageUrl' => $Qrcode->getImage($type)]);
$Qrcode = new InviteUser($userInfo, 'MP-WEIXIN', $type);
return $this->renderSuccess(['imageUrl' => $Qrcode->getImage()]);
}
/**

@ -19,15 +19,18 @@ class InviteUser extends BaseQRcode
// 用户信息
private UserModel $userInfo;
private int $type = 1;
/**
* 构造方法
* Goods constructor.
* @param UserModel $userInfo
* @param string $channel 二维码渠道(小程序码、h5码)
*/
public function __construct(UserModel $userInfo, string $channel = 'H5')
public function __construct(UserModel $userInfo, string $channel = 'H5', int $type = 1)
{
parent::__construct();
$this->type = $type;
// 用户信息
$this->userInfo = $userInfo;
// 当前客户端
@ -36,14 +39,13 @@ class InviteUser extends BaseQRcode
/**
* 拼接海报图
* @param int $type
* @return string
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getImage(int $type): string
public function getImage(): string
{
// 判断海报图文件存在则直接返回url
if (file_exists($this->getPosterPath())) {
@ -53,7 +55,7 @@ class InviteUser extends BaseQRcode
$storeId = $this->userInfo['store_id'];
$backdrop = __DIR__ . '/resource/invite_user.png';
// 商品海报背景图
if ($type != 1) {
if ($this->type != 1) {
$backdrop = __DIR__ . '/resource/invite_shop.png';
}
// 小程序码参数
@ -107,7 +109,7 @@ class InviteUser extends BaseQRcode
*/
private function getPosterName(): string
{
return 'invite_' . md5("{$this->userInfo['user_id']}_$this->channel") . '.png';
return 'invite_' . md5("{$this->userInfo['user_id']}_$this->channel_$this->type") . '.png';
}
/**

Loading…
Cancel
Save