diff --git a/app/api/controller/User.php b/app/api/controller/User.php index 0992b253..a4c871de 100644 --- a/app/api/controller/User.php +++ b/app/api/controller/User.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()]); } /** diff --git a/app/common/service/qrcode/InviteUser.php b/app/common/service/qrcode/InviteUser.php index cc41008d..99ec92ff 100644 --- a/app/common/service/qrcode/InviteUser.php +++ b/app/common/service/qrcode/InviteUser.php @@ -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'; } /**