diff --git a/application/plugins/petscms/Service.php b/application/plugins/petscms/Service.php
index 21ebc3951..6c5853d47 100644
--- a/application/plugins/petscms/Service.php
+++ b/application/plugins/petscms/Service.php
@@ -13,6 +13,7 @@ namespace app\plugins\petscms;
use think\Db;
use app\service\ResourcesService;
use app\service\RegionService;
+use app\service\PluginsService;
/**
* 宠物管理系统 - 服务层
@@ -111,8 +112,8 @@ class Service
$v['lose_features'] = str_replace("\n", '
', $v['lose_features']);
// 二维码
- $v['qrcode_url'] = MyUrl('index/qrcode/index', ['content'=>urlencode(base64_encode(PluginsHomeUrl('petscms', 'pets', 'detail', ['id'=>$v['id']])))]);
- $v['qrcode_download'] = MyUrl('index/qrcode/download', ['url'=>urlencode(base64_encode($v['qrcode_url']))]);
+ $v['qrcode_url'] = empty($v['qrcode_images']) ? MyUrl('index/qrcode/index', ['content'=>urlencode(base64_encode(PluginsHomeUrl('petscms', 'pets', 'detail', ['id'=>$v['id']])))]) : ResourcesService::AttachmentPathViewHandle($v['qrcode_images']);
+ $v['qrcode_download'] = MyUrl('index/qrcode/download', ['url'=>urlencode(base64_encode($v['qrcode_url'])), 'filename'=>$v['pest_no']]);
// 地址
$v['province_name'] = RegionService::RegionName($v['lose_province']);
@@ -126,7 +127,6 @@ class Service
$v['upd_time_date'] = empty($v['upd_time']) ? '' : date('Y-m-d', $v['upd_time']);
}
}
- //print_r($data);
return DataReturn('处理成功', 0, $data);
}
@@ -406,8 +406,12 @@ class Service
{
$data['pest_no'] = date('YmdHis').GetNumberCode(6);
$data['add_time'] = time();
- if(Db::name('PluginsPetscmsPets')->insertGetId($data) > 0)
+ $pets_id = Db::name('PluginsPetscmsPets')->insertGetId($data);
+ if($pets_id > 0)
{
+ // 生成二维码
+ self::PetsQrcodeCreate($pets_id);
+
return DataReturn('添加成功', 0);
}
return DataReturn('添加失败', -100);
@@ -421,6 +425,37 @@ class Service
}
}
+ /**
+ * 宠物二维码生成
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2019-04-19
+ * @desc description
+ * @param [type] $pets_id [description]
+ */
+ private static function PetsQrcodeCreate($pets_id)
+ {
+ if(!empty($pets_id))
+ {
+ $base = PluginsService::PluginsData('petscms', ['logo']);
+ $params = [
+ 'path' => DS.'static'.DS.'upload'.DS.'images'.DS.'plugins_petscms'.DS.'qrcode'.DS.date('Y').DS.date('m').DS.date('d').DS,
+ 'content' => PluginsHomeUrl('petscms', 'pets', 'detail', ['id'=>$pets_id]),
+ 'logo' => empty($base['data']['logo']) ? '' : $base['data']['logo'],
+ ];
+ $ret = (new \base\Qrcode())->Create($params);
+ if($ret['code'] == 0)
+ {
+ if(!Db::name('PluginsPetscmsPets')->where(['id'=>$pets_id])->update(['qrcode_images'=>$ret['data']['path'].$ret['data']['filename'], 'upd_time'=>time()]))
+ {
+ return DataReturn('二维码生成失败', -10);
+ }
+ }
+ }
+ return DataReturn('二维码生成成功', 0);
+ }
+
/**
* 获取宠物相册
* @author Devil
diff --git a/application/plugins/petscms/install.sql b/application/plugins/petscms/install.sql
index da57f5dcc..f69e00393 100644
--- a/application/plugins/petscms/install.sql
+++ b/application/plugins/petscms/install.sql
@@ -4,6 +4,7 @@ CREATE TABLE `s_plugins_petscms_pets` (
`user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用户id',
`pest_no` char(60) NOT NULL DEFAULT '' COMMENT '宠物编号',
`status` tinyint(2) unsigned NOT NULL DEFAULT '0' COMMENT '状态(0正常, 1丢失, 2去世, 3关闭)',
+ `qrcode_images` char(255) NOT NULL DEFAULT '' COMMENT '宠物二维码',
`title` char(60) NOT NULL DEFAULT '' COMMENT '标题',
`name` char(30) NOT NULL DEFAULT '' COMMENT '名字',
`birthday` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '出生日期',
@@ -36,7 +37,6 @@ CREATE TABLE `s_plugins_petscms_pets` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='宠物管理系统宠物 - 应用'
-
# 宠物管理系统宠物丢失帮助数据
CREATE TABLE `s_plugins_petscms_help` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id',
diff --git a/application/plugins/view/petscms/pets/detail.html b/application/plugins/view/petscms/pets/detail.html
index 55a902eb9..f9021a673 100644
--- a/application/plugins/view/petscms/pets/detail.html
+++ b/application/plugins/view/petscms/pets/detail.html
@@ -215,34 +215,36 @@
{{/if}}
{{else /}}
+ {{/if}}
- {{if !empty($plugins_base_data['alipay_qrcode_images']) or !empty($plugins_base_data['weixin_qrcode_images'])}}
-
- {{/if}}
+ {{if !empty($plugins_base_data['alipay_qrcode_images']) or !empty($plugins_base_data['weixin_qrcode_images'])}}
+
{{/if}}
diff --git a/extend/base/FileUpload.php b/extend/base/FileUpload.php
index 0b2630d6c..d091f7b74 100755
--- a/extend/base/FileUpload.php
+++ b/extend/base/FileUpload.php
@@ -34,8 +34,8 @@ class FileUpload
*/
public function __construct($params = [])
{
- $this->config['root_path'] = isset($params['root_path']) ? $params['root_path'] : ROOT_PATH;
- $this->config['path'] = isset($params['path']) ? $params['path'] : DS.'Public'.DS.'Upload'.DS.'file'.DS.date('Y').DS.date('m').DS.date('d').DS;
+ $this->config['root_path'] = isset($params['root_path']) ? $params['root_path'] : ROOT.'public';
+ $this->config['path'] = isset($params['path']) ? $params['path'] : DS.'static'.DS.'upload'.DS.'file'.DS.date('Y').DS.date('m').DS.date('d').DS;
}
/**
diff --git a/extend/base/Qrcode.php b/extend/base/Qrcode.php
index 0ef1481e8..d34de3060 100644
--- a/extend/base/Qrcode.php
+++ b/extend/base/Qrcode.php
@@ -19,6 +19,9 @@ namespace base;
*/
class Qrcode
{
+ // 配置
+ private $config;
+
/**
* 构造方法
* @author Devil
@@ -29,6 +32,10 @@ class Qrcode
public function __construct()
{
require_once ROOT.'extend'.DS.'qrcode'.DS.'phpqrcode.php';
+
+ // 默认配置
+ $this->config['root_path'] = isset($params['root_path']) ? $params['root_path'] : ROOT.'public';
+ $this->config['path'] = isset($params['path']) ? $params['path'] : DS.'static'.DS.'upload'.DS.'images'.DS.'qrcode'.DS.date('Y').DS.date('m').DS.date('d').DS;
}
/**
@@ -45,7 +52,7 @@ class Qrcode
$level = isset($params['level']) && in_array($params['level'], array('L','M','Q','H')) ? $params['level'] : 'L';
// 大小,最小1,最大10
- $point_size = isset($params['size']) ? min(max(intval($params['size']), 1), 10) : 6;
+ $point_size = isset($params['size']) ? min(max(intval($params['size']), 1), 30) : 6;
// 外边距
$mr = isset($params['mr']) ? intval($params['mr']) : 1;
@@ -57,6 +64,98 @@ class Qrcode
\QRcode::png($content, false, $level, $point_size, $mr);
}
+ /**
+ * 二维码创建
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2019-04-19
+ * @desc description
+ * @param [array] $params [输入参数]
+ */
+ public function Create($params = [])
+ {
+ // 数据参数
+ if(empty($params['content']))
+ {
+ return DataReturn('内容不能为空', -1);
+ }
+
+ // 自定义路径
+ if(!empty($params['root_path']))
+ {
+ $this->config['root_path'] = $params['root_path'];
+ }
+ if(!empty($params['path']))
+ {
+ $this->config['path'] = $params['path'];
+ }
+
+ // 存储目录校验
+ $dir = str_replace(['//', '\\\\'], ['/', '\\'], $this->config['root_path'].$this->config['path']);
+ $ret = $this->IsMkdir($dir);
+ if($ret['code'] != 0)
+ {
+ return $ret;
+ }
+
+ // 文件名称
+ $filename = empty($params['filename']) ? $this->RandNewFilename().'.png' : $params['filename'];
+
+ // 容错率
+ $level = isset($params['level']) && in_array($params['level'], array('L','M','Q','H')) ? $params['level'] : 'L';
+
+ // 大小,最小1,最大10
+ $point_size = isset($params['size']) ? min(max(intval($params['size']), 1), 30) : 10;
+
+ // 外边距
+ $mr = isset($params['mr']) ? intval($params['mr']) : 2;
+
+ // 生成二维码
+ \QRcode::png($params['content'], $dir.$filename, $level, $point_size, $mr);
+ if(!file_exists($dir.$filename))
+ {
+ return DataReturn('二维码创建失败', -100);
+ }
+
+ //判断是否生成带logo的二维码
+ if(!empty($params['logo']))
+ {
+ $logo = @file_get_contents($params['logo']);
+ if($logo !== false)
+ {
+ $qr = imagecreatefromstring(file_get_contents($dir.$filename)); //目标图象连接资源
+ $logo = imagecreatefromstring($logo); //源图象连接资源
+
+ $qr_width = imagesx($qr);
+ $qr_height = imagesy($qr);
+ $logo_width = imagesx($logo);
+ $logo_height = imagesy($logo);
+ $logo_qr_width = $qr_width / 5; //组合之后logo的宽度(占二维码的1/5)
+ $scale = $logo_width/$logo_qr_width; //logo的宽度缩放比(本身宽度/组合后的宽度)
+ $logo_qr_height = $logo_height/$scale; //组合之后logo的高度
+ $from_width = ($qr_width - $logo_qr_width) / 2; //组合之后logo左上角所在坐标点
+
+ //重新组合图片并调整大小
+ imagecopyresampled($qr, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height);
+
+ //输出图片
+ imagepng($qr, $dir.$filename);
+ imagedestroy($qr);
+ imagedestroy($logo);
+ }
+ }
+
+ $result = [
+ 'dir' => $dir.$filename,
+ 'root' => $this->config['root_path'],
+ 'path' => $this->config['path'],
+ 'filename' => $filename,
+ ];
+ return DataReturn('创建成功', 0, $result);
+
+ }
+
/**
* 二维码下载
* @author Devil
@@ -71,7 +170,7 @@ class Qrcode
$url = base64_decode(urldecode($params['url']));
// 随机文件名
- $filename = time().GetNumberCode().'.png';
+ $filename = empty($params['filename']) ? date('YmdHis').GetNumberCode().'.png' : $params['filename'].'.png';
// 设置头信息
header('Pragma: public');
@@ -84,5 +183,76 @@ class Qrcode
header('Connection: close');
readfile($url);
}
+
+ /**
+ * 生成新的文件名称
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-06-29
+ * @desc description
+ * @return [string] [文件名称]
+ */
+ private function RandNewFilename()
+ {
+ return date('YmdHis').rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
+ }
+
+ /**
+ * 路径不存在则创建
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-06-29
+ * @desc description
+ * @param [string] $dir [文件路径]
+ */
+ private function IsMkdir($dir)
+ {
+ if(!is_dir($dir))
+ {
+ // 目录是否有权限
+ $ret = $this->IsWritable($dir);
+ if($ret['code'] != 0)
+ {
+ return $ret;
+ }
+
+ // 创建目录
+ if(mkdir($dir, 0777, true) === false)
+ {
+ return DataReturn('目录创建失败', -1);
+ }
+ }
+ return DataReturn('操作成功', 0);
+ }
+
+ /**
+ * 目录是否有权限
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2019-04-19
+ * @desc description
+ * @param [string] $dir [文件路径]
+ */
+ private function IsWritable($dir)
+ {
+ $dirs = str_replace($this->config['root_path'], '', $dir);
+ $dll = explode(DS, $dirs);
+ if(!empty($dll) && is_array($dll))
+ {
+ $dstr = '';
+ foreach($dll as $d)
+ {
+ $dstr .= empty($d) ? '' : DS.$d;
+ if(is_dir($this->config['root_path'].$dstr) && !is_writable($this->config['root_path'].$dstr))
+ {
+ return DataReturn('目录没有权限['.$dstr.']', -1);
+ }
+ }
+ }
+ return DataReturn('有权限', 0);
+ }
}
?>
\ No newline at end of file
diff --git a/public/static/common/css/common.css b/public/static/common/css/common.css
index 958755450..7c3047362 100755
--- a/public/static/common/css/common.css
+++ b/public/static/common/css/common.css
@@ -35,8 +35,8 @@ form.am-form .am-form-group-label-tips-must { color: #f00; }
.am-tagsinput input[type="text"]:hover { box-shadow: 0 0 0 #fff !important; border: 0 !important; }
.chosen-choices li.search-field input[type="text"]:focus,
.am-tagsinput input[type="text"]:focus { border-color: #fff; -webkit-box-shadow: inset 0 0 0 0 !important; box-shadow: inset 0 0 0 0 !important; }
-.chosen-choices { padding: 0px 3px !important; min-height: 32px; }
-.chosen-container-single .chosen-single { height: 32px; line-height: 32px; }
+.chosen-choices { padding: 0px 3px !important; min-height: 28px; }
+.chosen-container-single .chosen-single { height: 28px; line-height: 28px; }
.chosen-container-multi .chosen-choices li.search-field { padding-left: 3px; }
.chosen-container-single .chosen-single { color: #444 !important; }
.chosen-container-single .chosen-default { color: #999 !important; }
diff --git a/public/static/plugins/css/petscms/pets.detail.css b/public/static/plugins/css/petscms/pets.detail.css
index 266928391..9509ed1c2 100644
--- a/public/static/plugins/css/petscms/pets.detail.css
+++ b/public/static/plugins/css/petscms/pets.detail.css
@@ -74,29 +74,37 @@
.pets-not-bind .am-btn {
margin-top: 10px;
}
-.pets-not-bind ul.qrcode {
- overflow: hidden;
+
+/**
+ * 相关二维码
+ */
+.pets-qrcode-related {
margin-top: 30px;
+}
+.pets-qrcode-related ul {
+ margin: 0 auto;
+ max-width: 600px;
+ overflow: hidden;
border: 1px solid;
border-top: 5px solid;
- border-color: #eee;
+ border-color: #1aa9f3;
}
-.pets-not-bind ul.qrcode li {
+.pets-qrcode-related li {
width: 50%;
float: left;
text-align: center;
padding: 20px;
}
-.pets-not-bind ul.qrcode li:first-child {
+.pets-qrcode-related li:first-child {
border-right: 1px solid #eee;
}
-.pets-not-bind ul.qrcode li:last-child {
+.pets-qrcode-related li:last-child {
border-left: 1px solid #fff;
}
-.pets-not-bind ul.qrcode li img {
+.pets-qrcode-related li img {
max-width: 150px;
}
-.pets-not-bind ul.qrcode li p {
+.pets-qrcode-related li p {
font-size: 14px;
font-weight: 500;
color: #666;
@@ -237,7 +245,7 @@ form.form-validation #map {
}
}
@media only screen and (max-width: 641px) {
- .base, .lose, .content {
+ .base, .lose, .content, .pets-qrcode-related {
padding: 0 5px;
}
.base h1 {
diff --git a/public/static/upload/images/plugins_petscms/2019/04/09/1554814711403578.jpg b/public/static/upload/images/plugins_petscms/2019/04/09/1554814711403578.jpg
old mode 100644
new mode 100755