| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\models\v1;
- use app\modules\client\models\ApiModel;
- use app\utils\GenerateShareQrcode;
- class QrcodeForm extends ApiModel
- {
- public $data;
- public $scene;
- public $width;
- public $page;
- public $store_id;
- public function getQrcode()
- {
- // 保存到本地
- $saveRoot = \Yii::$app->basePath . '/web/temp';
- $saveDir = '/';
- $saveName = md5($this->store_id . '_' . $this->scene . '_' . $this->page . '_' . $this->width) . '.jpg';
- $webRoot = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/web/temp/' . $saveName);
- if (file_exists($saveRoot . $saveDir . $saveName)) {
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'url' => $webRoot,
- ]
- ];
- }
- $res = GenerateShareQrcode::getQrcode($this->store_id, $this->scene, $this->width, $this->page);
- if ($res['code'] == 1) {
- return $res;
- }
- if (!is_dir($saveRoot . $saveDir)) {
- mkdir($saveRoot . $saveDir, 0777, true);
- file_put_contents($saveRoot . $saveDir . '.gitignore', "*\r\n!.gitignore");
- }
- file_put_contents($saveRoot . $saveDir . $saveName, file_get_contents($res['file_path']));
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'url' => $webRoot,
- ]
- ];
- }
- }
|