From 58c27d36cdcef1e3f22ccd4f62559d6bfb8e18f5 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 21 Jan 2024 15:41:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/StoreOrderCreateRepository.php | 2 +- app/controller/api/Common.php | 32 +++++++++++++++++++ app/controller/api/user/User.php | 9 ++++++ route/api.php | 2 ++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index ca3546fb..cb0418b6 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -1004,7 +1004,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository if ($order['consumption_money'] > 0) { $consumptionDetails[] = [ 'user_id' => $uid, - 'order_id' => $order['order_id'], + 'order_id' => $_order->order_id, 'group_order_id' => $groupOrder->group_order_id, 'coupon_user_id' => $order['consumption_id'], 'type' => 1, diff --git a/app/controller/api/Common.php b/app/controller/api/Common.php index 84cac40e..ba2ce62d 100644 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -57,6 +57,8 @@ use AlibabaCloud\Tea\Utils\Utils; use Darabonba\OpenApi\Models\Config; use AlibabaCloud\SDK\Ocr\V20191230\Models\RecognizeBusinessLicenseRequest; use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions; +use app\common\repositories\system\attachment\AttachmentRepository; +use crmeb\services\QrcodeService; /** * Class Common @@ -634,4 +636,34 @@ class Common extends BaseController Cache::set('promote_' . app('request')->ip(), $code, 86400); return app('json')->success(); } + + + /** + * 生成二维码 + */ + public function Qrcode($data) + { + $siteUrl = systemConfig('site_url'); + $name = md5('orcode' . date('Ymd')) . '.jpg'; + $attachmentRepository = app()->make(AttachmentRepository::class); + $imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]); + + if (isset($imageInfo['attachment_src']) && strstr($imageInfo['attachment_src'], 'http') !== false && curl_file_exist($imageInfo['attachment_src']) === false) { + $imageInfo->delete(); + $imageInfo = null; + } + if (!$imageInfo) { + $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($data['code'], $name); + if (is_string($imageInfo)) throw new ValidateException('二维码生成失败'); + + $imageInfo['dir'] = tidy_url($imageInfo['dir'], null, $siteUrl); + $attachmentRepository->create(systemConfig('upload_type') ?: 1, -2, $data['id'], [ + 'attachment_category_id' => 0, + 'attachment_name' => $imageInfo['name'], + 'attachment_src' => $imageInfo['dir'] + ]); + $urlCode = $imageInfo['dir']; + } else $urlCode = $imageInfo['attachment_src']; + return $urlCode; + } } diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 609cce5f..b584233f 100644 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -30,6 +30,7 @@ use think\App; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use app\controller\api\Common; class User extends BaseController { @@ -535,4 +536,12 @@ class User extends BaseController return app('json')->success('修改成功'); } + /** + * 生成二维码 + */ + public function qrcode(){ + $common= app()->make(Common::class); + $data=$common->Qrcode(['code'=>'shop_'.$this->user->uid,'id'=>$this->user->uid]); + return app('json')->success(['url'=>$data]); + } } diff --git a/route/api.php b/route/api.php index 3c13de02..b01acffa 100644 --- a/route/api.php +++ b/route/api.php @@ -46,6 +46,8 @@ Route::group('api/', function () { Route::post('articleCatch', 'api.Upload/article'); //强制登录 Route::group(function () { + + Route::any('qrcode', 'api.user.User/qrcode'); Route::post('merchant_license_identify', 'api.Common/merchant_license_identify');//营业执照识别