wanghousheng 9 months ago
parent 3048b9a993
commit d77af2917a
  1. 42
      app/api/controller/User.php
  2. 2
      app/common/library/wechat/Qrcode.php
  3. 118
      app/common/service/qrcode/InviteUser.php
  4. BIN
      app/common/service/qrcode/resource/invite_user.png

@ -12,20 +12,21 @@ declare (strict_types=1);
namespace app\api\controller;
use app\api\model\Agreement as AgreementModel;
use app\api\model\User as UserModel;
use app\api\model\user\BalanceLog;
use app\api\model\user\GoodSource as GoodsSourceModel;
use app\api\model\user\InvoiceOrder;
use app\api\model\user\UserInvoice;
use app\api\model\user\UserCoupon;
use app\api\model\user\UserInvoice;
use app\api\model\UserCoupon as UserCouponModel;
use app\api\model\Agreement as AgreementModel;
use app\api\service\Feedback;
use app\api\service\User as UserService;
use app\common\enum\dealer\withdraw\PayType;
use app\common\model\Agreement;
use app\common\service\qrcode\InviteUser;
use cores\exception\BaseException;
use think\facade\Log;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
/**
@ -40,10 +41,12 @@ class User extends Controller
* [delete description]
* @return [type] [description]
*/
public function delete(){
public function delete()
{
$user_id = UserService::getCurrentLoginUserId();
UserModel::where('user_id', $user_id)->update(['is_delete' => 1,'update_time' => time()]);
UserModel::where('user_id', $user_id)->update(['is_delete' => 1, 'update_time' => time()]);
}
/**
* 当前用户详情
* @return Json
@ -226,7 +229,7 @@ class User extends Controller
public function delInvoicing(): Json
{
$service = new UserInvoice();
if(!$service->del($this->request->param())) {
if (!$service->del($this->request->param())) {
return $this->renderSuccess($service->getError() ?: '操作失败');
}
return $this->renderSuccess('删除成功·');
@ -272,7 +275,8 @@ class User extends Controller
/**
* 个人中心协议
*/
public function getAgreement(): Json {
public function getAgreement(): Json
{
$params = $this->request->param();
if (empty($params['type'])) {
return $this->renderSuccess("参数错误");
@ -284,7 +288,8 @@ class User extends Controller
/**
* 添加用户浏览记录
*/
public function addView(): Json {
public function addView(): Json
{
$goods_id = $this->request->param('goods_id');
$user_id = UserService::getCurrentLoginUserId();
$userView = new UserCoupon();
@ -294,4 +299,21 @@ class User extends Controller
return $this->renderSuccess($userView->getError() ?: '记录失败');
}
/**
* @notes:邀请好友海报
* @return Json
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function InviteUserPoster(): Json
{
$userInfo = UserService::getCurrentLoginUser(true);
// 生成二维码
$Qrcode = new InviteUser($userInfo, 'MP-WEIXIN');
return $this->renderSuccess(['imageUrl' => $Qrcode->getImage()]);
}
}

@ -38,6 +38,8 @@ class Qrcode extends WxBase
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={$accessToken}";
// 构建请求
$data = compact('scene', 'width');
// $data['env_version'] = 'trial';
// $data['check_path'] = false;
!is_null($page) && $data['page'] = $page;
// 返回结果
$result = $this->post($url, helper::jsonEncode($data));

@ -0,0 +1,118 @@
<?php
namespace app\common\service\qrcode;
use app\common\model\User as UserModel;
use cores\exception\BaseException;
use Exception;
use Grafika\Grafika;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use function base_url;
class InviteUser extends BaseQRcode
{
// 当前客户端 (默认H5)
private string $channel;
// 用户信息
private UserModel $userInfo;
/**
* 构造方法
* Goods constructor.
* @param UserModel $userInfo
* @param string $channel 二维码渠道(小程序码、h5码)
*/
public function __construct(UserModel $userInfo, string $channel = 'H5')
{
parent::__construct();
// 用户信息
$this->userInfo = $userInfo;
// 当前客户端
$this->channel = $channel;
}
/**
* 拼接海报图
* @return string
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws Exception
*/
public function getImage(): string
{
// 判断海报图文件存在则直接返回url
if (file_exists($this->getPosterPath())) {
return $this->getPosterUrl();
}
// 商城ID
$storeId = $this->userInfo['store_id'];
// 商品海报背景图
$backdrop = __DIR__ . '/resource/invite_user.png';
// 小程序码参数
$scene = "refereeId:" . ($this->userInfo['user_id'] ?: '');
// 下载小程序码
$page = 'pages/login/index';
$qrcode = $this->getQrcode($storeId, $scene, null, $this->channel);
// 拼接海报图
return $this->savePoster($backdrop, $qrcode);
}
/**
* 拼接海报图
* @param string $backdrop 背景图路径
* @param string $qrcode 二维码图路径
* @return string
* @throws Exception
*/
private function savePoster(string $backdrop, string $qrcode): string
{
// 实例化图像编辑器
$editor = Grafika::createEditor(['Gd']);
// 打开海报背景图
$editor->open($backdropImage, $backdrop);
// 打开小程序码
$editor->open($qrcodeImage, $qrcode);
// 重设小程序码宽高
$editor->resizeExact($qrcodeImage, 140, 140);
// 小程序码添加到背景图
$editor->blend($backdropImage, $qrcodeImage, 'normal', 1.0, 'top-left', 520, 700);
// 保存图片
$editor->save($backdropImage, $this->getPosterPath());
return $this->getPosterUrl();
}
/**
* 海报图文件路径
* @return string
*/
private function getPosterPath(): string
{
// 保存路径
$tempPath = web_path() . "temp/{$this->userInfo['store_id']}/";
!is_dir($tempPath) && mkdir($tempPath, 0755, true);
return $tempPath . $this->getPosterName();
}
/**
* 海报图文件名称
* @return string
*/
private function getPosterName(): string
{
return 'invite_' . md5("{$this->userInfo['user_id']}_$this->channel") . '.png';
}
/**
* 海报图url
* @return string
*/
private function getPosterUrl(): string
{
return base_url() . 'temp/' . $this->userInfo['store_id'] . '/' . $this->getPosterName() . '?t=' . time();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 KiB

Loading…
Cancel
Save