From a3b5b0e0ce46c601460a516a86dd862c0ad07ce3 Mon Sep 17 00:00:00 2001 From: evoxwht <442384644@qq.com> Date: Mon, 8 May 2023 16:18:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0diy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/app/services/diy/DiyServices.php | 35 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/crmeb/app/services/diy/DiyServices.php b/crmeb/app/services/diy/DiyServices.php index c48dda153..4b7f27262 100644 --- a/crmeb/app/services/diy/DiyServices.php +++ b/crmeb/app/services/diy/DiyServices.php @@ -138,21 +138,30 @@ class DiyServices extends BaseServices /** * @param int $id - * @return mixed|string|null - * @author 等风来 - * @email 136327134@qq.com - * @date 2023/2/8 + * @return array|mixed|\think\Model|null + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 吴汐 + * @email 442384644@qq.com + * @date 2023/05/08 */ public function getDiyVersion(int $id) { if ($id) { - return $this->cacheDriver()->remember('index_diy_' . $id, function () use ($id) { - return $this->dao->getOne(['id' => $id], 'version,is_diy'); - }); + $cacheKey = 'index_diy_' . $id; + $where = ['id' => $id]; } else { - return $this->cacheDriver()->remember('index_diy_default', function () { - return $this->dao->getOne(['status' => 1, 'is_del' => 0], 'version,is_diy'); - }); + $cacheKey = 'index_diy_default'; + $where = ['status' => 1, 'is_del' => 0]; + } + $data = $this->cacheDriver()->remember($cacheKey, function () use ($where) { + return $this->dao->getOne($where, 'version,is_diy'); + }); + if (isset($data['version']) && isset($data['is_diy'])) { + return $data; + } else { + return $this->dao->getOne($where, 'version,is_diy'); } } @@ -422,6 +431,9 @@ class DiyServices extends BaseServices * 取单个diy小程序预览二维码 * @param int $id * @return string + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException */ public function getRoutineCode(int $id) { @@ -431,7 +443,6 @@ class DiyServices extends BaseServices } /** @var QrcodeServices $QrcodeService */ $QrcodeService = app()->make(QrcodeServices::class); - $image = $QrcodeService->getRoutineQrcodePath($id, 0, 6, [], false); - return $image; + return $QrcodeService->getRoutineQrcodePath($id, 0, 6, [], false); } }